// n should be less than 10000 when k==3
#include <stdio.h>
#include <cuda.h>

__global__ void parallel_max_each_chunk(float *dmaxarr, float * darr,  int n, int k);


int main(int argc, char **argv) {
				int n = atoi(argv[1]);
				int k = atoi(argv[2]); 
				
		//generate a 1d array
				float *arr = (float*) malloc(n*sizeof(float));
				int i;
				for (i = n; i > 0; i--) {
							arr[n-i] = (float)i;			
				}

		const int numthreadsBlock = 8;
		int numChunk;
		numChunk = ( n + numthreadsBlock - 1)/numthreadsBlock;
		float *maxarr = (float *)malloc(numChunk * sizeof(float));

  int numBlock = numChunk;

		// declare GPU memory pointers
		float *darr, * dmaxarr;
		cudaMalloc((void **)&darr, n*sizeof(float));
		cudaMalloc((void **)&dmaxarr, numChunk*sizeof(float));
		cudaMemcpy(darr, arr, n*sizeof(float), cudaMemcpyHostToDevice);

		dim3 dimGrid(numBlock,1);
		dim3 dimBlock(numthreadsBlock,1,1);

		parallel_max_each_chunk<<<dimGrid,dimBlock,(n+3*numthreadsBlock)*sizeof(float)>>>(dmaxarr, darr, n, k);
		cudaThreadSynchronize();
		cudaMemcpy(maxarr, dmaxarr, numChunk*sizeof(float), cudaMemcpyDeviceToHost);

  //truth
				float *smaxarr = (float *)malloc(numChunk*sizeof(float));
				for (i = 0; i < numChunk; i ++) {
        smaxarr[i] = i*numthreadsBlock + k <=n? arr[i*numthreadsBlock + k/2 ]:0; // k is an odd number
				}

		//check the results
				bool judge = true;
				for (i=0; i < numBlock; i++) {
						printf("max of block  %d,  %f %f\n ", i, smaxarr[i], maxarr[i]);
						judge = judge && (smaxarr[i] == maxarr[i]);
				}
				printf("\n--------correct or wrong---------\n");
				printf(judge ? "right\n": "wrong\n");

				// This is for developing: print out the 1d array

				printf("\n--------1d array---------\n");
    if ( n < 15) {
				for (i=0; i < n; i++) {
						printf("element  %d,  %f\n ", i, arr[i]);
				}
    }
		// check the exit state of CUDA code
		cudaError_t error = cudaGetLastError();
		if (error !=cudaSuccess) {
				printf("CUDA error: %s\n", cudaGetErrorString(error));
		}

		//free gpu memory
		cudaFree(dmaxarr);
		cudaFree(darr);
		return 0;
}

__global__ void parallel_max_each_chunk(float *dmaxarr, float * darr, int n,int k) {
 	int i, tid = threadIdx.x;
		//copy the whole series to shared memory
  //always round up and if n is a multiple of blockDim.x no rounding
		int chunkSize = (n+blockDim.x-1)/blockDim.x;
  extern __shared__ float sdata[];
  for (i = 0; i < chunkSize; i++) {
			  if (tid * chunkSize + i <n)
     sdata[tid*chunkSize + i ] = darr[tid*chunkSize + i];
			}
  __syncthreads();

  // declare three array for the maximum found by each thread 
  extern __shared__ float mymaxvals[];
  extern __shared__ float mystartmaxes[];
  extern __shared__ float myendmaxes[];
		
		int perstart = threadIdx.x + blockDim.x * blockIdx.x;
		int perlen, perend;
		double xbar; // a temporay variable used when computing mean of subsequence

		if (perstart <= n-k) {
    for (perlen = k ; perlen <= n - perstart ; perlen++) {
				  perend = perstart + perlen - 1;
						//compute the mean of subsequence incrementally
      if (perlen ==k) {
							  xbar = 0;
									for ( i = perstart; i <= perend; i++) {
           xbar += sdata[i];     
									}
									xbar /= (perend - perstart + 1);
									mymaxvals[tid] = xbar;
						} else {
        xbar = ( (perlen-1) * xbar + sdata[perend] ) / perlen;
						}
						//update the mymaxvals[tid] if the next longer subsequence has a higher mean
						if (xbar > mymaxvals[tid]) {
         mymaxvals[tid] = xbar;
									mystartmaxes[tid] = perstart;
									myendmaxes[tid] = perend;
						}
				}
		} else {
    mymaxvals[tid] = 0;//initialize it the smallest number
		}
//  mymaxvals[tid] = sdata[tid]; 
		__syncthreads(); //sync to make sure each thread in this block has done with the for loop

  // get the highest among the mymaxvals using reduce
  for (int s = blockDim.x/2; s > 0; s>>=1) {
     if (tid < s ) {
       if(mymaxvals[tid+s] > mymaxvals[tid]) {
						   	mymaxvals[tid] = 	mymaxvals[tid+s]; 
          mystartmaxes[tid] = mystartmaxes[tid + s];
									 myendmaxes[tid] = myendmaxes[tid + s];	
							}	
     }
     __syncthreads();
  }
  // the maximum among the mymaxvals in this block
  if(tid == 0) {
  dmaxarr[blockIdx.x] = mymaxvals[0];
  }
}


	.file	"tmpxft_003abd99_00000000-6_HW3_small_n.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z47__device_stub__Z23parallel_max_each_chunkPfS_iiPfS_ii
	.type	_Z47__device_stub__Z23parallel_max_each_chunkPfS_iiPfS_ii, @function
