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

const int M = 1024 * 1024;
const int thread_per_block = 512;

#define time_record_begin(start){ \
	cudaEventCreate(&start);	  \
	cudaEventRecord(start, 0);	  \
}
#define time_record_end(start, stop, time){ \
	cudaEventCreate(&stop);		\
	cudaEventRecord(stop, 0);	\
	cudaEventSynchronize(stop);	\
	cudaEventElapsedTime(&time, start, stop);\
}

__global__ void findMin(int *A){

    __shared__ int sdata[512];

	int tid = threadIdx.x;
	int i = blockIdx.x * blockDim.x + threadIdx.x;

	sdata[tid] = A[i];
	__syncthreads();

	for(unsigned int s = blockDim.x/2; s > 32; s /= 2)
	{
		if(tid < s)
		{
			if(sdata[tid] > sdata[tid + s])
				sdata[tid] = sdata[tid + s];
		}
		__syncthreads();
	}

	if(tid < 32)
	{
		if(sdata[tid] > sdata[tid + 32])
			sdata[tid] = sdata[tid + 32];
		if(sdata[tid] > sdata[tid + 16])
			sdata[tid] = sdata[tid + 16];
		if(sdata[tid] > sdata[tid + 8])
			sdata[tid] = sdata[tid + 8];
		if(sdata[tid] > sdata[tid + 4])
			sdata[tid] = sdata[tid + 4];
		if(sdata[tid] > sdata[tid + 2])
			sdata[tid] = sdata[tid + 2];
		if(sdata[tid] > sdata[tid + 1])
			sdata[tid] = sdata[tid + 1];
	}

	if(tid == 0)
		A[blockIdx.x] = sdata[0];
}

__global__ void findMax(int *A){

    __shared__ int sdata[512];

	int tid = threadIdx.x;
	int i = blockIdx.x * blockDim.x + threadIdx.x;

	sdata[tid] = A[i];
	__syncthreads();

	for(unsigned int s = blockDim.x/2; s > 32; s /= 2)
	{
		if(tid < s)
		{
			if(sdata[tid] < sdata[tid + s])
				sdata[tid] = sdata[tid + s];
		}
		__syncthreads();
	}

	if(tid < 32)
	{
		if(sdata[tid] < sdata[tid + 32])
			sdata[tid] = sdata[tid + 32];
		if(sdata[tid] < sdata[tid + 16])
			sdata[tid] = sdata[tid + 16];
		if(sdata[tid] < sdata[tid + 8])
			sdata[tid] = sdata[tid + 8];
		if(sdata[tid] < sdata[tid + 4])
			sdata[tid] = sdata[tid + 4];
		if(sdata[tid] < sdata[tid + 2])
			sdata[tid] = sdata[tid + 2];
		if(sdata[tid] < sdata[tid + 1])
			sdata[tid] = sdata[tid + 1];
	}

	__syncthreads();

	if(tid == 0)
		A[blockIdx.x] = sdata[0];
}

void random_number_generator(int *A, int size){
	time_t t;
	srand((unsigned) time(&t));
	for(int i = 0; i < size; i++){
		A[i] = rand();
	}
}

int main(int argc, char ** argv){
	int *A;
	int *d_A_MAX, *d_A_MIN;
	int SIZE[3] = {2, 8 ,32};

	int max_gpu = INT_MIN;
	int min_gpu = INT_MAX;
	int max_cpu = INT_MIN;
	int min_cpu = INT_MAX;

	for(int i = 0; i < 3; i++){

		int size = SIZE[i] * M;

		A = (int*) malloc(size * sizeof(int));
		random_number_generator(A, size);

		float total_max_average = 0;
		float total_min_average = 0;

		cudaMalloc((void**)&d_A_MAX, size * sizeof(int));
		cudaMalloc((void**)&d_A_MIN, size * sizeof(int));
		cudaMemcpy(d_A_MAX, A, size * sizeof(int), cudaMemcpyHostToDevice);
		cudaMemcpy(d_A_MIN, A, size * sizeof(int), cudaMemcpyHostToDevice);

		dim3 dimGrid1(size / thread_per_block);
		dim3 dimBlock1(thread_per_block);

		dim3 dimGrid2(size / thread_per_block / thread_per_block);
		dim3 dimBlock2(512);

		dim3 dimGrid3(1);
		dim3 dimBlock3(size / thread_per_block / thread_per_block);


		cudaEvent_t start,stop;
		float time_findMax, time_findMin;
		float total_max_average_gpu = 0;
		float total_min_average_gpu = 0;

		for(int j = 0; j < 10; j++){

			int max = INT_MIN, min = INT_MAX;

			clock_t start_t, end_t;

			start_t = clock();
			for(int i = 0; i < size; i++){
				if(A[i] > max)
					max = A[i];
			}
			max_cpu = max;
			end_t = clock();
			total_max_average += (float)(end_t - start_t) / CLOCKS_PER_SEC;

			start_t = clock();
			for(int i = 0; i < size; i++){
				if(A[i] < min)
					min = A[i];
			}
			min_cpu = min;
			end_t = clock();
			total_min_average += (float)(end_t - start_t) / CLOCKS_PER_SEC;

			cudaMemcpy(d_A_MAX, A, size * sizeof(int), cudaMemcpyHostToDevice);
			cudaMemcpy(d_A_MIN, A, size * sizeof(int), cudaMemcpyHostToDevice);

			time_record_begin(start);
			findMax<<<dimGrid1, dimBlock1>>>(d_A_MAX);
			findMax<<<dimGrid2, dimBlock2>>>(d_A_MAX);
			findMax<<<dimGrid3, dimBlock3>>>(d_A_MAX);
			time_record_end(start, stop, time_findMax);
			total_max_average_gpu += time_findMax / 1000;
			cudaMemcpy(&max_gpu, d_A_MAX, sizeof(int), cudaMemcpyDeviceToHost);

			time_record_begin(start);
			findMin<<<dimGrid1, dimBlock1>>>(d_A_MIN);
			findMin<<<dimGrid2, dimBlock2>>>(d_A_MIN);
			findMin<<<dimGrid3, dimBlock3>>>(d_A_MIN);
			time_record_end(start, stop, time_findMin);
			total_min_average_gpu += time_findMin / 1000;
			cudaMemcpy(&min_gpu, d_A_MIN, sizeof(int), cudaMemcpyDeviceToHost);

		}

		printf("N: %dM, GPUmax: %d, CPUmax: %d GPUtime: %f, CPUtime: %f, GPUSpeedup: %f   ", SIZE[i], max_gpu, max_cpu, total_max_average_gpu/10, total_max_average/10, total_max_average/total_max_average_gpu);
		printf("N: %dM, GPUmin: %d, CPUmin: %d GPUtime: %f, CPUtime: %f, GPUSpeedup: %f\n", SIZE[i], min_gpu, min_cpu, total_min_average_gpu/10, total_min_average/10, total_min_average/total_min_average_gpu);

		cudaFree(d_A_MAX);
		cudaFree(d_A_MIN);
		free(A);
	}
}





	.file	"tmpxft_0021f646_00000000-6_hw2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z23random_number_generatorPii
	.type	_Z23random_number_generatorPii, @function
