#include <cuda.h>

__global__ void deviceburst(float *x, float *initsums, int n, int k, float *bigmaxs, int *startend) {
  int partition = (n - k + 1) / (blockDim.x * gridDim.x) + 1;
  int me = blockIdx.x * blockDim.x + threadIdx.x;

  int left = me * partition;
  int left_limit = left + partition;
  int length = k;

  float sum = initsums[me];
  float mean = sum / length;

  startend[me * 2] = left;
  startend[me * 2 + 1] = left + length - 1;
  bigmaxs[me] = mean;

  while (left + length < n && left < left_limit) {
    float next = x[left + length];
    if (next > mean) {
      if (next > x[left]) {
        sum = sum + next - x[left];
        left += 1;
      } else {
        sum = sum + next;
        length += 1;
      }
    } else {
      for (int i = 0; i <= length - k + 1; i++) {
        sum = sum - x[left];
      }
      left += length - k + 1;
      length = k;
      sum = sum + x[left + length];
    }
    mean = sum / length;
    if (mean > bigmaxs[me]) {
      startend[me * 2] = left;
      startend[me * 2 + 1] = left + length - 1;
      bigmaxs[me] = mean;
    }
  }
}

float arraysum(float *x, int n, int start, int end) {
  float sum = 0;
  for (int i = start; i < n && i < end; i++) {
    sum = sum + x[i];
  }
  return sum;
}

int arraymaxidx(float *x, int n) {
  float max = x[0];
  int maxidx = 0;
  for (int i = 1; i < n; i++) {
    if (x[i] > max) {
      max = x[i];
      maxidx = i;
    }
  }
  return maxidx;
}

void maxburst(float *x, int n, int k, int *startend, float *bigmax) {
  int gridDimX = 128;
  int blockDimX = 256;
  int threads_count = gridDimX * blockDimX;

  float *device_x;
  cudaMalloc((void **)&device_x, sizeof(float) * n);
  cudaMemcpy(device_x, x, sizeof(float) * n, cudaMemcpyHostToDevice);

  float *device_bigmaxs;
  cudaMalloc((void **)&device_bigmaxs, sizeof(float) * threads_count);

  int *device_startends;
  cudaMalloc((void **)&device_startends, sizeof(int) * threads_count * 2);

  float *initsums = (float *)malloc(sizeof(float) * threads_count);
  int partition = (n - k + 1) / threads_count + 1;
  for (int i = 0; i < threads_count; i++) {
    initsums[i] = arraysum(x, n, i * partition, k);
  }
  float *device_initsums;
  cudaMalloc((void **)&device_initsums, sizeof(float) * threads_count);
  cudaMemcpy(device_initsums, initsums, sizeof(float) * threads_count, cudaMemcpyHostToDevice);
  free(initsums);

  dim3 dimGrid(gridDimX, 1);
  dim3 dimBlock(blockDimX, 1, 1);
  deviceburst<<<dimGrid, dimBlock>>>(device_x, device_initsums, n, k, device_bigmaxs, device_startends);
  cudaThreadSynchronize();

  cudaFree(device_x);

  float *bigmaxs = (float *)malloc(sizeof(float) * threads_count);
  cudaMemcpy(bigmaxs, device_bigmaxs, sizeof(float) * threads_count, cudaMemcpyDeviceToHost);
  cudaFree(device_bigmaxs);

  int *startends = (int *)malloc(sizeof(int) * threads_count * 2);
  cudaMemcpy(startends, device_startends, sizeof(int) * threads_count * 2, cudaMemcpyDeviceToHost);
  cudaFree(device_startends);

  int maxidx = arraymaxidx(bigmaxs, threads_count);
  bigmax[0] = bigmaxs[maxidx];
  startend[0] = startends[maxidx * 2];
  startend[1] = startends[maxidx * 2 + 1];
}

// -------
// Testing
//
// CSIF
// clear && /usr/local/cuda-8.0/bin/nvcc -Wno-deprecated-gpu-targets -g -G Skip.cu && a.out

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

int main() {
  int n = 50000;
  int k = 20000;
  float *x = (float *)malloc(sizeof(float) * n);
  srand(0);
  for (int i = 0; i < n; i++) {
    x[i] = (float)rand() / (float)(RAND_MAX / 100.0);
  }
  int startend[] = {0, 0};
  float bigmax = 0;
  struct timeval start;
  gettimeofday(&start, NULL);
  maxburst(x, n, k, startend, &bigmax);
  struct timeval end;
  gettimeofday(&end, NULL);
  float duration = (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_usec - start.tv_usec) / 1000.0;
  printf("%f (from %d to %d) (%fms)\n", bigmax, startend[0], startend[1], duration);
}

	.file	"tmpxft_0027d683_00000000-6_Skip2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z8arraysumPfiii
	.type	_Z8arraysumPfiii, @function
