#include <stdio.h>
#include <cuda.h>
#include <time.h>

struct Startup{
    int seed = time(nullptr);    
    int threadsPerBlock = 256;
    int datasetSize = 10000;
	int range = 100;
} startup;

struct DataSet{
    float* values;
    int  size;
};


inline int sizeOfDataSet(DataSet data)
{ return sizeof(float)*data.size; }

DataSet generateRandomDataSet(int size){
    DataSet data;
    data.size = size;
    data.values = (float*)malloc(sizeof(float)*data.size);

    for (int i = 0; i < data.size; i++)
        data.values[i] = (float)(rand()%startup.range);

    return data;
}

bool CompareDataSet(DataSet d1, DataSet d2){

    for (int i = 0; i < d1.size; i++)
        if (d1.values[i] != d2.values[i]){
            printf("Dataset is different");
            return false;
        }
        if (d1.size != d2.size) {printf("Datasets are not equal size\n"); return false;};
    	printf("D1 and D2 are equal!");
    	return true;

}

__global__ void DeviceCalculateSM_Global(float* input, int input_size, float* result, int result_size, int sample_size){
    int id_x = blockDim.x * blockIdx.x + threadIdx.x;
	float sum = 0;
    if (id_x < result_size){

        
        for (int i = 0; i < sample_size; i++)
            sum = sum + input[id_x+i];
           sum = sum/sample_size;

        result[id_x] = sum;
    }
}

__global__ void DeviceCalculateSM_Shared(float* input, int input_size, float* result, int result_size, int sample_size){
    int id_x = blockDim.x * blockIdx.x + threadIdx.x;

    if (id_x < input_size){

        extern __shared__ float cache[];

        int cachedSize = sample_size + blockDim.x;

        for (int i = 0; i < cachedSize/blockDim.x+1; i++){
            int cacheId = threadIdx.x+ i*blockDim.x;
            if (cacheId < cachedSize && cacheId+blockDim.x *blockIdx.x < input_size)
                cache[cacheId] = input[cacheId+blockDim.x *blockIdx.x];
        }
        __syncthreads();

        float sum = 0;
        for (int i = 0; i < sample_size; i++){
            if(i + threadIdx.x < cachedSize && i + id_x < input_size)
                sum = sum + cache[i+threadIdx.x];
        }
        sum = sum/sample_size;

        /*store in global memory*/
        if (id_x < result_size)
            result[id_x] = sum;
    }

}

DataSet CalculateSM(DataSet input, int sample_size, bool usesharedmemory){
    if(sample_size == 1 && input.size < 1 && sample_size < 1 && sample_size > input.size) 
	 { 
	 	printf("Error! Invalid Sample Size"); 
	 	exit(-1); 
	 }
    
    int result_size = input.size-sample_size+1;
    DataSet host_result = {(float*)malloc(sizeof(float)*(result_size)), result_size};

    float* device_input, *device_result;


    int threads_needed = host_result.size;
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);    

    if (usesharedmemory){
        int shared_memory_allocation_size = sizeof(float)*(startup.threadsPerBlock+sample_size);
        cudaEventRecord(start);
        DeviceCalculateSM_Shared<<<threads_needed/ startup.threadsPerBlock + 1, startup.threadsPerBlock, shared_memory_allocation_size>>> (device_input, input.size, device_result, host_result.size, sample_size);
        cudaEventRecord(stop);

    }else{
        cudaEventRecord(start);
        DeviceCalculateSM_Global<<<threads_needed/ startup.threadsPerBlock + 1, startup.threadsPerBlock>>> (device_input, input.size, device_result, host_result.size, sample_size);
        cudaEventRecord(stop);
    }

    cudaEventSynchronize(stop);

    float milliseconds = 0;
    cudaEventElapsedTime(&milliseconds, start, stop);
    if (usesharedmemory) printf("Shared Memory: "); else printf("Global Memory: ");
    printf("Kernel executed in %f milliseconds\n", milliseconds);

    return host_result;
}

void printDataSet(DataSet data){
    for (int i = 0; i < data.size; i++)
        printf("%.6g, ", data.values[i]);
    printf("\n");
}


int main(int argc, char** argv){

    for (int i = 0; i < argc; i++){
        
        if (strcmp(argv[i],  "Range")==0 && i+1 < argc) startup.range = atoi(argv[i+1]);
        if (strcmp(argv[i],  "Seed")==0 && i+1 < argc) startup.seed = atoi(argv[i+1]);
        if (strcmp(argv[i],  "Block threads")==0 && i+1 < argc) startup.threadsPerBlock = atoi(argv[i+1]);
    }

    srand(startup.seed);

    DataSet data = generateRandomDataSet(100);
    printDataSet( data );
    DataSet shared = CalculateSM(data, 2, true);
    DataSet global = CalculateSM(data, 2, false);


    printDataSet( shared );
    printf("\n");
    printDataSet( global );
    printf("\n");


    printf("Each should be %d elements in size\n", global.size);
    CompareDataSet(global, shared);
}

	.file	"tmpxft_002fd5de_00000000-6_Moving_Avg_Filtering.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2038:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2038:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z21generateRandomDataSeti
	.type	_Z21generateRandomDataSeti, @function
