#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 NUM_BUCKETS 10
#define Q2A_OUT_FILE "q2a.txt"
#define Q2B_OUT_FILE "q2b.txt"
#define Q2C_OUT_FILE "q2c.txt"

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

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);
void bucketize(vector *a, int *b);
int findMin(vector* vector);
void prefixSum(vector *a, int *b);

__global__ void global_reduce_kernel(int * d_out, int * d_in, int * d_intermediate, int size, bool phaseOne)
{
    int myId = threadIdx.x + blockDim.x * blockIdx.x;
	int tid  = threadIdx.x;
    // do reduction in global mem
	
	if(phaseOne)
	{
		int index = d_in[myId] / 100;
		//printf("block dim: %d\n", blockDim.x);
		d_intermediate[myId*NUM_BUCKETS + index] = 1;
		//printf("index: %d value: %d\n", myId*NUM_BUCKETS + index, d_in[myId] );
		__syncthreads(); //every thread computes its bucket for number
	}
	
	//then combine using reduce
	for (unsigned int s = blockDim.x / 2; s > 0; s >>= 1)
    {
		
		if(tid < s && myId + s < size)
		{
			for (int i = 0; i < NUM_BUCKETS; i++)
			{
				d_intermediate[myId*NUM_BUCKETS + i] += d_intermediate[(myId + s)* NUM_BUCKETS + i];
			}
			
		}
		__syncthreads();
	}
	
	//copy intermediate to block output
	if (tid == 0)
    {
		for(int i = 0; i < NUM_BUCKETS; i++)
		{
			d_out[blockIdx.x*NUM_BUCKETS + i] = d_intermediate[myId*NUM_BUCKETS + i];
		}
    }
}

__global__ void shmem_reduce_kernel(int * d_out, const int * d_in, int size, bool phaseOne)
{
    // sdata is allocated in the kernel call: 3rd arg to <<<b, t, shmem>>>
    extern __shared__ int sdata[];//let's use sdata like we use d_intermediate above
	//__shared__ int b[10] = {0};

    int myId = threadIdx.x + blockDim.x * blockIdx.x;
    int tid  = threadIdx.x;
	
    // load shared mem from global mem
	
	if(phaseOne)
	{
		int index = d_in[myId] / 100;
		for(int i = 0; i < NUM_BUCKETS; i++)
		{
			if(index == i)
			{
				sdata[tid*NUM_BUCKETS + i] = 1;
			}
			else
			{
				sdata[tid*NUM_BUCKETS + i] = 0;
			}
			
		}
		
	}
	else 
	{
		for(int i = 0; i < NUM_BUCKETS; i++)
		{
			sdata[tid*NUM_BUCKETS + i] = d_in[myId*NUM_BUCKETS + i];
		}
	}
    __syncthreads(); 
	
	           // make sure entire block is loaded!

    // do reduction in shared mem
    for (unsigned int s = blockDim.x / 2; s > 0; s >>= 1)
    {
        if(tid < s && myId + s < size)
		{
			for (int i = 0; i < NUM_BUCKETS; i++)
			{
				sdata[tid*NUM_BUCKETS + i] += sdata[(tid + s)* NUM_BUCKETS + i];
			}
			
		}
		__syncthreads();
    }

    // only thread 0 writes result for this block back to global mem
    if (tid == 0)
    {
		for(int i = 0; i < NUM_BUCKETS; i++)
		{
			d_out[blockIdx.x*NUM_BUCKETS + i] += sdata[tid * NUM_BUCKETS + i];
		}
        
    }
}

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

void reduce_a(int * b, int * b_intermediate, int * d_intermediate, int * d_in,
            int size)
{
    // assumes that size is not greater than maxThreadsPerBlock^2
    // and that size is a multiple of maxThreadsPerBlock
    const int maxThreadsPerBlock = 1024; //increased from 512 to 1024 to handle 1024^2 values
    int threads = maxThreadsPerBlock;
    int blocks = (size + (maxThreadsPerBlock - 1)) / maxThreadsPerBlock;
	//printf("blocks: %d, size: %d\n", blocks, size);
    global_reduce_kernel<<<blocks, threads>>>(b_intermediate, d_in, d_intermediate, size, true);
	int newSize = blocks;
	int powerOfTwo = 1;
	while (powerOfTwo < blocks) 
	{
		powerOfTwo *= 2;
	}
	threads = powerOfTwo; // launch one thread for each block in prev step
    blocks = 1;

	global_reduce_kernel<<<blocks, threads>>>(b, d_in, b_intermediate, newSize, false);
}

void reduce_b(int * b, int * d_intermediate, int * d_in,
            int size)
{
    // assumes that size is not greater than maxThreadsPerBlock^2
    // and that size is a multiple of maxThreadsPerBlock
    const int maxThreadsPerBlock = 1024; //increased from 512 to 1024 to handle 1024^2 values
    int threads = maxThreadsPerBlock;
    int blocks = (size + (maxThreadsPerBlock - 1)) / maxThreadsPerBlock;
    
    shmem_reduce_kernel<<<blocks, threads, NUM_BUCKETS * threads * sizeof(int)>>>(d_intermediate, d_in, size, true);
    int newSize = blocks;
	int powerOfTwo = 1;
	while (powerOfTwo < blocks) 
	{
		powerOfTwo *= 2;
	}
	threads = powerOfTwo; // launch one thread for each block in prev step
    blocks = 1;

	shmem_reduce_kernel<<<blocks, threads, threads* NUM_BUCKETS * sizeof(int)>>>(b, d_intermediate, newSize, false);

}

void run_c(int *b, int * d_in, int size) {
	parallel_prefix_kernel<<<10, 1>>>(b, d_in, size); 
}

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);
	
	cudaDeviceProp devProps;
    if (cudaGetDeviceProperties(&devProps, dev) == 0)
    {
        
    }

	FILE *fp;
	if((fp = fopen(INPUT_FILE, "r")) == 0)
	{
		printf("%s cannot be found\n", INPUT_FILE);
		exit(-1);
	}
	char separators[] = " ,";
	//int num;
	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);
		
			
	}
	int min = findMin(a); 
	int b[10] = {0};
	bucketize(a, b);
	for(int i = 0; i < NUM_BUCKETS; i++)
	{
		//printf("index: %d count: %d\n", i, b[i]);
	}
	
	const int ARRAY_BYTES = sizeof(int) * a->size;

    // declare GPU memory pointers
    int * d_in, * d_intermediate, * b_intermediate, *a_out, *b_out, *c_out;

    // allocate GPU memory
    cudaMalloc((void **) &d_in, ARRAY_BYTES);
    cudaMalloc((void **) &d_intermediate, ARRAY_BYTES * NUM_BUCKETS); // overallocated
	cudaMalloc((void **) &b_intermediate, ARRAY_BYTES * NUM_BUCKETS);
    //cudaMalloc((void **) &d_out, sizeof(int));
	cudaMalloc((void **) &a_out, sizeof(int) * NUM_BUCKETS);
	cudaMalloc((void **) &b_out, sizeof(int) * NUM_BUCKETS);
	cudaMalloc((void **) &c_out, sizeof(int) * NUM_BUCKETS);
	//free CPU memory
	
	
	//cudaMemset(b_out, 0, sizeof(int) * NUM_BUCKETS);
	cudaMemset(b_out, 0, sizeof(int) * NUM_BUCKETS);
	cudaMemset(a_out, 0, sizeof(int) * NUM_BUCKETS);
	
	cudaMemset(b_intermediate, 0, ARRAY_BYTES * NUM_BUCKETS);//
	cudaMemset(d_intermediate, 0, ARRAY_BYTES * NUM_BUCKETS);//
    // transfer the input array to the GPU
    cudaMemcpy(d_in, a->elements, ARRAY_BYTES, cudaMemcpyHostToDevice);
	
	int_vector_free(a);

	
	cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
	
	cudaEventRecord(start, 0);
    // launch the kernel
	reduce_a(a_out, b_intermediate,  d_intermediate, d_in, a->size);
	cudaEventRecord(stop, 0);
	cudaEventSynchronize(stop);
	
	cudaEventRecord(start, 0);
	reduce_b(b_out, d_intermediate, d_in, a->size);
	cudaEventRecord(stop, 0);
	cudaEventSynchronize(stop);
	
	cudaEventRecord(start, 0);
	run_c(c_out, b_out, NUM_BUCKETS);
	cudaEventRecord(stop, 0);
	cudaEventSynchronize(stop);
	
    float elapsedTime;
    cudaEventElapsedTime(&elapsedTime, start, stop);
    
	int h_a_out[NUM_BUCKETS];
	int h_b_out[NUM_BUCKETS];
	int h_c_out[NUM_BUCKETS];
	
	// copy back data from GPU
    cudaMemcpy(h_a_out, a_out, sizeof(int) * NUM_BUCKETS, cudaMemcpyDeviceToHost);
	cudaMemcpy(h_b_out, b_out, sizeof(int) * NUM_BUCKETS, cudaMemcpyDeviceToHost);
	cudaMemcpy(h_c_out, c_out, sizeof(int) * NUM_BUCKETS, cudaMemcpyDeviceToHost);
	
	/****************** write to q2a.txt *******************************/
	
	FILE *outFp = fopen(Q2A_OUT_FILE, "w");
	if(outFp == NULL)
	{
		printf("can't open file %s to write\n", Q2A_OUT_FILE);
	}
	fprintf(outFp, "%d", h_a_out[0]);
	for(int i = 1; i < NUM_BUCKETS; i++)
	{
		fprintf(outFp, ", %d", h_a_out[i]);
	}
	fprintf(outFp, "\n");
	
	fclose(outFp);
	
	/*********************** write to q2b.txt ***********************/
	
	outFp = fopen(Q2B_OUT_FILE, "w");
	if(outFp == NULL)
	{
		printf("can't open file %s to write\n", Q2A_OUT_FILE);
	}
	fprintf(outFp, "%d", h_b_out[0]);
	for(int i = 1; i < NUM_BUCKETS; i++)
	{
		fprintf(outFp, ", %d", h_b_out[i]);
	}
	fprintf(outFp, "\n");
	
	fclose(outFp);
	
	/***********************debug parallel prefix sum*********************/
	//printf("parallel prefix sum cpu: ");
	vector * wrapper = (vector*) malloc(sizeof(vector));
	int_vector_init(wrapper);
	for (int i = 0; i < NUM_BUCKETS; i++)
	{
		int_vector_add(wrapper, h_b_out[i]);
	}
	int cpu_prefix_out[10] = {0};
	prefixSum(wrapper, cpu_prefix_out);
	//printf("%d", cpu_prefix_out[0]);
	for(int i = 1; i < NUM_BUCKETS; i++)
	{
		//printf( ", %d", cpu_prefix_out[i]);
	}
	//printf("\n");
	
	/************************write to q2c.txt***********************************/
	
	
	outFp = fopen(Q2C_OUT_FILE, "w");
	if(outFp == NULL)
	{
		printf("can't open file %s to write\n", Q2C_OUT_FILE);
	}
	fprintf(outFp, "%d", h_c_out[0]);
	for(int i = 1; i < NUM_BUCKETS; i++)
	{
		fprintf(outFp, ", %d", h_c_out[i]);
	}
	fprintf(outFp, "\n");
	
	fclose(outFp);
	
	
    // free GPU memory allocation
    cudaFree(d_in);
    cudaFree(d_intermediate);
	cudaFree(b_intermediate);
	cudaFree(a_out);
	cudaFree(b_out);
	cudaFree(c_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);
}