_Z8arraysumPfiii:
.LFB2008:
	.cfi_startproc
	endbr64
	cmpl	%ecx, %esi
	movslq	%edx, %rdx
	xorps	%xmm0, %xmm0
	cmovg	%ecx, %esi
.L3:
	cmpl	%edx, %esi
	jle	.L6
	addss	(%rdi,%rdx,4), %xmm0
	incq	%rdx
	jmp	.L3
.L6:
	ret
	.cfi_endproc
.LFE2008:
	.size	_Z8arraysumPfiii, .-_Z8arraysumPfiii
	.globl	_Z11arraymaxidxPfi
	.type	_Z11arraymaxidxPfi, @function
_Z11arraymaxidxPfi:
.LFB2009:
	.cfi_startproc
	endbr64
	movss	(%rdi), %xmm0
	movl	$1, %eax
	xorl	%edx, %edx
.L8:
	cmpl	%eax, %esi
	jle	.L13
	movss	(%rdi,%rax,4), %xmm1
	comiss	%xmm0, %xmm1
	maxss	%xmm0, %xmm1
	cmova	%eax, %edx
	movaps	%xmm1, %xmm0
	incq	%rax
	jmp	.L8
.L13:
	movl	%edx, %eax
	ret
	.cfi_endproc
.LFE2009:
	.size	_Z11arraymaxidxPfi, .-_Z11arraymaxidxPfi
	.globl	_Z39__device_stub__Z11deviceburstPfS_iiS_PiPfS_iiS_Pi
	.type	_Z39__device_stub__Z11deviceburstPfS_iiS_PiPfS_iiS_Pi, @function