_Z21generateRandomDataSeti:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movslq	%edi, %rdi
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %rbp
.L3:
	cmpl	%r12d, %ebx
	jle	.L7
	call	rand@PLT
	cltd
	idivl	12+startup(%rip)
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, 0(%rbp,%r12,4)
	incq	%r12
	jmp	.L3
.L7:
	movl	%ebx, %edx
	movq	%rbp, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z21generateRandomDataSeti, .-_Z21generateRandomDataSeti
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Dataset is different"
.LC1:
	.string	"Datasets are not equal size\n"
.LC2:
	.string	"D1 and D2 are equal!"
	.text
	.globl	_Z14CompareDataSet7DataSetS_
	.type	_Z14CompareDataSet7DataSetS_, @function
_Z14CompareDataSet7DataSetS_:
.LFB2032:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	pushq	%r8
	.cfi_def_cfa_offset 16
	movl	%esi, %r8d
.L9:
	cmpl	%eax, %r8d
	jle	.L19
	movss	(%rdi,%rax,4), %xmm0
	incq	%rax
	ucomiss	-4(%rdx,%rax,4), %xmm0
	jp	.L15
	je	.L9
.L15:
	leaq	.LC0(%rip), %rsi
	jmp	.L18
.L19:
	cmpl	%ecx, %esi
	je	.L13
	leaq	.LC1(%rip), %rsi
.L18:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	jmp	.L8
.L13:
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movb	$1, %al
.L8:
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z14CompareDataSet7DataSetS_, .-_Z14CompareDataSet7DataSetS_
	.section	.rodata.str1.1
.LC3:
	.string	"%.6g, "
.LC4:
	.string	"\n"
	.text
	.globl	_Z12printDataSet7DataSet
	.type	_Z12printDataSet7DataSet, @function
_Z12printDataSet7DataSet:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC3(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 48
.L21:
	cmpl	%ebx, %ebp
	jle	.L24
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%r12,%rbx,4), %xmm0
	call	__printf_chk@PLT
	incq	%rbx
	jmp	.L21
