#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>

#define INPUT_FILE "inp.txt"
#define Q3_OUT_FILE "q3.txt"

typedef struct vector {
  int *elements;
  int capacity;
  int size;
} vector;

// Method definitions
void int_vector_init(vector *vector);
int int_vector_add(vector* vector, int element);
void int_vector_free(vector *vector);

int chopString(char *buf, size_t size);

__global__ void get_odd_array(int* d_out, int* d_in, int size) {
  int myId = threadIdx.x + blockDim.x * blockIdx.x;

  if (myId < size) {
    int f = d_in[myId];
    d_out[myId] = f % 2;
  } 
}

__global__ void parallel_prefix_kernel(int * d_out, int * d_in, int size) {
  int myId = threadIdx.x + blockDim.x * blockIdx.x;
  int d = 1;
  
  while(d < size) {
    if(myId+1 > d && myId < size) {
      d_in[myId] += d_in[myId - d];
    }
    d *= 2;
    __syncthreads();
  }
  
  d_out[myId] = d_in[myId];
}

__global__ void move_odds(int* d_out, int* d_in, int* prefix, int size) {
  int myId = threadIdx.x + blockDim.x * blockIdx.x;

  if (myId < size) {
    int index = prefix[myId] - 1;
    
    if (d_in[myId] % 2 == 1) {
      d_out[index] = d_in[myId];
    }
  }
}

int main(int argc, char ** argv) {
  int deviceCount;
  cudaGetDeviceCount(&deviceCount);
  if (deviceCount == 0) {
    fprintf(stderr, "error: no devices supporting CUDA.\n");
    exit(EXIT_FAILURE);
  }
  
  int dev = 0;
  cudaSetDevice(dev);
  
  // Read in file
  FILE *fp;
  if((fp = fopen(INPUT_FILE, "r")) == 0) {
    printf("%s cannot be found\n", INPUT_FILE);
    exit(-1);
  }
  
  char separators[] = " ,";
  char number[7];
  char buf[100];
  char* token;
  int offset = 0;
  vector *a = (vector*) malloc(sizeof(vector));
  int_vector_init(a);

  while(fgets(buf + offset, sizeof buf - offset, fp) != NULL) {
    //chop off number from string if it ends with digit
    offset = chopString(buf, sizeof buf);
    int indexOfLastNum = sizeof buf - offset - 1;// -1 to not copy '\0'

    //printf("buffer: %s\n", buf);  
  
    token = strtok(buf, separators);
    while (token != NULL) {
      int num = atoi(token);
      //printf("%d\n", num); 
      int_vector_add(a, num);
      token = strtok(NULL, separators);
    }

    memcpy(buf, &buf[indexOfLastNum], offset); 
  }
  const int ARRAY_BYTES = sizeof(int) * a->size;

  // declare GPU memory pointers
  int* d_in, * d_ones, * d_prefix, * d_out;

  // allocate GPU memory
  cudaMalloc((void**) &d_in, ARRAY_BYTES);
  cudaMalloc((void**) &d_ones, ARRAY_BYTES);
  cudaMalloc((void**) &d_prefix, ARRAY_BYTES);
  cudaMalloc((void**) &d_out, ARRAY_BYTES);

  // transfer the array to the GPU
  cudaMemcpy(d_in, a->elements, ARRAY_BYTES, cudaMemcpyHostToDevice);

  // kernels
  const int maxThreadsPerBlock = 1024; //increased from 512 to 1024 to handle 1024^2 values
  int threads = maxThreadsPerBlock;
  int blocks = (a->size + (maxThreadsPerBlock-1)) / maxThreadsPerBlock;

  // STEP 1: ones array
  get_odd_array<<<blocks, threads>>>(d_ones, d_in, a->size);

  // STEP 2: parallel prefix sum
  parallel_prefix_kernel<<<blocks, threads>>>(d_prefix, d_ones, a->size);

  // STEP 3: move odds into out using the prefix (gives the index to move to)
  move_odds<<<blocks, threads>>>(d_out, d_in, d_prefix, a->size);

  // copy back the result array to the CPU
  int h_out[a->size];
  cudaMemcpy(h_out, d_out, ARRAY_BYTES, cudaMemcpyDeviceToHost);

  // write to file
  FILE *outfile = fopen(Q3_OUT_FILE, "w");
  if (outfile == NULL) {
    printf("can't open file %s to write\n", Q3_OUT_FILE);
  }

  bool first = true;
  for (int i = 0; i < a->size; i++) {
    if (h_out[i] == 0) break;    

    if (first) {
      fprintf(outfile, "%d", h_out[i]);
      first = false;
    } else {
      fprintf(outfile, ",%d", h_out[i]);
    }
  }

  fclose(outfile);

  int_vector_free(a);

  cudaFree(d_in);
  cudaFree(d_ones);
  cudaFree(d_prefix);
  cudaFree(d_out);

  return 0;
}

void int_vector_init(vector *vector) {
  if(vector == NULL)
  {
    return;
  }
  vector -> elements = (int*)malloc(sizeof( int));
  vector -> capacity = 1;
  vector -> size = 0;
}

int int_vector_add(vector* vector, int element) {
  if(vector->size + 1 == vector->capacity)
  {
    int *temp = (int*)realloc(vector->elements, vector->capacity*2 * sizeof (int));
    if(temp == NULL)
    {
      return 0;
    }
    vector -> capacity *= 2;
    vector -> elements = temp;
  }
  vector -> elements[vector->size] = element;
  vector -> size += 1;
  return 1;
}

void int_vector_free(vector *vector){
  free(vector->elements);
  free(vector);
}