_Z39__device_stub__Z11deviceburstPfS_iiS_PiPfS_iiS_Pi:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movl	%edx, 28(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 24(%rsp)
	leaq	64(%rsp), %rcx
	movq	%r8, 16(%rsp)
	movq	%r9, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z11deviceburstPfS_iiS_Pi(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L14:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z39__device_stub__Z11deviceburstPfS_iiS_PiPfS_iiS_Pi, .-_Z39__device_stub__Z11deviceburstPfS_iiS_PiPfS_iiS_Pi
	.globl	_Z11deviceburstPfS_iiS_Pi
	.type	_Z11deviceburstPfS_iiS_Pi, @function
_Z11deviceburstPfS_iiS_Pi:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z11deviceburstPfS_iiS_PiPfS_iiS_Pi
	.cfi_endproc
.LFE2056:
	.size	_Z11deviceburstPfS_iiS_Pi, .-_Z11deviceburstPfS_iiS_Pi
	.globl	_Z8maxburstPfiiPiS_
	.type	_Z8maxburstPfiiPiS_, @function
_Z8maxburstPfiiPiS_:
.LFB2010:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movslq	%esi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%r8, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rcx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%r14, %rbx
	salq	$2, %r14
	movq	%r14, %rsi
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	movq	%r14, %rdx
	movq	%r15, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	8(%rsp), %rdi
	movl	$131072, %esi
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	movl	$131072, %edi
	call	malloc@PLT
	movl	$32768, %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%rax, %r14
	movl	%ebx, %eax
	subl	%r12d, %eax
	incl	%eax
	cltd
	idivl	%ecx
	incl	%eax
.L20:
	movl	%r9d, %edx
	movl	%r12d, %ecx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	_Z8arraysumPfiii
	addl	%eax, %r9d
	movss	%xmm0, (%r14,%r8,4)
	incq	%r8
	cmpq	$32768, %r8
	jne	.L20
	leaq	24(%rsp), %rdi
	movl	$131072, %esi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r14, %rsi
	movl	$131072, %edx
	call	cudaMemcpy@PLT
	movq	%r14, %rdi
	call	free@PLT
	movl	$16777217, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$33554433, %edi
	salq	$8, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	salq	$7, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	movq	16(%rsp), %r9
	movq	8(%rsp), %r8
	movl	%r12d, %ecx
	movl	%ebx, %edx
	movq	24(%rsp), %rsi
	movq	(%rsp), %rdi
	call	_Z39__device_stub__Z11deviceburstPfS_iiS_PiPfS_iiS_Pi
.L21:
	call	cudaThreadSynchronize@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movl	$131072, %edi
	call	malloc@PLT
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movl	$131072, %edx
	movq	%rax, %rdi
	movq	%rax, %r12
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movl	$262144, %edi
	call	malloc@PLT
	movq	16(%rsp), %rsi
	movl	$262144, %edx
	movl	$2, %ecx
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	$32768, %esi
	movq	%r12, %rdi
	call	_Z11arraymaxidxPfi
	movslq	%eax, %rdx
	addl	%eax, %eax
	movss	(%r12,%rdx,4), %xmm0
	movslq	%eax, %rdx
	movl	(%rbx,%rdx,4), %eax
	movss	%xmm0, 0(%r13)
	movl	%eax, 0(%rbp)
	movl	4(%rbx,%rdx,4), %eax
	movl	%eax, 4(%rbp)
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	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
.LFE2010:
	.size	_Z8maxburstPfiiPiS_, .-_Z8maxburstPfiiPiS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	"%f (from %d to %d) (%fms)\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	$200000, %edi
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$72, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	xorl	%edi, %edi
	movq	%rax, %rbx
	call	srand@PLT
.L26:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	divss	.LC1(%rip), %xmm0
	movss	%xmm0, (%rbx,%rbp,4)
	incq	%rbp
	cmpq	$50000, %rbp
	jne	.L26
	xorl	%eax, %eax
	xorl	%esi, %esi
	leaq	16(%rsp), %rdi
	movl	$0x00000000, 12(%rsp)
	movq	%rax, 48(%rsp)
	call	gettimeofday@PLT
	leaq	48(%rsp), %rcx
	movl	$20000, %edx
	movq	%rbx, %rdi
	leaq	12(%rsp), %r8
	movl	$50000, %esi
	call	_Z8maxburstPfiiPiS_
	xorl	%esi, %esi
	leaq	32(%rsp), %rdi
	call	gettimeofday@PLT
	movq	32(%rsp), %rax
	subq	16(%rsp), %rax
	leaq	.LC3(%rip), %rsi
	cvtsi2sdq	%rax, %xmm1
	movq	40(%rsp), %rax
	subq	24(%rsp), %rax
	movl	$2, %edi
	cvtsi2sdq	%rax, %xmm0
	movl	52(%rsp), %ecx
	movl	48(%rsp), %edx
	movb	$2, %al
	movsd	.LC2(%rip), %xmm2
	mulsd	%xmm2, %xmm1
	divsd	%xmm2, %xmm0
	addsd	%xmm0, %xmm1
	cvtss2sd	12(%rsp), %xmm0
	cvtsd2ss	%xmm1, %xmm1
	cvtss2sd	%xmm1, %xmm1
	call	__printf_chk@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$72, %rsp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC4:
	.string	"_Z11deviceburstPfS_iiS_Pi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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	.LC4(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z11deviceburstPfS_iiS_Pi(%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
.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	1269028618
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	0
	.long	1083129856
	.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>

__global__ void deviceburst(float *x, float *initsums, int n, int k, float *bigmaxs, int *startend) {
  int partition = (n - k + 1) / (blockDim.x * gridDim.x) + 1;
  int me = blockIdx.x * blockDim.x + threadIdx.x;

  int left = me * partition;
  int left_limit = left + partition;
  int length = k;

  float sum = initsums[me];
  float mean = sum / length;

  startend[me * 2] = left;
  startend[me * 2 + 1] = left + length - 1;
  bigmaxs[me] = mean;

  while (left + length < n && left < left_limit) {
    float next = x[left + length];
    if (next > mean) {
      if (next > x[left]) {
        sum = sum + next - x[left];
        left += 1;
      } else {
        sum = sum + next;
        length += 1;
      }
    } else {
      for (int i = 0; i <= length - k + 1; i++) {
        sum = sum - x[left];
      }
      left += length - k + 1;
      length = k;
      sum = sum + x[left + length];
    }
    mean = sum / length;
    if (mean > bigmaxs[me]) {
      startend[me * 2] = left;
      startend[me * 2 + 1] = left + length - 1;
      bigmaxs[me] = mean;
    }
  }
}

float arraysum(float *x, int n, int start, int end) {
  float sum = 0;
  for (int i = start; i < n && i < end; i++) {
    sum = sum + x[i];
  }
  return sum;
}

int arraymaxidx(float *x, int n) {
  float max = x[0];
  int maxidx = 0;
  for (int i = 1; i < n; i++) {
    if (x[i] > max) {
      max = x[i];
      maxidx = i;
    }
  }
  return maxidx;
}

void maxburst(float *x, int n, int k, int *startend, float *bigmax) {
  int gridDimX = 128;
  int blockDimX = 256;
  int threads_count = gridDimX * blockDimX;

  float *device_x;
  hipMalloc((void **)&device_x, sizeof(float) * n);
  hipMemcpy(device_x, x, sizeof(float) * n, hipMemcpyHostToDevice);

  float *device_bigmaxs;
  hipMalloc((void **)&device_bigmaxs, sizeof(float) * threads_count);

  int *device_startends;
  hipMalloc((void **)&device_startends, sizeof(int) * threads_count * 2);

  float *initsums = (float *)malloc(sizeof(float) * threads_count);
  int partition = (n - k + 1) / threads_count + 1;
  for (int i = 0; i < threads_count; i++) {
    initsums[i] = arraysum(x, n, i * partition, k);
  }
  float *device_initsums;
  hipMalloc((void **)&device_initsums, sizeof(float) * threads_count);
  hipMemcpy(device_initsums, initsums, sizeof(float) * threads_count, hipMemcpyHostToDevice);
  free(initsums);

  dim3 dimGrid(gridDimX, 1);
  dim3 dimBlock(blockDimX, 1, 1);
  deviceburst<<<dimGrid, dimBlock>>>(device_x, device_initsums, n, k, device_bigmaxs, device_startends);
  hipDeviceSynchronize();

  hipFree(device_x);

  float *bigmaxs = (float *)malloc(sizeof(float) * threads_count);
  hipMemcpy(bigmaxs, device_bigmaxs, sizeof(float) * threads_count, hipMemcpyDeviceToHost);
  hipFree(device_bigmaxs);

  int *startends = (int *)malloc(sizeof(int) * threads_count * 2);
  hipMemcpy(startends, device_startends, sizeof(int) * threads_count * 2, hipMemcpyDeviceToHost);
  hipFree(device_startends);

  int maxidx = arraymaxidx(bigmaxs, threads_count);
  bigmax[0] = bigmaxs[maxidx];
  startend[0] = startends[maxidx * 2];
  startend[1] = startends[maxidx * 2 + 1];
}

// -------
// Testing
//
// CSIF
// clear && /usr/local/cuda-8.0/bin/nvcc -Wno-deprecated-gpu-targets -g -G Skip.cu && a.out

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

int main() {
  int n = 50000;
  int k = 20000;
  float *x = (float *)malloc(sizeof(float) * n);
  srand(0);
  for (int i = 0; i < n; i++) {
    x[i] = (float)rand() / (float)(RAND_MAX / 100.0);
  }
  int startend[] = {0, 0};
  float bigmax = 0;
  struct timeval start;
  gettimeofday(&start, NULL);
  maxburst(x, n, k, startend, &bigmax);
  struct timeval end;
  gettimeofday(&end, NULL);
  float duration = (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_usec - start.tv_usec) / 1000.0;
  printf("%f (from %d to %d) (%fms)\n", bigmax, startend[0], startend[1], duration);
}

	.text
	.file	"Skip2.hip"
	.globl	_Z26__device_stub__deviceburstPfS_iiS_Pi # -- Begin function _Z26__device_stub__deviceburstPfS_iiS_Pi
	.type	_Z26__device_stub__deviceburstPfS_iiS_Pi,@function
_Z26__device_stub__deviceburstPfS_iiS_Pi: # @_Z26__device_stub__deviceburstPfS_iiS_Pi
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	32(%rsp), %r8
	movq	%r9, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%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	$_Z11deviceburstPfS_iiS_Pi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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	_Z26__device_stub__deviceburstPfS_iiS_Pi, .Lfunc_end0-_Z26__device_stub__deviceburstPfS_iiS_Pi
	.cfi_endproc
                                        # -- End function
	.globl	_Z8arraysumPfiii                # -- Begin function _Z8arraysumPfiii
	.type	_Z8arraysumPfiii,@function
_Z8arraysumPfiii:                       # @_Z8arraysumPfiii
	.cfi_startproc
# %bb.0:
	cmpl	%ecx, %esi
	cmovll	%esi, %ecx
	xorps	%xmm0, %xmm0
	cmpl	%edx, %ecx
	jle	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	movslq	%edx, %rax
	movslq	%ecx, %rcx
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	addss	(%rdi,%rax,4), %xmm0
	incq	%rax
	cmpq	%rax, %rcx
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	retq
.Lfunc_end1:
	.size	_Z8arraysumPfiii, .Lfunc_end1-_Z8arraysumPfiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z11arraymaxidxPfi              # -- Begin function _Z11arraymaxidxPfi
	.type	_Z11arraymaxidxPfi,@function
_Z11arraymaxidxPfi:                     # @_Z11arraymaxidxPfi
	.cfi_startproc
# %bb.0:
	xorl	%eax, %eax
	cmpl	$2, %esi
	jl	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	movss	(%rdi), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movl	%esi, %ecx
	xorl	%eax, %eax
	movl	$1, %edx
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%rdx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	cmoval	%edx, %eax
	maxss	%xmm0, %xmm1
	incq	%rdx
	movaps	%xmm1, %xmm0
	cmpq	%rdx, %rcx
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	retq
.Lfunc_end2:
	.size	_Z11arraymaxidxPfi, .Lfunc_end2-_Z11arraymaxidxPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z8maxburstPfiiPiS_             # -- Begin function _Z8maxburstPfiiPiS_
	.type	_Z8maxburstPfiiPiS_,@function
_Z8maxburstPfiiPiS_:                    # @_Z8maxburstPfiiPiS_
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	%r8, 32(%rsp)                   # 8-byte Spill
	movq	%rcx, 40(%rsp)                  # 8-byte Spill
	movl	%edx, %ebp
	movl	%esi, %r15d
	movq	%rdi, %r12
	movslq	%esi, %rbx
	leaq	(,%rbx,4), %r13
	leaq	24(%rsp), %r14
	movq	%r14, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	%r12, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	16(%rsp), %rdi
	movl	$131072, %esi                   # imm = 0x20000
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$262144, %esi                   # imm = 0x40000
	callq	hipMalloc
	movl	$131072, %edi                   # imm = 0x20000
	callq	malloc
	movq	%rax, %r13
	subl	%ebp, %ebx
	leal	1(%rbx), %eax
	leal	32768(%rbx), %edx
	movl	%ebp, %ecx
	cmovll	%r15d, %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %edx
	sarl	$15, %edx
	leal	1(%rdx), %esi
	movslq	%ecx, %rax
	movslq	%esi, %rcx
	movslq	%edx, %rdx
	leaq	4(,%rdx,4), %rsi
	notq	%rdx
	xorl	%edi, %edi
	movq	%rax, %r8
.LBB3_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_3 Depth 2
	movq	%rdi, %r9
	imulq	%rcx, %r9
	xorps	%xmm0, %xmm0
	cmpq	%rax, %r9
	jge	.LBB3_4
# %bb.2:                                # %.lr.ph.i.preheader
                                        #   in Loop: Header=BB3_1 Depth=1
	xorl	%r9d, %r9d
.LBB3_3:                                # %.lr.ph.i
                                        #   Parent Loop BB3_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	addss	(%r12,%r9,4), %xmm0
	incq	%r9
	cmpq	%r9, %r8
	jne	.LBB3_3
.LBB3_4:                                # %_Z8arraysumPfiii.exit
                                        #   in Loop: Header=BB3_1 Depth=1
	movss	%xmm0, (%r13,%rdi,4)
	incq	%rdi
	addq	%rdx, %r8
	addq	%rsi, %r12
	cmpq	$32768, %rdi                    # imm = 0x8000
	jne	.LBB3_1
# %bb.5:
	leaq	48(%rsp), %r14
	movl	$131072, %esi                   # imm = 0x20000
	movq	%r14, %rdi
	callq	hipMalloc
	movq	(%r14), %rdi
	movl	$131072, %edx                   # imm = 0x20000
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r13, %rdi
	callq	free
	movabsq	$4294967424, %rdi               # imm = 0x100000080
	leaq	128(%rdi), %rdx
	xorl	%r14d, %r14d
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.6:
	movq	24(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	16(%rsp), %r8
	movq	8(%rsp), %r9
	movl	%r15d, %edx
	movl	%ebp, %ecx
	callq	_Z26__device_stub__deviceburstPfS_iiS_Pi
.LBB3_7:
	callq	hipDeviceSynchronize
	movq	24(%rsp), %rdi
	callq	hipFree
	movl	$131072, %edi                   # imm = 0x20000
	callq	malloc
	movq	%rax, %r15
	movq	16(%rsp), %rsi
	movl	$131072, %edx                   # imm = 0x20000
	movq	%rax, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	$262144, %edi                   # imm = 0x40000
	callq	malloc
	movq	%rax, %r12
	movq	8(%rsp), %rsi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%rax, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	callq	hipFree
	movss	(%r15), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movl	$1, %eax
.LBB3_8:                                # %.lr.ph.i52
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r15,%rax,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	cmoval	%eax, %r14d
	maxss	%xmm0, %xmm1
	incq	%rax
	movaps	%xmm1, %xmm0
	cmpq	$32768, %rax                    # imm = 0x8000
	jne	.LBB3_8
# %bb.9:                                # %_Z11arraymaxidxPfi.exit
	movslq	%r14d, %rax
	movss	(%r15,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movq	32(%rsp), %rcx                  # 8-byte Reload
	movss	%xmm0, (%rcx)
	leal	(%rax,%rax), %ecx
	movslq	%ecx, %rcx
	movl	(%r12,%rcx,4), %ecx
	movq	40(%rsp), %rdx                  # 8-byte Reload
	movl	%ecx, (%rdx)
	leal	1(%rax,%rax), %eax
	cltq
	movl	(%r12,%rax,4), %eax
	movl	%eax, 4(%rdx)
	addq	$56, %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	_Z8maxburstPfiiPiS_, .Lfunc_end3-_Z8maxburstPfiiPiS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x4ba3d70a                      # float 21474836
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI4_1:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$200000, %edi                   # imm = 0x30D40
	callq	malloc
	movq	%rax, %r14
	xorl	%ebx, %ebx
	xorl	%edi, %edi
	callq	srand
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	.LCPI4_0(%rip), %xmm0
	movss	%xmm0, (%r14,%rbx,4)
	incq	%rbx
	cmpq	$50000, %rbx                    # imm = 0xC350
	jne	.LBB4_1
# %bb.2:
	leaq	16(%rsp), %rbx
	movq	$0, (%rbx)
	leaq	12(%rsp), %r15
	movl	$0, (%r15)
	leaq	40(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	%r14, %rdi
	movl	$50000, %esi                    # imm = 0xC350
	movl	$20000, %edx                    # imm = 0x4E20
	movq	%rbx, %rcx
	movq	%r15, %r8
	callq	_Z8maxburstPfiiPiS_
	leaq	24(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r14), %rax
	movq	8(%r14), %rcx
	subq	(%r12), %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm0
	subq	8(%r12), %rcx
	cvtsi2sd	%rcx, %xmm2
	divsd	%xmm1, %xmm2
	addsd	%xmm0, %xmm2
	xorps	%xmm1, %xmm1
	cvtsd2ss	%xmm2, %xmm1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r15), %xmm0
	movl	(%rbx), %esi
	movl	4(%rbx), %edx
	cvtss2sd	%xmm1, %xmm1
	movl	$.L.str, %edi
	movb	$2, %al
	callq	printf
	xorl	%eax, %eax
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	main, .Lfunc_end4-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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z11deviceburstPfS_iiS_Pi, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z11deviceburstPfS_iiS_Pi,@object # @_Z11deviceburstPfS_iiS_Pi
	.section	.rodata,"a",@progbits
	.globl	_Z11deviceburstPfS_iiS_Pi
	.p2align	3, 0x0
_Z11deviceburstPfS_iiS_Pi:
	.quad	_Z26__device_stub__deviceburstPfS_iiS_Pi
	.size	_Z11deviceburstPfS_iiS_Pi, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%f (from %d to %d) (%fms)\n"
	.size	.L.str, 27

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11deviceburstPfS_iiS_Pi"
	.size	.L__unnamed_1, 26

	.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 _Z26__device_stub__deviceburstPfS_iiS_Pi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z11deviceburstPfS_iiS_Pi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11deviceburstPfS_iiS_Pi ; -- Begin function _Z11deviceburstPfS_iiS_Pi
	.globl	_Z11deviceburstPfS_iiS_Pi
	.p2align	8
	.type	_Z11deviceburstPfS_iiS_Pi,@function
_Z11deviceburstPfS_iiS_Pi:              ; @_Z11deviceburstPfS_iiS_Pi
; %bb.0:
	s_clause 0x3
	s_load_b32 s2, s[0:1], 0x34
	s_load_b32 s3, s[0:1], 0x28
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[8:9], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_cvt_f32_i32_e32 v7, s9
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_add_co_u32 v4, vcc_lo, s6, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v3, vcc_lo
	s_mul_i32 s6, s3, s2
	s_sub_i32 s7, s8, s9
	v_cvt_f32_u32_e32 v0, s6
	global_load_b32 v8, v[4:5], off
	s_sub_i32 s3, 0, s6
	s_add_i32 s7, s7, 1
	v_lshlrev_b32_e32 v4, 1, v1
	v_rcp_iflag_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_waitcnt vmcnt(0)
	v_div_scale_f32 v10, vcc_lo, v8, v7, v8
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	v_div_scale_f32 v6, null, v7, v7, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_u32_f32_e32 v0, v0
	v_rcp_f32_e32 v9, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_readfirstlane_b32 s2, v0
	s_mul_i32 s3, s3, s2
	s_waitcnt_depctr 0xfff
	v_fma_f32 v0, -v6, v9, 1.0
	s_mul_hi_u32 s3, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(SALU_CYCLE_1)
	s_add_i32 s10, s2, s3
	s_load_b128 s[0:3], s[0:1], 0x18
	s_mul_hi_u32 s10, s7, s10
	v_fmac_f32_e32 v9, v0, v9
	s_mul_i32 s11, s10, s6
	s_sub_i32 s7, s7, s11
	s_add_i32 s11, s10, 1
	s_sub_i32 s12, s7, s6
	s_cmp_ge_u32 s7, s6
	v_mul_f32_e32 v11, v10, v9
	s_cselect_b32 s10, s11, s10
	s_cselect_b32 s7, s12, s7
	s_add_i32 s11, s10, 1
	s_cmp_ge_u32 s7, s6
	v_fma_f32 v0, -v6, v11, v10
	s_cselect_b32 s7, s11, s10
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_add_i32 s6, s7, 1
	s_cmp_lt_u32 s7, 0x7fffffff
	v_fmac_f32_e32 v11, v0, v9
	v_mul_lo_u32 v0, v1, s6
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, s0, s0, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_add_co_ci_u32_e64 v3, s0, s1, v3, s0
	v_fma_f32 v1, -v6, v11, v10
	s_cselect_b32 s0, -1, 0
	s_mov_b32 s1, 0
	v_add_nc_u32_e32 v6, s9, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_4)
	v_div_fmas_f32 v9, v1, v9, v11
	v_add_co_u32 v4, vcc_lo, s2, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s3, v5, vcc_lo
	v_cmp_gt_i32_e32 vcc_lo, s8, v6
	v_add3_u32 v1, s9, -1, v0
	v_div_fixup_f32 v9, v9, v7, v8
	s_and_b32 s0, vcc_lo, s0
	global_store_b64 v[4:5], v[0:1], off
	global_store_b32 v[2:3], v9, off
	s_and_saveexec_b32 s2, s0
	s_cbranch_execz .LBB0_17
; %bb.1:                                ; %.lr.ph95.preheader
	v_dual_mov_b32 v11, s9 :: v_dual_add_nc_u32 v10, s6, v0
	v_mov_b32_e32 v12, v9
	s_ashr_i32 s2, s9, 31
	s_add_u32 s6, s4, 4
	s_mov_b32 s3, s9
	s_addc_u32 s7, s5, 0
.LBB0_2:                                ; %.lr.ph95
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_5 Depth 2
	v_ashrrev_i32_e32 v7, 31, v6
	s_mov_b32 s0, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[6:7], 2, v[6:7]
	v_add_co_u32 v6, vcc_lo, s4, v6
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v7, vcc_lo
	global_load_b32 v6, v[6:7], off
	s_waitcnt vmcnt(0)
	v_cmpx_ngt_f32_e32 v6, v12
	s_xor_b32 s0, exec_lo, s0
	s_cbranch_execz .LBB0_8
; %bb.3:                                ; %.preheader
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_subrev_nc_u32_e32 v6, s9, v11
	s_mov_b32 s10, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_lt_i32_e32 -2, v6
	s_cbranch_execz .LBB0_7
; %bb.4:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_ashrrev_i32_e32 v1, 31, v0
	s_mov_b32 s12, -1
	s_mov_b32 s11, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[11:12], 2, v[0:1]
	v_add_co_u32 v11, vcc_lo, s4, v11
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v12, vcc_lo, s5, v12, vcc_lo
	global_load_b32 v1, v[11:12], off
.LBB0_5:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_add_i32 s12, s12, 1
	s_waitcnt vmcnt(0)
	v_sub_f32_e32 v8, v8, v1
	v_cmp_gt_i32_e32 vcc_lo, s12, v6
	s_or_b32 s11, vcc_lo, s11
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s11
	s_cbranch_execnz .LBB0_5
; %bb.6:                                ; %Flow
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s11
.LBB0_7:                                ; %Flow114
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(VALU_DEP_3)
	s_or_b32 exec_lo, exec_lo, s10
	v_ashrrev_i32_e32 v1, 31, v0
	v_ashrrev_i32_e32 v7, 31, v6
	v_add_co_u32 v11, vcc_lo, v0, v6
	v_add3_u32 v0, v6, v0, 1
                                        ; implicit-def: $vgpr6
	v_add_co_ci_u32_e32 v1, vcc_lo, v1, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v11, vcc_lo, v11, s3
	v_add_co_ci_u32_e32 v12, vcc_lo, s2, v1, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[11:12], 2, v[11:12]
	v_add_co_u32 v11, vcc_lo, s6, v11
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v12, vcc_lo, s7, v12, vcc_lo
	global_load_b32 v1, v[11:12], off
                                        ; implicit-def: $vgpr11
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v8, v8, v1
.LBB0_8:                                ; %Flow117
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_saveexec_b32 s0, s0
	v_mov_b32_e32 v7, s9
	s_xor_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB0_14
; %bb.9:                                ;   in Loop: Header=BB0_2 Depth=1
	v_ashrrev_i32_e32 v1, 31, v0
	v_add_f32_e32 v8, v8, v6
	s_mov_b32 s10, exec_lo
                                        ; implicit-def: $vgpr7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[12:13], 2, v[0:1]
	v_add_co_u32 v12, vcc_lo, s4, v12
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v13, vcc_lo, s5, v13, vcc_lo
	global_load_b32 v1, v[12:13], off
	s_waitcnt vmcnt(0)
	v_cmpx_ngt_f32_e32 v6, v1
	s_xor_b32 s10, exec_lo, s10
; %bb.10:                               ;   in Loop: Header=BB0_2 Depth=1
	v_add_nc_u32_e32 v7, 1, v11
                                        ; implicit-def: $vgpr1
                                        ; implicit-def: $vgpr11
; %bb.11:                               ; %Flow115
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_and_not1_saveexec_b32 s10, s10
; %bb.12:                               ;   in Loop: Header=BB0_2 Depth=1
	v_dual_sub_f32 v8, v8, v1 :: v_dual_mov_b32 v7, v11
	v_add_nc_u32_e32 v0, 1, v0
; %bb.13:                               ; %Flow116
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
.LBB0_14:                               ;   in Loop: Header=BB0_2 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s0
	v_cvt_f32_i32_e32 v1, v7
	s_mov_b32 s0, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f32 v6, null, v1, v1, v8
	v_rcp_f32_e32 v11, v6
	s_waitcnt_depctr 0xfff
	v_fma_f32 v12, -v6, v11, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v11, v12, v11
	v_div_scale_f32 v12, vcc_lo, v8, v1, v8
	v_mul_f32_e32 v13, v12, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v14, -v6, v13, v12
	v_fmac_f32_e32 v13, v14, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v6, -v6, v13, v12
	v_div_fmas_f32 v6, v6, v11, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f32 v12, v6, v1, v8
	v_cmpx_gt_f32_e32 v12, v9
	s_cbranch_execz .LBB0_16
; %bb.15:                               ;   in Loop: Header=BB0_2 Depth=1
	v_add3_u32 v1, v7, v0, -1
	v_mov_b32_e32 v9, v12
	global_store_b64 v[4:5], v[0:1], off
	global_store_b32 v[2:3], v12, off
.LBB0_16:                               ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	v_dual_mov_b32 v11, v7 :: v_dual_add_nc_u32 v6, v0, v7
	v_cmp_ge_i32_e32 vcc_lo, v0, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_le_i32_e64 s0, s8, v6
	s_or_b32 s0, s0, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, exec_lo, s0
	s_or_b32 s1, s0, s1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB0_2
.LBB0_17:                               ; %._crit_edge96
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11deviceburstPfS_iiS_Pi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 15
		.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	_Z11deviceburstPfS_iiS_Pi, .Lfunc_end0-_Z11deviceburstPfS_iiS_Pi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1044
; NumSgprs: 18
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 15
; 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
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11deviceburstPfS_iiS_Pi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z11deviceburstPfS_iiS_Pi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