.L24:
	popq	%rdx
	.cfi_def_cfa_offset 40
	leaq	.LC4(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 32
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2034:
	.size	_Z12printDataSet7DataSet, .-_Z12printDataSet7DataSet
	.globl	_Z49__device_stub__Z24DeviceCalculateSM_GlobalPfiS_iiPfiS_ii
	.type	_Z49__device_stub__Z24DeviceCalculateSM_GlobalPfiS_iiPfiS_ii, @function
_Z49__device_stub__Z24DeviceCalculateSM_GlobalPfiS_iiPfiS_ii:
.LFB2060:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 16(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z24DeviceCalculateSM_GlobalPfiS_ii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L25:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2060:
	.size	_Z49__device_stub__Z24DeviceCalculateSM_GlobalPfiS_iiPfiS_ii, .-_Z49__device_stub__Z24DeviceCalculateSM_GlobalPfiS_iiPfiS_ii
	.globl	_Z24DeviceCalculateSM_GlobalPfiS_ii
	.type	_Z24DeviceCalculateSM_GlobalPfiS_ii, @function
_Z24DeviceCalculateSM_GlobalPfiS_ii:
.LFB2061:
	.cfi_startproc
	endbr64
	jmp	_Z49__device_stub__Z24DeviceCalculateSM_GlobalPfiS_iiPfiS_ii
	.cfi_endproc
.LFE2061:
	.size	_Z24DeviceCalculateSM_GlobalPfiS_ii, .-_Z24DeviceCalculateSM_GlobalPfiS_ii
	.globl	_Z49__device_stub__Z24DeviceCalculateSM_SharedPfiS_iiPfiS_ii
	.type	_Z49__device_stub__Z24DeviceCalculateSM_SharedPfiS_iiPfiS_ii, @function
_Z49__device_stub__Z24DeviceCalculateSM_SharedPfiS_iiPfiS_ii:
.LFB2062:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 16(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L30
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z24DeviceCalculateSM_SharedPfiS_ii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L30:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L32
	call	__stack_chk_fail@PLT
.L32:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2062:
	.size	_Z49__device_stub__Z24DeviceCalculateSM_SharedPfiS_iiPfiS_ii, .-_Z49__device_stub__Z24DeviceCalculateSM_SharedPfiS_iiPfiS_ii
	.globl	_Z24DeviceCalculateSM_SharedPfiS_ii
	.type	_Z24DeviceCalculateSM_SharedPfiS_ii, @function
_Z24DeviceCalculateSM_SharedPfiS_ii:
.LFB2063:
	.cfi_startproc
	endbr64
	jmp	_Z49__device_stub__Z24DeviceCalculateSM_SharedPfiS_iiPfiS_ii
	.cfi_endproc
.LFE2063:
	.size	_Z24DeviceCalculateSM_SharedPfiS_ii, .-_Z24DeviceCalculateSM_SharedPfiS_ii
	.section	.rodata.str1.1
.LC6:
	.string	"Shared Memory: "
.LC7:
	.string	"Global Memory: "
.LC8:
	.string	"Kernel executed in %f milliseconds\n"
	.text
	.globl	_Z11CalculateSM7DataSetib
	.type	_Z11CalculateSM7DataSetib, @function
_Z11CalculateSM7DataSetib:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%esi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%ecx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subl	%edx, %ebx
	incl	%ebx
	movslq	%ebx, %rdi
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rsp, %rdi
	movq	%rax, %r14
	call	cudaEventCreate@PLT
	leaq	8(%rsp), %rdi
	call	cudaEventCreate@PLT
	testb	%r12b, %r12b
	movq	(%rsp), %rdi
	je	.L36
	xorl	%esi, %esi
	movl	4+startup(%rip), %r15d
	call	cudaEventRecord@PLT
	movl	4+startup(%rip), %ecx
	movl	%ebx, %eax
	xorl	%r9d, %r9d
	movabsq	$4294967297, %rsi
	cltd
	addl	%ebp, %r15d
	idivl	%ecx
	movq	%rsi, 32(%rsp)
	movl	%ecx, 28(%rsp)
	movl	36(%rsp), %ecx
	movq	%rsi, 20(%rsp)
	movq	28(%rsp), %rdx
	movl	24(%rsp), %esi
	sall	$2, %r15d
	movslq	%r15d, %r8
	incl	%eax
	movl	%eax, 16(%rsp)
	movq	16(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	movl	%ebp, %r8d
	movl	%ebx, %ecx
	xorl	%edx, %edx
	movl	%r13d, %esi
	xorl	%edi, %edi
	call	_Z49__device_stub__Z24DeviceCalculateSM_SharedPfiS_iiPfiS_ii
	jmp	.L39
.L36:
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	4+startup(%rip), %ecx
	movl	%ebx, %eax
	xorl	%r9d, %r9d
	movabsq	$4294967297, %rsi
	cltd
	xorl	%r8d, %r8d
	idivl	%ecx
	movq	%rsi, 32(%rsp)
	movl	%ecx, 28(%rsp)
	movl	36(%rsp), %ecx
	movq	%rsi, 20(%rsp)
	movq	28(%rsp), %rdx
	movl	24(%rsp), %esi
	incl	%eax
	movl	%eax, 16(%rsp)
	movq	16(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	movl	%ebp, %r8d
	movl	%ebx, %ecx
	xorl	%edx, %edx
	movl	%r13d, %esi
	xorl	%edi, %edi
	call	_Z49__device_stub__Z24DeviceCalculateSM_GlobalPfiS_iiPfiS_ii
.L39:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	8(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	28(%rsp), %rdi
	movl	$0x00000000, 28(%rsp)
	call	cudaEventElapsedTime@PLT
	leaq	.LC6(%rip), %rsi
	testb	%r12b, %r12b
	jne	.L44
	leaq	.LC7(%rip), %rsi
.L44:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	28(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	%ebx, %edx
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L42
	call	__stack_chk_fail@PLT
.L42:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	movq	%r14, %rax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z11CalculateSM7DataSetib, .-_Z11CalculateSM7DataSetib
	.section	.rodata.str1.1
.LC9:
	.string	"Range"
.LC10:
	.string	"Seed"
.LC11:
	.string	"Block threads"
.LC12:
	.string	"Each should be %d elements in size\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC11(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC10(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	.LC9(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	$1, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L46:
	leal	-1(%r12), %eax
	cmpl	%ebx, %eax
	jge	.L52
	movq	-8(%rbp,%r12,8), %rax
	movq	%r13, %rsi
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L47
	cmpl	%r12d, %ebx
	jle	.L47
	movq	0(%rbp,%r12,8), %rdi
	call	atoi@PLT
	movl	%eax, 12+startup(%rip)
.L47:
	movq	8(%rsp), %rdi
	movq	%r14, %rsi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L48
	cmpl	%r12d, %ebx
	jle	.L48
	movq	0(%rbp,%r12,8), %rdi
	call	atoi@PLT
	movl	%eax, startup(%rip)
.L48:
	movq	8(%rsp), %rdi
	movq	%r15, %rsi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L49
	cmpl	%r12d, %ebx
	jle	.L49
	movq	0(%rbp,%r12,8), %rdi
	call	atoi@PLT
	movl	%eax, 4+startup(%rip)
.L49:
	incq	%r12
	jmp	.L46
.L52:
	movl	startup(%rip), %edi
	leaq	.LC4(%rip), %r14
	call	srand@PLT
	movl	$100, %edi
	call	_Z21generateRandomDataSeti
	movq	%rax, %rbp
	movq	%rdx, %rbx
	movq	%rax, %rdi
	movq	%rdx, %rsi
	call	_Z12printDataSet7DataSet
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	movl	$1, %ecx
	movl	$2, %edx
	call	_Z11CalculateSM7DataSetib
	xorl	%ecx, %ecx
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	movq	%rax, %r13
	movq	%rdx, %r12
	movl	$2, %edx
	call	_Z11CalculateSM7DataSetib
	movq	%r13, %rdi
	movq	%r12, %rsi
	movq	%rdx, %rbx
	movq	%rax, %rbp
	call	_Z12printDataSet7DataSet
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	call	_Z12printDataSet7DataSet
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %edx
	leaq	.LC12(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%r13, %rdx
	movq	%r12, %rcx
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	call	_Z14CompareDataSet7DataSetS_
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2035:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z24DeviceCalculateSM_SharedPfiS_ii"
.LC14:
	.string	"_Z24DeviceCalculateSM_GlobalPfiS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2065:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC13(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z24DeviceCalculateSM_SharedPfiS_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC14(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z24DeviceCalculateSM_GlobalPfiS_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2065:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text.startup
	.type	_GLOBAL__sub_I_startup, @function
_GLOBAL__sub_I_startup:
.LFB2182:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%edi, %edi
	call	time@PLT
	movl	$256, 4+startup(%rip)
	movl	%eax, startup(%rip)
	movabsq	$429496739600, %rax
	movq	%rax, 8+startup(%rip)
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2182:
	.size	_GLOBAL__sub_I_startup, .-_GLOBAL__sub_I_startup
	.section	.init_array
	.align 8
	.quad	_GLOBAL__sub_I_startup
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	startup
	.bss
	.align 16
	.type	startup, @object
	.size	startup, 16
startup:
	.zero	16
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <hip/hip_runtime.h>
#include <time.h>

struct Startup{
    int seed = time(nullptr);    
    int threadsPerBlock = 256;
    int datasetSize = 10000;
	int range = 100;
} startup;

struct DataSet{
    float* values;
    int  size;
};


inline int sizeOfDataSet(DataSet data)
{ return sizeof(float)*data.size; }

DataSet generateRandomDataSet(int size){
    DataSet data;
    data.size = size;
    data.values = (float*)malloc(sizeof(float)*data.size);

    for (int i = 0; i < data.size; i++)
        data.values[i] = (float)(rand()%startup.range);

    return data;
}

bool CompareDataSet(DataSet d1, DataSet d2){

    for (int i = 0; i < d1.size; i++)
        if (d1.values[i] != d2.values[i]){
            printf("Dataset is different");
            return false;
        }
        if (d1.size != d2.size) {printf("Datasets are not equal size\n"); return false;};
    	printf("D1 and D2 are equal!");
    	return true;

}

__global__ void DeviceCalculateSM_Global(float* input, int input_size, float* result, int result_size, int sample_size){
    int id_x = blockDim.x * blockIdx.x + threadIdx.x;
	float sum = 0;
    if (id_x < result_size){

        
        for (int i = 0; i < sample_size; i++)
            sum = sum + input[id_x+i];
           sum = sum/sample_size;

        result[id_x] = sum;
    }
}

__global__ void DeviceCalculateSM_Shared(float* input, int input_size, float* result, int result_size, int sample_size){
    int id_x = blockDim.x * blockIdx.x + threadIdx.x;

    if (id_x < input_size){

        extern __shared__ float cache[];

        int cachedSize = sample_size + blockDim.x;

        for (int i = 0; i < cachedSize/blockDim.x+1; i++){
            int cacheId = threadIdx.x+ i*blockDim.x;
            if (cacheId < cachedSize && cacheId+blockDim.x *blockIdx.x < input_size)
                cache[cacheId] = input[cacheId+blockDim.x *blockIdx.x];
        }
        __syncthreads();

        float sum = 0;
        for (int i = 0; i < sample_size; i++){
            if(i + threadIdx.x < cachedSize && i + id_x < input_size)
                sum = sum + cache[i+threadIdx.x];
        }
        sum = sum/sample_size;

        /*store in global memory*/
        if (id_x < result_size)
            result[id_x] = sum;
    }

}

DataSet CalculateSM(DataSet input, int sample_size, bool usesharedmemory){
    if(sample_size == 1 && input.size < 1 && sample_size < 1 && sample_size > input.size) 
	 { 
	 	printf("Error! Invalid Sample Size"); 
	 	exit(-1); 
	 }
    
    int result_size = input.size-sample_size+1;
    DataSet host_result = {(float*)malloc(sizeof(float)*(result_size)), result_size};

    float* device_input, *device_result;


    int threads_needed = host_result.size;
    hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);    

    if (usesharedmemory){
        int shared_memory_allocation_size = sizeof(float)*(startup.threadsPerBlock+sample_size);
        hipEventRecord(start);
        DeviceCalculateSM_Shared<<<threads_needed/ startup.threadsPerBlock + 1, startup.threadsPerBlock, shared_memory_allocation_size>>> (device_input, input.size, device_result, host_result.size, sample_size);
        hipEventRecord(stop);

    }else{
        hipEventRecord(start);
        DeviceCalculateSM_Global<<<threads_needed/ startup.threadsPerBlock + 1, startup.threadsPerBlock>>> (device_input, input.size, device_result, host_result.size, sample_size);
        hipEventRecord(stop);
    }

    hipEventSynchronize(stop);

    float milliseconds = 0;
    hipEventElapsedTime(&milliseconds, start, stop);
    if (usesharedmemory) printf("Shared Memory: "); else printf("Global Memory: ");
    printf("Kernel executed in %f milliseconds\n", milliseconds);

    return host_result;
}

void printDataSet(DataSet data){
    for (int i = 0; i < data.size; i++)
        printf("%.6g, ", data.values[i]);
    printf("\n");
}


int main(int argc, char** argv){

    for (int i = 0; i < argc; i++){
        
        if (strcmp(argv[i],  "Range")==0 && i+1 < argc) startup.range = atoi(argv[i+1]);
        if (strcmp(argv[i],  "Seed")==0 && i+1 < argc) startup.seed = atoi(argv[i+1]);
        if (strcmp(argv[i],  "Block threads")==0 && i+1 < argc) startup.threadsPerBlock = atoi(argv[i+1]);
    }

    srand(startup.seed);

    DataSet data = generateRandomDataSet(100);
    printDataSet( data );
    DataSet shared = CalculateSM(data, 2, true);
    DataSet global = CalculateSM(data, 2, false);


    printDataSet( shared );
    printf("\n");
    printDataSet( global );
    printf("\n");


    printf("Each should be %d elements in size\n", global.size);
    CompareDataSet(global, shared);
}

	.text
	.file	"Moving_Avg_Filtering.hip"
	.globl	_Z21generateRandomDataSeti      # -- Begin function _Z21generateRandomDataSeti
	.type	_Z21generateRandomDataSeti,@function
_Z21generateRandomDataSeti:             # @_Z21generateRandomDataSeti
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edi, %ebx
	movslq	%edi, %r15
	leaq	(,%r15,4), %rdi
	callq	malloc
	movq	%rax, %r14
	testl	%r15d, %r15d
	jle	.LBB0_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebx, %r15d
	xorl	%r12d, %r12d
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltd
	idivl	startup+12(%rip)
	xorps	%xmm0, %xmm0
	cvtsi2ss	%edx, %xmm0
	movss	%xmm0, (%r14,%r12,4)
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB0_2
.LBB0_3:                                # %._crit_edge
	movq	%r14, %rax
	movl	%ebx, %edx
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z21generateRandomDataSeti, .Lfunc_end0-_Z21generateRandomDataSeti
	.cfi_endproc
                                        # -- End function
	.globl	_Z14CompareDataSet7DataSetS_    # -- Begin function _Z14CompareDataSet7DataSetS_
	.type	_Z14CompareDataSet7DataSetS_,@function
_Z14CompareDataSet7DataSetS_:           # @_Z14CompareDataSet7DataSetS_
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	testl	%esi, %esi
	jle	.LBB1_5
# %bb.1:                                # %.lr.ph.preheader
	movl	%esi, %eax
	xorl	%r8d, %r8d
.LBB1_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%r8,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%rdx,%r8,4), %xmm0
	jne	.LBB1_4
	jp	.LBB1_4
# %bb.2:                                #   in Loop: Header=BB1_3 Depth=1
	incq	%r8
	cmpq	%r8, %rax
	jne	.LBB1_3
.LBB1_5:                                # %._crit_edge
	cmpl	%ecx, %esi
	jne	.LBB1_6
# %bb.7:
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	movb	$1, %bl
	jmp	.LBB1_8
.LBB1_6:
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%ebx, %ebx
	jmp	.LBB1_8
.LBB1_4:
	xorl	%ebx, %ebx
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
.LBB1_8:
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z14CompareDataSet7DataSetS_, .Lfunc_end1-_Z14CompareDataSet7DataSetS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii # -- Begin function _Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii
	.type	_Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii,@function
_Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii: # @_Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	12(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z24DeviceCalculateSM_GlobalPfiS_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii, .Lfunc_end2-_Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii # -- Begin function _Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii
	.type	_Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii,@function
_Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii: # @_Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	12(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z24DeviceCalculateSM_SharedPfiS_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii, .Lfunc_end3-_Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z11CalculateSM7DataSetib       # -- Begin function _Z11CalculateSM7DataSetib
	.type	_Z11CalculateSM7DataSetib,@function
_Z11CalculateSM7DataSetib:              # @_Z11CalculateSM7DataSetib
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %r12d
	movl	%edx, %ebp
	movl	%esi, %r15d
	movabsq	$4294967296, %r13               # imm = 0x100000000
	movl	%esi, %ebx
	subl	%edx, %ebx
	movslq	%ebx, %rax
	incl	%ebx
	leaq	4(,%rax,4), %rdi
	callq	malloc
	movq	%rax, %r14
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	testl	%r12d, %r12d
	je	.LBB4_3
# %bb.1:
	movl	startup+4(%rip), %r12d
	addl	%ebp, %r12d
	shll	$2, %r12d
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	startup+4(%rip), %ecx
	movl	%ebx, %eax
	cltd
	idivl	%ecx
                                        # kill: def $eax killed $eax def $rax
	leal	1(%rax), %edi
	movslq	%r12d, %r8
	orq	%r13, %rdi
	orq	%r13, %rcx
	movl	$1, %esi
	movq	%rcx, %rdx
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	movl	$.L.str.4, %r12d
	testl	%eax, %eax
	jne	.LBB4_5
# %bb.2:
	movl	%r15d, %esi
	movl	%ebx, %ecx
	movl	%ebp, %r8d
	callq	_Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii
	jmp	.LBB4_5
.LBB4_3:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	startup+4(%rip), %ecx
	movl	%ebx, %eax
	cltd
	idivl	%ecx
                                        # kill: def $eax killed $eax def $rax
	leal	1(%rax), %edi
	orq	%r13, %rdi
	orq	%r13, %rcx
	movl	$1, %esi
	movq	%rcx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	movl	$.L.str.5, %r12d
	testl	%eax, %eax
	jne	.LBB4_5
# %bb.4:
	movl	%r15d, %esi
	movl	%ebx, %ecx
	movl	%ebp, %r8d
	callq	_Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii
.LBB4_5:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	20(%rsp), %r15
	movl	$0, (%r15)
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movq	%r12, %rdi
	xorl	%eax, %eax
	callq	printf
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movq	%r14, %rax
	movl	%ebx, %edx
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z11CalculateSM7DataSetib, .Lfunc_end4-_Z11CalculateSM7DataSetib
	.cfi_endproc
                                        # -- End function
	.globl	_Z12printDataSet7DataSet        # -- Begin function _Z12printDataSet7DataSet
	.type	_Z12printDataSet7DataSet,@function
_Z12printDataSet7DataSet:               # @_Z12printDataSet7DataSet
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB5_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r15,4), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB5_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB5_4:                                # %._crit_edge
	movl	$10, %edi
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end5:
	.size	_Z12printDataSet7DataSet, .Lfunc_end5-_Z12printDataSet7DataSet
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	testl	%edi, %edi
	jle	.LBB6_12
# %bb.1:                                # %.lr.ph.preheader
	movq	%rsi, %rbx
	movl	%edi, %r15d
	movq	%r15, %r12
	negq	%r12
	movl	$1, %r13d
.LBB6_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	-8(%rbx,%r13,8), %r14
	movl	$.L.str.9, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB6_5
# %bb.3:                                #   in Loop: Header=BB6_2 Depth=1
	cmpq	%r15, %r13
	jae	.LBB6_5
# %bb.4:                                #   in Loop: Header=BB6_2 Depth=1
	movq	(%rbx,%r13,8), %rdi
	callq	atoi
	movl	%eax, startup+12(%rip)
.LBB6_5:                                #   in Loop: Header=BB6_2 Depth=1
	movl	$.L.str.10, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB6_8
# %bb.6:                                #   in Loop: Header=BB6_2 Depth=1
	cmpq	%r15, %r13
	jae	.LBB6_8
# %bb.7:                                #   in Loop: Header=BB6_2 Depth=1
	movq	(%rbx,%r13,8), %rdi
	callq	atoi
	movl	%eax, startup(%rip)
.LBB6_8:                                #   in Loop: Header=BB6_2 Depth=1
	movl	$.L.str.11, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.9:                                #   in Loop: Header=BB6_2 Depth=1
	cmpq	%r15, %r13
	jae	.LBB6_11
# %bb.10:                               #   in Loop: Header=BB6_2 Depth=1
	movq	(%rbx,%r13,8), %rdi
	callq	atoi
	movl	%eax, startup+4(%rip)
.LBB6_11:                               # %._crit_edge59
                                        #   in Loop: Header=BB6_2 Depth=1
	leaq	(%r12,%r13), %rax
	incq	%rax
	incq	%r13
	cmpq	$1, %rax
	jne	.LBB6_2
.LBB6_12:                               # %._crit_edge
	movl	startup(%rip), %edi
	callq	srand
	movl	$100, %edi
	callq	_Z21generateRandomDataSeti
	movl	%edx, %r14d
	movq	%rax, %rdi
	movl	%edx, %esi
	callq	_Z12printDataSet7DataSet
	movl	%r14d, %esi
	movl	$2, %edx
	movl	$1, %ecx
	callq	_Z11CalculateSM7DataSetib
	movq	%rax, %rbx
	movl	%edx, %ebp
	movl	%r14d, %esi
	movl	$2, %edx
	xorl	%ecx, %ecx
	callq	_Z11CalculateSM7DataSetib
	movq	%rax, %r14
	movl	%edx, %r15d
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	_Z12printDataSet7DataSet
	movl	$10, %edi
	callq	putchar@PLT
	movq	%r14, %rdi
	movl	%r15d, %esi
	callq	_Z12printDataSet7DataSet
	movl	$10, %edi
	callq	putchar@PLT
	movl	$.L.str.12, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	movq	%r14, %rdi
	movl	%r15d, %esi
	movq	%rbx, %rdx
	movl	%ebp, %ecx
	callq	_Z14CompareDataSet7DataSetS_
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	main, .Lfunc_end6-main
	.cfi_endproc
                                        # -- End function
	.section	.text.startup,"ax",@progbits
	.type	_GLOBAL__sub_I_Moving_Avg_Filtering.hip,@function # -- Begin function _GLOBAL__sub_I_Moving_Avg_Filtering.hip
_GLOBAL__sub_I_Moving_Avg_Filtering.hip: # @_GLOBAL__sub_I_Moving_Avg_Filtering.hip
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%edi, %edi
	callq	time
	movl	%eax, startup(%rip)
	movabsq	$42949672960256, %rax           # imm = 0x271000000100
	movq	%rax, startup+4(%rip)
	movl	$100, startup+12(%rip)
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	_GLOBAL__sub_I_Moving_Avg_Filtering.hip, .Lfunc_end7-_GLOBAL__sub_I_Moving_Avg_Filtering.hip
	.cfi_endproc
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z24DeviceCalculateSM_GlobalPfiS_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z24DeviceCalculateSM_SharedPfiS_ii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB9_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	startup,@object                 # @startup
	.bss
	.globl	startup
	.p2align	2, 0x0
startup:
	.zero	16
	.size	startup, 16

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Dataset is different"
	.size	.L.str, 21

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"D1 and D2 are equal!"
	.size	.L.str.2, 21

	.type	_Z24DeviceCalculateSM_GlobalPfiS_ii,@object # @_Z24DeviceCalculateSM_GlobalPfiS_ii
	.section	.rodata,"a",@progbits
	.globl	_Z24DeviceCalculateSM_GlobalPfiS_ii
	.p2align	3, 0x0
_Z24DeviceCalculateSM_GlobalPfiS_ii:
	.quad	_Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii
	.size	_Z24DeviceCalculateSM_GlobalPfiS_ii, 8

	.type	_Z24DeviceCalculateSM_SharedPfiS_ii,@object # @_Z24DeviceCalculateSM_SharedPfiS_ii
	.globl	_Z24DeviceCalculateSM_SharedPfiS_ii
	.p2align	3, 0x0
_Z24DeviceCalculateSM_SharedPfiS_ii:
	.quad	_Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii
	.size	_Z24DeviceCalculateSM_SharedPfiS_ii, 8

	.type	.L.str.4,@object                # @.str.4
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.4:
	.asciz	"Shared Memory: "
	.size	.L.str.4, 16

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Global Memory: "
	.size	.L.str.5, 16

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Kernel executed in %f milliseconds\n"
	.size	.L.str.6, 36

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%.6g, "
	.size	.L.str.7, 7

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Range"
	.size	.L.str.9, 6

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Seed"
	.size	.L.str.10, 5

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Block threads"
	.size	.L.str.11, 14

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Each should be %d elements in size\n"
	.size	.L.str.12, 36

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z24DeviceCalculateSM_GlobalPfiS_ii"
	.size	.L__unnamed_1, 36

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z24DeviceCalculateSM_SharedPfiS_ii"
	.size	.L__unnamed_2, 36

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	_GLOBAL__sub_I_Moving_Avg_Filtering.hip
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Datasets are not equal size"
	.size	.Lstr, 28

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z39__device_stub__DeviceCalculateSM_GlobalPfiS_ii
	.addrsig_sym _Z39__device_stub__DeviceCalculateSM_SharedPfiS_ii
	.addrsig_sym _GLOBAL__sub_I_Moving_Avg_Filtering.hip
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z24DeviceCalculateSM_GlobalPfiS_ii
	.addrsig_sym _Z24DeviceCalculateSM_SharedPfiS_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z24DeviceCalculateSM_GlobalPfiS_ii ; -- Begin function _Z24DeviceCalculateSM_GlobalPfiS_ii
	.globl	_Z24DeviceCalculateSM_GlobalPfiS_ii
	.p2align	8
	.type	_Z24DeviceCalculateSM_GlobalPfiS_ii,@function
_Z24DeviceCalculateSM_GlobalPfiS_ii:    ; @_Z24DeviceCalculateSM_GlobalPfiS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x2c
	s_load_b64 s[2:3], s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_cmp_gt_i32_e32 vcc_lo, s2, v1
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_6
; %bb.1:                                ; %.preheader
	s_cmp_lt_i32 s3, 1
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph.preheader
	s_load_b64 s[4:5], s[0:1], 0x0
	v_mov_b32_e32 v0, 0
	v_mov_b32_e32 v2, v1
	s_mov_b32 s2, s3
.LBB0_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_ashrrev_i32_e32 v3, 31, v2
	s_add_i32 s2, s2, -1
	s_cmp_eq_u32 s2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	v_add_nc_u32_e32 v2, 1, v2
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s4, v3
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	global_load_b32 v3, v[3:4], off
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v0, v0, v3
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_5
.LBB0_4:
	v_mov_b32_e32 v0, 0
.LBB0_5:                                ; %Flow31
	v_cvt_f32_i32_e32 v3, s3
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f32 v2, null, v3, v3, v0
	v_div_scale_f32 v6, vcc_lo, v0, v3, v0
	v_rcp_f32_e32 v4, v2
	s_waitcnt_depctr 0xfff
	v_fma_f32 v5, -v2, v4, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v4, v5, v4
	v_mul_f32_e32 v5, v6, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v7, -v2, v5, v6
	v_fmac_f32_e32 v5, v7, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fma_f32 v6, -v2, v5, v6
	v_ashrrev_i32_e32 v2, 31, v1
	v_div_fmas_f32 v4, v6, v4, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_div_fixup_f32 v3, v4, v3, v0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v0, vcc_lo, s0, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v2, vcc_lo
	global_store_b32 v[0:1], v3, off
.LBB0_6:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z24DeviceCalculateSM_GlobalPfiS_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z24DeviceCalculateSM_GlobalPfiS_ii, .Lfunc_end0-_Z24DeviceCalculateSM_GlobalPfiS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 324
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z24DeviceCalculateSM_SharedPfiS_ii ; -- Begin function _Z24DeviceCalculateSM_SharedPfiS_ii
	.globl	_Z24DeviceCalculateSM_SharedPfiS_ii
	.p2align	8
	.type	_Z24DeviceCalculateSM_SharedPfiS_ii,@function
_Z24DeviceCalculateSM_SharedPfiS_ii:    ; @_Z24DeviceCalculateSM_SharedPfiS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s3, s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s9, s2, 0xffff
	s_mov_b32 s2, exec_lo
	s_mul_i32 s15, s15, s9
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v1, s15, v0
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB1_13
; %bb.1:
	v_cvt_f32_u32_e32 v2, s9
	s_load_b64 s[4:5], s[0:1], 0x18
	s_sub_i32 s6, 0, s9
	v_lshl_add_u32 v4, v0, 2, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v2, v2
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v2, 0x4f7ffffe, v2
	v_cvt_u32_f32_e32 v2, v2
	s_waitcnt lgkmcnt(0)
	s_add_i32 s8, s9, s5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_readfirstlane_b32 s2, v2
	s_mul_i32 s6, s6, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s6, s2, s6
	s_add_i32 s2, s2, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s2, s8, s2
	s_mul_i32 s6, s2, s9
	s_add_i32 s7, s2, 1
	s_sub_i32 s6, s8, s6
	s_delay_alu instid0(SALU_CYCLE_1)
	s_sub_i32 s10, s6, s9
	s_cmp_ge_u32 s6, s9
	s_cselect_b32 s2, s7, s2
	s_cselect_b32 s6, s10, s6
	s_add_i32 s7, s2, 1
	s_cmp_ge_u32 s6, s9
	s_mov_b32 s10, 0
	s_cselect_b32 s2, s7, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v5, s2, s2, 1
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB1_6
; %bb.2:                                ; %.lr.ph.preheader
	s_load_b64 s[6:7], s[0:1], 0x0
	v_lshl_add_u32 v6, v0, 2, 0
	v_mov_b32_e32 v3, 0
	v_mov_b32_e32 v7, v0
	s_lshl_b32 s11, s9, 2
.LBB1_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, s15, v7
	v_cmp_gt_i32_e32 vcc_lo, s8, v7
	v_cmp_gt_u32_e64 s2, s3, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s12, vcc_lo, s2
	s_and_saveexec_b32 s2, s12
	s_cbranch_execz .LBB1_5
; %bb.4:                                ;   in Loop: Header=BB1_3 Depth=1
	v_lshlrev_b64 v[8:9], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v8, vcc_lo, s6, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s7, v9, vcc_lo
	global_load_b32 v2, v[8:9], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v6, v2
.LBB1_5:                                ;   in Loop: Header=BB1_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s2
	s_add_i32 s10, s10, 1
	v_add_nc_u32_e32 v6, s11, v6
	v_cmp_ge_u32_e32 vcc_lo, s10, v5
	v_add_nc_u32_e32 v7, s9, v7
	s_cbranch_vccz .LBB1_3
.LBB1_6:                                ; %._crit_edge
	v_mov_b32_e32 v3, 0
	s_cmp_lt_i32 s5, 1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_11
; %bb.7:                                ; %.lr.ph43.preheader
	s_mov_b32 s6, s5
.LBB1_8:                                ; %.lr.ph43
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, s15, v0
	v_cmp_gt_u32_e32 vcc_lo, s8, v0
	v_cmp_gt_i32_e64 s2, s3, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s7, vcc_lo, s2
	s_and_saveexec_b32 s2, s7
	s_cbranch_execz .LBB1_10
; %bb.9:                                ;   in Loop: Header=BB1_8 Depth=1
	ds_load_b32 v2, v4
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v3, v3, v2
.LBB1_10:                               ;   in Loop: Header=BB1_8 Depth=1
	s_or_b32 exec_lo, exec_lo, s2
	v_add_nc_u32_e32 v4, 4, v4
	v_add_nc_u32_e32 v0, 1, v0
	s_add_i32 s6, s6, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s6, 0
	s_cbranch_scc0 .LBB1_8
.LBB1_11:                               ; %Flow66
	v_cmp_gt_i32_e32 vcc_lo, s4, v1
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_13
; %bb.12:
	v_cvt_f32_i32_e32 v4, s5
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f32 v0, null, v4, v4, v3
	v_div_scale_f32 v6, vcc_lo, v3, v4, v3
	v_rcp_f32_e32 v5, v0
	s_waitcnt_depctr 0xfff
	v_fma_f32 v2, -v0, v5, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v5, v2, v5
	v_mul_f32_e32 v7, v6, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v2, -v0, v7, v6
	v_fmac_f32_e32 v7, v2, v5
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v0, -v0, v7, v6
	v_div_fmas_f32 v5, v0, v5, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_div_fixup_f32 v2, v5, v4, v3
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB1_13:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z24DeviceCalculateSM_SharedPfiS_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 10
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z24DeviceCalculateSM_SharedPfiS_ii, .Lfunc_end1-_Z24DeviceCalculateSM_SharedPfiS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 636
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 10
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z24DeviceCalculateSM_GlobalPfiS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z24DeviceCalculateSM_GlobalPfiS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         152
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z24DeviceCalculateSM_SharedPfiS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z24DeviceCalculateSM_SharedPfiS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