//input: a array of int; output: b array of 10 int
void bucketize(vector *a, int *b) {
	for(int i = 0; i < a->size; i++)
	{
		int index = a->elements[i] / 100;
		b[index] += 1;
	}
}

//goal is a running sum of a
//b must have 10 elements
void prefixSum(vector *a, int *b) {
	int * elements = a->elements;
	vector * firstPass = (vector*) malloc(sizeof(vector));
	int_vector_init(firstPass);
	int size = a->size;
	b[0] = elements[0];
	for(int i = 1; i < size; i++)
	{
		//int_vector_add(firstPass, sum);
		b[i] = b[i-1] + elements[i];
	}
}

//assumes vector size >= 1
int findMin(vector* vector) {
	int min = INT_MAX;
	if(vector == NULL)
	{
		return min;
	}
	int size = vector->size;
	int* arr = vector->elements;
	
	for(int i = 0; i < size; i++)
	{
		if(arr[i] < min)
		{
			min = arr[i];
		}
	}
	return min;
}

//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_0023fc19_00000000-6_q2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2040:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2040:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z15int_vector_initP6vector
	.type	_Z15int_vector_initP6vector, @function
_Z15int_vector_initP6vector:
.LFB2031:
	.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
.LFE2031:
	.size	_Z15int_vector_initP6vector, .-_Z15int_vector_initP6vector
	.globl	_Z14int_vector_addP6vectori
	.type	_Z14int_vector_addP6vectori, @function
_Z14int_vector_addP6vectori:
.LFB2032:
	.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
.LFE2032:
	.size	_Z14int_vector_addP6vectori, .-_Z14int_vector_addP6vectori
	.globl	_Z15int_vector_freeP6vector
	.type	_Z15int_vector_freeP6vector, @function
_Z15int_vector_freeP6vector:
.LFB2033:
	.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
.LFE2033:
	.size	_Z15int_vector_freeP6vector, .-_Z15int_vector_freeP6vector
	.globl	_Z9bucketizeP6vectorPi
	.type	_Z9bucketizeP6vectorPi, @function
_Z9bucketizeP6vectorPi:
.LFB2034:
	.cfi_startproc
	endbr64
	xorl	%ecx, %ecx
	movl	$100, %r8d
.L20:
	cmpl	%ecx, 12(%rdi)
	jle	.L22
	movq	(%rdi), %rax
	movl	(%rax,%rcx,4), %eax
	incq	%rcx
	cltd
	idivl	%r8d
	cltq
	incl	(%rsi,%rax,4)
	jmp	.L20
.L22:
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z9bucketizeP6vectorPi, .-_Z9bucketizeP6vectorPi
	.globl	_Z9prefixSumP6vectorPi
	.type	_Z9prefixSumP6vectorPi, @function
_Z9prefixSumP6vectorPi:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	(%rdi), %r12
	movl	$16, %edi
	movq	%rsi, %rbx
	call	malloc@PLT
	movq	%rax, %rdi
	call	_Z15int_vector_initP6vector
	movl	(%r12), %eax
	movl	12(%rbp), %ecx
	movl	%eax, (%rbx)
	xorl	%eax, %eax
.L24:
	incq	%rax
	cmpl	%eax, %ecx
	jle	.L27
	movl	(%r12,%rax,4), %edx
	addl	-4(%rbx,%rax,4), %edx
	movl	%edx, (%rbx,%rax,4)
	jmp	.L24
.L27:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2035:
	.size	_Z9prefixSumP6vectorPi, .-_Z9prefixSumP6vectorPi
	.globl	_Z7findMinP6vector
	.type	_Z7findMinP6vector, @function
_Z7findMinP6vector:
.LFB2036:
	.cfi_startproc
	endbr64
	movl	$2147483647, %eax
	testq	%rdi, %rdi
	je	.L28
	movl	12(%rdi), %esi
	movq	(%rdi), %rdi
	xorl	%edx, %edx
.L30:
	cmpl	%edx, %esi
	jle	.L28
	movl	(%rdi,%rdx,4), %ecx
	cmpl	%ecx, %eax
	cmovg	%ecx, %eax
	incq	%rdx
	jmp	.L30
.L28:
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z7findMinP6vector, .-_Z7findMinP6vector
	.globl	_Z10chopStringPcm
	.type	_Z10chopStringPcm, @function
_Z10chopStringPcm:
.LFB2037:
	.cfi_startproc
	endbr64
	movsbl	-2(%rdi,%rsi), %eax
	leal	-48(%rax), %edx
	xorl	%eax, %eax
	cmpl	$9, %edx
	ja	.L33
	leal	-2(%rsi), %eax
	cltq
.L35:
	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	.L35
	movb	$0, (%rdi,%rdx)
	subl	%edx, %esi
	leal	-2(%rsi), %eax
.L33:
	ret
	.cfi_endproc
.LFE2037:
	.size	_Z10chopStringPcm, .-_Z10chopStringPcm
	.globl	_Z46__device_stub__Z20global_reduce_kernelPiS_S_ibPiS_S_ib
	.type	_Z46__device_stub__Z20global_reduce_kernelPiS_S_ibPiS_S_ib, @function