_Z47__device_stub__Z23parallel_max_each_chunkPfS_iiPfS_ii:
.LFB2052:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z23parallel_max_each_chunkPfS_ii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z47__device_stub__Z23parallel_max_each_chunkPfS_iiPfS_ii, .-_Z47__device_stub__Z23parallel_max_each_chunkPfS_iiPfS_ii
	.globl	_Z23parallel_max_each_chunkPfS_ii
	.type	_Z23parallel_max_each_chunkPfS_ii, @function
_Z23parallel_max_each_chunkPfS_ii:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z47__device_stub__Z23parallel_max_each_chunkPfS_iiPfS_ii
	.cfi_endproc
.LFE2053:
	.size	_Z23parallel_max_each_chunkPfS_ii, .-_Z23parallel_max_each_chunkPfS_ii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"right\n"
.LC2:
	.string	"wrong\n"
.LC3:
	.string	"max of block  %d,  %f %f\n "
.LC4:
	.string	"\n--------correct or wrong---------\n"
.LC5:
	.string	"\n--------1d array---------\n"
.LC6:
	.string	"element  %d,  %f\n "
.LC7:
	.string	"CUDA error: %s\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.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
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	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
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movq	16(%rbp), %rdi
	movslq	%eax, %r12
	call	atoi@PLT
	leaq	0(,%r12,4), %r15
	movq	%r12, %rbx
	movq	%r15, %rdi
	movl	%eax, %ebp
	call	malloc@PLT
	movq	%rax, %r13
.L9:
	testl	%r12d, %r12d
	jle	.L32
	cvtsi2ssl	%r12d, %xmm0
	addq	$4, %rax
	decq	%r12
	movss	%xmm0, -4(%rax)
	jmp	.L9