_Z23random_number_generatorPii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
.L3:
	cmpl	%ebx, %ebp
	jle	.L8
	call	rand@PLT
	movl	%eax, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L3
.L8:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z23random_number_generatorPii, .-_Z23random_number_generatorPii
	.globl	_Z26__device_stub__Z7findMinPiPi
	.type	_Z26__device_stub__Z7findMinPiPi, @function
_Z26__device_stub__Z7findMinPiPi:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L9
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z7findMinPi(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L9:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z26__device_stub__Z7findMinPiPi, .-_Z26__device_stub__Z7findMinPiPi
	.globl	_Z7findMinPi
	.type	_Z7findMinPi, @function
_Z7findMinPi:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z7findMinPiPi
	.cfi_endproc
.LFE2054:
	.size	_Z7findMinPi, .-_Z7findMinPi
	.globl	_Z26__device_stub__Z7findMaxPiPi
	.type	_Z26__device_stub__Z7findMaxPiPi, @function
_Z26__device_stub__Z7findMaxPiPi:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z7findMaxPi(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L14:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z26__device_stub__Z7findMaxPiPi, .-_Z26__device_stub__Z7findMaxPiPi
	.globl	_Z7findMaxPi
	.type	_Z7findMaxPi, @function
_Z7findMaxPi:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z7findMaxPiPi
	.cfi_endproc
.LFE2056:
	.size	_Z7findMaxPi, .-_Z7findMaxPi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC4:
	.string	"N: %dM, GPUmax: %d, CPUmax: %d GPUtime: %f, CPUtime: %f, GPUSpeedup: %f   "
.LC5:
	.string	"N: %dM, GPUmin: %d, CPUmin: %d GPUtime: %f, CPUtime: %f, GPUSpeedup: %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movabsq	$4294967297, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$200, %rsp
	.cfi_def_cfa_offset 256
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	movabsq	$34359738370, %rax
	movl	$-2147483648, 48(%rsp)
	movl	$32, 180(%rsp)
	movl	$2147483647, 52(%rsp)
	movq	%rax, 172(%rsp)
.L31:
	movl	172(%rsp,%r12,4), %eax
	movl	%eax, %ebp
	movl	%eax, 40(%rsp)
	sall	$20, %ebp
	movslq	%ebp, %rax
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movl	%ebp, %esi
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	_Z23random_number_generatorPii
	movq	(%rsp), %rsi
	leaq	64(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	72(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	64(%rsp), %rdi
	movq	%rbx, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movq	72(%rsp), %rdi
	movq	%rbx, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebp, %eax
	movl	$512, %ecx
	movl	$262144, %esi
	cltd
	movq	%r15, 104(%rsp)
	idivl	%ecx
	movl	$1, 120(%rsp)
	movq	%r15, 128(%rsp)
	movl	$1, 144(%rsp)
	movq	%r15, 148(%rsp)
	movl	$1, 156(%rsp)
	movq	%r15, 164(%rsp)
	movl	$10, 44(%rsp)
	movl	$0x00000000, 20(%rsp)
	movl	$0x00000000, 16(%rsp)
	movl	$8388609, %ecx
	movl	$0x00000000, 12(%rsp)
	salq	$9, %rcx
	movl	$0x00000000, 8(%rsp)
	movq	%rcx, 112(%rsp)
	movq	%rcx, 136(%rsp)
	movl	%eax, 100(%rsp)
	movl	%ebp, %eax
	cltd
	idivl	%esi
	movl	%eax, 124(%rsp)
	movl	%eax, 160(%rsp)
.L30:
	call	clock@PLT
	movl	$-2147483648, %r14d
	xorl	%edx, %edx
	movq	%rax, %r13
.L20:
	cmpl	%edx, %ebp
	jle	.L36
	movl	(%rbx,%rdx,4), %eax
	cmpl	%eax, %r14d
	cmovl	%eax, %r14d
	incq	%rdx
	jmp	.L20
.L36:
	call	clock@PLT
	subq	%r13, %rax
	movl	$2147483647, %r13d
	cvtsi2ssq	%rax, %xmm0
	divss	.LC1(%rip), %xmm0
	addss	8(%rsp), %xmm0
	movss	%xmm0, 8(%rsp)
	call	clock@PLT
	xorl	%edx, %edx
	movq	%rax, %rcx
.L22:
	cmpl	%edx, %ebp
	jle	.L37
	movl	(%rbx,%rdx,4), %eax
	cmpl	%eax, %r13d
	cmovg	%eax, %r13d
	incq	%rdx
	jmp	.L22
.L37:
	movq	%rcx, 24(%rsp)
	call	clock@PLT
	movq	24(%rsp), %rcx
	movq	(%rsp), %rdx
	movq	%rbx, %rsi
	movq	64(%rsp), %rdi
	subq	%rcx, %rax
	movl	$1, %ecx
	cvtsi2ssq	%rax, %xmm0
	divss	.LC1(%rip), %xmm0
	addss	12(%rsp), %xmm0
	movss	%xmm0, 12(%rsp)
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movq	72(%rsp), %rdi
	movq	%rbx, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	80(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 24(%rsp)
	call	cudaEventCreate@PLT
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	120(%rsp), %ecx
	movl	108(%rsp), %esi
	xorl	%r9d, %r9d
	movq	112(%rsp), %rdx
	movq	100(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	movq	64(%rsp), %rdi
	call	_Z26__device_stub__Z7findMaxPiPi
.L24:
	movl	144(%rsp), %ecx
	movq	124(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	136(%rsp), %rdx
	movl	132(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	64(%rsp), %rdi
	call	_Z26__device_stub__Z7findMaxPiPi
.L25:
	movl	168(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	160(%rsp), %rdx
	movq	148(%rsp), %rdi
	movl	156(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	movq	64(%rsp), %rdi
	call	_Z26__device_stub__Z7findMaxPiPi
.L26:
	leaq	88(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 32(%rsp)
	call	cudaEventCreate@PLT
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	88(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	leaq	56(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movss	56(%rsp), %xmm0
	movq	64(%rsp), %rsi
	divss	.LC2(%rip), %xmm0
	addss	16(%rsp), %xmm0
	movl	$2, %ecx
	movl	$4, %edx
	leaq	48(%rsp), %rdi
	movss	%xmm0, 16(%rsp)
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	120(%rsp), %ecx
	movl	108(%rsp), %esi
	xorl	%r9d, %r9d
	movq	112(%rsp), %rdx
	movq	100(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	72(%rsp), %rdi
	call	_Z26__device_stub__Z7findMinPiPi
.L27:
	movl	144(%rsp), %ecx
	movq	124(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	136(%rsp), %rdx
	movl	132(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L28
	movq	72(%rsp), %rdi
	call	_Z26__device_stub__Z7findMinPiPi
.L28:
	movl	168(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	160(%rsp), %rdx
	movq	148(%rsp), %rdi
	movl	156(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	movq	72(%rsp), %rdi
	call	_Z26__device_stub__Z7findMinPiPi
.L29:
	movq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	88(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	leaq	60(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movss	60(%rsp), %xmm0
	movq	72(%rsp), %rsi
	divss	.LC2(%rip), %xmm0
	addss	20(%rsp), %xmm0
	leaq	52(%rsp), %rdi
	movl	$2, %ecx
	movl	$4, %edx
	movss	%xmm0, 20(%rsp)
	call	cudaMemcpy@PLT
	decl	44(%rsp)
	jne	.L30
	movss	8(%rsp), %xmm1
	movl	48(%rsp), %ecx
	movl	%r14d, %r8d
	movb	$3, %al
	movss	.LC3(%rip), %xmm3
	movss	16(%rsp), %xmm0
	incq	%r12
	leaq	.LC4(%rip), %rsi
	movl	40(%rsp), %edx
	movl	$2, %edi
	movss	8(%rsp), %xmm2
	divss	16(%rsp), %xmm2
	divss	%xmm3, %xmm1
	cvtss2sd	%xmm2, %xmm2
	divss	%xmm3, %xmm0
	cvtss2sd	%xmm1, %xmm1
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	52(%rsp), %ecx
	movl	%r13d, %r8d
	movss	.LC3(%rip), %xmm3
	movl	40(%rsp), %edx
	movl	$2, %edi
	movb	$3, %al
	movss	12(%rsp), %xmm1
	movss	20(%rsp), %xmm0
	leaq	.LC5(%rip), %rsi
	movss	12(%rsp), %xmm2
	divss	20(%rsp), %xmm2
	cvtss2sd	%xmm2, %xmm2
	divss	%xmm3, %xmm1
	divss	%xmm3, %xmm0
	cvtss2sd	%xmm1, %xmm1
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbx, %rdi
	call	free@PLT
	cmpq	$3, %r12
	jne	.L31
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L32
	call	__stack_chk_fail@PLT
.L32:
	addq	$200, %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
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC6:
	.string	"_Z7findMaxPi"
.LC7:
	.string	"_Z7findMinPi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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	.LC6(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7findMaxPi(%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	.LC7(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z7findMinPi(%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
.LFE2058:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.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
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1232348160
	.align 4
.LC2:
	.long	1148846080
	.align 4
.LC3:
	.long	1092616192
	.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 <hip/hip_runtime.h>
#include <stdio.h>
#include <time.h>

const int M = 1024 * 1024;
const int thread_per_block = 512;

#define time_record_begin(start){ \
	hipEventCreate(&start);	  \
	hipEventRecord(start, 0);	  \
}
#define time_record_end(start, stop, time){ \
	hipEventCreate(&stop);		\
	hipEventRecord(stop, 0);	\
	hipEventSynchronize(stop);	\
	hipEventElapsedTime(&time, start, stop);\
}

__global__ void findMin(int *A){

    __shared__ int sdata[512];

	int tid = threadIdx.x;
	int i = blockIdx.x * blockDim.x + threadIdx.x;

	sdata[tid] = A[i];
	__syncthreads();

	for(unsigned int s = blockDim.x/2; s > 32; s /= 2)
	{
		if(tid < s)
		{
			if(sdata[tid] > sdata[tid + s])
				sdata[tid] = sdata[tid + s];
		}
		__syncthreads();
	}

	if(tid < 32)
	{
		if(sdata[tid] > sdata[tid + 32])
			sdata[tid] = sdata[tid + 32];
		if(sdata[tid] > sdata[tid + 16])
			sdata[tid] = sdata[tid + 16];
		if(sdata[tid] > sdata[tid + 8])
			sdata[tid] = sdata[tid + 8];
		if(sdata[tid] > sdata[tid + 4])
			sdata[tid] = sdata[tid + 4];
		if(sdata[tid] > sdata[tid + 2])
			sdata[tid] = sdata[tid + 2];
		if(sdata[tid] > sdata[tid + 1])
			sdata[tid] = sdata[tid + 1];
	}

	if(tid == 0)
		A[blockIdx.x] = sdata[0];
}

__global__ void findMax(int *A){

    __shared__ int sdata[512];

	int tid = threadIdx.x;
	int i = blockIdx.x * blockDim.x + threadIdx.x;

	sdata[tid] = A[i];
	__syncthreads();

	for(unsigned int s = blockDim.x/2; s > 32; s /= 2)
	{
		if(tid < s)
		{
			if(sdata[tid] < sdata[tid + s])
				sdata[tid] = sdata[tid + s];
		}
		__syncthreads();
	}

	if(tid < 32)
	{
		if(sdata[tid] < sdata[tid + 32])
			sdata[tid] = sdata[tid + 32];
		if(sdata[tid] < sdata[tid + 16])
			sdata[tid] = sdata[tid + 16];
		if(sdata[tid] < sdata[tid + 8])
			sdata[tid] = sdata[tid + 8];
		if(sdata[tid] < sdata[tid + 4])
			sdata[tid] = sdata[tid + 4];
		if(sdata[tid] < sdata[tid + 2])
			sdata[tid] = sdata[tid + 2];
		if(sdata[tid] < sdata[tid + 1])
			sdata[tid] = sdata[tid + 1];
	}

	__syncthreads();

	if(tid == 0)
		A[blockIdx.x] = sdata[0];
}

void random_number_generator(int *A, int size){
	time_t t;
	srand((unsigned) time(&t));
	for(int i = 0; i < size; i++){
		A[i] = rand();
	}
}

int main(int argc, char ** argv){
	int *A;
	int *d_A_MAX, *d_A_MIN;
	int SIZE[3] = {2, 8 ,32};

	int max_gpu = INT_MIN;
	int min_gpu = INT_MAX;
	int max_cpu = INT_MIN;
	int min_cpu = INT_MAX;

	for(int i = 0; i < 3; i++){

		int size = SIZE[i] * M;

		A = (int*) malloc(size * sizeof(int));
		random_number_generator(A, size);

		float total_max_average = 0;
		float total_min_average = 0;

		hipMalloc((void**)&d_A_MAX, size * sizeof(int));
		hipMalloc((void**)&d_A_MIN, size * sizeof(int));
		hipMemcpy(d_A_MAX, A, size * sizeof(int), hipMemcpyHostToDevice);
		hipMemcpy(d_A_MIN, A, size * sizeof(int), hipMemcpyHostToDevice);

		dim3 dimGrid1(size / thread_per_block);
		dim3 dimBlock1(thread_per_block);

		dim3 dimGrid2(size / thread_per_block / thread_per_block);
		dim3 dimBlock2(512);

		dim3 dimGrid3(1);
		dim3 dimBlock3(size / thread_per_block / thread_per_block);


		hipEvent_t start,stop;
		float time_findMax, time_findMin;
		float total_max_average_gpu = 0;
		float total_min_average_gpu = 0;

		for(int j = 0; j < 10; j++){

			int max = INT_MIN, min = INT_MAX;

			clock_t start_t, end_t;

			start_t = clock();
			for(int i = 0; i < size; i++){
				if(A[i] > max)
					max = A[i];
			}
			max_cpu = max;
			end_t = clock();
			total_max_average += (float)(end_t - start_t) / CLOCKS_PER_SEC;

			start_t = clock();
			for(int i = 0; i < size; i++){
				if(A[i] < min)
					min = A[i];
			}
			min_cpu = min;
			end_t = clock();
			total_min_average += (float)(end_t - start_t) / CLOCKS_PER_SEC;

			hipMemcpy(d_A_MAX, A, size * sizeof(int), hipMemcpyHostToDevice);
			hipMemcpy(d_A_MIN, A, size * sizeof(int), hipMemcpyHostToDevice);

			time_record_begin(start);
			findMax<<<dimGrid1, dimBlock1>>>(d_A_MAX);
			findMax<<<dimGrid2, dimBlock2>>>(d_A_MAX);
			findMax<<<dimGrid3, dimBlock3>>>(d_A_MAX);
			time_record_end(start, stop, time_findMax);
			total_max_average_gpu += time_findMax / 1000;
			hipMemcpy(&max_gpu, d_A_MAX, sizeof(int), hipMemcpyDeviceToHost);

			time_record_begin(start);
			findMin<<<dimGrid1, dimBlock1>>>(d_A_MIN);
			findMin<<<dimGrid2, dimBlock2>>>(d_A_MIN);
			findMin<<<dimGrid3, dimBlock3>>>(d_A_MIN);
			time_record_end(start, stop, time_findMin);
			total_min_average_gpu += time_findMin / 1000;
			hipMemcpy(&min_gpu, d_A_MIN, sizeof(int), hipMemcpyDeviceToHost);

		}

		printf("N: %dM, GPUmax: %d, CPUmax: %d GPUtime: %f, CPUtime: %f, GPUSpeedup: %f   ", SIZE[i], max_gpu, max_cpu, total_max_average_gpu/10, total_max_average/10, total_max_average/total_max_average_gpu);
		printf("N: %dM, GPUmin: %d, CPUmin: %d GPUtime: %f, CPUtime: %f, GPUSpeedup: %f\n", SIZE[i], min_gpu, min_cpu, total_min_average_gpu/10, total_min_average/10, total_min_average/total_min_average_gpu);

		hipFree(d_A_MAX);
		hipFree(d_A_MIN);
		free(A);
	}
}





	.text
	.file	"hw2.hip"
	.globl	_Z22__device_stub__findMinPi    # -- Begin function _Z22__device_stub__findMinPi
	.type	_Z22__device_stub__findMinPi,@function
_Z22__device_stub__findMinPi:           # @_Z22__device_stub__findMinPi
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z7findMinPi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end0:
	.size	_Z22__device_stub__findMinPi, .Lfunc_end0-_Z22__device_stub__findMinPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__findMaxPi    # -- Begin function _Z22__device_stub__findMaxPi
	.type	_Z22__device_stub__findMaxPi,@function
_Z22__device_stub__findMaxPi:           # @_Z22__device_stub__findMaxPi
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z7findMaxPi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end1:
	.size	_Z22__device_stub__findMaxPi, .Lfunc_end1-_Z22__device_stub__findMaxPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z23random_number_generatorPii  # -- Begin function _Z23random_number_generatorPii
	.type	_Z23random_number_generatorPii,@function
_Z23random_number_generatorPii:         # @_Z23random_number_generatorPii
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movq	%rdi, %rbx
	movq	%rsp, %rdi
	callq	time
	movl	%eax, %edi
	callq	srand
	testl	%ebp, %ebp
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movl	%eax, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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_end2:
	.size	_Z23random_number_generatorPii, .Lfunc_end2-_Z23random_number_generatorPii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI3_0:
	.long	0x49742400                      # float 1.0E+6
.LCPI3_1:
	.long	0x447a0000                      # float 1000
.LCPI3_2:
	.long	0x41200000                      # float 10
	.text
	.globl	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
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movabsq	$4294967808, %r12               # imm = 0x100000200
	movabsq	$34359738370, %rax              # imm = 0x800000002
	movq	%rax, 124(%rsp)
	movl	$32, 132(%rsp)
	leaq	52(%rsp), %rax
	movl	$-2147483648, (%rax)            # imm = 0x80000000
	leaq	48(%rsp), %rax
	movl	$2147483647, (%rax)             # imm = 0x7FFFFFFF
	xorl	%eax, %eax
.LBB3_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_2 Depth 2
                                        #       Child Loop BB3_9 Depth 3
                                        #       Child Loop BB3_11 Depth 3
	movq	%rax, 104(%rsp)                 # 8-byte Spill
	movslq	124(%rsp,%rax,4), %rbx
	movl	%ebx, %r13d
	shll	$20, %r13d
	movq	%rbx, %r14
	shlq	$22, %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rax, %rdi
	movl	%r13d, %esi
	callq	_Z23random_number_generatorPii
	leaq	16(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	16(%rsp), %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	movq	%r15, %rsi
	movq	%r14, 112(%rsp)                 # 8-byte Spill
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%ebx, %eax
	shll	$11, %eax
	addq	%r12, %rax
	addq	$-512, %rax                     # imm = 0xFE00
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	movq	%rbx, 56(%rsp)                  # 8-byte Spill
	leal	(,%rbx,4), %eax
	addq	%r12, %rax
	addq	$-512, %rax                     # imm = 0xFE00
	movq	%rax, 88(%rsp)                  # 8-byte Spill
	cmpl	$2, %r13d
	movl	$1, %eax
	cmovll	%eax, %r13d
	xorps	%xmm0, %xmm0
	movss	%xmm0, 28(%rsp)                 # 4-byte Spill
	movss	%xmm0, 36(%rsp)                 # 4-byte Spill
	movss	%xmm0, 24(%rsp)                 # 4-byte Spill
	movss	%xmm0, 32(%rsp)                 # 4-byte Spill
	xorl	%ebp, %ebp
.LBB3_2:                                #   Parent Loop BB3_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_9 Depth 3
                                        #       Child Loop BB3_11 Depth 3
	movl	%ebp, 76(%rsp)                  # 4-byte Spill
	callq	clock
	movq	%rax, %r14
	cmpl	$0, 56(%rsp)                    # 4-byte Folded Reload
	jle	.LBB3_3
# %bb.8:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB3_2 Depth=2
	movl	$-2147483648, %ebx              # imm = 0x80000000
	xorl	%eax, %eax
.LBB3_9:                                # %.lr.ph
                                        #   Parent Loop BB3_1 Depth=1
                                        #     Parent Loop BB3_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	(%r15,%rax,4), %ecx
	cmpl	%ebx, %ecx
	cmovgl	%ecx, %ebx
	incq	%rax
	cmpq	%rax, %r13
	jne	.LBB3_9
	jmp	.LBB3_4
.LBB3_3:                                #   in Loop: Header=BB3_2 Depth=2
	movl	$-2147483648, %ebx              # imm = 0x80000000
.LBB3_4:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=2
	callq	clock
	movq	%rax, %r12
	subq	%r14, %r12
	callq	clock
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r12, %xmm0
	movq	%rax, %r12
	divss	.LCPI3_0(%rip), %xmm0
	movss	%xmm0, 72(%rsp)                 # 4-byte Spill
	cmpl	$0, 56(%rsp)                    # 4-byte Folded Reload
	jle	.LBB3_5
# %bb.10:                               # %.lr.ph156.preheader
                                        #   in Loop: Header=BB3_2 Depth=2
	movl	$2147483647, %r14d              # imm = 0x7FFFFFFF
	xorl	%eax, %eax
.LBB3_11:                               # %.lr.ph156
                                        #   Parent Loop BB3_1 Depth=1
                                        #     Parent Loop BB3_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	(%r15,%rax,4), %ecx
	cmpl	%r14d, %ecx
	cmovll	%ecx, %r14d
	incq	%rax
	cmpq	%rax, %r13
	jne	.LBB3_11
	jmp	.LBB3_12
.LBB3_5:                                #   in Loop: Header=BB3_2 Depth=2
	movl	$2147483647, %r14d              # imm = 0x7FFFFFFF
.LBB3_12:                               # %._crit_edge157
                                        #   in Loop: Header=BB3_2 Depth=2
	callq	clock
	subq	%r12, %rax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	divss	.LCPI3_0(%rip), %xmm0
	movss	%xmm0, 68(%rsp)                 # 4-byte Spill
	movq	16(%rsp), %rdi
	movq	%r15, %rsi
	movq	112(%rsp), %r12                 # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	96(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movabsq	$4294967808, %r12               # imm = 0x100000200
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_14
# %bb.13:                               #   in Loop: Header=BB3_2 Depth=2
	movq	16(%rsp), %rdi
	callq	_Z22__device_stub__findMaxPi
.LBB3_14:                               #   in Loop: Header=BB3_2 Depth=2
	movq	88(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_16
# %bb.15:                               #   in Loop: Header=BB3_2 Depth=2
	movq	16(%rsp), %rdi
	callq	_Z22__device_stub__findMaxPi
.LBB3_16:                               #   in Loop: Header=BB3_2 Depth=2
	addq	$-511, %r12                     # imm = 0xFE01
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_18
# %bb.17:                               #   in Loop: Header=BB3_2 Depth=2
	movq	16(%rsp), %rdi
	callq	_Z22__device_stub__findMaxPi
.LBB3_18:                               #   in Loop: Header=BB3_2 Depth=2
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	40(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	84(%rsp), %rdi
	callq	hipEventElapsedTime
	movss	84(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	divss	.LCPI3_1(%rip), %xmm0
	movss	%xmm0, 64(%rsp)                 # 4-byte Spill
	movq	16(%rsp), %rsi
	movl	$4, %edx
	leaq	52(%rsp), %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	96(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movabsq	$4294967808, %rdx               # imm = 0x100000200
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_20
# %bb.19:                               #   in Loop: Header=BB3_2 Depth=2
	movq	8(%rsp), %rdi
	callq	_Z22__device_stub__findMinPi
.LBB3_20:                               #   in Loop: Header=BB3_2 Depth=2
	movq	88(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rdi
	movl	$1, %esi
	movabsq	$4294967808, %rdx               # imm = 0x100000200
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_22
# %bb.21:                               #   in Loop: Header=BB3_2 Depth=2
	movq	8(%rsp), %rdi
	callq	_Z22__device_stub__findMinPi
.LBB3_22:                               #   in Loop: Header=BB3_2 Depth=2
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	movl	76(%rsp), %ebp                  # 4-byte Reload
	jne	.LBB3_24
# %bb.23:                               #   in Loop: Header=BB3_2 Depth=2
	movq	8(%rsp), %rdi
	callq	_Z22__device_stub__findMinPi
.LBB3_24:                               #   in Loop: Header=BB3_2 Depth=2
	movss	28(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addss	72(%rsp), %xmm0                 # 4-byte Folded Reload
	movss	%xmm0, 28(%rsp)                 # 4-byte Spill
	movss	36(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addss	68(%rsp), %xmm0                 # 4-byte Folded Reload
	movss	%xmm0, 36(%rsp)                 # 4-byte Spill
	movss	24(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addss	64(%rsp), %xmm0                 # 4-byte Folded Reload
	movss	%xmm0, 24(%rsp)                 # 4-byte Spill
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	40(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	80(%rsp), %rdi
	callq	hipEventElapsedTime
	movss	80(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	divss	.LCPI3_1(%rip), %xmm0
	movss	32(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm1
	movss	%xmm1, 32(%rsp)                 # 4-byte Spill
	movq	8(%rsp), %rsi
	movl	$4, %edx
	leaq	48(%rsp), %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	incl	%ebp
	cmpl	$10, %ebp
	movabsq	$4294967808, %r12               # imm = 0x100000200
	jne	.LBB3_2
# %bb.6:                                #   in Loop: Header=BB3_1 Depth=1
	movl	52(%rsp), %edx
	movss	24(%rsp), %xmm3                 # 4-byte Reload
                                        # xmm3 = mem[0],zero,zero,zero
	movaps	%xmm3, %xmm0
	movss	.LCPI3_2(%rip), %xmm4           # xmm4 = mem[0],zero,zero,zero
	divss	%xmm4, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movss	28(%rsp), %xmm2                 # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	movaps	%xmm2, %xmm1
	divss	%xmm4, %xmm1
	cvtss2sd	%xmm1, %xmm1
	divss	%xmm3, %xmm2
	cvtss2sd	%xmm2, %xmm2
	movl	$.L.str, %edi
	movq	56(%rsp), %r13                  # 8-byte Reload
	movl	%r13d, %esi
	movl	%ebx, %ecx
	movb	$3, %al
	callq	printf
	movl	48(%rsp), %edx
	movss	32(%rsp), %xmm3                 # 4-byte Reload
                                        # xmm3 = mem[0],zero,zero,zero
	movaps	%xmm3, %xmm0
	movss	.LCPI3_2(%rip), %xmm4           # xmm4 = mem[0],zero,zero,zero
	divss	%xmm4, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movss	36(%rsp), %xmm2                 # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	movaps	%xmm2, %xmm1
	divss	%xmm4, %xmm1
	cvtss2sd	%xmm1, %xmm1
	divss	%xmm3, %xmm2
	cvtss2sd	%xmm2, %xmm2
	movl	$.L.str.1, %edi
	movl	%r13d, %esi
	movl	%r14d, %ecx
	movb	$3, %al
	callq	printf
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%r15, %rdi
	callq	free
	movq	104(%rsp), %rax                 # 8-byte Reload
	incq	%rax
	cmpq	$3, %rax
	jne	.LBB3_1
# %bb.7:
	xorl	%eax, %eax
	addq	$136, %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_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7findMinPi, %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	$_Z7findMaxPi, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z7findMinPi,@object            # @_Z7findMinPi
	.section	.rodata,"a",@progbits
	.globl	_Z7findMinPi
	.p2align	3, 0x0
_Z7findMinPi:
	.quad	_Z22__device_stub__findMinPi
	.size	_Z7findMinPi, 8

	.type	_Z7findMaxPi,@object            # @_Z7findMaxPi
	.globl	_Z7findMaxPi
	.p2align	3, 0x0
_Z7findMaxPi:
	.quad	_Z22__device_stub__findMaxPi
	.size	_Z7findMaxPi, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"N: %dM, GPUmax: %d, CPUmax: %d GPUtime: %f, CPUtime: %f, GPUSpeedup: %f   "
	.size	.L.str, 75

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"N: %dM, GPUmin: %d, CPUmin: %d GPUtime: %f, CPUtime: %f, GPUSpeedup: %f\n"
	.size	.L.str.1, 73

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7findMinPi"
	.size	.L__unnamed_1, 13

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z7findMaxPi"
	.size	.L__unnamed_2, 13

	.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	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.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 _Z22__device_stub__findMinPi
	.addrsig_sym _Z22__device_stub__findMaxPi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z7findMinPi
	.addrsig_sym _Z7findMaxPi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7findMinPi            ; -- Begin function _Z7findMinPi
	.globl	_Z7findMinPi
	.p2align	8
	.type	_Z7findMinPi,@function
_Z7findMinPi:                           ; @_Z7findMinPi
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x14
	s_load_b64 s[0:1], s[0:1], 0x0
	s_mov_b32 s2, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s2, s3, v[0:1]
	s_cmpk_lt_u32 s3, 0x42
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_load_b32 v2, v[1:2], off
	v_lshlrev_b32_e32 v1, 2, v0
	s_waitcnt vmcnt(0)
	ds_store_b32 v1, v2
	s_waitcnt vmcnt(0) lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_6
; %bb.2:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_mov_b32 s4, s3
	s_lshr_b32 s3, s3, 1
	s_mov_b32 s5, exec_lo
	v_cmpx_gt_u32_e64 s3, v0
	s_cbranch_execz .LBB0_5
; %bb.3:                                ;   in Loop: Header=BB0_1 Depth=1
	v_lshl_add_u32 v2, s3, 2, v1
	ds_load_b32 v3, v1
	ds_load_b32 v2, v2
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, v3, v2
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_1 Depth=1
	ds_store_b32 v1, v2
.LBB0_5:                                ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
	s_waitcnt lgkmcnt(0)
	s_cmpk_lt_u32 s4, 0x84
	s_branch .LBB0_1
.LBB0_6:                                ; %._crit_edge
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_u32_e32 32, v0
	s_cbranch_execz .LBB0_19
; %bb.7:
	ds_load_b32 v2, v1
	ds_load_b32 v3, v1 offset:128
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_gt_i32_e64 v2, v3
	s_cbranch_execz .LBB0_9
; %bb.8:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB0_9:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:64
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_gt_i32_e64 v2, v3
	s_cbranch_execz .LBB0_11
; %bb.10:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB0_11:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:32
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_gt_i32_e64 v2, v3
	s_cbranch_execz .LBB0_13
; %bb.12:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB0_13:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:16
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_gt_i32_e64 v2, v3
	s_cbranch_execz .LBB0_15
; %bb.14:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB0_15:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:8
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_gt_i32_e64 v2, v3
	s_cbranch_execz .LBB0_17
; %bb.16:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB0_17:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:4
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, v2, v3
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_19
; %bb.18:
	ds_store_b32 v1, v3
.LBB0_19:                               ; %Flow51
	s_or_b32 exec_lo, exec_lo, s3
	s_mov_b32 s3, 0
	s_mov_b32 s4, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_21
; %bb.20:
	v_mov_b32_e32 v0, 0
	s_lshl_b64 s[2:3], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s0, s2
	s_addc_u32 s1, s1, s3
	ds_load_b32 v1, v0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB0_21:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7findMinPi
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.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 4
		.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	_Z7findMinPi, .Lfunc_end0-_Z7findMinPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 568
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; 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	_Z7findMaxPi            ; -- Begin function _Z7findMaxPi
	.globl	_Z7findMaxPi
	.p2align	8
	.type	_Z7findMaxPi,@function
_Z7findMaxPi:                           ; @_Z7findMaxPi
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x14
	s_load_b64 s[0:1], s[0:1], 0x0
	s_mov_b32 s2, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s2, s3, v[0:1]
	s_cmpk_lt_u32 s3, 0x42
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_load_b32 v2, v[1:2], off
	v_lshlrev_b32_e32 v1, 2, v0
	s_waitcnt vmcnt(0)
	ds_store_b32 v1, v2
	s_waitcnt vmcnt(0) lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
.LBB1_1:                                ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_6
; %bb.2:                                ; %.lr.ph
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_mov_b32 s4, s3
	s_lshr_b32 s3, s3, 1
	s_mov_b32 s5, exec_lo
	v_cmpx_gt_u32_e64 s3, v0
	s_cbranch_execz .LBB1_5
; %bb.3:                                ;   in Loop: Header=BB1_1 Depth=1
	v_lshl_add_u32 v2, s3, 2, v1
	ds_load_b32 v3, v1
	ds_load_b32 v2, v2
	s_waitcnt lgkmcnt(0)
	v_cmp_lt_i32_e32 vcc_lo, v3, v2
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_5
; %bb.4:                                ;   in Loop: Header=BB1_1 Depth=1
	ds_store_b32 v1, v2
.LBB1_5:                                ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
	s_waitcnt lgkmcnt(0)
	s_cmpk_lt_u32 s4, 0x84
	s_branch .LBB1_1
.LBB1_6:                                ; %._crit_edge
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_u32_e32 32, v0
	s_cbranch_execz .LBB1_19
; %bb.7:
	ds_load_b32 v2, v1
	ds_load_b32 v3, v1 offset:128
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_lt_i32_e64 v2, v3
	s_cbranch_execz .LBB1_9
; %bb.8:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB1_9:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:64
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_lt_i32_e64 v2, v3
	s_cbranch_execz .LBB1_11
; %bb.10:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB1_11:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:32
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_lt_i32_e64 v2, v3
	s_cbranch_execz .LBB1_13
; %bb.12:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB1_13:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:16
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_lt_i32_e64 v2, v3
	s_cbranch_execz .LBB1_15
; %bb.14:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB1_15:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:8
	s_mov_b32 s4, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_lt_i32_e64 v2, v3
	s_cbranch_execz .LBB1_17
; %bb.16:
	v_mov_b32_e32 v2, v3
	ds_store_b32 v1, v3
.LBB1_17:
	s_or_b32 exec_lo, exec_lo, s4
	ds_load_b32 v3, v1 offset:4
	s_waitcnt lgkmcnt(0)
	v_cmp_lt_i32_e32 vcc_lo, v2, v3
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_19
; %bb.18:
	ds_store_b32 v1, v3
.LBB1_19:                               ; %Flow51
	s_or_b32 exec_lo, exec_lo, s3
	s_mov_b32 s3, 0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_mov_b32 s4, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB1_21
; %bb.20:
	v_mov_b32_e32 v0, 0
	s_lshl_b64 s[2:3], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s0, s2
	s_addc_u32 s1, s1, s3
	ds_load_b32 v1, v0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB1_21:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7findMaxPi
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.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 4
		.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	_Z7findMaxPi, .Lfunc_end1-_Z7findMaxPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 584
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; 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:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7findMinPi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7findMinPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .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:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7findMaxPi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7findMaxPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