_Z46__device_stub__Z20global_reduce_kernelPiS_S_ibPiS_S_ib:
.LFB2062:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	40(%rsp), %rcx
	movb	%r8b, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L38
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z20global_reduce_kernelPiS_S_ib(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L38:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2062:
	.size	_Z46__device_stub__Z20global_reduce_kernelPiS_S_ibPiS_S_ib, .-_Z46__device_stub__Z20global_reduce_kernelPiS_S_ibPiS_S_ib
	.globl	_Z20global_reduce_kernelPiS_S_ib
	.type	_Z20global_reduce_kernelPiS_S_ib, @function
_Z20global_reduce_kernelPiS_S_ib:
.LFB2063:
	.cfi_startproc
	endbr64
	movzbl	%r8b, %r8d
	jmp	_Z46__device_stub__Z20global_reduce_kernelPiS_S_ibPiS_S_ib
	.cfi_endproc
.LFE2063:
	.size	_Z20global_reduce_kernelPiS_S_ib, .-_Z20global_reduce_kernelPiS_S_ib
	.globl	_Z8reduce_aPiS_S_S_i
	.type	_Z8reduce_aPiS_S_S_i, @function
_Z8reduce_aPiS_S_S_i:
.LFB2027:
	.cfi_startproc
	endbr64
	leal	1023(%r8), %eax
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdx, %r15
	xorl	%r9d, %r9d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	cltd
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%r8d, %r13d
	xorl	%r8d, %r8d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rcx, %rbp
	movl	$1024, %ecx
	idivl	%ecx
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movl	$4194305, %edx
	movl	$1, %ecx
	salq	$10, %rdx
	movl	$1, 28(%rsp)
	movq	%rdx, 20(%rsp)
	movl	%eax, 8(%rsp)
	movl	%eax, %ebx
	movabsq	$4294967297, %rax
	movq	%rax, 12(%rsp)
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L44
	movl	$1, %r8d
	movl	%r13d, %ecx
	movq	%r15, %rdx
	movq	%rbp, %rsi
	movq	%r12, %rdi
	call	_Z46__device_stub__Z20global_reduce_kernelPiS_S_ibPiS_S_ib
.L44:
	movl	$1, %eax
.L45:
	cmpl	%ebx, %eax
	jge	.L49
	addl	%eax, %eax
	jmp	.L45
.L49:
	movl	%eax, 20(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movl	$1, 16(%rsp)
	movq	%rdi, 24(%rsp)
	movl	28(%rsp), %ecx
	movq	20(%rsp), %rdx
	movq	%rdi, 8(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L43
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%ebx, %ecx
	movq	%r12, %rdx
	movq	%rbp, %rsi
	popq	%rbx
	.cfi_def_cfa_offset 48
	movq	%r14, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 40
	xorl	%r8d, %r8d
	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
	jmp	_Z46__device_stub__Z20global_reduce_kernelPiS_S_ibPiS_S_ib
.L43:
	.cfi_restore_state
	addq	$40, %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
.LFE2027:
	.size	_Z8reduce_aPiS_S_S_i, .-_Z8reduce_aPiS_S_S_i
	.globl	_Z44__device_stub__Z19shmem_reduce_kernelPiPKiibPiPKiib
	.type	_Z44__device_stub__Z19shmem_reduce_kernelPiPKiibPiPKiib, @function
_Z44__device_stub__Z19shmem_reduce_kernelPiPKiibPiPKiib:
.LFB2064:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movb	%cl, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L50
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z19shmem_reduce_kernelPiPKiib(%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
.L50:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L52
	call	__stack_chk_fail@PLT
.L52:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2064:
	.size	_Z44__device_stub__Z19shmem_reduce_kernelPiPKiibPiPKiib, .-_Z44__device_stub__Z19shmem_reduce_kernelPiPKiibPiPKiib
	.globl	_Z19shmem_reduce_kernelPiPKiib
	.type	_Z19shmem_reduce_kernelPiPKiib, @function
_Z19shmem_reduce_kernelPiPKiib:
.LFB2065:
	.cfi_startproc
	endbr64
	movzbl	%cl, %ecx
	jmp	_Z44__device_stub__Z19shmem_reduce_kernelPiPKiibPiPKiib
	.cfi_endproc
.LFE2065:
	.size	_Z19shmem_reduce_kernelPiPKiib, .-_Z19shmem_reduce_kernelPiPKiib
	.globl	_Z8reduce_bPiS_S_i
	.type	_Z8reduce_bPiS_S_i, @function
_Z8reduce_bPiS_S_i:
.LFB2028:
	.cfi_startproc
	endbr64
	leal	1023(%rcx), %eax
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rdx, %r14
	xorl	%r9d, %r9d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	cltd
	movl	%ecx, %r13d
	movl	$1024, %ecx
	idivl	%ecx
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	movq	%rdi, %r12
	movq	%rsi, %rbp
	movl	$4194305, %edx
	salq	$10, %rdx
	movl	$40960, %r8d
	movl	$1, %ecx
	movl	$1, 28(%rsp)
	movq	%rdx, 20(%rsp)
	movl	%eax, 8(%rsp)
	movl	%eax, %ebx
	movabsq	$4294967297, %rax
	movq	%rax, 12(%rsp)
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L56
	movl	$1, %ecx
	movl	%r13d, %edx
	movq	%r14, %rsi
	movq	%rbp, %rdi
	call	_Z44__device_stub__Z19shmem_reduce_kernelPiPKiibPiPKiib
.L56:
	movl	$1, %ecx
.L57:
	cmpl	%ebx, %ecx
	jge	.L61
	addl	%ecx, %ecx
	jmp	.L57
.L61:
	movl	%ecx, 20(%rsp)
	imull	$10, %ecx, %ecx
	xorl	%r9d, %r9d
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movl	$1, 16(%rsp)
	movq	%rdi, 24(%rsp)
	movl	28(%rsp), %eax
	movslq	%ecx, %rcx
	movq	20(%rsp), %rdx
	movq	%rdi, 8(%rsp)
	leaq	0(,%rcx,4), %r8
	movq	%rax, %rcx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L55
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	movl	%ebx, %edx
	movq	%rbp, %rsi
	movq	%r12, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 40
	xorl	%ecx, %ecx
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	_Z44__device_stub__Z19shmem_reduce_kernelPiPKiibPiPKiib
.L55:
	.cfi_restore_state
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z8reduce_bPiS_S_i, .-_Z8reduce_bPiS_S_i
	.globl	_Z46__device_stub__Z22parallel_prefix_kernelPiPKiiPiPKii
	.type	_Z46__device_stub__Z22parallel_prefix_kernelPiPKiiPiPKii, @function
_Z46__device_stub__Z22parallel_prefix_kernelPiPKiiPiPKii:
.LFB2066:
	.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	.L62
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z22parallel_prefix_kernelPiPKii(%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
.L62:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L64
	call	__stack_chk_fail@PLT
.L64:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2066:
	.size	_Z46__device_stub__Z22parallel_prefix_kernelPiPKiiPiPKii, .-_Z46__device_stub__Z22parallel_prefix_kernelPiPKiiPiPKii
	.globl	_Z22parallel_prefix_kernelPiPKii
	.type	_Z22parallel_prefix_kernelPiPKii, @function
_Z22parallel_prefix_kernelPiPKii:
.LFB2067:
	.cfi_startproc
	endbr64
	jmp	_Z46__device_stub__Z22parallel_prefix_kernelPiPKiiPiPKii
	.cfi_endproc
.LFE2067:
	.size	_Z22parallel_prefix_kernelPiPKii, .-_Z22parallel_prefix_kernelPiPKii
	.globl	_Z5run_cPiS_i
	.type	_Z5run_cPiS_i, @function
_Z5run_cPiS_i:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorl	%r9d, %r9d
	movl	%edx, %r12d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rdx
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	$1, %ecx
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	movl	$2147483653, %edi
	movl	$1, %esi
	addq	%rdi, %rdi
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L67
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	movl	%r12d, %edx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	_Z46__device_stub__Z22parallel_prefix_kernelPiPKiiPiPKii
.L67:
	.cfi_restore_state
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z5run_cPiS_i, .-_Z5run_cPiS_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	"q2a.txt"
.LC6:
	.string	"can't open file %s to write\n"
.LC7:
	.string	"%d"
.LC8:
	.string	", %d"
.LC9:
	.string	"\n"
.LC10:
	.string	"q2b.txt"
.LC11:
	.string	"q2c.txt"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$1448, %rsp
	.cfi_def_cfa_offset 1504
	movq	%fs:40, %rax
	movq	%rax, 1432(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	cmpl	$0, 24(%rsp)
	jne	.L71
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	jmp	.L91
.L71:
	xorl	%edi, %edi
	leaq	.LC2(%rip), %rbx
	call	cudaSetDevice@PLT
	leaq	296(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaGetDeviceProperties_v2@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rbx, %rdi
	call	fopen@PLT
	movq	%rax, %r13
	testq	%rax, %rax
	jne	.L72
	movl	$2, %edi
	movq	%rbx, %rdx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %edi
.L91:
	call	exit@PLT
.L72:
	movl	$16, %edi
	movb	$0, 1331(%rsp)
	xorl	%ebp, %ebp
	movl	$100, %r15d
	movw	$11296, 1329(%rsp)
	call	malloc@PLT
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	_Z15int_vector_initP6vector
.L73:
	movslq	%ebp, %rdi
	movl	$100, %esi
	movl	%r15d, %edx
	movq	%r13, %rcx
	subl	%ebp, %edx
	cmpq	%rsi, %rdi
	leaq	1332(%rsp), %r12
	cmovnb	%rdi, %rsi
	subq	%rdi, %rsi
	addq	%r12, %rdi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L92
	movl	$100, %esi
	movq	%r12, %rdi
	leaq	1329(%rsp), %r14
	call	_Z10chopStringPcm
	movq	%r14, %rsi
	movl	%eax, %ebp
	movl	$99, %eax
	subl	%ebp, %eax
	movl	%eax, 12(%rsp)
.L90:
	call	strtok@PLT
	testq	%rax, %rax
	je	.L93
	movq	%rax, %rdi
	call	atoi@PLT
	movq	%rbx, %rdi
	movl	%eax, %esi
	call	_Z14int_vector_addP6vectori
	movq	%r14, %rsi
	xorl	%edi, %edi
	jmp	.L90
.L93:
	movslq	12(%rsp), %rsi
	movslq	%ebp, %rdx
	movl	$100, %ecx
	movq	%r12, %rdi
	addq	%r12, %rsi
	call	__memcpy_chk@PLT
	jmp	.L73
.L92:
	leaq	96(%rsp), %rdi
	movl	$10, %ecx
	leaq	96(%rsp), %rsi
	rep stosl
	movq	%rbx, %rdi
	leaq	136(%rsp), %r15
	leaq	216(%rsp), %r14
	call	_Z9bucketizeP6vectorPi
	movl	12(%rbx), %eax
	leaq	32(%rsp), %rdi
	leaq	.LC5(%rip), %r13
	leal	0(,%rax,4), %ebp
	movslq	%ebp, %r12
	imull	$10, %ebp, %ebp
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movslq	%ebp, %rbp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	leaq	48(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movl	$40, %esi
	call	cudaMalloc@PLT
	leaq	64(%rsp), %rdi
	movl	$40, %esi
	call	cudaMalloc@PLT
	leaq	72(%rsp), %rdi
	movl	$40, %esi
	call	cudaMalloc@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	movl	$40, %edx
	call	cudaMemset@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	movl	$40, %edx
	call	cudaMemset@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rbp, %rdx
	call	cudaMemset@PLT
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rbp, %rdx
	call	cudaMemset@PLT
	movq	(%rbx), %rsi
	movq	32(%rsp), %rdi
	movq	%r12, %rdx
	movl	$1, %ecx
	leaq	176(%rsp), %r12
	call	cudaMemcpy@PLT
	movq	%rbx, %rdi
	call	_Z15int_vector_freeP6vector
	leaq	80(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	88(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	12(%rbx), %ebx
	movq	32(%rsp), %rcx
	movq	40(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	56(%rsp), %rdi
	movl	%ebx, %r8d
	call	_Z8reduce_aPiS_S_S_i
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	88(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdx
	movq	40(%rsp), %rsi
	movl	%ebx, %ecx
	movq	64(%rsp), %rdi
	call	_Z8reduce_bPiS_S_i
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	88(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rsi
	movq	72(%rsp), %rdi
	movl	$10, %edx
	call	_Z5run_cPiS_i
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	88(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	leaq	28(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movq	%r15, %rdi
	movl	$40, %edx
	call	cudaMemcpy@PLT
	movq	64(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	movl	$40, %edx
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rsi
	movl	$2, %ecx
	movq	%r14, %rdi
	movl	$40, %edx
	call	cudaMemcpy@PLT
	leaq	.LC4(%rip), %rsi
	movq	%r13, %rdi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L77
	movq	%r13, %rdx
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L77:
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$1, %ebp
	movl	136(%rsp), %ecx
	leaq	.LC7(%rip), %rdx
	call	__fprintf_chk@PLT
.L78:
	movl	(%r15,%rbp,4), %ecx
	leaq	.LC8(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$2, %esi
	incq	%rbp
	call	__fprintf_chk@PLT
	cmpq	$10, %rbp
	jne	.L78
	leaq	.LC9(%rip), %r15
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movq	%r15, %rdx
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	leaq	.LC4(%rip), %rsi
	leaq	.LC10(%rip), %rdi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L79
	movq	%r13, %rdx
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L79:
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$1, %r13d
	movl	176(%rsp), %ecx
	leaq	.LC7(%rip), %rdx
	call	__fprintf_chk@PLT
.L80:
	movl	(%r12,%r13,4), %ecx
	leaq	.LC8(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$2, %esi
	incq	%r13
	call	__fprintf_chk@PLT
	cmpq	$10, %r13
	jne	.L80
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	xorl	%r13d, %r13d
	call	fclose@PLT
	movl	$16, %edi
	call	malloc@PLT
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	_Z15int_vector_initP6vector
.L81:
	movl	(%r12,%r13,4), %esi
	movq	%rbx, %rdi
	incq	%r13
	call	_Z14int_vector_addP6vectori
	cmpq	$10, %r13
	jne	.L81
	xorl	%eax, %eax
	leaq	256(%rsp), %rdi
	movq	%r13, %rcx
	rep stosl
	leaq	256(%rsp), %rsi
	movq	%rbx, %rdi
	leaq	.LC11(%rip), %rbp
	call	_Z9prefixSumP6vectorPi
	leaq	.LC4(%rip), %rsi
	movq	%rbp, %rdi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L82
	movq	%rbp, %rdx
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L82:
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$1, %ebp
	movl	216(%rsp), %ecx
	leaq	.LC7(%rip), %rdx
	call	__fprintf_chk@PLT
.L83:
	movl	(%r14,%rbp,4), %ecx
	leaq	.LC8(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$2, %esi
	incq	%rbp
	call	__fprintf_chk@PLT
	cmpq	$10, %rbp
	jne	.L83
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	1432(%rsp), %rax
	subq	%fs:40, %rax
	je	.L84
	call	__stack_chk_fail@PLT
.L84:
	addq	$1448, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z22parallel_prefix_kernelPiPKii"
.LC13:
	.string	"_Z19shmem_reduce_kernelPiPKiib"
.LC14:
	.string	"_Z20global_reduce_kernelPiS_S_ib"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2069:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z22parallel_prefix_kernelPiPKii(%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	.LC13(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z19shmem_reduce_kernelPiPKiib(%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	.LC14(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z20global_reduce_kernelPiS_S_ib(%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
.LFE2069:
	.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 NUM_BUCKETS 10
#define Q2A_OUT_FILE "q2a.txt"
#define Q2B_OUT_FILE "q2b.txt"
#define Q2C_OUT_FILE "q2c.txt"

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

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);
void bucketize(vector *a, int *b);
int findMin(vector* vector);
void prefixSum(vector *a, int *b);

__global__ void global_reduce_kernel(int * d_out, int * d_in, int * d_intermediate, int size, bool phaseOne)
{
    int myId = threadIdx.x + blockDim.x * blockIdx.x;
	int tid  = threadIdx.x;
    // do reduction in global mem
	
	if(phaseOne)
	{
		int index = d_in[myId] / 100;
		//printf("block dim: %d\n", blockDim.x);
		d_intermediate[myId*NUM_BUCKETS + index] = 1;
		//printf("index: %d value: %d\n", myId*NUM_BUCKETS + index, d_in[myId] );
		__syncthreads(); //every thread computes its bucket for number
	}
	
	//then combine using reduce
	for (unsigned int s = blockDim.x / 2; s > 0; s >>= 1)
    {
		
		if(tid < s && myId + s < size)
		{
			for (int i = 0; i < NUM_BUCKETS; i++)
			{
				d_intermediate[myId*NUM_BUCKETS + i] += d_intermediate[(myId + s)* NUM_BUCKETS + i];
			}
			
		}
		__syncthreads();
	}
	
	//copy intermediate to block output
	if (tid == 0)
    {
		for(int i = 0; i < NUM_BUCKETS; i++)
		{
			d_out[blockIdx.x*NUM_BUCKETS + i] = d_intermediate[myId*NUM_BUCKETS + i];
		}
    }
}

__global__ void shmem_reduce_kernel(int * d_out, const int * d_in, int size, bool phaseOne)
{
    // sdata is allocated in the kernel call: 3rd arg to <<<b, t, shmem>>>
    extern __shared__ int sdata[];//let's use sdata like we use d_intermediate above
	//__shared__ int b[10] = {0};

    int myId = threadIdx.x + blockDim.x * blockIdx.x;
    int tid  = threadIdx.x;
	
    // load shared mem from global mem
	
	if(phaseOne)
	{
		int index = d_in[myId] / 100;
		for(int i = 0; i < NUM_BUCKETS; i++)
		{
			if(index == i)
			{
				sdata[tid*NUM_BUCKETS + i] = 1;
			}
			else
			{
				sdata[tid*NUM_BUCKETS + i] = 0;
			}
			
		}
		
	}
	else 
	{
		for(int i = 0; i < NUM_BUCKETS; i++)
		{
			sdata[tid*NUM_BUCKETS + i] = d_in[myId*NUM_BUCKETS + i];
		}
	}
    __syncthreads(); 
	
	           // make sure entire block is loaded!

    // do reduction in shared mem
    for (unsigned int s = blockDim.x / 2; s > 0; s >>= 1)
    {
        if(tid < s && myId + s < size)
		{
			for (int i = 0; i < NUM_BUCKETS; i++)
			{
				sdata[tid*NUM_BUCKETS + i] += sdata[(tid + s)* NUM_BUCKETS + i];
			}
			
		}
		__syncthreads();
    }

    // only thread 0 writes result for this block back to global mem
    if (tid == 0)
    {
		for(int i = 0; i < NUM_BUCKETS; i++)
		{
			d_out[blockIdx.x*NUM_BUCKETS + i] += sdata[tid * NUM_BUCKETS + i];
		}
        
    }
}

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

void reduce_a(int * b, int * b_intermediate, int * d_intermediate, int * d_in,
            int size)
{
    // assumes that size is not greater than maxThreadsPerBlock^2
    // and that size is a multiple of maxThreadsPerBlock
    const int maxThreadsPerBlock = 1024; //increased from 512 to 1024 to handle 1024^2 values
    int threads = maxThreadsPerBlock;
    int blocks = (size + (maxThreadsPerBlock - 1)) / maxThreadsPerBlock;
	//printf("blocks: %d, size: %d\n", blocks, size);
    global_reduce_kernel<<<blocks, threads>>>(b_intermediate, d_in, d_intermediate, size, true);
	int newSize = blocks;
	int powerOfTwo = 1;
	while (powerOfTwo < blocks) 
	{
		powerOfTwo *= 2;
	}
	threads = powerOfTwo; // launch one thread for each block in prev step
    blocks = 1;

	global_reduce_kernel<<<blocks, threads>>>(b, d_in, b_intermediate, newSize, false);
}

void reduce_b(int * b, int * d_intermediate, int * d_in,
            int size)
{
    // assumes that size is not greater than maxThreadsPerBlock^2
    // and that size is a multiple of maxThreadsPerBlock
    const int maxThreadsPerBlock = 1024; //increased from 512 to 1024 to handle 1024^2 values
    int threads = maxThreadsPerBlock;
    int blocks = (size + (maxThreadsPerBlock - 1)) / maxThreadsPerBlock;
    
    shmem_reduce_kernel<<<blocks, threads, NUM_BUCKETS * threads * sizeof(int)>>>(d_intermediate, d_in, size, true);
    int newSize = blocks;
	int powerOfTwo = 1;
	while (powerOfTwo < blocks) 
	{
		powerOfTwo *= 2;
	}
	threads = powerOfTwo; // launch one thread for each block in prev step
    blocks = 1;

	shmem_reduce_kernel<<<blocks, threads, threads* NUM_BUCKETS * sizeof(int)>>>(b, d_intermediate, newSize, false);

}

void run_c(int *b, int * d_in, int size) {
	parallel_prefix_kernel<<<10, 1>>>(b, d_in, size); 
}

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);
	
	hipDeviceProp_t devProps;
    if (hipGetDeviceProperties(&devProps, dev) == 0)
    {
        
    }

	FILE *fp;
	if((fp = fopen(INPUT_FILE, "r")) == 0)
	{
		printf("%s cannot be found\n", INPUT_FILE);
		exit(-1);
	}
	char separators[] = " ,";
	//int num;
	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);
		
			
	}
	int min = findMin(a); 
	int b[10] = {0};
	bucketize(a, b);
	for(int i = 0; i < NUM_BUCKETS; i++)
	{
		//printf("index: %d count: %d\n", i, b[i]);
	}
	
	const int ARRAY_BYTES = sizeof(int) * a->size;

    // declare GPU memory pointers
    int * d_in, * d_intermediate, * b_intermediate, *a_out, *b_out, *c_out;

    // allocate GPU memory
    hipMalloc((void **) &d_in, ARRAY_BYTES);
    hipMalloc((void **) &d_intermediate, ARRAY_BYTES * NUM_BUCKETS); // overallocated
	hipMalloc((void **) &b_intermediate, ARRAY_BYTES * NUM_BUCKETS);
    //cudaMalloc((void **) &d_out, sizeof(int));
	hipMalloc((void **) &a_out, sizeof(int) * NUM_BUCKETS);
	hipMalloc((void **) &b_out, sizeof(int) * NUM_BUCKETS);
	hipMalloc((void **) &c_out, sizeof(int) * NUM_BUCKETS);
	//free CPU memory
	
	
	//cudaMemset(b_out, 0, sizeof(int) * NUM_BUCKETS);
	hipMemset(b_out, 0, sizeof(int) * NUM_BUCKETS);
	hipMemset(a_out, 0, sizeof(int) * NUM_BUCKETS);
	
	hipMemset(b_intermediate, 0, ARRAY_BYTES * NUM_BUCKETS);//
	hipMemset(d_intermediate, 0, ARRAY_BYTES * NUM_BUCKETS);//
    // transfer the input array to the GPU
    hipMemcpy(d_in, a->elements, ARRAY_BYTES, hipMemcpyHostToDevice);
	
	int_vector_free(a);

	
	hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);
	
	hipEventRecord(start, 0);
    // launch the kernel
	reduce_a(a_out, b_intermediate,  d_intermediate, d_in, a->size);
	hipEventRecord(stop, 0);
	hipEventSynchronize(stop);
	
	hipEventRecord(start, 0);
	reduce_b(b_out, d_intermediate, d_in, a->size);
	hipEventRecord(stop, 0);
	hipEventSynchronize(stop);
	
	hipEventRecord(start, 0);
	run_c(c_out, b_out, NUM_BUCKETS);
	hipEventRecord(stop, 0);
	hipEventSynchronize(stop);
	
    float elapsedTime;
    hipEventElapsedTime(&elapsedTime, start, stop);
    
	int h_a_out[NUM_BUCKETS];
	int h_b_out[NUM_BUCKETS];
	int h_c_out[NUM_BUCKETS];
	
	// copy back data from GPU
    hipMemcpy(h_a_out, a_out, sizeof(int) * NUM_BUCKETS, hipMemcpyDeviceToHost);
	hipMemcpy(h_b_out, b_out, sizeof(int) * NUM_BUCKETS, hipMemcpyDeviceToHost);
	hipMemcpy(h_c_out, c_out, sizeof(int) * NUM_BUCKETS, hipMemcpyDeviceToHost);
	
	/****************** write to q2a.txt *******************************/
	
	FILE *outFp = fopen(Q2A_OUT_FILE, "w");
	if(outFp == NULL)
	{
		printf("can't open file %s to write\n", Q2A_OUT_FILE);
	}
	fprintf(outFp, "%d", h_a_out[0]);
	for(int i = 1; i < NUM_BUCKETS; i++)
	{
		fprintf(outFp, ", %d", h_a_out[i]);
	}
	fprintf(outFp, "\n");
	
	fclose(outFp);
	
	/*********************** write to q2b.txt ***********************/
	
	outFp = fopen(Q2B_OUT_FILE, "w");
	if(outFp == NULL)
	{
		printf("can't open file %s to write\n", Q2A_OUT_FILE);
	}
	fprintf(outFp, "%d", h_b_out[0]);
	for(int i = 1; i < NUM_BUCKETS; i++)
	{
		fprintf(outFp, ", %d", h_b_out[i]);
	}
	fprintf(outFp, "\n");
	
	fclose(outFp);
	
	/***********************debug parallel prefix sum*********************/
	//printf("parallel prefix sum cpu: ");
	vector * wrapper = (vector*) malloc(sizeof(vector));
	int_vector_init(wrapper);
	for (int i = 0; i < NUM_BUCKETS; i++)
	{
		int_vector_add(wrapper, h_b_out[i]);
	}
	int cpu_prefix_out[10] = {0};
	prefixSum(wrapper, cpu_prefix_out);
	//printf("%d", cpu_prefix_out[0]);
	for(int i = 1; i < NUM_BUCKETS; i++)
	{
		//printf( ", %d", cpu_prefix_out[i]);
	}
	//printf("\n");
	
	/************************write to q2c.txt***********************************/
	
	
	outFp = fopen(Q2C_OUT_FILE, "w");
	if(outFp == NULL)
	{
		printf("can't open file %s to write\n", Q2C_OUT_FILE);
	}
	fprintf(outFp, "%d", h_c_out[0]);
	for(int i = 1; i < NUM_BUCKETS; i++)
	{
		fprintf(outFp, ", %d", h_c_out[i]);
	}
	fprintf(outFp, "\n");
	
	fclose(outFp);
	
	
    // free GPU memory allocation
    hipFree(d_in);
    hipFree(d_intermediate);
	hipFree(b_intermediate);
	hipFree(a_out);
	hipFree(b_out);
	hipFree(c_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);
}

//input: a array of int; output: b array of 10 int
void bucketize(vector *a, int *b) {
	for(int i = 0; i < a->size; i++)
	{
		int index = a->elements[i] / 100;
		b[index] += 1;
	}
}

//goal is a running sum of a
//b must have 10 elements
void prefixSum(vector *a, int *b) {
	int * elements = a->elements;
	vector * firstPass = (vector*) malloc(sizeof(vector));
	int_vector_init(firstPass);
	int size = a->size;
	b[0] = elements[0];
	for(int i = 1; i < size; i++)
	{
		//int_vector_add(firstPass, sum);
		b[i] = b[i-1] + elements[i];
	}
}

//assumes vector size >= 1
int findMin(vector* vector) {
	int min = INT_MAX;
	if(vector == NULL)
	{
		return min;
	}
	int size = vector->size;
	int* arr = vector->elements;
	
	for(int i = 0; i < size; i++)
	{
		if(arr[i] < min)
		{
			min = arr[i];
		}
	}
	return min;
}

//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	"q2.hip"
	.globl	_Z35__device_stub__global_reduce_kernelPiS_S_ib # -- Begin function _Z35__device_stub__global_reduce_kernelPiS_S_ib
	.type	_Z35__device_stub__global_reduce_kernelPiS_S_ib,@function
_Z35__device_stub__global_reduce_kernelPiS_S_ib: # @_Z35__device_stub__global_reduce_kernelPiS_S_ib
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	3(%rsp), %rcx
	movb	%r8b, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	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	$_Z20global_reduce_kernelPiS_S_ib, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z35__device_stub__global_reduce_kernelPiS_S_ib, .Lfunc_end0-_Z35__device_stub__global_reduce_kernelPiS_S_ib
	.cfi_endproc
                                        # -- End function
	.globl	_Z34__device_stub__shmem_reduce_kernelPiPKiib # -- Begin function _Z34__device_stub__shmem_reduce_kernelPiPKiib
	.type	_Z34__device_stub__shmem_reduce_kernelPiPKiib,@function
_Z34__device_stub__shmem_reduce_kernelPiPKiib: # @_Z34__device_stub__shmem_reduce_kernelPiPKiib
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	11(%rsp), %rdx
	movb	%cl, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z19shmem_reduce_kernelPiPKiib, %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	_Z34__device_stub__shmem_reduce_kernelPiPKiib, .Lfunc_end1-_Z34__device_stub__shmem_reduce_kernelPiPKiib
	.cfi_endproc
                                        # -- End function
	.globl	_Z37__device_stub__parallel_prefix_kernelPiPKii # -- Begin function _Z37__device_stub__parallel_prefix_kernelPiPKii
	.type	_Z37__device_stub__parallel_prefix_kernelPiPKii,@function
_Z37__device_stub__parallel_prefix_kernelPiPKii: # @_Z37__device_stub__parallel_prefix_kernelPiPKii
	.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_kernelPiPKii, %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	_Z37__device_stub__parallel_prefix_kernelPiPKii, .Lfunc_end2-_Z37__device_stub__parallel_prefix_kernelPiPKii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8reduce_aPiS_S_S_i            # -- Begin function _Z8reduce_aPiS_S_S_i
	.type	_Z8reduce_aPiS_S_S_i,@function
_Z8reduce_aPiS_S_S_i:                   # @_Z8reduce_aPiS_S_S_i
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%r8d, %ebp
	movq	%rcx, 8(%rsp)                   # 8-byte Spill
	movq	%rdx, %r15
	movq	%rsi, %r14
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	movabsq	$4294967296, %r13               # imm = 0x100000000
	leal	1023(%rbp), %eax
	leal	2046(%rbp), %r12d
	testl	%eax, %eax
	cmovnsl	%eax, %r12d
	sarl	$10, %r12d
	movq	%r12, %rdi
	btsq	$32, %rdi
	leaq	1024(%r13), %rdx
	movl	$1, %ebx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_2
# %bb.1:
	movq	%r14, %rdi
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movq	%r15, %rdx
	movl	%ebp, %ecx
	movl	$1, %r8d
	callq	_Z35__device_stub__global_reduce_kernelPiS_S_ib
.LBB3_2:                                # =>This Inner Loop Header: Depth=1
	movl	%ebx, %eax
	leal	(%rax,%rax), %ebx
	cmpl	%r12d, %eax
	jl	.LBB3_2
# %bb.3:
	movl	%eax, %edx
	orq	%r13, %rdx
	incq	%r13
	movq	%r13, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	je	.LBB3_5
# %bb.4:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_5:
	.cfi_def_cfa_offset 80
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movq	%r14, %rdx
	movl	%r12d, %ecx
	xorl	%r8d, %r8d
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	_Z35__device_stub__global_reduce_kernelPiS_S_ib # TAILCALL
.Lfunc_end3:
	.size	_Z8reduce_aPiS_S_S_i, .Lfunc_end3-_Z8reduce_aPiS_S_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z8reduce_bPiS_S_i              # -- Begin function _Z8reduce_bPiS_S_i
	.type	_Z8reduce_bPiS_S_i,@function
_Z8reduce_bPiS_S_i:                     # @_Z8reduce_bPiS_S_i
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %r13d
	movq	%rdx, %rbp
	movq	%rsi, %rbx
	movq	%rdi, (%rsp)                    # 8-byte Spill
	movabsq	$4294967296, %r12               # imm = 0x100000000
	leal	1023(%r13), %eax
	leal	2046(%r13), %r15d
	testl	%eax, %eax
	cmovnsl	%eax, %r15d
	sarl	$10, %r15d
	movq	%r15, %rdi
	btsq	$32, %rdi
	leaq	1024(%r12), %rdx
	movl	$1, %r14d
	movl	$40960, %r8d                    # imm = 0xA000
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_2
# %bb.1:
	movq	%rbx, %rdi
	movq	%rbp, %rsi
	movl	%r13d, %edx
	movl	$1, %ecx
	callq	_Z34__device_stub__shmem_reduce_kernelPiPKiib
.LBB4_2:                                # =>This Inner Loop Header: Depth=1
	movl	%r14d, %eax
	leal	(%rax,%rax), %r14d
	cmpl	%r15d, %eax
	jl	.LBB4_2
# %bb.3:
	leal	(%rax,%rax), %ecx
	leal	(%rcx,%rcx,4), %r8d
	shlq	$2, %r8
	movl	%eax, %edx
	orq	%r12, %rdx
	incq	%r12
	movq	%r12, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	je	.LBB4_5
# %bb.4:
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB4_5:
	.cfi_def_cfa_offset 64
	movq	(%rsp), %rdi                    # 8-byte Reload
	movq	%rbx, %rsi
	movl	%r15d, %edx
	xorl	%ecx, %ecx
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	_Z34__device_stub__shmem_reduce_kernelPiPKiib # TAILCALL
.Lfunc_end4:
	.size	_Z8reduce_bPiS_S_i, .Lfunc_end4-_Z8reduce_bPiS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z5run_cPiS_i                   # -- Begin function _Z5run_cPiS_i
	.type	_Z5run_cPiS_i,@function
_Z5run_cPiS_i:                          # @_Z5run_cPiS_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edx, %ebx
	movq	%rsi, %r14
	movq	%rdi, %r15
	movabsq	$4294967297, %rdx               # imm = 0x100000001
	leaq	9(%rdx), %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	je	.LBB5_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB5_2:
	.cfi_def_cfa_offset 32
	movq	%r15, %rdi
	movq	%r14, %rsi
	movl	%ebx, %edx
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	_Z37__device_stub__parallel_prefix_kernelPiPKii # TAILCALL
.Lfunc_end5:
	.size	_Z5run_cPiS_i, .Lfunc_end5-_Z5run_cPiS_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
	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	$1896, %rsp                     # imm = 0x768
	.cfi_def_cfa_offset 1952
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	60(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%rbx)
	je	.LBB6_38
# %bb.1:
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	424(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	$.L.str.1, %edi
	movl	$.L.str.2, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB6_39
# %bb.2:
	movq	%rax, %r14
	movw	$11296, 5(%rsp)                 # imm = 0x2C20
	movb	$0, 7(%rsp)
	movl	$16, %edi
	callq	malloc
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.LBB6_4
# %bb.3:
	movl	$4, %edi
	callq	malloc
	movq	%rax, (%rbx)
	movq	$1, 8(%rbx)
.LBB6_4:                                # %_Z15int_vector_initP6vector.exit
	leaq	320(%rsp), %rdi
	movl	$100, %esi
	movq	%r14, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB6_15
# %bb.5:                                # %.lr.ph87
	leaq	320(%rsp), %r15
	leaq	5(%rsp), %r12
.LBB6_6:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_8 Depth 2
                                        #     Child Loop BB6_13 Depth 2
	movsbl	418(%rsp), %eax
	addl	$-48, %eax
	movl	$0, %ebp
	cmpl	$9, %eax
	ja	.LBB6_11
# %bb.7:                                # %.preheader.preheader
                                        #   in Loop: Header=BB6_6 Depth=1
	movl	$98, %ecx
	movl	$-1, %ebp
	movl	$98, %eax
.LBB6_8:                                # %.preheader
                                        #   Parent Loop BB6_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	incl	%ebp
	addq	$-1, %rax
	jae	.LBB6_10
# %bb.9:                                # %.preheader
                                        #   in Loop: Header=BB6_8 Depth=2
	movsbl	320(%rsp,%rcx), %edx
	addl	$-48, %edx
	movq	%rax, %rcx
	cmpl	$10, %edx
	jb	.LBB6_8
.LBB6_10:                               #   in Loop: Header=BB6_6 Depth=1
	movb	$0, 321(%rsp,%rax)
.LBB6_11:                               # %_Z10chopStringPcm.exit
                                        #   in Loop: Header=BB6_6 Depth=1
	movq	%r15, %rdi
.LBB6_13:                               # %.lr.ph
                                        #   Parent Loop BB6_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r12, %rsi
	callq	strtok
	testq	%rax, %rax
	je	.LBB6_14
# %bb.12:                               # %.lr.ph
                                        #   in Loop: Header=BB6_13 Depth=2
	movq	%rax, %rdi
	callq	atoi
	movq	%rbx, %rdi
	movl	%eax, %esi
	callq	_Z14int_vector_addP6vectori
	xorl	%edi, %edi
	jmp	.LBB6_13
.LBB6_14:                               # %._crit_edge
                                        #   in Loop: Header=BB6_6 Depth=1
	movslq	%ebp, %r13
	movl	$99, %eax
	subl	%r13d, %eax
	cltq
	leaq	(%rsp,%rax), %rsi
	addq	$320, %rsi                      # imm = 0x140
	movq	%r15, %rdi
	movq	%r13, %rdx
	callq	memcpy@PLT
	leaq	(%rsp,%r13), %rdi
	addq	$320, %rdi                      # imm = 0x140
	movl	$100, %esi
	subl	%r13d, %esi
	movq	%r14, %rdx
	callq	fgets
	testq	%rax, %rax
	jne	.LBB6_6
.LBB6_15:                               # %._crit_edge88
	movl	12(%rbx), %r14d
	xorps	%xmm0, %xmm0
	movaps	%xmm0, 192(%rsp)
	movaps	%xmm0, 176(%rsp)
	movq	$0, 208(%rsp)
	testl	%r14d, %r14d
	jle	.LBB6_18
# %bb.16:                               # %.lr.ph.i73
	movq	(%rbx), %rax
	xorl	%ecx, %ecx
.LBB6_17:                               # =>This Inner Loop Header: Depth=1
	movslq	(%rax,%rcx,4), %rdx
	imulq	$1374389535, %rdx, %rdx         # imm = 0x51EB851F
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$37, %rdx
	addl	%esi, %edx
	movslq	%edx, %rdx
	incl	176(%rsp,%rdx,4)
	incq	%rcx
	cmpq	%rcx, %r14
	jne	.LBB6_17
.LBB6_18:                               # %_Z9bucketizeP6vectorPi.exit
	leal	(,%r14,4), %eax
	movslq	%eax, %r15
	leaq	48(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	shll	$3, %r14d
	leal	(%r14,%r14,4), %eax
	movslq	%eax, %r12
	leaq	40(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %r14
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rbp
	movl	$40, %esi
	movq	%rbp, %rdi
	callq	hipMalloc
	leaq	16(%rsp), %r13
	movl	$40, %esi
	movq	%r13, %rdi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$40, %esi
	callq	hipMalloc
	movq	(%r13), %rdi
	movl	$40, %edx
	xorl	%esi, %esi
	callq	hipMemset
	movq	(%rbp), %rdi
	movq	%rbp, %r13
	movl	$40, %edx
	xorl	%esi, %esi
	callq	hipMemset
	movq	(%r14), %rdi
	xorl	%esi, %esi
	movq	%r12, %rdx
	callq	hipMemset
	leaq	40(%rsp), %rbp
	movq	(%rbp), %rdi
	xorl	%esi, %esi
	movq	%r12, %rdx
	callq	hipMemset
	leaq	48(%rsp), %r14
	movq	(%r14), %rdi
	movq	(%rbx), %r12
	movq	%r12, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r12, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	leaq	120(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	leaq	112(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r13), %rdi
	leaq	32(%rsp), %rax
	movq	(%rax), %rsi
	movq	(%rbp), %rdx
	movq	(%r14), %rcx
	movq	%r14, %r13
	movl	12(%rbx), %ebx
	movl	%ebx, %r8d
	callq	_Z8reduce_aPiS_S_S_i
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r15), %rdi
	callq	hipEventSynchronize
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	16(%rsp), %r14
	movq	(%r14), %rdi
	movq	(%rbp), %rsi
	movq	(%r13), %rdx
	movl	%ebx, %ecx
	callq	_Z8reduce_bPiS_S_i
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r15), %rdi
	callq	hipEventSynchronize
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	8(%rsp), %rbx
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movl	$10, %edx
	callq	_Z5run_cPiS_i
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r15), %rdi
	callq	hipEventSynchronize
	movq	(%r12), %rsi
	movq	(%r15), %rdx
	leaq	56(%rsp), %rdi
	callq	hipEventElapsedTime
	leaq	24(%rsp), %rax
	movq	(%rax), %rsi
	leaq	272(%rsp), %rdi
	movl	$40, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%r14), %rsi
	leaq	128(%rsp), %rdi
	movl	$40, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%rbx), %rsi
	leaq	224(%rsp), %rdi
	movl	$40, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.4, %edi
	movl	$.L.str.5, %esi
	callq	fopen
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.LBB6_20
# %bb.19:
	movl	$.L.str.6, %edi
	movl	$.L.str.4, %esi
	xorl	%eax, %eax
	callq	printf
.LBB6_20:
	movl	272(%rsp), %edx
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %r14d
.LBB6_21:                               # =>This Inner Loop Header: Depth=1
	movl	272(%rsp,%r14,4), %edx
	movl	$.L.str.8, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r14
	cmpq	$10, %r14
	jne	.LBB6_21
# %bb.22:
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movq	%rbx, %rdi
	callq	fclose
	movl	$.L.str.10, %edi
	movl	$.L.str.5, %esi
	callq	fopen
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.LBB6_24
# %bb.23:
	movl	$.L.str.6, %edi
	movl	$.L.str.4, %esi
	xorl	%eax, %eax
	callq	printf
.LBB6_24:
	movl	128(%rsp), %edx
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %r14d
.LBB6_25:                               # =>This Inner Loop Header: Depth=1
	movl	128(%rsp,%r14,4), %edx
	movl	$.L.str.8, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r14
	cmpq	$10, %r14
	jne	.LBB6_25
# %bb.26:
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movq	%rbx, %rdi
	callq	fclose
	movl	$16, %edi
	callq	malloc
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.LBB6_28
# %bb.27:
	movl	$4, %edi
	callq	malloc
	movq	%rax, (%rbx)
	movq	$1, 8(%rbx)
.LBB6_28:                               # %_Z15int_vector_initP6vector.exit76.preheader
	xorl	%r14d, %r14d
.LBB6_29:                               # %_Z15int_vector_initP6vector.exit76
                                        # =>This Inner Loop Header: Depth=1
	movl	128(%rsp,%r14,4), %esi
	movq	%rbx, %rdi
	callq	_Z14int_vector_addP6vectori
	incq	%r14
	cmpq	$10, %r14
	jne	.LBB6_29
# %bb.30:
	xorps	%xmm0, %xmm0
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm0, 64(%rsp)
	movq	$0, 96(%rsp)
	movq	(%rbx), %rax
	movl	12(%rbx), %ecx
	movl	(%rax), %edx
	movl	%edx, 64(%rsp)
	cmpl	$2, %ecx
	jl	.LBB6_33
# %bb.31:                               # %.lr.ph.preheader.i77
	movl	$1, %edx
	movl	64(%rsp), %esi
.LBB6_32:                               # %.lr.ph.i79
                                        # =>This Inner Loop Header: Depth=1
	addl	(%rax,%rdx,4), %esi
	movl	%esi, 64(%rsp,%rdx,4)
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB6_32
.LBB6_33:                               # %_Z9prefixSumP6vectorPi.exit
	movl	$.L.str.11, %edi
	movl	$.L.str.5, %esi
	callq	fopen
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.LBB6_35
# %bb.34:
	movl	$.L.str.6, %edi
	movl	$.L.str.11, %esi
	xorl	%eax, %eax
	callq	printf
.LBB6_35:
	movl	224(%rsp), %edx
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %r14d
.LBB6_36:                               # =>This Inner Loop Header: Depth=1
	movl	224(%rsp,%r14,4), %edx
	movl	$.L.str.8, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r14
	cmpq	$10, %r14
	jne	.LBB6_36
# %bb.37:
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movq	%rbx, %rdi
	callq	fclose
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$1896, %rsp                     # imm = 0x768
	.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
.LBB6_38:
	.cfi_def_cfa_offset 1952
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$35, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %edi
	callq	exit
.LBB6_39:
	movl	$.L.str.3, %edi
	movl	$.L.str.1, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %edi
	callq	exit
.Lfunc_end6:
	.size	main, .Lfunc_end6-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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	_Z15int_vector_initP6vector, .Lfunc_end7-_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	.LBB8_5
# %bb.1:
	addq	$-2, %rsi
	movslq	%esi, %rcx
	movl	$-1, %eax
.LBB8_2:                                # =>This Inner Loop Header: Depth=1
	leaq	-1(%rcx), %rdx
	incl	%eax
	testq	%rcx, %rcx
	jle	.LBB8_4
# %bb.3:                                #   in Loop: Header=BB8_2 Depth=1
	movsbl	(%rdi,%rcx), %esi
	addl	$-48, %esi
	movq	%rdx, %rcx
	cmpl	$10, %esi
	jb	.LBB8_2
.LBB8_4:
	movb	$0, 1(%rdi,%rdx)
.LBB8_5:
	retq
.Lfunc_end8:
	.size	_Z10chopStringPcm, .Lfunc_end8-_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	.LBB9_4
# %bb.1:
	shlq	$3, %rsi
	movq	%rax, %rdi
	callq	realloc
	testq	%rax, %rax
	je	.LBB9_2
# %bb.3:                                # %.thread
	shll	8(%rbx)
	movq	%rax, (%rbx)
	movl	12(%rbx), %ecx
.LBB9_4:
	movslq	%ecx, %rcx
	movl	%ebp, (%rax,%rcx,4)
	incl	12(%rbx)
	movl	$1, %eax
.LBB9_5:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB9_2:
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	jmp	.LBB9_5
.Lfunc_end9:
	.size	_Z14int_vector_addP6vectori, .Lfunc_end9-_Z14int_vector_addP6vectori
	.cfi_endproc
                                        # -- End function
	.globl	_Z7findMinP6vector              # -- Begin function _Z7findMinP6vector
	.type	_Z7findMinP6vector,@function
_Z7findMinP6vector:                     # @_Z7findMinP6vector
	.cfi_startproc
# %bb.0:
	movl	$2147483647, %eax               # imm = 0x7FFFFFFF
	testq	%rdi, %rdi
	je	.LBB10_4
# %bb.1:
	movl	12(%rdi), %ecx
	testl	%ecx, %ecx
	jle	.LBB10_4
# %bb.2:                                # %.lr.ph.preheader
	movq	(%rdi), %rdx
	xorl	%esi, %esi
.LBB10_3:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rdx,%rsi,4), %edi
	cmpl	%eax, %edi
	cmovll	%edi, %eax
	incq	%rsi
	cmpq	%rsi, %rcx
	jne	.LBB10_3
.LBB10_4:                               # %.loopexit
	retq
.Lfunc_end10:
	.size	_Z7findMinP6vector, .Lfunc_end10-_Z7findMinP6vector
	.cfi_endproc
                                        # -- End function
	.globl	_Z9bucketizeP6vectorPi          # -- Begin function _Z9bucketizeP6vectorPi
	.type	_Z9bucketizeP6vectorPi,@function
_Z9bucketizeP6vectorPi:                 # @_Z9bucketizeP6vectorPi
	.cfi_startproc
# %bb.0:
	cmpl	$0, 12(%rdi)
	jle	.LBB11_3
# %bb.1:                                # %.lr.ph
	movq	(%rdi), %rax
	xorl	%ecx, %ecx
.LBB11_2:                               # =>This Inner Loop Header: Depth=1
	movslq	(%rax,%rcx,4), %rdx
	imulq	$1374389535, %rdx, %rdx         # imm = 0x51EB851F
	movq	%rdx, %r8
	shrq	$63, %r8
	sarq	$37, %rdx
	addl	%r8d, %edx
	movslq	%edx, %rdx
	incl	(%rsi,%rdx,4)
	incq	%rcx
	movslq	12(%rdi), %rdx
	cmpq	%rdx, %rcx
	jl	.LBB11_2
.LBB11_3:                               # %._crit_edge
	retq
.Lfunc_end11:
	.size	_Z9bucketizeP6vectorPi, .Lfunc_end11-_Z9bucketizeP6vectorPi
	.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_end12:
	.size	_Z15int_vector_freeP6vector, .Lfunc_end12-_Z15int_vector_freeP6vector
	.cfi_endproc
                                        # -- End function
	.globl	_Z9prefixSumP6vectorPi          # -- Begin function _Z9prefixSumP6vectorPi
	.type	_Z9prefixSumP6vectorPi,@function
_Z9prefixSumP6vectorPi:                 # @_Z9prefixSumP6vectorPi
	.cfi_startproc
# %bb.0:                                # %_Z15int_vector_initP6vector.exit
	movq	(%rdi), %rax
	movl	12(%rdi), %ecx
	movl	(%rax), %edx
	movl	%edx, (%rsi)
	cmpl	$2, %ecx
	jl	.LBB13_3
# %bb.1:                                # %.lr.ph.preheader
	movl	(%rsi), %edx
	movl	$1, %edi
.LBB13_2:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	addl	(%rax,%rdi,4), %edx
	movl	%edx, (%rsi,%rdi,4)
	incq	%rdi
	cmpq	%rdi, %rcx
	jne	.LBB13_2
.LBB13_3:                               # %._crit_edge
	retq
.Lfunc_end13:
	.size	_Z9prefixSumP6vectorPi, .Lfunc_end13-_Z9prefixSumP6vectorPi
	.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	.LBB14_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB14_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z20global_reduce_kernelPiS_S_ib, %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	$_Z19shmem_reduce_kernelPiPKiib, %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	$_Z22parallel_prefix_kernelPiPKii, %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_end14:
	.size	__hip_module_ctor, .Lfunc_end14-__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	.LBB15_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
.LBB15_2:
	retq
.Lfunc_end15:
	.size	__hip_module_dtor, .Lfunc_end15-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z20global_reduce_kernelPiS_S_ib,@object # @_Z20global_reduce_kernelPiS_S_ib
	.section	.rodata,"a",@progbits
	.globl	_Z20global_reduce_kernelPiS_S_ib
	.p2align	3, 0x0
_Z20global_reduce_kernelPiS_S_ib:
	.quad	_Z35__device_stub__global_reduce_kernelPiS_S_ib
	.size	_Z20global_reduce_kernelPiS_S_ib, 8

	.type	_Z19shmem_reduce_kernelPiPKiib,@object # @_Z19shmem_reduce_kernelPiPKiib
	.globl	_Z19shmem_reduce_kernelPiPKiib
	.p2align	3, 0x0
_Z19shmem_reduce_kernelPiPKiib:
	.quad	_Z34__device_stub__shmem_reduce_kernelPiPKiib
	.size	_Z19shmem_reduce_kernelPiPKiib, 8

	.type	_Z22parallel_prefix_kernelPiPKii,@object # @_Z22parallel_prefix_kernelPiPKii
	.globl	_Z22parallel_prefix_kernelPiPKii
	.p2align	3, 0x0
_Z22parallel_prefix_kernelPiPKii:
	.quad	_Z37__device_stub__parallel_prefix_kernelPiPKii
	.size	_Z22parallel_prefix_kernelPiPKii, 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	"q2a.txt"
	.size	.L.str.4, 8

	.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, 5

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"q2b.txt"
	.size	.L.str.10, 8

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"q2c.txt"
	.size	.L.str.11, 8

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z20global_reduce_kernelPiS_S_ib"
	.size	.L__unnamed_1, 33

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z19shmem_reduce_kernelPiPKiib"
	.size	.L__unnamed_2, 31

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z22parallel_prefix_kernelPiPKii"
	.size	.L__unnamed_3, 33

	.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 _Z35__device_stub__global_reduce_kernelPiS_S_ib
	.addrsig_sym _Z34__device_stub__shmem_reduce_kernelPiPKiib
	.addrsig_sym _Z37__device_stub__parallel_prefix_kernelPiPKii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z20global_reduce_kernelPiS_S_ib
	.addrsig_sym _Z19shmem_reduce_kernelPiPKiib
	.addrsig_sym _Z22parallel_prefix_kernelPiPKii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z20global_reduce_kernelPiS_S_ib ; -- Begin function _Z20global_reduce_kernelPiS_S_ib
	.globl	_Z20global_reduce_kernelPiS_S_ib
	.p2align	8
	.type	_Z20global_reduce_kernelPiS_S_ib,@function
_Z20global_reduce_kernelPiS_S_ib:       ; @_Z20global_reduce_kernelPiS_S_ib
; %bb.0:
	s_clause 0x1
	s_load_b32 s8, s[0:1], 0x2c
	s_load_b256 s[0:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s8, s8, 0xffff
	s_bitcmp0_b32 s7, 0
	s_mul_i32 s9, s15, s8
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v3, s9, v0
	v_mul_lo_u32 v1, v3, 10
	s_cbranch_scc1 .LBB0_2
; %bb.1:
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[4:5], 2, v[3:4]
	v_add_co_u32 v4, vcc_lo, s2, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v5, vcc_lo, s3, v5, vcc_lo
	global_load_b32 v2, v[4:5], off
	s_waitcnt vmcnt(0)
	v_mul_hi_i32 v2, 0x51eb851f, v2
	v_lshrrev_b32_e32 v4, 31, v2
	v_ashrrev_i32_e32 v2, 5, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add3_u32 v4, v2, v4, v1
	v_mov_b32_e32 v2, 1
	v_ashrrev_i32_e32 v5, 31, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	v_add_co_u32 v4, vcc_lo, s4, v4
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	global_store_b32 v[4:5], v2, off
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
.LBB0_2:
	s_cmp_lt_u32 s8, 2
	s_cbranch_scc1 .LBB0_9
; %bb.3:                                ; %.lr.ph
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v2, 31, v1
	s_mul_i32 s9, s9, 10
	v_mov_b32_e32 v7, 0
	v_lshlrev_b64 v[4:5], 2, v[1:2]
	v_mad_u32_u24 v2, v0, 10, s9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v4, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
.LBB0_4:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_7 Depth 2
	s_mov_b32 s2, s8
	s_lshr_b32 s8, s8, 1
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_u32_e64 s8, v0
	s_cbranch_execz .LBB0_8
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=1
	v_add_nc_u32_e32 v6, s8, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_gt_u32_e32 vcc_lo, s6, v6
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_8
; %bb.6:                                ; %.preheader35
                                        ;   in Loop: Header=BB0_4 Depth=1
	v_mad_u64_u32 v[8:9], null, s8, 10, v[2:3]
	v_dual_mov_b32 v10, v5 :: v_dual_mov_b32 v9, v4
	s_mov_b32 s7, 0
.LBB0_7:                                ;   Parent Loop BB0_4 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v6, s7, v8
	global_load_b32 v13, v[9:10], off
	s_add_i32 s7, s7, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_cmp_lg_u32 s7, 10
	v_lshlrev_b64 v[11:12], 2, v[6:7]
	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 v6, v[11:12], off
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v6, v13, v6
	global_store_b32 v[9:10], v6, off
	v_add_co_u32 v9, vcc_lo, v9, 4
	v_add_co_ci_u32_e32 v10, vcc_lo, 0, v10, vcc_lo
	s_cbranch_scc1 .LBB0_7
.LBB0_8:                                ; %.loopexit36
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_cmp_lt_u32 s2, 4
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_4
.LBB0_9:                                ; %._crit_edge
	s_mov_b32 s3, 0
	s_mov_b32 s2, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_12
; %bb.10:                               ; %.preheader
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_mov_b32_e32 v2, 0
	v_add_co_u32 v0, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	s_mul_i32 s4, s15, 10
	s_mov_b32 s5, 0
.LBB0_11:                               ; =>This Inner Loop Header: Depth=1
	global_load_b32 v3, v[0:1], off
	s_add_i32 s2, s4, s5
	v_add_co_u32 v0, vcc_lo, v0, 4
	s_lshl_b64 s[6:7], s[2:3], 2
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
	s_add_u32 s6, s0, s6
	s_addc_u32 s7, s1, s7
	s_add_i32 s5, s5, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lg_u32 s5, 10
	s_waitcnt vmcnt(0)
	global_store_b32 v2, v3, s[6:7]
	s_cbranch_scc1 .LBB0_11
.LBB0_12:                               ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z20global_reduce_kernelPiS_S_ib
		.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 14
		.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	_Z20global_reduce_kernelPiS_S_ib, .Lfunc_end0-_Z20global_reduce_kernelPiS_S_ib
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 572
; NumSgprs: 18
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 14
; 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
	.protected	_Z19shmem_reduce_kernelPiPKiib ; -- Begin function _Z19shmem_reduce_kernelPiPKiib
	.globl	_Z19shmem_reduce_kernelPiPKiib
	.p2align	8
	.type	_Z19shmem_reduce_kernelPiPKiib,@function
_Z19shmem_reduce_kernelPiPKiib:         ; @_Z19shmem_reduce_kernelPiPKiib
; %bb.0:
	s_clause 0x2
	s_load_b64 s[2:3], s[0:1], 0x10
	s_load_b32 s8, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	v_mul_u32_u24_e32 v4, 10, v0
	s_waitcnt lgkmcnt(0)
	s_bitcmp1_b32 s3, 0
	s_cselect_b32 s0, -1, 0
	s_and_b32 s1, s8, 0xffff
	s_and_b32 vcc_lo, exec_lo, s0
	v_mad_u64_u32 v[1:2], null, s15, s1, v[0:1]
	s_mov_b32 s0, -1
	s_cbranch_vccnz .LBB1_4
; %bb.1:                                ; %.preheader49
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v2, v1, 10
	v_lshl_add_u32 v5, v4, 2, 0
	s_mov_b32 s0, 0
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	v_add_co_u32 v2, vcc_lo, s6, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	global_load_b32 v6, v[2:3], off
	v_add_co_u32 v2, vcc_lo, v2, 4
	v_add_nc_u32_e32 v7, s0, v5
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_add_i32 s0, s0, 4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lg_u32 s0, 40
	s_waitcnt vmcnt(0)
	ds_store_b32 v7, v6
	s_cbranch_scc1 .LBB1_2
; %bb.3:                                ; %Flow96
	s_mov_b32 s0, 0
.LBB1_4:                                ; %Flow99
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 vcc_lo, exec_lo, s0
	s_cbranch_vccz .LBB1_11
; %bb.5:
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_ashrrev_i32_e32 v2, 31, v1
	v_mov_b32_e32 v7, 1
	s_mov_b32 s0, 0
	v_mov_b32_e32 v5, 0
	v_lshlrev_b64 v[2:3], 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, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	v_mul_hi_i32 v2, 0x51eb851f, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v3, 31, v2
	v_ashrrev_i32_e32 v2, 5, v2
	v_add_nc_u32_e32 v2, v2, v3
	v_lshl_add_u32 v3, v4, 2, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u32_u24 v6, v0, 10, v2
	v_lshl_add_u32 v6, v6, 2, 0
.LBB1_6:                                ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s3, exec_lo
	v_cmpx_ne_u32_e64 s0, v2
	s_xor_b32 s3, exec_lo, s3
	s_cbranch_execz .LBB1_8
; %bb.7:                                ;   in Loop: Header=BB1_6 Depth=1
	ds_store_b32 v3, v5
.LBB1_8:                                ; %Flow97
                                        ;   in Loop: Header=BB1_6 Depth=1
	s_and_not1_saveexec_b32 s3, s3
	s_cbranch_execz .LBB1_10
; %bb.9:                                ;   in Loop: Header=BB1_6 Depth=1
	ds_store_b32 v6, v7
.LBB1_10:                               ;   in Loop: Header=BB1_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	v_add_nc_u32_e32 v3, 4, v3
	s_add_i32 s0, s0, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s0, 10
	s_cbranch_scc0 .LBB1_6
.LBB1_11:                               ; %.loopexit48
	s_cmp_lt_u32 s1, 2
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_17
; %bb.12:                               ; %.lr.ph
	v_lshl_add_u32 v2, v4, 2, 0
.LBB1_13:                               ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_15 Depth 2
	s_lshr_b32 s3, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v3, s3, v1
	v_cmp_gt_u32_e32 vcc_lo, s3, v0
	v_cmp_gt_u32_e64 s0, s2, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s6, vcc_lo, s0
	s_and_saveexec_b32 s0, s6
	s_cbranch_execz .LBB1_16
; %bb.14:                               ; %.preheader46
                                        ;   in Loop: Header=BB1_13 Depth=1
	v_add_nc_u32_e32 v3, s3, v0
	s_mov_b32 s6, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_u32_u24_e32 v3, 10, v3
	v_lshl_add_u32 v3, v3, 2, 0
.LBB1_15:                               ;   Parent Loop BB1_13 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v4, s6, v3
	v_add_nc_u32_e32 v5, s6, v2
	s_add_i32 s6, s6, 4
	ds_load_b32 v4, v4
	ds_load_b32 v6, v5
	s_cmp_lg_u32 s6, 40
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v4, v6, v4
	ds_store_b32 v5, v4
	s_cbranch_scc1 .LBB1_15
.LBB1_16:                               ; %Flow93
                                        ;   in Loop: Header=BB1_13 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	s_cmp_lt_u32 s1, 4
	s_mov_b32 s1, s3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB1_13
.LBB1_17:                               ; %._crit_edge
	s_mov_b32 s1, 0
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB1_20
; %bb.18:                               ; %.preheader
	v_mov_b32_e32 v0, 0
	s_mul_i32 s0, s15, 10
	s_mov_b32 s2, s1
.LBB1_19:                               ; =>This Inner Loop Header: Depth=1
	s_lshl_b64 s[6:7], s[0:1], 2
	s_add_i32 s3, s2, 0
	s_add_u32 s6, s4, s6
	s_addc_u32 s7, s5, s7
	v_mov_b32_e32 v2, s3
	global_load_b32 v1, v0, s[6:7]
	s_add_i32 s2, s2, 4
	s_add_i32 s0, s0, 1
	s_cmp_lg_u32 s2, 40
	ds_load_b32 v2, v2
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_add_nc_u32_e32 v1, v1, v2
	global_store_b32 v0, v1, s[6:7]
	s_cbranch_scc1 .LBB1_19
.LBB1_20:                               ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19shmem_reduce_kernelPiPKiib
		.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 8
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z19shmem_reduce_kernelPiPKiib, .Lfunc_end1-_Z19shmem_reduce_kernelPiPKiib
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 668
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z22parallel_prefix_kernelPiPKii ; -- Begin function _Z22parallel_prefix_kernelPiPKii
	.globl	_Z22parallel_prefix_kernelPiPKii
	.p2align	8
	.type	_Z22parallel_prefix_kernelPiPKii,@function
_Z22parallel_prefix_kernelPiPKii:       ; @_Z22parallel_prefix_kernelPiPKii
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b32 s1, s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_cmp_lt_i32 s1, 2
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v3, vcc_lo
	v_add_co_u32 v2, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	global_load_b32 v0, v[4:5], off
	s_waitcnt vmcnt(0)
	global_store_b32 v[2:3], v0, off
	s_cbranch_scc1 .LBB2_5
; %bb.1:                                ; %.lr.ph
	v_cmp_gt_i32_e32 vcc_lo, s1, v1
	s_mov_b32 s2, 1
.LBB2_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_le_i32_e64 s0, s2, v1
	s_and_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s0
	s_cbranch_execz .LBB2_4
; %bb.3:                                ;   in Loop: Header=BB2_2 Depth=1
	v_subrev_nc_u32_e32 v4, s2, v1
	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_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v4, s0, s4, v4
	v_add_co_ci_u32_e64 v5, s0, s5, v5, s0
	s_clause 0x1
	global_load_b32 v0, v[4:5], off
	global_load_b32 v4, v[2:3], off
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v0, v4, v0
	global_store_b32 v[2:3], v0, off
.LBB2_4:                                ;   in Loop: Header=BB2_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_lshl_b32 s2, s2, 1
	s_waitcnt_vscnt null, 0x0
	s_cmp_lt_i32 s2, s1
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB2_2
.LBB2_5:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z22parallel_prefix_kernelPiPKii
		.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 6
		.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	_Z22parallel_prefix_kernelPiPKii, .Lfunc_end2-_Z22parallel_prefix_kernelPiPKii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 276
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; 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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           1
        .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:           _Z20global_reduce_kernelPiS_S_ib
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z20global_reduce_kernelPiS_S_ib.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     14
    .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:         20
        .size:           1
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z19shmem_reduce_kernelPiPKiib
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19shmem_reduce_kernelPiPKiib.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .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_kernelPiPKii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z22parallel_prefix_kernelPiPKii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