.L32:
	leal	7(%rbx), %eax
	movl	$8, %ecx
	cltd
	idivl	%ecx
	cltq
	movq	%rax, %r12
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	movq	%rax, %r14
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	24(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movq	%r15, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%r12d, 32(%rsp)
	xorl	%r9d, %r9d
	leaq	96(%r15), %r8
	movabsq	$4294967297, %rax
	movl	$536870913, %edx
	movl	$1, %ecx
	movq	%rax, 36(%rsp)
	movq	32(%rsp), %rdi
	salq	$3, %rdx
	movl	40(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	movq	16(%rsp), %rsi
	movq	24(%rsp), %rdi
	movl	%ebp, %ecx
	movl	%ebx, %edx
	call	_Z47__device_stub__Z23parallel_max_each_chunkPfS_iiPfS_ii
.L11:
	call	cudaThreadSynchronize@PLT
	movq	(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	%r14, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdi
	call	malloc@PLT
	movl	$2, %ecx
	movq	%rax, %r8
	movl	%ebp, %eax
	cltd
	idivl	%ecx
	xorl	%edx, %edx
	subl	%eax, %ebp
.L12:
	cmpl	%edx, %r12d
	jle	.L33
	leal	0(%rbp,%rax), %ecx
	xorps	%xmm0, %xmm0
	cmpl	%ecx, %ebx
	jl	.L13
	movslq	%eax, %rcx
	movss	0(%r13,%rcx,4), %xmm0
.L13:
	movss	%xmm0, (%r8,%rdx,4)
	addl	$8, %eax
	incq	%rdx
	jmp	.L12
.L33:
	xorl	%ebp, %ebp
	movb	$1, %r15b
.L15:
	movl	%ebp, %edx
	cmpl	%ebp, %r12d
	jle	.L34
	movss	(%r8,%rbp,4), %xmm2
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movb	$2, %al
	movq	%r8, 8(%rsp)
	cvtss2sd	(%r14,%rbp,4), %xmm1
	movss	%xmm2, (%rsp)
	cvtss2sd	%xmm2, %xmm0
	call	__printf_chk@PLT
	testb	%r15b, %r15b
	movq	8(%rsp), %r8
	je	.L16
	movss	(%rsp), %xmm2
	ucomiss	(%r14,%rbp,4), %xmm2
	movb	$0, %al
	setnp	%cl
	cmove	%ecx, %eax
	movl	%eax, %r15d
.L16:
	incq	%rbp
	jmp	.L15
.L34:
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	testb	%r15b, %r15b
	movl	$2, %edi
	leaq	.LC1(%rip), %rax
	leaq	.LC2(%rip), %rsi
	cmovne	%rax, %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC5(%rip), %rsi
	call	__printf_chk@PLT
	cmpl	$14, %ebx
	jle	.L27
.L23:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L21
.L27:
	xorl	%ebp, %ebp
	leaq	.LC6(%rip), %r12
.L19:
	movl	%ebp, %edx
	cmpl	%ebp, %ebx
	jle	.L23
	movq	%r12, %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	0(%r13,%rbp,4), %xmm0
	call	__printf_chk@PLT
	incq	%rbp
	jmp	.L19
.L21:
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$72, %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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC8:
	.string	"_Z23parallel_max_each_chunkPfS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 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	.LC8(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z23parallel_max_each_chunkPfS_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	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	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2055:
	.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
	.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:

// n should be less than 10000 when k==3
#include <stdio.h>
#include <hip/hip_runtime.h>

__global__ void parallel_max_each_chunk(float *dmaxarr, float * darr,  int n, int k);


int main(int argc, char **argv) {
				int n = atoi(argv[1]);
				int k = atoi(argv[2]); 
				
		//generate a 1d array
				float *arr = (float*) malloc(n*sizeof(float));
				int i;
				for (i = n; i > 0; i--) {
							arr[n-i] = (float)i;			
				}

		const int numthreadsBlock = 8;
		int numChunk;
		numChunk = ( n + numthreadsBlock - 1)/numthreadsBlock;
		float *maxarr = (float *)malloc(numChunk * sizeof(float));

  int numBlock = numChunk;

		// declare GPU memory pointers
		float *darr, * dmaxarr;
		hipMalloc((void **)&darr, n*sizeof(float));
		hipMalloc((void **)&dmaxarr, numChunk*sizeof(float));
		hipMemcpy(darr, arr, n*sizeof(float), hipMemcpyHostToDevice);

		dim3 dimGrid(numBlock,1);
		dim3 dimBlock(numthreadsBlock,1,1);

		parallel_max_each_chunk<<<dimGrid,dimBlock,(n+3*numthreadsBlock)*sizeof(float)>>>(dmaxarr, darr, n, k);
		hipDeviceSynchronize();
		hipMemcpy(maxarr, dmaxarr, numChunk*sizeof(float), hipMemcpyDeviceToHost);

  //truth
				float *smaxarr = (float *)malloc(numChunk*sizeof(float));
				for (i = 0; i < numChunk; i ++) {
        smaxarr[i] = i*numthreadsBlock + k <=n? arr[i*numthreadsBlock + k/2 ]:0; // k is an odd number
				}

		//check the results
				bool judge = true;
				for (i=0; i < numBlock; i++) {
						printf("max of block  %d,  %f %f\n ", i, smaxarr[i], maxarr[i]);
						judge = judge && (smaxarr[i] == maxarr[i]);
				}
				printf("\n--------correct or wrong---------\n");
				printf(judge ? "right\n": "wrong\n");

				// This is for developing: print out the 1d array

				printf("\n--------1d array---------\n");
    if ( n < 15) {
				for (i=0; i < n; i++) {
						printf("element  %d,  %f\n ", i, arr[i]);
				}
    }
		// check the exit state of CUDA code
		hipError_t error = hipGetLastError();
		if (error !=hipSuccess) {
				printf("CUDA error: %s\n", hipGetErrorString(error));
		}

		//free gpu memory
		hipFree(dmaxarr);
		hipFree(darr);
		return 0;
}

__global__ void parallel_max_each_chunk(float *dmaxarr, float * darr, int n,int k) {
 	int i, tid = threadIdx.x;
		//copy the whole series to shared memory
  //always round up and if n is a multiple of blockDim.x no rounding
		int chunkSize = (n+blockDim.x-1)/blockDim.x;
  extern __shared__ float sdata[];
  for (i = 0; i < chunkSize; i++) {
			  if (tid * chunkSize + i <n)
     sdata[tid*chunkSize + i ] = darr[tid*chunkSize + i];
			}
  __syncthreads();

  // declare three array for the maximum found by each thread 
  extern __shared__ float mymaxvals[];
  extern __shared__ float mystartmaxes[];
  extern __shared__ float myendmaxes[];
		
		int perstart = threadIdx.x + blockDim.x * blockIdx.x;
		int perlen, perend;
		double xbar; // a temporay variable used when computing mean of subsequence

		if (perstart <= n-k) {
    for (perlen = k ; perlen <= n - perstart ; perlen++) {
				  perend = perstart + perlen - 1;
						//compute the mean of subsequence incrementally
      if (perlen ==k) {
							  xbar = 0;
									for ( i = perstart; i <= perend; i++) {
           xbar += sdata[i];     
									}
									xbar /= (perend - perstart + 1);
									mymaxvals[tid] = xbar;
						} else {
        xbar = ( (perlen-1) * xbar + sdata[perend] ) / perlen;
						}
						//update the mymaxvals[tid] if the next longer subsequence has a higher mean
						if (xbar > mymaxvals[tid]) {
         mymaxvals[tid] = xbar;
									mystartmaxes[tid] = perstart;
									myendmaxes[tid] = perend;
						}
				}
		} else {
    mymaxvals[tid] = 0;//initialize it the smallest number
		}
//  mymaxvals[tid] = sdata[tid]; 
		__syncthreads(); //sync to make sure each thread in this block has done with the for loop

  // get the highest among the mymaxvals using reduce
  for (int s = blockDim.x/2; s > 0; s>>=1) {
     if (tid < s ) {
       if(mymaxvals[tid+s] > mymaxvals[tid]) {
						   	mymaxvals[tid] = 	mymaxvals[tid+s]; 
          mystartmaxes[tid] = mystartmaxes[tid + s];
									 myendmaxes[tid] = myendmaxes[tid + s];	
							}	
     }
     __syncthreads();
  }
  // the maximum among the mymaxvals in this block
  if(tid == 0) {
  dmaxarr[blockIdx.x] = mymaxvals[0];
  }
}


	.text
	.file	"HW3_small_n.hip"
	.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
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	movslq	%ebp, %r14
	leaq	(,%r14,4), %rdi
	movq	%rdi, 32(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, %rbx
	testl	%r14d, %r14d
	jle	.LBB0_3
# %bb.1:                                # %.lr.ph.preheader
	leaq	1(%r14), %rax
	movl	%ebp, %ecx
	movq	%rbx, %rdx
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ecx, %xmm0
	movss	%xmm0, (%rdx)
	decq	%rax
	addq	$4, %rdx
	decl	%ecx
	cmpq	$1, %rax
	jg	.LBB0_2
.LBB0_3:                                # %._crit_edge
	leal	7(%r14), %eax
	leal	14(%r14), %r13d
	testl	%eax, %eax
	cmovnsl	%eax, %r13d
	sarl	$3, %r13d
	movslq	%r13d, %r12
	shlq	$2, %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rbp, 24(%rsp)                  # 8-byte Spill
	leaq	16(%rsp), %rdi
	movq	32(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rax
	movq	(%rax), %rdi
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	%rbx, %rsi
	movq	%rbp, %rdx
	movq	%rax, %rbp
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r13, %rdi
	btsq	$32, %rdi
	leaq	96(,%r14,4), %r8
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$8, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_5
# %bb.4:
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	%ebp, %edx
	movl	4(%rsp), %ecx                   # 4-byte Reload
	callq	_Z38__device_stub__parallel_max_each_chunkPfS_ii
.LBB0_5:
	callq	hipDeviceSynchronize
	movq	8(%rsp), %rsi
	movq	%r15, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r12, %rdi
	callq	malloc
	movl	$.L.str.2, %edi
	testl	%ebp, %ebp
	jle	.LBB0_17
# %bb.6:                                # %.lr.ph76
	movq	%rax, %r12
	movl	4(%rsp), %edx                   # 4-byte Reload
	movl	%edx, %eax
	shrl	$31, %eax
	addl	%edx, %eax
	sarl	%eax
	movslq	%eax, %rcx
	movslq	%edx, %rdx
	cmpl	$2, %r13d
	movl	$1, %eax
	cmovgel	%r13d, %eax
	subq	%rdx, %r14
	leaq	(%rbx,%rcx,4), %rcx
	shlq	$3, %rax
	xorl	%edx, %edx
	movq	%r12, %rsi
.LBB0_7:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cmpq	%r14, %rdx
	jg	.LBB0_9
# %bb.8:                                #   in Loop: Header=BB0_7 Depth=1
	movss	(%rcx,%rdx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
.LBB0_9:                                #   in Loop: Header=BB0_7 Depth=1
	movss	%xmm0, (%rsi)
	addq	$8, %rdx
	addq	$4, %rsi
	cmpq	%rdx, %rax
	jne	.LBB0_7
# %bb.10:                               # %.preheader72
	testl	%ebp, %ebp
	jle	.LBB0_17
# %bb.11:                               # %.lr.ph79.preheader
	cmpl	$2, %r13d
	movl	$1, %r14d
	cmovgel	%r13d, %r14d
	movb	$1, %bpl
	xorl	%r13d, %r13d
.LBB0_12:                               # %.lr.ph79
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r12,%r13,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	(%r15,%r13,4), %xmm1
	movl	$.L.str, %edi
	movl	%r13d, %esi
	movb	$2, %al
	callq	printf
	testb	$1, %bpl
	je	.LBB0_13
# %bb.14:                               #   in Loop: Header=BB0_12 Depth=1
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	cmpeqss	(%r15,%r13,4), %xmm0
	movd	%xmm0, %ebp
	andl	$1, %ebp
	jmp	.LBB0_15
.LBB0_13:                               #   in Loop: Header=BB0_12 Depth=1
	xorl	%ebp, %ebp
.LBB0_15:                               #   in Loop: Header=BB0_12 Depth=1
	incq	%r13
	cmpq	%r13, %r14
	jne	.LBB0_12
# %bb.16:                               # %._crit_edge80.loopexit
	movl	$.L.str.2, %eax
	movl	$.L.str.3, %edi
	testb	%bpl, %bpl
	cmovneq	%rax, %rdi
	movq	24(%rsp), %rbp                  # 8-byte Reload
.LBB0_17:                               # %._crit_edge80
	movq	%rdi, %r14
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	leal	-1(%rbp), %eax
	cmpl	$13, %eax
	ja	.LBB0_20
# %bb.18:                               # %.lr.ph82.preheader
	movl	%ebp, %r15d
	xorl	%r14d, %r14d
.LBB0_19:                               # %.lr.ph82
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r14,4), %xmm0
	movl	$.L.str.5, %edi
	movl	%r14d, %esi
	movb	$1, %al
	callq	printf
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB0_19
.LBB0_20:                               # %.loopexit
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB0_22
# %bb.21:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.6, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB0_22:
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$40, %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_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z38__device_stub__parallel_max_each_chunkPfS_ii # -- Begin function _Z38__device_stub__parallel_max_each_chunkPfS_ii
	.type	_Z38__device_stub__parallel_max_each_chunkPfS_ii,@function
_Z38__device_stub__parallel_max_each_chunkPfS_ii: # @_Z38__device_stub__parallel_max_each_chunkPfS_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	$112, %rsp
	.cfi_def_cfa_offset 160
	.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	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%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	$_Z23parallel_max_each_chunkPfS_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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	_Z38__device_stub__parallel_max_each_chunkPfS_ii, .Lfunc_end1-_Z38__device_stub__parallel_max_each_chunkPfS_ii
	.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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z23parallel_max_each_chunkPfS_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z23parallel_max_each_chunkPfS_ii,@object # @_Z23parallel_max_each_chunkPfS_ii
	.section	.rodata,"a",@progbits
	.globl	_Z23parallel_max_each_chunkPfS_ii
	.p2align	3, 0x0
_Z23parallel_max_each_chunkPfS_ii:
	.quad	_Z38__device_stub__parallel_max_each_chunkPfS_ii
	.size	_Z23parallel_max_each_chunkPfS_ii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"max of block  %d,  %f %f\n "
	.size	.L.str, 27

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"right\n"
	.size	.L.str.2, 7

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"wrong\n"
	.size	.L.str.3, 7

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"element  %d,  %f\n "
	.size	.L.str.5, 19

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"CUDA error: %s\n"
	.size	.L.str.6, 16

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z23parallel_max_each_chunkPfS_ii"
	.size	.L__unnamed_1, 34

	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"\n--------correct or wrong---------"
	.size	.Lstr, 35

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\n--------1d array---------"
	.size	.Lstr.1, 27

	.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 _Z38__device_stub__parallel_max_each_chunkPfS_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z23parallel_max_each_chunkPfS_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z23parallel_max_each_chunkPfS_ii ; -- Begin function _Z23parallel_max_each_chunkPfS_ii
	.globl	_Z23parallel_max_each_chunkPfS_ii
	.p2align	8
	.type	_Z23parallel_max_each_chunkPfS_ii,@function
_Z23parallel_max_each_chunkPfS_ii:      ; @_Z23parallel_max_each_chunkPfS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b64 s[6:7], s[0:1], 0x10
	s_mov_b32 s4, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s5, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_cvt_f32_u32_e32 v1, s5
	s_sub_i32 s3, 0, s5
	s_add_i32 s8, s6, s5
	s_add_i32 s8, s8, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	v_cvt_u32_f32_e32 v1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_readfirstlane_b32 s2, v1
	s_mul_i32 s3, s3, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s3, s2, s3
	s_add_i32 s9, s2, s3
	s_load_b128 s[0:3], s[0:1], 0x0
	s_mul_hi_u32 s9, s8, s9
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s10, s9, s5
	s_sub_i32 s8, s8, s10
	s_add_i32 s10, s9, 1
	s_sub_i32 s11, s8, s5
	s_cmp_ge_u32 s8, s5
	s_cselect_b32 s9, s10, s9
	s_cselect_b32 s8, s11, s8
	s_add_i32 s10, s9, 1
	s_cmp_ge_u32 s8, s5
	s_cselect_b32 s8, s10, s9
	s_mov_b32 s9, 0
	s_cmp_lt_i32 s8, 1
	s_cbranch_scc1 .LBB0_5
; %bb.1:                                ; %.lr.ph
	v_mul_lo_u32 v1, s8, v0
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_lshl_add_u32 v4, v1, 2, 0
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s2, v2
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v3, vcc_lo
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	v_add_nc_u32_e32 v5, s9, v1
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s6, v5
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	global_load_b32 v5, v[2:3], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v4, v5
.LBB0_4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s2
	v_add_co_u32 v2, vcc_lo, v2, 4
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	v_add_nc_u32_e32 v4, 4, v4
	s_add_i32 s9, s9, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lt_i32 s9, s8
	s_cbranch_scc1 .LBB0_2
.LBB0_5:                                ; %._crit_edge
	v_mad_u64_u32 v[1:2], null, s4, s5, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_sub_i32 s2, s6, s7
	s_barrier
	buffer_gl0_inv
	v_cmp_ge_i32_e32 vcc_lo, s2, v1
	s_and_saveexec_b32 s2, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s2, exec_lo, s2
	s_cbranch_execz .LBB0_21
; %bb.6:                                ; %.preheader83
	v_sub_nc_u32_e32 v6, s6, v1
	s_mov_b32 s3, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_le_i32_e64 s7, v6
	s_cbranch_execz .LBB0_20
; %bb.7:                                ; %.lr.ph93
	v_cvt_f64_i32_e32 v[2:3], s7
	v_lshl_add_u32 v7, v0, 2, 0
	v_cvt_f32_i32_e32 v8, v1
	v_lshl_add_u32 v9, v1, 2, 0
	s_cmp_gt_i32 s7, 0
	s_mov_b32 s8, 0
	ds_load_b32 v11, v7
	s_cselect_b32 s6, -1, 0
	s_mov_b32 s9, s7
                                        ; implicit-def: $vgpr4_vgpr5
.LBB0_8:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_14 Depth 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v12, s9, v1
	s_cmp_lg_u32 s9, s7
	v_add_nc_u32_e32 v10, -1, v12
	s_cbranch_scc0 .LBB0_10
; %bb.9:                                ;   in Loop: Header=BB0_8 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_lshl_add_u32 v13, v10, 2, 0
	s_add_i32 s10, s9, -1
	v_cvt_f64_i32_e32 v[17:18], s9
	ds_load_b32 v15, v13
	v_cvt_f64_i32_e32 v[13:14], s10
	s_mov_b32 s10, 0
	s_waitcnt lgkmcnt(0)
	v_cvt_f64_f32_e32 v[15:16], v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[4:5], v[4:5], v[13:14], v[15:16]
	v_div_scale_f64 v[13:14], null, v[17:18], v[17:18], v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[15:16], v[13:14]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[19:20], -v[13:14], v[15:16], 1.0
	v_fma_f64 v[15:16], v[15:16], v[19:20], v[15:16]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[19:20], -v[13:14], v[15:16], 1.0
	v_fma_f64 v[15:16], v[15:16], v[19:20], v[15:16]
	v_div_scale_f64 v[19:20], vcc_lo, v[4:5], v[17:18], v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[21:22], v[19:20], v[15:16]
	v_fma_f64 v[13:14], -v[13:14], v[21:22], v[19:20]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[13:14], v[13:14], v[15:16], v[21:22]
	v_div_fixup_f64 v[4:5], v[13:14], v[17:18], v[4:5]
	s_branch .LBB0_11
.LBB0_10:                               ;   in Loop: Header=BB0_8 Depth=1
	s_mov_b32 s10, -1
                                        ; implicit-def: $vgpr4_vgpr5
                                        ; implicit-def: $vgpr11
.LBB0_11:                               ; %Flow122
                                        ;   in Loop: Header=BB0_8 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s10
	s_cbranch_vccnz .LBB0_17
; %bb.12:                               ; %.preheader
                                        ;   in Loop: Header=BB0_8 Depth=1
	v_mov_b32_e32 v4, 0
	v_mov_b32_e32 v5, 0
	s_and_not1_b32 vcc_lo, exec_lo, s6
	s_cbranch_vccnz .LBB0_16
; %bb.13:                               ; %.lr.ph88.preheader
                                        ;   in Loop: Header=BB0_8 Depth=1
	s_waitcnt lgkmcnt(0)
	v_mov_b32_e32 v11, v9
	v_mov_b32_e32 v13, v1
	s_mov_b32 s10, 0
.LBB0_14:                               ; %.lr.ph88
                                        ;   Parent Loop BB0_8 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	ds_load_b32 v14, v11
	v_add_nc_u32_e32 v13, 1, v13
	v_add_nc_u32_e32 v11, 4, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_cmp_ge_i32_e32 vcc_lo, v13, v12
	s_or_b32 s10, vcc_lo, s10
	s_waitcnt lgkmcnt(0)
	v_cvt_f64_f32_e32 v[14:15], v14
	v_add_f64 v[4:5], v[4:5], v[14:15]
	s_and_not1_b32 exec_lo, exec_lo, s10
	s_cbranch_execnz .LBB0_14
; %bb.15:                               ; %Flow120
                                        ;   in Loop: Header=BB0_8 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
.LBB0_16:                               ; %._crit_edge89
                                        ;   in Loop: Header=BB0_8 Depth=1
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f64 v[11:12], null, v[2:3], v[2:3], v[4:5]
	v_rcp_f64_e32 v[13:14], v[11:12]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[15:16], -v[11:12], v[13:14], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[13:14], v[13:14], v[15:16], v[13:14]
	v_fma_f64 v[15:16], -v[11:12], v[13:14], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fma_f64 v[13:14], v[13:14], v[15:16], v[13:14]
	v_div_scale_f64 v[15:16], vcc_lo, v[4:5], v[2:3], v[4:5]
	v_mul_f64 v[17:18], v[15:16], v[13:14]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[11:12], -v[11:12], v[17:18], v[15:16]
	v_div_fmas_f64 v[11:12], v[11:12], v[13:14], v[17:18]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f64 v[4:5], v[11:12], v[2:3], v[4:5]
	v_cvt_f32_f64_e32 v11, v[4:5]
	ds_store_b32 v7, v11
.LBB0_17:                               ;   in Loop: Header=BB0_8 Depth=1
	s_waitcnt lgkmcnt(0)
	v_cvt_f64_f32_e32 v[12:13], v11
	s_mov_b32 s10, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_f64_e32 v[4:5], v[12:13]
	s_cbranch_execz .LBB0_19
; %bb.18:                               ;   in Loop: Header=BB0_8 Depth=1
	v_cvt_f32_f64_e32 v11, v[4:5]
	v_cvt_f32_i32_e32 v10, v10
	ds_store_b32 v7, v11
	ds_store_b32 v7, v8
	ds_store_b32 v7, v10
.LBB0_19:                               ;   in Loop: Header=BB0_8 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	v_cmp_ge_i32_e32 vcc_lo, s9, v6
	s_add_i32 s9, s9, 1
	s_or_b32 s8, vcc_lo, s8
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s8
	s_cbranch_execnz .LBB0_8
.LBB0_20:                               ; %Flow125
	s_or_b32 exec_lo, exec_lo, s3
.LBB0_21:                               ; %Flow126
	s_or_saveexec_b32 s2, s2
	v_lshl_add_u32 v1, v0, 2, 0
	s_xor_b32 exec_lo, exec_lo, s2
	s_cbranch_execz .LBB0_23
; %bb.22:
	v_mov_b32_e32 v2, 0
	ds_store_b32 v1, v2
.LBB0_23:                               ; %.loopexit
	s_or_b32 exec_lo, exec_lo, s2
	s_cmp_lt_u32 s5, 2
	s_waitcnt vmcnt(0) lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
.LBB0_24:                               ; %.loopexit
                                        ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_29
; %bb.25:                               ;   in Loop: Header=BB0_24 Depth=1
	s_mov_b32 s2, s5
	s_lshr_b32 s5, s5, 1
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_u32_e64 s5, v0
	s_cbranch_execz .LBB0_28
; %bb.26:                               ;   in Loop: Header=BB0_24 Depth=1
	v_lshl_add_u32 v2, s5, 2, v1
	ds_load_b32 v2, v2
	ds_load_b32 v3, v1
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_f32_e32 vcc_lo, v2, v3
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_28
; %bb.27:                               ;   in Loop: Header=BB0_24 Depth=1
	s_lshl_b32 s6, s5, 2
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_nc_u32_e32 v3, s6, v1
	ds_load_b32 v4, v3
	ds_load_b32 v3, v3
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(2)
	ds_store_b32 v1, v4
	s_waitcnt lgkmcnt(2)
	ds_store_b32 v1, v3
.LBB0_28:                               ;   in Loop: Header=BB0_24 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_u32 s2, 4
	s_branch .LBB0_24
.LBB0_29:                               ; %._crit_edge99
	s_mov_b32 s5, 0
	s_mov_b32 s2, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_31
; %bb.30:
	v_mov_b32_e32 v0, 0
	s_lshl_b64 s[2:3], s[4:5], 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_31:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z23parallel_max_each_chunkPfS_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 23
		.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	_Z23parallel_max_each_chunkPfS_ii, .Lfunc_end0-_Z23parallel_max_each_chunkPfS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1200
; NumSgprs: 18
; NumVgprs: 23
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 23
; 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z23parallel_max_each_chunkPfS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z23parallel_max_each_chunkPfS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     23
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