//returns offset - difference between size and index of last number and offset
int chopString(char *buf, size_t size){
  int offset = 0;
  int indexOfLastNum = size-2;
  if(isdigit(buf[size-2]))
  {
    int index = size-2;
    while(isdigit(buf[index]) && index > 0)
    {
      index--;
    }
    buf[index] = '\0';
    indexOfLastNum = index+1;
    offset = size - indexOfLastNum -1;//-1 to not copy '\0'
    
  } else 
  {
    offset = 0;
  }    
  return offset;
}


	.file	"tmpxft_002fbdb0_00000000-6_q3.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z15int_vector_initP6vector
	.type	_Z15int_vector_initP6vector, @function
_Z15int_vector_initP6vector:
.LFB2028:
	.cfi_startproc
	endbr64
	testq	%rdi, %rdi
	je	.L8
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	movl	$4, %edi
	call	malloc@PLT
	movq	$1, 8(%rbx)
	movq	%rax, (%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore 3
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z15int_vector_initP6vector, .-_Z15int_vector_initP6vector
	.globl	_Z14int_vector_addP6vectori
	.type	_Z14int_vector_addP6vectori, @function
_Z14int_vector_addP6vectori:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 32
	movl	12(%rbx), %eax
	movq	(%rdi), %rdi
	incl	%eax
	cmpl	8(%rbx), %eax
	jne	.L13
	leal	(%rax,%rax), %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	realloc@PLT
	xorl	%edx, %edx
	testq	%rax, %rax
	je	.L12
	movd	8(%rbx), %xmm0
	movq	%rax, (%rbx)
	pslld	$1, %xmm0
	movd	%xmm0, 8(%rbx)
.L13:
	movslq	12(%rbx), %rdx
	movq	(%rbx), %rax
	movl	%ebp, (%rax,%rdx,4)
	movl	$1, %edx
	incl	12(%rbx)
.L12:
	movl	%edx, %eax
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z14int_vector_addP6vectori, .-_Z14int_vector_addP6vectori
	.globl	_Z15int_vector_freeP6vector
	.type	_Z15int_vector_freeP6vector, @function
_Z15int_vector_freeP6vector:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	movq	(%rdi), %rdi
	call	free@PLT
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	free@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z15int_vector_freeP6vector, .-_Z15int_vector_freeP6vector
	.globl	_Z10chopStringPcm
	.type	_Z10chopStringPcm, @function
_Z10chopStringPcm:
.LFB2031:
	.cfi_startproc
	endbr64
	movsbl	-2(%rdi,%rsi), %eax
	leal	-48(%rax), %edx
	xorl	%eax, %eax
	cmpl	$9, %edx
	ja	.L19
	leal	-2(%rsi), %eax
	cltq
.L21:
	movsbl	(%rdi,%rax), %edx
	subl	$48, %edx
	cmpl	$9, %edx
	movq	%rax, %rdx
	setbe	%r8b
	testl	%eax, %eax
	setg	%cl
	decq	%rax
	testb	%cl, %r8b
	jne	.L21
	movb	$0, (%rdi,%rdx)
	subl	%edx, %esi
	leal	-2(%rsi), %eax
.L19:
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z10chopStringPcm, .-_Z10chopStringPcm
	.globl	_Z36__device_stub__Z13get_odd_arrayPiS_iPiS_i
	.type	_Z36__device_stub__Z13get_odd_arrayPiS_iPiS_i, @function
_Z36__device_stub__Z13get_odd_arrayPiS_iPiS_i:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z13get_odd_arrayPiS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L24:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z36__device_stub__Z13get_odd_arrayPiS_iPiS_i, .-_Z36__device_stub__Z13get_odd_arrayPiS_iPiS_i
	.globl	_Z13get_odd_arrayPiS_i
	.type	_Z13get_odd_arrayPiS_i, @function
_Z13get_odd_arrayPiS_i:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z13get_odd_arrayPiS_iPiS_i
	.cfi_endproc
.LFE2057:
	.size	_Z13get_odd_arrayPiS_i, .-_Z13get_odd_arrayPiS_i
	.globl	_Z45__device_stub__Z22parallel_prefix_kernelPiS_iPiS_i
	.type	_Z45__device_stub__Z22parallel_prefix_kernelPiS_iPiS_i, @function
_Z45__device_stub__Z22parallel_prefix_kernelPiS_iPiS_i:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z22parallel_prefix_kernelPiS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L29:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z45__device_stub__Z22parallel_prefix_kernelPiS_iPiS_i, .-_Z45__device_stub__Z22parallel_prefix_kernelPiS_iPiS_i
	.globl	_Z22parallel_prefix_kernelPiS_i
	.type	_Z22parallel_prefix_kernelPiS_i, @function
_Z22parallel_prefix_kernelPiS_i:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z22parallel_prefix_kernelPiS_iPiS_i
	.cfi_endproc
.LFE2059:
	.size	_Z22parallel_prefix_kernelPiS_i, .-_Z22parallel_prefix_kernelPiS_i
	.globl	_Z33__device_stub__Z9move_oddsPiS_S_iPiS_S_i
	.type	_Z33__device_stub__Z9move_oddsPiS_S_iPiS_S_i, @function
_Z33__device_stub__Z9move_oddsPiS_S_iPiS_S_i:
.LFB2060:
	.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
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%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	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%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	.L34
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z9move_oddsPiS_S_i(%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
.L34:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2060:
	.size	_Z33__device_stub__Z9move_oddsPiS_S_iPiS_S_i, .-_Z33__device_stub__Z9move_oddsPiS_S_iPiS_S_i
	.globl	_Z9move_oddsPiS_S_i
	.type	_Z9move_oddsPiS_S_i, @function
_Z9move_oddsPiS_S_i:
.LFB2061:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z9move_oddsPiS_S_iPiS_S_i
	.cfi_endproc
.LFE2061:
	.size	_Z9move_oddsPiS_S_i, .-_Z9move_oddsPiS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"error: no devices supporting CUDA.\n"
.LC1:
	.string	"r"
.LC2:
	.string	"inp.txt"
.LC3:
	.string	"%s cannot be found\n"
.LC4:
	.string	"w"
.LC5:
	.string	"q3.txt"
.LC6:
	.string	"can't open file %s to write\n"
.LC7:
	.string	"%d"
.LC8:
	.string	",%d"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	leaq	-220(%rbp), %rdi
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$200, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	cudaGetDeviceCount@PLT
	cmpl	$0, -220(%rbp)
	jne	.L40
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	jmp	.L67
.L40:
	xorl	%edi, %edi
	leaq	.LC2(%rip), %rbx
	call	cudaSetDevice@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rbx, %rdi
	call	fopen@PLT
	movq	%rax, %r14
	testq	%rax, %rax
	jne	.L41
	movl	$2, %edi
	movq	%rbx, %rdx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %edi
.L67:
	call	exit@PLT
.L41:
	movl	$16, %edi
	movb	$0, -157(%rbp)
	xorl	%r12d, %r12d
	movl	$100, %r15d
	movw	$11296, -159(%rbp)
	call	malloc@PLT
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	_Z15int_vector_initP6vector
.L42:
	movslq	%r12d, %rdi
	movl	$100, %esi
	movl	%r15d, %edx
	movq	%r14, %rcx
	subl	%r12d, %edx
	cmpq	%rsi, %rdi
	leaq	-156(%rbp), %r13
	cmovnb	%rdi, %rsi
	subq	%rdi, %rsi
	addq	%r13, %rdi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L68
	movl	$100, %esi
	movq	%r13, %rdi
	call	_Z10chopStringPcm
	movl	%eax, %r12d
	movl	$99, %eax
	subl	%r12d, %eax
	movl	%eax, -236(%rbp)
	leaq	-159(%rbp), %rax
	movq	%rax, -232(%rbp)
	movq	%rax, %rsi
.L65:
	call	strtok@PLT
	testq	%rax, %rax
	je	.L69
	movq	%rax, %rdi
	call	atoi@PLT
	movq	%rbx, %rdi
	movl	%eax, %esi
	call	_Z14int_vector_addP6vectori
	movq	-232(%rbp), %rsi
	xorl	%edi, %edi
	jmp	.L65
.L69:
	movslq	-236(%rbp), %rsi
	movslq	%r12d, %rdx
	movl	$100, %ecx
	movq	%r13, %rdi
	addq	%r13, %rsi
	call	__memcpy_chk@PLT
	jmp	.L42
.L68:
	movslq	12(%rbx), %r15
	leaq	-216(%rbp), %rdi
	leal	0(,%r15,4), %r12d
	movq	%r15, %r13
	movslq	%r12d, %r12
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	leaq	-208(%rbp), %rdi
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	leaq	-200(%rbp), %rdi
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	leaq	-192(%rbp), %rdi
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	movq	(%rbx), %rsi
	movl	$1, %ecx
	movq	%r12, %rdx
	movq	-216(%rbp), %rdi
	call	cudaMemcpy@PLT
	movl	$1024, %esi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	leal	1023(%r15), %eax
	movl	$4194305, %ecx
	movl	$1, -164(%rbp)
	cltd
	salq	$10, %rcx
	idivl	%esi
	movq	%rcx, -172(%rbp)
	movq	%rcx, %rdx
	movl	$1, %ecx
	movl	%eax, -184(%rbp)
	movl	%eax, %r14d
	movabsq	$4294967297, %rax
	movq	%rax, -180(%rbp)
	movq	-184(%rbp), %rdi
	movl	-176(%rbp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	movq	-216(%rbp), %rsi
	movq	-208(%rbp), %rdi
	movl	%r15d, %edx
	call	_Z36__device_stub__Z13get_odd_arrayPiS_iPiS_i
.L46:
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$4294967297, %rax
	salq	$10, %rdx
	movl	%r14d, -184(%rbp)
	movq	%rax, -180(%rbp)
	movl	-176(%rbp), %esi
	movq	-184(%rbp), %rdi
	movq	%rdx, -172(%rbp)
	movl	$1, -164(%rbp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L47
	movq	-208(%rbp), %rsi
	movq	-200(%rbp), %rdi
	movl	%r13d, %edx
	call	_Z45__device_stub__Z22parallel_prefix_kernelPiS_iPiS_i
.L47:
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$4294967297, %rax
	salq	$10, %rdx
	movl	%r14d, -184(%rbp)
	movq	%rax, -180(%rbp)
	movl	-176(%rbp), %esi
	movq	-184(%rbp), %rdi
	movq	%rdx, -172(%rbp)
	movl	$1, -164(%rbp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L48
	movq	-200(%rbp), %rdx
	movq	-216(%rbp), %rsi
	movl	%r13d, %ecx
	movq	-192(%rbp), %rdi
	call	_Z33__device_stub__Z9move_oddsPiS_S_iPiS_S_i
.L48:
	leaq	15(,%r15,4), %rdx
	movq	%rsp, %rcx
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L49:
	cmpq	%rcx, %rsp
	je	.L50
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L49
.L50:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L51
	orq	$0, -8(%rsp,%rax)
.L51:
	movq	-192(%rbp), %rsi
	movq	%r12, %rdx
	movl	$2, %ecx
	movq	%rsp, %rdi
	leaq	.LC5(%rip), %r15
	movq	%rsp, -232(%rbp)
	call	cudaMemcpy@PLT
	leaq	.LC4(%rip), %rsi
	movq	%r15, %rdi
	call	fopen@PLT
	movq	%rax, %r12
	testq	%rax, %rax
	jne	.L52
	movq	%r15, %rdx
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L52:
	xorl	%r14d, %r14d
	movb	$1, %al
	leaq	.LC8(%rip), %r15
.L53:
	cmpl	%r14d, %r13d
	jle	.L58
	movq	-232(%rbp), %rcx
	movl	(%rcx,%r14,4), %ecx
	testl	%ecx, %ecx
	jne	.L54
.L58:
	movq	%r12, %rdi
	call	fclose@PLT
	movq	%rbx, %rdi
	call	_Z15int_vector_freeP6vector
	movq	-216(%rbp), %rdi
	call	cudaFree@PLT
	movq	-208(%rbp), %rdi
	call	cudaFree@PLT
	movq	-200(%rbp), %rdi
	call	cudaFree@PLT
	movq	-192(%rbp), %rdi
	call	cudaFree@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L59
	call	__stack_chk_fail@PLT
.L54:
	leaq	.LC7(%rip), %rdx
	testb	%al, %al
	jne	.L66
	movq	%r15, %rdx
.L66:
	movl	$2, %esi
	movq	%r12, %rdi
	xorl	%eax, %eax
	incq	%r14
	call	__fprintf_chk@PLT
	xorl	%eax, %eax
	jmp	.L53
.L59:
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z9move_oddsPiS_S_i"
.LC10:
	.string	"_Z22parallel_prefix_kernelPiS_i"
.LC11:
	.string	"_Z13get_odd_arrayPiS_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2063:
	.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	.LC9(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z9move_oddsPiS_S_i(%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	.LC10(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z22parallel_prefix_kernelPiS_i(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC11(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z13get_odd_arrayPiS_i(%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
.LFE2063:
	.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:

#include <stdio.h>
#include <stdlib.h>
#include <hip/hip_runtime.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>

#define INPUT_FILE "inp.txt"
#define Q3_OUT_FILE "q3.txt"

typedef struct vector {
  int *elements;
  int capacity;
  int size;
} vector;

// Method definitions
void int_vector_init(vector *vector);
int int_vector_add(vector* vector, int element);
void int_vector_free(vector *vector);

int chopString(char *buf, size_t size);

__global__ void get_odd_array(int* d_out, int* d_in, int size) {
  int myId = threadIdx.x + blockDim.x * blockIdx.x;

  if (myId < size) {
    int f = d_in[myId];
    d_out[myId] = f % 2;
  } 
}

__global__ void parallel_prefix_kernel(int * d_out, int * d_in, int size) {
  int myId = threadIdx.x + blockDim.x * blockIdx.x;
  int d = 1;
  
  while(d < size) {
    if(myId+1 > d && myId < size) {
      d_in[myId] += d_in[myId - d];
    }
    d *= 2;
    __syncthreads();
  }
  
  d_out[myId] = d_in[myId];
}

__global__ void move_odds(int* d_out, int* d_in, int* prefix, int size) {
  int myId = threadIdx.x + blockDim.x * blockIdx.x;

  if (myId < size) {
    int index = prefix[myId] - 1;
    
    if (d_in[myId] % 2 == 1) {
      d_out[index] = d_in[myId];
    }
  }
}

int main(int argc, char ** argv) {
  int deviceCount;
  hipGetDeviceCount(&deviceCount);
  if (deviceCount == 0) {
    fprintf(stderr, "error: no devices supporting CUDA.\n");
    exit(EXIT_FAILURE);
  }
  
  int dev = 0;
  hipSetDevice(dev);
  
  // Read in file
  FILE *fp;
  if((fp = fopen(INPUT_FILE, "r")) == 0) {
    printf("%s cannot be found\n", INPUT_FILE);
    exit(-1);
  }
  
  char separators[] = " ,";
  char number[7];
  char buf[100];
  char* token;
  int offset = 0;
  vector *a = (vector*) malloc(sizeof(vector));
  int_vector_init(a);

  while(fgets(buf + offset, sizeof buf - offset, fp) != NULL) {
    //chop off number from string if it ends with digit
    offset = chopString(buf, sizeof buf);
    int indexOfLastNum = sizeof buf - offset - 1;// -1 to not copy '\0'

    //printf("buffer: %s\n", buf);  
  
    token = strtok(buf, separators);
    while (token != NULL) {
      int num = atoi(token);
      //printf("%d\n", num); 
      int_vector_add(a, num);
      token = strtok(NULL, separators);
    }

    memcpy(buf, &buf[indexOfLastNum], offset); 
  }
  const int ARRAY_BYTES = sizeof(int) * a->size;

  // declare GPU memory pointers
  int* d_in, * d_ones, * d_prefix, * d_out;

  // allocate GPU memory
  hipMalloc((void**) &d_in, ARRAY_BYTES);
  hipMalloc((void**) &d_ones, ARRAY_BYTES);
  hipMalloc((void**) &d_prefix, ARRAY_BYTES);
  hipMalloc((void**) &d_out, ARRAY_BYTES);

  // transfer the array to the GPU
  hipMemcpy(d_in, a->elements, ARRAY_BYTES, hipMemcpyHostToDevice);

  // kernels
  const int maxThreadsPerBlock = 1024; //increased from 512 to 1024 to handle 1024^2 values
  int threads = maxThreadsPerBlock;
  int blocks = (a->size + (maxThreadsPerBlock-1)) / maxThreadsPerBlock;

  // STEP 1: ones array
  get_odd_array<<<blocks, threads>>>(d_ones, d_in, a->size);

  // STEP 2: parallel prefix sum
  parallel_prefix_kernel<<<blocks, threads>>>(d_prefix, d_ones, a->size);

  // STEP 3: move odds into out using the prefix (gives the index to move to)
  move_odds<<<blocks, threads>>>(d_out, d_in, d_prefix, a->size);

  // copy back the result array to the CPU
  int h_out[a->size];
  hipMemcpy(h_out, d_out, ARRAY_BYTES, hipMemcpyDeviceToHost);

  // write to file
  FILE *outfile = fopen(Q3_OUT_FILE, "w");
  if (outfile == NULL) {
    printf("can't open file %s to write\n", Q3_OUT_FILE);
  }

  bool first = true;
  for (int i = 0; i < a->size; i++) {
    if (h_out[i] == 0) break;    

    if (first) {
      fprintf(outfile, "%d", h_out[i]);
      first = false;
    } else {
      fprintf(outfile, ",%d", h_out[i]);
    }
  }

  fclose(outfile);

  int_vector_free(a);

  hipFree(d_in);
  hipFree(d_ones);
  hipFree(d_prefix);
  hipFree(d_out);

  return 0;
}

void int_vector_init(vector *vector) {
  if(vector == NULL)
  {
    return;
  }
  vector -> elements = (int*)malloc(sizeof( int));
  vector -> capacity = 1;
  vector -> size = 0;
}

int int_vector_add(vector* vector, int element) {
  if(vector->size + 1 == vector->capacity)
  {
    int *temp = (int*)realloc(vector->elements, vector->capacity*2 * sizeof (int));
    if(temp == NULL)
    {
      return 0;
    }
    vector -> capacity *= 2;
    vector -> elements = temp;
  }
  vector -> elements[vector->size] = element;
  vector -> size += 1;
  return 1;
}

void int_vector_free(vector *vector){
  free(vector->elements);
  free(vector);
}

//returns offset - difference between size and index of last number and offset
int chopString(char *buf, size_t size){
  int offset = 0;
  int indexOfLastNum = size-2;
  if(isdigit(buf[size-2]))
  {
    int index = size-2;
    while(isdigit(buf[index]) && index > 0)
    {
      index--;
    }
    buf[index] = '\0';
    indexOfLastNum = index+1;
    offset = size - indexOfLastNum -1;//-1 to not copy '\0'
    
  } else 
  {
    offset = 0;
  }    
  return offset;
}


	.text
	.file	"q3.hip"
	.globl	_Z28__device_stub__get_odd_arrayPiS_i # -- Begin function _Z28__device_stub__get_odd_arrayPiS_i
	.type	_Z28__device_stub__get_odd_arrayPiS_i,@function
_Z28__device_stub__get_odd_arrayPiS_i:  # @_Z28__device_stub__get_odd_arrayPiS_i
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z13get_odd_arrayPiS_i, %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_end0:
	.size	_Z28__device_stub__get_odd_arrayPiS_i, .Lfunc_end0-_Z28__device_stub__get_odd_arrayPiS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z37__device_stub__parallel_prefix_kernelPiS_i # -- Begin function _Z37__device_stub__parallel_prefix_kernelPiS_i
	.type	_Z37__device_stub__parallel_prefix_kernelPiS_i,@function
_Z37__device_stub__parallel_prefix_kernelPiS_i: # @_Z37__device_stub__parallel_prefix_kernelPiS_i
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z22parallel_prefix_kernelPiS_i, %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	_Z37__device_stub__parallel_prefix_kernelPiS_i, .Lfunc_end1-_Z37__device_stub__parallel_prefix_kernelPiS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__move_oddsPiS_S_i # -- Begin function _Z24__device_stub__move_oddsPiS_S_i
	.type	_Z24__device_stub__move_oddsPiS_S_i,@function
_Z24__device_stub__move_oddsPiS_S_i:    # @_Z24__device_stub__move_oddsPiS_S_i
	.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	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%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	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	$_Z9move_oddsPiS_S_i, %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_end2:
	.size	_Z24__device_stub__move_oddsPiS_S_i, .Lfunc_end2-_Z24__device_stub__move_oddsPiS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$168, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	leaq	-108(%rbp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%rbx)
	je	.LBB3_30
# %bb.1:
	xorl	%edi, %edi
	callq	hipSetDevice
	movl	$.L.str.1, %edi
	movl	$.L.str.2, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB3_31
# %bb.2:
	movq	%rax, %r14
	movw	$11296, -43(%rbp)               # imm = 0x2C20
	movb	$0, -41(%rbp)
	movl	$16, %edi
	callq	malloc
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.LBB3_4
# %bb.3:
	movl	$4, %edi
	callq	malloc
	movq	%rax, (%rbx)
	movq	$1, 8(%rbx)
.LBB3_4:                                # %_Z15int_vector_initP6vector.exit
	leaq	-208(%rbp), %rdi
	movl	$100, %esi
	movq	%r14, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB3_5
# %bb.6:                                # %.lr.ph83
	leaq	-208(%rbp), %r15
	leaq	-43(%rbp), %r12
.LBB3_7:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_9 Depth 2
                                        #     Child Loop BB3_14 Depth 2
	movsbl	-110(%rbp), %eax
	addl	$-48, %eax
	movl	$0, %r13d
	cmpl	$9, %eax
	ja	.LBB3_12
# %bb.8:                                # %.preheader.preheader
                                        #   in Loop: Header=BB3_7 Depth=1
	movl	$98, %ecx
	movl	$-1, %r13d
	movl	$98, %eax
.LBB3_9:                                # %.preheader
                                        #   Parent Loop BB3_7 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	incl	%r13d
	addq	$-1, %rax
	jae	.LBB3_11
# %bb.10:                               # %.preheader
                                        #   in Loop: Header=BB3_9 Depth=2
	movsbl	-208(%rbp,%rcx), %edx
	addl	$-48, %edx
	movq	%rax, %rcx
	cmpl	$10, %edx
	jb	.LBB3_9
.LBB3_11:                               #   in Loop: Header=BB3_7 Depth=1
	movb	$0, -207(%rbp,%rax)
.LBB3_12:                               # %_Z10chopStringPcm.exit
                                        #   in Loop: Header=BB3_7 Depth=1
	movq	%r15, %rdi
.LBB3_14:                               # %.lr.ph
                                        #   Parent Loop BB3_7 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r12, %rsi
	callq	strtok
	testq	%rax, %rax
	je	.LBB3_15
# %bb.13:                               # %.lr.ph
                                        #   in Loop: Header=BB3_14 Depth=2
	movq	%rax, %rdi
	callq	atoi
	movq	%rbx, %rdi
	movl	%eax, %esi
	callq	_Z14int_vector_addP6vectori
	xorl	%edi, %edi
	jmp	.LBB3_14
.LBB3_15:                               # %._crit_edge
                                        #   in Loop: Header=BB3_7 Depth=1
	movslq	%r13d, %r13
	movl	$99, %eax
	subl	%r13d, %eax
	cltq
	leaq	(%rax,%rbp), %rsi
	addq	$-208, %rsi
	movq	%r15, %rdi
	movq	%r13, %rdx
	callq	memcpy@PLT
	leaq	-208(,%r13), %rdi
	addq	%rbp, %rdi
	movl	$100, %esi
	subl	%r13d, %esi
	movq	%r14, %rdx
	callq	fgets
	testq	%rax, %rax
	jne	.LBB3_7
# %bb.16:                               # %._crit_edge84.loopexit
	movl	12(%rbx), %r15d
	jmp	.LBB3_17
.LBB3_5:
	xorl	%r15d, %r15d
.LBB3_17:                               # %._crit_edge84
	movabsq	$4294968320, %r13               # imm = 0x100000400
	leal	(,%r15,4), %eax
	movslq	%eax, %r12
	leaq	-80(%rbp), %r14
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	-72(%rbp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	-64(%rbp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	-56(%rbp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	(%rbx), %rsi
	movq	%rsi, -96(%rbp)                 # 8-byte Spill
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leal	1023(%r15), %eax
	leal	2046(%r15), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	sarl	$10, %ecx
	leaq	(%rcx,%r13), %r14
	addq	$-1024, %r14                    # imm = 0xFC00
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_19
# %bb.18:
	movq	-72(%rbp), %rdi
	movq	-80(%rbp), %rsi
	movl	%r15d, %edx
	callq	_Z28__device_stub__get_odd_arrayPiS_i
.LBB3_19:
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_21
# %bb.20:
	movq	-64(%rbp), %rdi
	movq	-72(%rbp), %rsi
	movl	%r15d, %edx
	callq	_Z37__device_stub__parallel_prefix_kernelPiS_i
.LBB3_21:
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_23
# %bb.22:
	movq	-56(%rbp), %rdi
	movq	-80(%rbp), %rsi
	movq	-64(%rbp), %rdx
	movl	%r15d, %ecx
	callq	_Z24__device_stub__move_oddsPiS_S_i
.LBB3_23:
	movq	%rsp, -88(%rbp)                 # 8-byte Spill
	movl	%r15d, %eax
	movq	%rsp, %r13
	movq	%rax, -104(%rbp)                # 8-byte Spill
	leaq	15(,%rax,4), %rax
	andq	$-16, %rax
	subq	%rax, %r13
	movq	%r13, %rsp
	movq	-56(%rbp), %rsi
	movq	%r13, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.4, %edi
	movl	$.L.str.5, %esi
	callq	fopen
	movq	%rax, %r12
	testq	%rax, %rax
	jne	.LBB3_25
# %bb.24:
	movl	$.L.str.6, %edi
	movl	$.L.str.4, %esi
	xorl	%eax, %eax
	callq	printf
.LBB3_25:
	testl	%r15d, %r15d
	jle	.LBB3_29
# %bb.26:                               # %.lr.ph88.preheader
	movb	$1, %r15b
	xorl	%r14d, %r14d
.LBB3_27:                               # %.lr.ph88
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r13,%r14,4), %edx
	testl	%edx, %edx
	je	.LBB3_29
# %bb.28:                               #   in Loop: Header=BB3_27 Depth=1
	testb	$1, %r15b
	movl	$.L.str.7, %esi
	movl	$.L.str.8, %eax
	cmoveq	%rax, %rsi
	movzbl	%r15b, %r15d
	movl	$0, %eax
	cmovnel	%eax, %r15d
	movq	%r12, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r14
	cmpq	%r14, -104(%rbp)                # 8-byte Folded Reload
	jne	.LBB3_27
.LBB3_29:                               # %._crit_edge89
	movq	%r12, %rdi
	callq	fclose
	movq	-96(%rbp), %rdi                 # 8-byte Reload
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	-80(%rbp), %rdi
	callq	hipFree
	movq	-72(%rbp), %rdi
	callq	hipFree
	movq	-64(%rbp), %rdi
	callq	hipFree
	movq	-56(%rbp), %rdi
	callq	hipFree
	movq	-88(%rbp), %rsp                 # 8-byte Reload
	xorl	%eax, %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.LBB3_30:
	.cfi_def_cfa %rbp, 16
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$35, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %edi
	callq	exit
.LBB3_31:
	movl	$.L.str.3, %edi
	movl	$.L.str.1, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z15int_vector_initP6vector     # -- Begin function _Z15int_vector_initP6vector
	.type	_Z15int_vector_initP6vector,@function
_Z15int_vector_initP6vector:            # @_Z15int_vector_initP6vector
	.cfi_startproc
# %bb.0:
	testq	%rdi, %rdi
	je	.LBB4_2
# %bb.1:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movl	$4, %edi
	callq	malloc
	movq	%rax, (%rbx)
	movq	$1, 8(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB4_2:
	retq
.Lfunc_end4:
	.size	_Z15int_vector_initP6vector, .Lfunc_end4-_Z15int_vector_initP6vector
	.cfi_endproc
                                        # -- End function
	.globl	_Z10chopStringPcm               # -- Begin function _Z10chopStringPcm
	.type	_Z10chopStringPcm,@function
_Z10chopStringPcm:                      # @_Z10chopStringPcm
	.cfi_startproc
# %bb.0:
	movsbl	-2(%rdi,%rsi), %ecx
	addl	$-48, %ecx
	xorl	%eax, %eax
	cmpl	$9, %ecx
	ja	.LBB5_5
# %bb.1:
	addq	$-2, %rsi
	movslq	%esi, %rcx
	movl	$-1, %eax
.LBB5_2:                                # =>This Inner Loop Header: Depth=1
	leaq	-1(%rcx), %rdx
	incl	%eax
	testq	%rcx, %rcx
	jle	.LBB5_4
# %bb.3:                                #   in Loop: Header=BB5_2 Depth=1
	movsbl	(%rdi,%rcx), %esi
	addl	$-48, %esi
	movq	%rdx, %rcx
	cmpl	$10, %esi
	jb	.LBB5_2
.LBB5_4:
	movb	$0, 1(%rdi,%rdx)
.LBB5_5:
	retq
.Lfunc_end5:
	.size	_Z10chopStringPcm, .Lfunc_end5-_Z10chopStringPcm
	.cfi_endproc
                                        # -- End function
	.globl	_Z14int_vector_addP6vectori     # -- Begin function _Z14int_vector_addP6vectori
	.type	_Z14int_vector_addP6vectori,@function
_Z14int_vector_addP6vectori:            # @_Z14int_vector_addP6vectori
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movq	%rdi, %rbx
	movslq	12(%rdi), %rcx
	movq	%rcx, %rsi
	incq	%rsi
	movq	(%rdi), %rax
	cmpl	8(%rdi), %esi
	jne	.LBB6_4
# %bb.1:
	shlq	$3, %rsi
	movq	%rax, %rdi
	callq	realloc
	testq	%rax, %rax
	je	.LBB6_2
# %bb.3:                                # %.thread
	shll	8(%rbx)
	movq	%rax, (%rbx)
	movl	12(%rbx), %ecx
.LBB6_4:
	movslq	%ecx, %rcx
	movl	%ebp, (%rax,%rcx,4)
	incl	12(%rbx)
	movl	$1, %eax
.LBB6_5:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB6_2:
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	jmp	.LBB6_5
.Lfunc_end6:
	.size	_Z14int_vector_addP6vectori, .Lfunc_end6-_Z14int_vector_addP6vectori
	.cfi_endproc
                                        # -- End function
	.globl	_Z15int_vector_freeP6vector     # -- Begin function _Z15int_vector_freeP6vector
	.type	_Z15int_vector_freeP6vector,@function
_Z15int_vector_freeP6vector:            # @_Z15int_vector_freeP6vector
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movq	(%rdi), %rdi
	callq	free
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.Lfunc_end7:
	.size	_Z15int_vector_freeP6vector, .Lfunc_end7-_Z15int_vector_freeP6vector
	.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	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13get_odd_arrayPiS_i, %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	$_Z22parallel_prefix_kernelPiS_i, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9move_oddsPiS_S_i, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB9_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z13get_odd_arrayPiS_i,@object  # @_Z13get_odd_arrayPiS_i
	.section	.rodata,"a",@progbits
	.globl	_Z13get_odd_arrayPiS_i
	.p2align	3, 0x0
_Z13get_odd_arrayPiS_i:
	.quad	_Z28__device_stub__get_odd_arrayPiS_i
	.size	_Z13get_odd_arrayPiS_i, 8

	.type	_Z22parallel_prefix_kernelPiS_i,@object # @_Z22parallel_prefix_kernelPiS_i
	.globl	_Z22parallel_prefix_kernelPiS_i
	.p2align	3, 0x0
_Z22parallel_prefix_kernelPiS_i:
	.quad	_Z37__device_stub__parallel_prefix_kernelPiS_i
	.size	_Z22parallel_prefix_kernelPiS_i, 8

	.type	_Z9move_oddsPiS_S_i,@object     # @_Z9move_oddsPiS_S_i
	.globl	_Z9move_oddsPiS_S_i
	.p2align	3, 0x0
_Z9move_oddsPiS_S_i:
	.quad	_Z24__device_stub__move_oddsPiS_S_i
	.size	_Z9move_oddsPiS_S_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"error: no devices supporting CUDA.\n"
	.size	.L.str, 36

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"inp.txt"
	.size	.L.str.1, 8

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"r"
	.size	.L.str.2, 2

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%s cannot be found\n"
	.size	.L.str.3, 20

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"q3.txt"
	.size	.L.str.4, 7

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"w"
	.size	.L.str.5, 2

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"can't open file %s to write\n"
	.size	.L.str.6, 29

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%d"
	.size	.L.str.7, 3

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	",%d"
	.size	.L.str.8, 4

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z13get_odd_arrayPiS_i"
	.size	.L__unnamed_1, 23

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z22parallel_prefix_kernelPiS_i"
	.size	.L__unnamed_2, 32

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z9move_oddsPiS_S_i"
	.size	.L__unnamed_3, 20

	.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 _Z28__device_stub__get_odd_arrayPiS_i
	.addrsig_sym _Z37__device_stub__parallel_prefix_kernelPiS_i
	.addrsig_sym _Z24__device_stub__move_oddsPiS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z13get_odd_arrayPiS_i
	.addrsig_sym _Z22parallel_prefix_kernelPiS_i
	.addrsig_sym _Z9move_oddsPiS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z13get_odd_arrayPiS_i  ; -- Begin function _Z13get_odd_arrayPiS_i
	.globl	_Z13get_odd_arrayPiS_i
	.p2align	8
	.type	_Z13get_odd_arrayPiS_i,@function
_Z13get_odd_arrayPiS_i:                 ; @_Z13get_odd_arrayPiS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s3, 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_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	v_lshrrev_b32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v3, v2, v3
	v_and_b32_e32 v3, -2, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_sub_nc_u32_e32 v2, v2, v3
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13get_odd_arrayPiS_i
		.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 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	_Z13get_odd_arrayPiS_i, .Lfunc_end0-_Z13get_odd_arrayPiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 172
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 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	_Z22parallel_prefix_kernelPiS_i ; -- Begin function _Z22parallel_prefix_kernelPiS_i
	.globl	_Z22parallel_prefix_kernelPiS_i
	.p2align	8
	.type	_Z22parallel_prefix_kernelPiS_i,@function
_Z22parallel_prefix_kernelPiS_i:        ; @_Z22parallel_prefix_kernelPiS_i
; %bb.0:
	s_clause 0x2
	s_load_b32 s3, s[0:1], 0x24
	s_load_b32 s2, s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s0, s3, 0xffff
	s_cmp_gt_i32 s2, 1
	v_mad_u64_u32 v[1:2], null, s15, s0, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	s_cbranch_scc1 .LBB1_2
; %bb.1:                                ; %.._crit_edge_crit_edge
	s_mov_b32 s0, 0
	s_branch .LBB1_3
.LBB1_2:
	s_mov_b32 s0, -1
.LBB1_3:                                ; %Flow27
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s0
	s_cbranch_vccnz .LBB1_8
; %bb.4:                                ; %.lr.ph
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_cmp_gt_i32_e32 vcc_lo, s2, v1
	s_mov_b32 s1, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v3, s0, s6, v3
	v_add_co_ci_u32_e64 v4, s0, s7, v4, s0
.LBB1_5:                                ; =>This Inner Loop Header: Depth=1
	v_cmp_le_i32_e64 s0, s1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, vcc_lo, s0
	s_and_saveexec_b32 s3, s0
	s_cbranch_execz .LBB1_7
; %bb.6:                                ;   in Loop: Header=BB1_5 Depth=1
	v_subrev_nc_u32_e32 v5, s1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v6, 31, v5
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v5, s0, s6, v5
	v_add_co_ci_u32_e64 v6, s0, s7, v6, s0
	s_clause 0x1
	global_load_b32 v0, v[5:6], off
	global_load_b32 v5, v[3:4], off
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v0, v5, v0
	global_store_b32 v[3:4], v0, off
.LBB1_7:                                ;   in Loop: Header=BB1_5 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_lshl_b32 s1, s1, 1
	s_waitcnt_vscnt null, 0x0
	s_cmp_lt_i32 s1, s2
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_5
.LBB1_8:                                ; %._crit_edge
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z22parallel_prefix_kernelPiS_i
		.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 7
		.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	_Z22parallel_prefix_kernelPiS_i, .Lfunc_end1-_Z22parallel_prefix_kernelPiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 324
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; 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	_Z9move_oddsPiS_S_i     ; -- Begin function _Z9move_oddsPiS_S_i
	.globl	_Z9move_oddsPiS_S_i
	.p2align	8
	.type	_Z9move_oddsPiS_S_i,@function
_Z9move_oddsPiS_S_i:                    ; @_Z9move_oddsPiS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s3, s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB2_3
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s6, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v1, vcc_lo
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	v_and_b32_e32 v3, 0x80000001, v2
	v_cmp_eq_u32_e32 vcc_lo, 1, v3
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB2_3
; %bb.2:
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_store_b32 v[0:1], v2, off offset:-4
.LBB2_3:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9move_oddsPiS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 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_end2:
	.size	_Z9move_oddsPiS_S_i, .Lfunc_end2-_Z9move_oddsPiS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 224
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; Occupancy: 16
; WaveLimiterHint : 1
; 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:         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
    .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:           _Z13get_odd_arrayPiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z13get_odd_arrayPiS_i.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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .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
    .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:           _Z22parallel_prefix_kernelPiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z22parallel_prefix_kernelPiS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9move_oddsPiS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9move_oddsPiS_S_i.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
