#include <stdio.h>
#include <numeric>
#include <stdlib.h>
#include <cuda.h>
#include <iostream>
#include <fstream>

using namespace std;

#define BLOCK_SIZE 32

__global__ void reduceKernel(float *device_output, float *device_input, float *final_output);

//function to call reduce kernel for array size
string reduceInvoker(int arraySize) {
	int N = arraySize;
	printf("%i\n", N);

	//Create variables for input and output array sizes
	size_t size = N * sizeof(float);
	size_t size_output = size / BLOCK_SIZE;
	size_t size_final_output = sizeof(float);

	//initialising host input and output arrays
	float host_input[N];
	float host_output[1];

	//initialising pointers for device arrays
	float *device_input, *device_output, *final_output;

	//initialising variables and events for cuda timer
	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);

	cudaError_t err;

	//filling host input array with values
	for (int i = 0; i < N; i++) {
		host_input[i] = 1.0f;
	}

	//allocating space for device input array
	cudaMalloc((void**) &device_input, size);
	//copying host input array to device
	cudaMemcpy(device_input, host_input, size, cudaMemcpyHostToDevice);
	//allocating space for device and final output arrays
	cudaMalloc((void**) &device_output, size_output);
	cudaMalloc((void**) &final_output, size_final_output);

	//calculating grid size
	int grid_size = N / BLOCK_SIZE;
	printf("Grid Size is: %d\n", grid_size);
	printf("Block Size is: %d\n", BLOCK_SIZE);

	dim3 threadsPerBlock(BLOCK_SIZE);
	dim3 blocks(grid_size);
	//start timer
	cudaEventRecord(start);
	//call kernel
	reduceKernel<<<blocks, threadsPerBlock>>>(device_output, device_input, final_output);


	//stop timer
	cudaEventRecord(stop);
	// Wait for GPU to finish before accessing on host
	err = cudaDeviceSynchronize();
	printf("Run kernel: %s\n", cudaGetErrorString(err));
	printf("\n");
	//copy final output array to host
	err = cudaMemcpy(host_output, final_output, size_final_output, cudaMemcpyDeviceToHost);
	printf("Copy host_output off device: %s\n", cudaGetErrorString(err));
	printf("\n");

	//calculate elapsed time
	float milliseconds = 0;
	cudaEventElapsedTime(&milliseconds, start, stop);
	printf("Elapsed time was: %f\n", milliseconds);

	printf("And the final reduction is: %f\n", host_output[0]);

	//free device memory
	cudaFree(device_input);
	cudaFree(device_output);
	cudaFree(final_output);
	//format string for csv file
	string csv = to_string(arraySize) + "," + to_string(milliseconds) + ","
			+ to_string(BLOCK_SIZE) + "," + to_string(grid_size) + "\n";
	return csv;
}

int main(void) {
	//Open file
	std::ofstream myFile;
	myFile.open("times.csv", std::ofstream::trunc);
	//Write headers
	myFile << "Array Size,Elapsed Time,Block Size,Grid Size\n";

	//Call reduce function invoker for different array sizes and write result to file
	for (unsigned int i = 1; i <= (1 << 20); i <<= 1) {
		printf("%i\n", i);
		string csv = reduceInvoker(i);
		myFile << csv;
	}

	//close file
	myFile.close();
}
__global__ void reduceKernel(float* device_output, float* device_input, float *final_output) {
	//work out global thread id
	int myId = threadIdx.x + blockDim.x * blockIdx.x; // ID relative
	//work out local thread id
	int tid = threadIdx.x; // Local ID
	//initialise static shared memory
	__shared__ float temp[BLOCK_SIZE];
	//set value in shared memory
	temp[tid] = device_input[myId];
	//make sure threads are synced before adding values
	__syncthreads();
	// do reduction in shared memory
	for (unsigned int s = blockDim.x / 2; s >= 1; s >>= 1) {
		if (tid < s) {
			temp[tid] += temp[tid + s];
		}
		__syncthreads(); // make sure all adds at one stage are
	}
	// only thread 0 writes result for this block back to global memory
	if (tid == 0) {
		device_output[blockIdx.x] = temp[tid];
		//add partial reductions to get final reduction
		atomicAdd(&final_output[0], device_output[blockIdx.x]);
	}
}

	.file	"tmpxft_0022105e_00000000-6_Lab5Test.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3809:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3809:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata._ZNSt7__cxx119to_stringEi.str1.1,"aMS",@progbits,1
.LC0:
	.string	"00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899"
	.section	.text._ZNSt7__cxx119to_stringEi,"axG",@progbits,_ZNSt7__cxx119to_stringEi,comdat
	.weak	_ZNSt7__cxx119to_stringEi
	.type	_ZNSt7__cxx119to_stringEi, @function
_ZNSt7__cxx119to_stringEi:
.LFB2865:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA2865
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%esi, %r13d
	movl	$10000, %ecx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	shrl	$31, %r13d
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	$1, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%esi, %ebx
	subq	$232, %rsp
	.cfi_def_cfa_offset 272
	movq	%fs:40, %rax
	movq	%rax, 216(%rsp)
	xorl	%eax, %eax
	negl	%ebx
	cmovs	%esi, %ebx
	movl	%ebx, %eax
.L8:
	cmpl	$9, %eax
	jbe	.L4
	cmpl	$99, %eax
	ja	.L5
	incl	%ebp
	jmp	.L4
.L5:
	cmpl	$999, %eax
	ja	.L6
	addl	$2, %ebp
	jmp	.L4
.L6:
	cmpl	$9999, %eax
	ja	.L7
	addl	$3, %ebp
	jmp	.L4
.L7:
	movl	%eax, %eax
	xorl	%edx, %edx
	addl	$4, %ebp
	divq	%rcx
	jmp	.L8
.L4:
	leaq	16(%r12), %rax
	leal	0(%r13,%rbp), %esi
	movq	%r12, %rdi
	decl	%ebp
	movq	%rax, (%r12)
	movl	$45, %edx
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructEmc@PLT
	movzbl	%r13b, %r8d
	leaq	15(%rsp), %rdi
	leaq	.LC0(%rip), %rsi
	movl	$201, %ecx
	addq	(%r12), %r8
	rep movsb
	movl	$100, %ecx
.L9:
	cmpl	$99, %ebx
	jbe	.L16
	movl	%ebx, %eax
	xorl	%edx, %edx
	movl	%ebp, %esi
	divl	%ecx
	addl	%edx, %edx
	movl	%eax, %ebx
	leal	1(%rdx), %eax
	movb	15(%rsp,%rdx), %dl
	movb	15(%rsp,%rax), %al
	movb	%al, (%r8,%rsi)
	leal	-1(%rbp), %eax
	subl	$2, %ebp
	movb	%dl, (%r8,%rax)
	jmp	.L9
.L16:
	leal	48(%rbx), %eax
	cmpl	$9, %ebx
	jbe	.L12
	addl	%ebx, %ebx
	leal	1(%rbx), %eax
	movb	15(%rsp,%rax), %al
	movb	%al, 1(%r8)
	movb	15(%rsp,%rbx), %al
.L12:
	movb	%al, (%r8)
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$232, %rsp
	.cfi_def_cfa_offset 40
	movq	%r12, %rax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2865:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table._ZNSt7__cxx119to_stringEi,"aG",@progbits,_ZNSt7__cxx119to_stringEi,comdat
.LLSDA2865:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE2865-.LLSDACSB2865
.LLSDACSB2865:
.LLSDACSE2865:
	.section	.text._ZNSt7__cxx119to_stringEi,"axG",@progbits,_ZNSt7__cxx119to_stringEi,comdat
	.size	_ZNSt7__cxx119to_stringEi, .-_ZNSt7__cxx119to_stringEi
	.text
	.globl	_Z36__device_stub__Z12reduceKernelPfS_S_PfS_S_
	.type	_Z36__device_stub__Z12reduceKernelPfS_S_PfS_S_, @function
_Z36__device_stub__Z12reduceKernelPfS_S_PfS_S_:
.LFB3831:
	.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
	movq	%rdx, 8(%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	8(%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	.L17
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z12reduceKernelPfS_S_(%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
.L17:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3831:
	.size	_Z36__device_stub__Z12reduceKernelPfS_S_PfS_S_, .-_Z36__device_stub__Z12reduceKernelPfS_S_PfS_S_
	.globl	_Z12reduceKernelPfS_S_
	.type	_Z12reduceKernelPfS_S_, @function
_Z12reduceKernelPfS_S_:
.LFB3832:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z12reduceKernelPfS_S_PfS_S_
	.cfi_endproc
.LFE3832:
	.size	_Z12reduceKernelPfS_S_, .-_Z12reduceKernelPfS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"_Z12reduceKernelPfS_S_"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3834:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC1(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12reduceKernelPfS_S_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3834:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z,"axG",@progbits,_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z,comdat
	.weak	_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z
	.type	_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z, @function
_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z:
.LFB4006:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %r10
	movq	%rdx, %rsi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	.cfi_offset 13, -24
	.cfi_offset 12, -32
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	movq	%rcx, %rdi
	subq	$232, %rsp
	movq	%r8, -176(%rbp)
	movq	%r9, -168(%rbp)
	testb	%al, %al
	je	.L25
	movaps	%xmm0, -160(%rbp)
	movaps	%xmm1, -144(%rbp)
	movaps	%xmm2, -128(%rbp)
	movaps	%xmm3, -112(%rbp)
	movaps	%xmm4, -96(%rbp)
	movaps	%xmm5, -80(%rbp)
	movaps	%xmm6, -64(%rbp)
	movaps	%xmm7, -48(%rbp)
.L25:
	movq	%fs:40, %rax
	movq	%rax, -216(%rbp)
	xorl	%eax, %eax
	leaq	23(%rsi), %rdx
	movq	%rsp, %rcx
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L26:
	cmpq	%rcx, %rsp
	je	.L27
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L26
.L27:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L28
	orq	$0, -8(%rsp,%rax)
.L28:
	leaq	16(%rbp), %rax
	leaq	15(%rsp), %r12
	movq	%rdi, %rdx
	movl	$32, -240(%rbp)
	movq	%rax, -232(%rbp)
	andq	$-16, %r12
	leaq	-208(%rbp), %rax
	leaq	-240(%rbp), %rcx
	movl	$48, -236(%rbp)
	movq	%r12, %rdi
	movq	%rax, -224(%rbp)
	call	*%r10
	leaq	16(%rbx), %rdx
	cltq
	movq	%rdx, (%rbx)
	xorl	%edx, %edx
	movq	%rdx, 8(%rbx)
	leaq	(%r12,%rax), %r13
	movq	%rax, -248(%rbp)
	cmpq	$15, %rax
	jbe	.L29
	leaq	-248(%rbp), %rsi
	xorl	%edx, %edx
	movq	%rbx, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm@PLT
	movq	%rax, (%rbx)
	movq	-248(%rbp), %rax
	movq	%rax, 16(%rbx)
.L29:
	movq	(%rbx), %rdi
	movq	%r13, %rdx
	movq	%r12, %rsi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE13_S_copy_charsEPcS5_S5_@PLT
	movq	-248(%rbp), %rax
	movq	(%rbx), %rdx
	movq	%rax, 8(%rbx)
	movb	$0, (%rdx,%rax)
	movq	-216(%rbp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	leaq	-24(%rbp), %rsp
	movq	%rbx, %rax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE4006:
	.size	_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z, .-_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z
	.section	.text._ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_,"axG",@progbits,_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_,comdat
	.weak	_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_
	.type	_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_, @function
_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_:
.LFB4151:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	movq	%rsi, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rdx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rsi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	movq	8(%rdx), %r13
	addq	8(%rsi), %r13
	call	_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv@PLT
	cmpq	%r13, %rax
	jnb	.L36
	movq	%rbp, %rdi
	call	_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv@PLT
	cmpq	%r13, %rax
	jb	.L36
	movq	%rbx, %rdx
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6insertEmRKS4_@PLT
	jmp	.L39
.L36:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendERKS4_@PLT
.L39:
	movq	%rax, %rsi
	movq	%r12, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EOS4_@PLT
	popq	%rdx
	.cfi_def_cfa_offset 40
	movq	%r12, %rax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4151:
	.size	_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_, .-_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_
	.section	.rodata.str1.1
.LC2:
	.string	"%i\n"
.LC4:
	.string	"Grid Size is: %d\n"
.LC5:
	.string	"Block Size is: %d\n"
.LC6:
	.string	"Run kernel: %s\n"
.LC7:
	.string	"\n"
.LC8:
	.string	"Copy host_output off device: %s\n"
.LC10:
	.string	"Elapsed time was: %f\n"
.LC11:
	.string	"And the final reduction is: %f\n"
.LC12:
	.string	"%f"
.LC13:
	.string	","
	.text
	.globl	_Z13reduceInvokerB5cxx11i
	.type	_Z13reduceInvokerB5cxx11i, @function
_Z13reduceInvokerB5cxx11i:
.LFB3805:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3805
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movslq	%esi, %rbx
	leaq	.LC2(%rip), %rsi
	movl	%ebx, %edx
	movq	%rbx, %r12
	salq	$2, %rbx
	movq	%rbx, %r13
	subq	$488, %rsp
	movq	%rdi, -520(%rbp)
	movl	$2, %edi
	shrq	$5, %r13
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
.LEHB0:
	call	__printf_chk@PLT
	leaq	15(%rbx), %rdx
	movq	%rsp, %rcx
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L41:
	cmpq	%rcx, %rsp
	je	.L42
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L41
.L42:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L43
	orq	$0, -8(%rsp,%rax)
.L43:
	leaq	-424(%rbp), %rdi
	movq	%rsp, %r14
	call	cudaEventCreate@PLT
	leaq	-416(%rbp), %rdi
	call	cudaEventCreate@PLT
	movss	.LC3(%rip), %xmm0
	xorl	%eax, %eax
.L44:
	cmpl	%eax, %r12d
	jle	.L70
	movss	%xmm0, (%r14,%rax,4)
	incq	%rax
	jmp	.L44
.L70:
	leaq	-448(%rbp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r14, %rsi
	movq	-448(%rbp), %rdi
	call	cudaMemcpy@PLT
	movq	%r13, %rsi
	leaq	-440(%rbp), %rdi
	call	cudaMalloc@PLT
	leaq	-432(%rbp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movl	%r12d, %eax
	movl	$32, %ecx
	leaq	.LC4(%rip), %rsi
	cltd
	movl	$2, %edi
	idivl	%ecx
	movl	%eax, %edx
	movl	%eax, %r13d
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$32, %edx
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$134217729, %eax
	xorl	%esi, %esi
	movq	-424(%rbp), %rdi
	salq	$5, %rax
	movl	%r13d, -392(%rbp)
	movq	%rax, -404(%rbp)
	subq	$31, %rax
	movl	$1, -396(%rbp)
	movq	%rax, -388(%rbp)
	call	cudaEventRecord@PLT
	movl	-396(%rbp), %ecx
	xorl	%r9d, %r9d
	movq	-404(%rbp), %rdx
	movq	-392(%rbp), %rdi
	movl	-384(%rbp), %esi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	movq	-432(%rbp), %rdx
	movq	-448(%rbp), %rsi
	movq	-440(%rbp), %rdi
	call	_Z36__device_stub__Z12reduceKernelPfS_S_PfS_S_
.L46:
	movq	-416(%rbp), %rdi
	xorl	%esi, %esi
	leaq	.LC7(%rip), %rbx
	call	cudaEventRecord@PLT
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$2, %ecx
	movq	-432(%rbp), %rsi
	movl	$4, %edx
	leaq	-380(%rbp), %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	-416(%rbp), %rdx
	movq	-424(%rbp), %rsi
	leaq	-452(%rbp), %rdi
	movl	$0x00000000, -452(%rbp)
	call	cudaEventElapsedTime@PLT
	leaq	.LC10(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	cvtss2sd	-452(%rbp), %xmm0
	call	__printf_chk@PLT
	movb	$1, %al
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	-380(%rbp), %xmm0
	call	__printf_chk@PLT
	movq	-448(%rbp), %rdi
	call	cudaFree@PLT
	movq	-440(%rbp), %rdi
	call	cudaFree@PLT
	movq	-432(%rbp), %rdi
	call	cudaFree@PLT
.LEHE0:
	leaq	-120(%rbp), %rax
	movl	%r13d, %esi
	movq	%rax, %rdi
	movq	%rax, -472(%rbp)
	call	_ZNSt7__cxx119to_stringEi
	leaq	-216(%rbp), %rax
	movl	$32, %esi
	movq	%rax, %rdi
	movq	%rax, -480(%rbp)
	call	_ZNSt7__cxx119to_stringEi
	leaq	-312(%rbp), %rax
	movl	$58, %edx
	movq	vsnprintf@GOTPCREL(%rip), %rsi
	movq	%rax, -488(%rbp)
	movq	%rax, %rdi
	leaq	.LC12(%rip), %rcx
	movb	$1, %al
	cvtss2sd	-452(%rbp), %xmm0
.LEHB1:
	call	_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z
.LEHE1:
	leaq	-376(%rbp), %rax
	movl	%r12d, %esi
	leaq	.LC13(%rip), %r14
	movq	%rax, %rdi
	movq	%rax, -496(%rbp)
	call	_ZNSt7__cxx119to_stringEi
	movq	-496(%rbp), %rdi
	movq	%r14, %rsi
.LEHB2:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc@PLT
.LEHE2:
	movq	%rax, %rsi
	leaq	-344(%rbp), %rax
	movq	%rax, %rdi
	movq	%rax, -504(%rbp)
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EOS4_@PLT
	leaq	-280(%rbp), %rax
	movq	-488(%rbp), %rdx
	movq	-504(%rbp), %rsi
	movq	%rax, %rdi
	movq	%rax, -512(%rbp)
.LEHB3:
	call	_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_
.LEHE3:
	movq	-512(%rbp), %rdi
	movq	%r14, %rsi
.LEHB4:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc@PLT
.LEHE4:
	leaq	-248(%rbp), %r12
	movq	%rax, %rsi
	leaq	-184(%rbp), %r13
	movq	%r12, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EOS4_@PLT
	movq	-480(%rbp), %rdx
	movq	%r12, %rsi
	movq	%r13, %rdi
.LEHB5:
	call	_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_
.LEHE5:
	movq	%r14, %rsi
	movq	%r13, %rdi
.LEHB6:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc@PLT
.LEHE6:
	leaq	-152(%rbp), %r14
	movq	%rax, %rsi
	leaq	-88(%rbp), %r15
	movq	%r14, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EOS4_@PLT
	movq	-472(%rbp), %rdx
	movq	%r14, %rsi
	movq	%r15, %rdi
.LEHB7:
	call	_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_S9_
.LEHE7:
	movq	%rbx, %rsi
	movq	%r15, %rdi
.LEHB8:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc@PLT
.LEHE8:
	movq	-520(%rbp), %rdi
	movq	%rax, %rsi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EOS4_@PLT
	movq	%r15, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	%r14, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	%r13, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	%r12, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-512(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-504(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-496(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-488(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-480(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-472(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L56
	jmp	.L68
.L64:
	endbr64
	movq	%rax, %rbx
.L47:
	movq	%r15, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L48
.L63:
	endbr64
	movq	%rax, %rbx
.L48:
	movq	%r14, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L49
.L62:
	endbr64
	movq	%rax, %rbx
.L49:
	movq	%r13, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L50
.L61:
	endbr64
	movq	%rax, %rbx
.L50:
	movq	%r12, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L51
.L60:
	endbr64
	movq	%rax, %rbx
.L51:
	movq	-512(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L52
.L59:
	endbr64
	movq	%rax, %rbx
.L52:
	movq	-504(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L53
.L58:
	endbr64
	movq	%rax, %rbx
.L53:
	movq	-496(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-488(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L54
.L57:
	endbr64
	movq	%rax, %rbx
.L54:
	movq	-480(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-472(%rbp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L68
	movq	%rbx, %rdi
.LEHB9:
	call	_Unwind_Resume@PLT
.LEHE9:
.L68:
	call	__stack_chk_fail@PLT
.L56:
	movq	-520(%rbp), %rax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3805:
	.section	.gcc_except_table,"a",@progbits
.LLSDA3805:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3805-.LLSDACSB3805
.LLSDACSB3805:
	.uleb128 .LEHB0-.LFB3805
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3805
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L57-.LFB3805
	.uleb128 0
	.uleb128 .LEHB2-.LFB3805
	.uleb128 .LEHE2-.LEHB2
	.uleb128 .L58-.LFB3805
	.uleb128 0
	.uleb128 .LEHB3-.LFB3805
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L59-.LFB3805
	.uleb128 0
	.uleb128 .LEHB4-.LFB3805
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L60-.LFB3805
	.uleb128 0
	.uleb128 .LEHB5-.LFB3805
	.uleb128 .LEHE5-.LEHB5
	.uleb128 .L61-.LFB3805
	.uleb128 0
	.uleb128 .LEHB6-.LFB3805
	.uleb128 .LEHE6-.LEHB6
	.uleb128 .L62-.LFB3805
	.uleb128 0
	.uleb128 .LEHB7-.LFB3805
	.uleb128 .LEHE7-.LEHB7
	.uleb128 .L63-.LFB3805
	.uleb128 0
	.uleb128 .LEHB8-.LFB3805
	.uleb128 .LEHE8-.LEHB8
	.uleb128 .L64-.LFB3805
	.uleb128 0
	.uleb128 .LEHB9-.LFB3805
	.uleb128 .LEHE9-.LEHB9
	.uleb128 0
	.uleb128 0
.LLSDACSE3805:
	.text
	.size	_Z13reduceInvokerB5cxx11i, .-_Z13reduceInvokerB5cxx11i
	.section	.rodata.str1.1
.LC14:
	.string	"times.csv"
.LC15:
	.string	"Array Size,Elapsed Time,Block Size,Grid Size\n"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3806:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3806
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	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	$560, %rsp
	.cfi_def_cfa_offset 608
	movq	%fs:40, %rax
	movq	%rax, 552(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rbp
	movq	%rbp, %rdi
.LEHB10:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev@PLT
.LEHE10:
	movl	$32, %edx
	leaq	.LC14(%rip), %rsi
	movq	%rbp, %rdi
.LEHB11:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode@PLT
	movl	$45, %edx
	leaq	.LC15(%rip), %rsi
	movq	%rbp, %rdi
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	movl	$21, %r13d
	movl	$1, %ebx
	leaq	.LC2(%rip), %r14
.L72:
	movl	%ebx, %edx
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	8(%rsp), %r12
	movl	%ebx, %esi
	movq	%r12, %rdi
	call	_Z13reduceInvokerB5cxx11i
.LEHE11:
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movq	%rbp, %rdi
.LEHB12:
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
.LEHE12:
	movq	%r12, %rdi
	addl	%ebx, %ebx
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	decl	%r13d
	jne	.L72
	movq	%rbp, %rdi
.LEHB13:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv@PLT
.LEHE13:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	552(%rsp), %rax
	subq	%fs:40, %rax
	je	.L76
	jmp	.L80
.L78:
	endbr64
	movq	%rax, %rbx
.L73:
	movq	%r12, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L74
.L77:
	endbr64
	movq	%rax, %rbx
.L74:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	552(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L80
	movq	%rbx, %rdi
.LEHB14:
	call	_Unwind_Resume@PLT
.LEHE14:
.L80:
	call	__stack_chk_fail@PLT
.L76:
	addq	$560, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	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
.LFE3806:
	.section	.gcc_except_table
.LLSDA3806:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3806-.LLSDACSB3806
.LLSDACSB3806:
	.uleb128 .LEHB10-.LFB3806
	.uleb128 .LEHE10-.LEHB10
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB11-.LFB3806
	.uleb128 .LEHE11-.LEHB11
	.uleb128 .L77-.LFB3806
	.uleb128 0
	.uleb128 .LEHB12-.LFB3806
	.uleb128 .LEHE12-.LEHB12
	.uleb128 .L78-.LFB3806
	.uleb128 0
	.uleb128 .LEHB13-.LFB3806
	.uleb128 .LEHE13-.LEHB13
	.uleb128 .L77-.LFB3806
	.uleb128 0
	.uleb128 .LEHB14-.LFB3806
	.uleb128 .LEHE14-.LEHB14
	.uleb128 0
	.uleb128 0
.LLSDACSE3806:
	.section	.text.startup
	.size	main, .-main
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC3:
	.long	1065353216
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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 <numeric>
#include <stdlib.h>
#include <hip/hip_runtime.h>
#include <iostream>
#include <fstream>

using namespace std;

#define BLOCK_SIZE 32

__global__ void reduceKernel(float *device_output, float *device_input, float *final_output);

//function to call reduce kernel for array size
string reduceInvoker(int arraySize) {
	int N = arraySize;
	printf("%i\n", N);

	//Create variables for input and output array sizes
	size_t size = N * sizeof(float);
	size_t size_output = size / BLOCK_SIZE;
	size_t size_final_output = sizeof(float);

	//initialising host input and output arrays
	float host_input[N];
	float host_output[1];

	//initialising pointers for device arrays
	float *device_input, *device_output, *final_output;

	//initialising variables and events for cuda timer
	hipEvent_t start, stop;
	hipEventCreate(&start);
	hipEventCreate(&stop);

	hipError_t err;

	//filling host input array with values
	for (int i = 0; i < N; i++) {
		host_input[i] = 1.0f;
	}

	//allocating space for device input array
	hipMalloc((void**) &device_input, size);
	//copying host input array to device
	hipMemcpy(device_input, host_input, size, hipMemcpyHostToDevice);
	//allocating space for device and final output arrays
	hipMalloc((void**) &device_output, size_output);
	hipMalloc((void**) &final_output, size_final_output);

	//calculating grid size
	int grid_size = N / BLOCK_SIZE;
	printf("Grid Size is: %d\n", grid_size);
	printf("Block Size is: %d\n", BLOCK_SIZE);

	dim3 threadsPerBlock(BLOCK_SIZE);
	dim3 blocks(grid_size);
	//start timer
	hipEventRecord(start);
	//call kernel
	reduceKernel<<<blocks, threadsPerBlock>>>(device_output, device_input, final_output);


	//stop timer
	hipEventRecord(stop);
	// Wait for GPU to finish before accessing on host
	err = hipDeviceSynchronize();
	printf("Run kernel: %s\n", hipGetErrorString(err));
	printf("\n");
	//copy final output array to host
	err = hipMemcpy(host_output, final_output, size_final_output, hipMemcpyDeviceToHost);
	printf("Copy host_output off device: %s\n", hipGetErrorString(err));
	printf("\n");

	//calculate elapsed time
	float milliseconds = 0;
	hipEventElapsedTime(&milliseconds, start, stop);
	printf("Elapsed time was: %f\n", milliseconds);

	printf("And the final reduction is: %f\n", host_output[0]);

	//free device memory
	hipFree(device_input);
	hipFree(device_output);
	hipFree(final_output);
	//format string for csv file
	string csv = to_string(arraySize) + "," + to_string(milliseconds) + ","
			+ to_string(BLOCK_SIZE) + "," + to_string(grid_size) + "\n";
	return csv;
}

int main(void) {
	//Open file
	std::ofstream myFile;
	myFile.open("times.csv", std::ofstream::trunc);
	//Write headers
	myFile << "Array Size,Elapsed Time,Block Size,Grid Size\n";

	//Call reduce function invoker for different array sizes and write result to file
	for (unsigned int i = 1; i <= (1 << 20); i <<= 1) {
		printf("%i\n", i);
		string csv = reduceInvoker(i);
		myFile << csv;
	}

	//close file
	myFile.close();
}
__global__ void reduceKernel(float* device_output, float* device_input, float *final_output) {
	//work out global thread id
	int myId = threadIdx.x + blockDim.x * blockIdx.x; // ID relative
	//work out local thread id
	int tid = threadIdx.x; // Local ID
	//initialise static shared memory
	__shared__ float temp[BLOCK_SIZE];
	//set value in shared memory
	temp[tid] = device_input[myId];
	//make sure threads are synced before adding values
	__syncthreads();
	// do reduction in shared memory
	for (unsigned int s = blockDim.x / 2; s >= 1; s >>= 1) {
		if (tid < s) {
			temp[tid] += temp[tid + s];
		}
		__syncthreads(); // make sure all adds at one stage are
	}
	// only thread 0 writes result for this block back to global memory
	if (tid == 0) {
		device_output[blockIdx.x] = temp[tid];
		//add partial reductions to get final reduction
		atomicAdd(&final_output[0], device_output[blockIdx.x]);
	}
}

	.text
	.file	"Lab5Test.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z13reduceInvokerB5cxx11i       # -- Begin function _Z13reduceInvokerB5cxx11i
	.type	_Z13reduceInvokerB5cxx11i,@function
_Z13reduceInvokerB5cxx11i:              # @_Z13reduceInvokerB5cxx11i
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$392, %rsp                      # imm = 0x188
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movl	%esi, %ebx
	movq	%rdi, -360(%rbp)                # 8-byte Spill
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, -128(%rbp)                # 8-byte Spill
	movslq	%ebx, %r15
	leaq	(,%r15,4), %r13
	movq	%r13, %r12
	shrq	$5, %r12
	movl	%r15d, %r14d
	movq	%rsp, %rbx
	leaq	15(,%r14,4), %rax
	andq	$-16, %rax
	subq	%rax, %rbx
	movq	%rbx, %rsp
	leaq	-176(%rbp), %rdi
	callq	hipEventCreate
	leaq	-168(%rbp), %rdi
	callq	hipEventCreate
	testl	%r15d, %r15d
	jle	.LBB0_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%eax, %eax
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$1065353216, (%rbx,%rax,4)      # imm = 0x3F800000
	incq	%rax
	cmpq	%rax, %r14
	jne	.LBB0_2
.LBB0_3:                                # %._crit_edge
	leaq	-192(%rbp), %r14
	movq	%r14, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movl	$1, %r14d
	movq	%rbx, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	-184(%rbp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	-48(%rbp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	movq	-128(%rbp), %r15                # 8-byte Reload
	leal	31(%r15), %r12d
	testl	%r15d, %r15d
	cmovnsl	%r15d, %r12d
	sarl	$5, %r12d
	movl	$.L.str.1, %edi
	movl	%r12d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.2, %edi
	movl	$32, %esi
	xorl	%eax, %eax
	callq	printf
	movq	%r12, %rbx
	btsq	$32, %rbx
	movq	-176(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$32, %rdx
	movq	%rbx, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_5
# %bb.4:
	movq	-184(%rbp), %rdi
	movq	-192(%rbp), %rsi
	movq	-48(%rbp), %rdx
	callq	_Z27__device_stub__reduceKernelPfS_S_
.LBB0_5:
	movq	-168(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	callq	hipDeviceSynchronize
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$10, %edi
	callq	putchar@PLT
	movq	-48(%rbp), %rsi
	leaq	-396(%rbp), %r13
	movl	$4, %edx
	movq	%r13, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$10, %edi
	callq	putchar@PLT
	leaq	-52(%rbp), %rbx
	movl	$0, (%rbx)
	movq	-176(%rbp), %rsi
	movq	-168(%rbp), %rdx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r13), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movq	-192(%rbp), %rdi
	callq	hipFree
	movq	-184(%rbp), %rdi
	callq	hipFree
	movq	-48(%rbp), %rdi
	callq	hipFree
	movl	%r15d, %r13d
	negl	%r13d
	cmovsl	%r15d, %r13d
	cmpl	$10, %r13d
	jb	.LBB0_14
# %bb.6:                                # %.lr.ph.i.i.preheader
	movl	$4, %r14d
	movl	$3518437209, %eax               # imm = 0xD1B71759
	movl	%r13d, %ecx
.LBB0_7:                                # %.lr.ph.i.i
                                        # =>This Inner Loop Header: Depth=1
	cmpl	$99, %ecx
	jbe	.LBB0_12
# %bb.8:                                #   in Loop: Header=BB0_7 Depth=1
	cmpl	$999, %ecx                      # imm = 0x3E7
	jbe	.LBB0_13
# %bb.9:                                #   in Loop: Header=BB0_7 Depth=1
	cmpl	$10000, %ecx                    # imm = 0x2710
	jb	.LBB0_14
# %bb.10:                               #   in Loop: Header=BB0_7 Depth=1
	movl	%ecx, %edx
	imulq	%rax, %rdx
	shrq	$45, %rdx
	addl	$4, %r14d
	cmpl	$99999, %ecx                    # imm = 0x1869F
	movl	%edx, %ecx
	ja	.LBB0_7
# %bb.11:                               # %_ZNSt8__detail14__to_chars_lenIjEEjT_i.exit.i.loopexit
	addl	$-3, %r14d
	jmp	.LBB0_14
.LBB0_12:
	addl	$-2, %r14d
	jmp	.LBB0_14
.LBB0_13:
	decl	%r14d
.LBB0_14:                               # %_ZNSt8__detail14__to_chars_lenIjEEjT_i.exit.i
	movl	%r15d, %ebx
	shrl	$31, %ebx
	leal	(%r14,%rbx), %esi
	leaq	-416(%rbp), %rax
	movq	%rax, -16(%rax)
.Ltmp0:
	leaq	-432(%rbp), %rdi
	movl	$45, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructEmc
.Ltmp1:
# %bb.15:                               # %_ZNSt7__cxx119to_stringEi.exit
	movl	%ebx, %edi
	leaq	-432(%rbp), %rbx
	addq	(%rbx), %rdi
	movl	%r14d, %esi
	movl	%r13d, %edx
	callq	_ZNSt8__detail18__to_chars_10_implIjEEvPcjT_
.Ltmp3:
	movl	$.L.str.8, %esi
	movq	%rbx, %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc
.Ltmp4:
# %bb.16:                               # %.noexc
	movq	%rax, %rbx
	leaq	-144(%rbp), %r15
	movq	%r15, -16(%r15)
	movq	(%rax), %rsi
	movq	%rax, %r14
	addq	$16, %r14
	cmpq	%r14, %rsi
	je	.LBB0_18
# %bb.17:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	movq	%rsi, -160(%rbp)
	movq	16(%rbx), %rax
	movq	%rax, -144(%rbp)
	movq	8(%rbx), %r13
	jmp	.LBB0_19
.LBB0_18:
	movq	8(%rbx), %r13
	leaq	1(%r13), %rdx
	movq	%r15, %rdi
	callq	memcpy@PLT
.LBB0_19:
	movq	%r13, -152(%rbp)
	movq	%r14, (%rbx)
	movq	$0, 8(%rbx)
	movb	$0, 16(%rbx)
	xorps	%xmm0, %xmm0
	cvtss2sd	-52(%rbp), %xmm0
.Ltmp6:
	leaq	-392(%rbp), %rdi
	movl	$vsnprintf, %esi
	movl	$58, %edx
	movl	$.L.str.11, %ecx
	movb	$1, %al
	callq	_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z
.Ltmp7:
# %bb.20:                               # %_ZNSt7__cxx119to_stringEf.exit
	movq	-160(%rbp), %rcx
	movq	-152(%rbp), %r8
	movq	-384(%rbp), %rdx
	leaq	(%rdx,%r8), %rax
	movl	$15, %edi
	cmpq	%r15, %rcx
	je	.LBB0_22
# %bb.21:                               # %_ZNSt7__cxx119to_stringEf.exit
	movq	-144(%rbp), %rdi
.LBB0_22:                               # %_ZNSt7__cxx119to_stringEf.exit
	movq	-392(%rbp), %rsi
	cmpq	%rdi, %rax
	movq	-128(%rbp), %r15                # 8-byte Reload
	jbe	.LBB0_26
# %bb.23:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv.exit12.i
	leaq	-376(%rbp), %r9
	movl	$15, %edi
	cmpq	%r9, %rsi
	je	.LBB0_25
# %bb.24:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv.exit12.i
	movq	-376(%rbp), %rdi
.LBB0_25:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv.exit12.i
	cmpq	%rdi, %rax
	jbe	.LBB0_27
.LBB0_26:
.Ltmp11:
	leaq	-160(%rbp), %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKcm
.Ltmp12:
	jmp	.LBB0_28
.LBB0_27:                               # %.critedge.i
.Ltmp9:
	leaq	-392(%rbp), %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7replaceEmmPKcm
.Ltmp10:
.LBB0_28:                               # %.noexc50
	movq	%rax, %rbx
	leaq	-240(%rbp), %rdi
	movq	%rdi, -16(%rdi)
	movq	(%rax), %rsi
	leaq	16(%rax), %r14
	cmpq	%r14, %rsi
	je	.LBB0_30
# %bb.29:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i13.i
	movq	%rsi, -256(%rbp)
	movq	(%r14), %rax
	movq	%rax, -240(%rbp)
	jmp	.LBB0_31
.LBB0_30:
	movq	8(%rbx), %rdx
	incq	%rdx
	callq	memcpy@PLT
.LBB0_31:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2EOS4_.exit14.i
	movq	%rbx, %rax
	addq	$8, %rax
	movq	8(%rbx), %rcx
	movq	%rcx, -248(%rbp)
	movq	%r14, (%rbx)
	movq	$0, (%rax)
	movb	$0, (%r14)
.Ltmp14:
	leaq	-256(%rbp), %rdi
	movl	$.L.str.8, %esi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc
.Ltmp15:
# %bb.32:                               # %.noexc56
	movq	%rax, %rbx
	leaq	-72(%rbp), %rdi
	movq	%rdi, -16(%rdi)
	movq	(%rax), %rsi
	movq	%rax, %r14
	addq	$16, %r14
	cmpq	%r14, %rsi
	je	.LBB0_34
# %bb.33:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i52
	movq	%rsi, -88(%rbp)
	movq	16(%rbx), %rax
	movq	%rax, -72(%rbp)
	movq	8(%rbx), %r13
	jmp	.LBB0_35
.LBB0_34:
	movq	8(%rbx), %r13
	leaq	1(%r13), %rdx
	callq	memcpy@PLT
.LBB0_35:                               # %_ZNSt8__detail14__to_chars_lenIjEEjT_i.exit.i61
	movq	%r13, -80(%rbp)
	movq	%r14, (%rbx)
	movq	$0, 8(%rbx)
	movb	$0, 16(%rbx)
	leaq	-208(%rbp), %rbx
	movq	%rbx, -16(%rbx)
.Ltmp17:
	leaq	-224(%rbp), %rdi
	movl	$2, %esi
	movl	$45, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructEmc
.Ltmp18:
# %bb.36:                               # %_ZNSt7__cxx119to_stringEi.exit63
	movq	-224(%rbp), %rax
	movw	$12851, (%rax)                  # imm = 0x3233
	movq	-88(%rbp), %rcx
	movq	-80(%rbp), %r8
	movq	-216(%rbp), %rdx
	leaq	(%rdx,%r8), %rax
	movl	$15, %edi
	leaq	-72(%rbp), %rsi
	cmpq	%rsi, %rcx
	je	.LBB0_38
# %bb.37:                               # %_ZNSt7__cxx119to_stringEi.exit63
	movq	-72(%rbp), %rdi
.LBB0_38:                               # %_ZNSt7__cxx119to_stringEi.exit63
	movq	-224(%rbp), %rsi
	cmpq	%rdi, %rax
	jbe	.LBB0_42
# %bb.39:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv.exit12.i70
	movl	$15, %edi
	cmpq	%rbx, %rsi
	je	.LBB0_41
# %bb.40:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv.exit12.i70
	movq	-208(%rbp), %rdi
.LBB0_41:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv.exit12.i70
	cmpq	%rdi, %rax
	jbe	.LBB0_43
.LBB0_42:
.Ltmp22:
	leaq	-88(%rbp), %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKcm
.Ltmp23:
	jmp	.LBB0_44
.LBB0_43:                               # %.critedge.i72
.Ltmp20:
	leaq	-224(%rbp), %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7replaceEmmPKcm
.Ltmp21:
.LBB0_44:                               # %.noexc75
	movq	%rax, %rbx
	leaq	-272(%rbp), %rdi
	movq	%rdi, -16(%rdi)
	movq	(%rax), %rsi
	leaq	16(%rax), %r14
	cmpq	%r14, %rsi
	je	.LBB0_46
# %bb.45:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i13.i66
	movq	%rsi, -288(%rbp)
	movq	(%r14), %rax
	movq	%rax, -272(%rbp)
	jmp	.LBB0_47
.LBB0_46:
	movq	8(%rbx), %rdx
	incq	%rdx
	callq	memcpy@PLT
.LBB0_47:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2EOS4_.exit14.i67
	movq	%rbx, %rax
	addq	$8, %rax
	movq	8(%rbx), %rcx
	movq	%rcx, -280(%rbp)
	movq	%r14, (%rbx)
	movq	$0, (%rax)
	movb	$0, (%r14)
.Ltmp25:
	leaq	-288(%rbp), %rdi
	movl	$.L.str.8, %esi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc
.Ltmp26:
# %bb.48:                               # %.noexc82
	movq	%rax, %rbx
	leaq	-104(%rbp), %rdi
	movq	%rdi, -16(%rdi)
	movq	(%rax), %rsi
	movq	%rax, %r14
	addq	$16, %r14
	cmpq	%r14, %rsi
	je	.LBB0_50
# %bb.49:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i78
	movq	%rsi, -120(%rbp)
	movq	16(%rbx), %rax
	movq	%rax, -104(%rbp)
	movq	8(%rbx), %r13
	jmp	.LBB0_51
.LBB0_50:
	movq	8(%rbx), %r13
	leaq	1(%r13), %rdx
	callq	memcpy@PLT
.LBB0_51:
	movq	%r13, -112(%rbp)
	movq	%r14, (%rbx)
	movq	$0, 8(%rbx)
	movb	$0, 16(%rbx)
	movl	%r12d, %r13d
	negl	%r13d
	cmovsl	%r12d, %r13d
	movl	$1, %r12d
	cmpl	$10, %r13d
	jb	.LBB0_60
# %bb.52:                               # %.lr.ph.i.i84.preheader
	movl	$4, %r12d
	movl	$3518437209, %eax               # imm = 0xD1B71759
	movl	%r13d, %ecx
.LBB0_53:                               # %.lr.ph.i.i84
                                        # =>This Inner Loop Header: Depth=1
	cmpl	$99, %ecx
	jbe	.LBB0_58
# %bb.54:                               #   in Loop: Header=BB0_53 Depth=1
	cmpl	$999, %ecx                      # imm = 0x3E7
	jbe	.LBB0_59
# %bb.55:                               #   in Loop: Header=BB0_53 Depth=1
	cmpl	$10000, %ecx                    # imm = 0x2710
	jb	.LBB0_60
# %bb.56:                               #   in Loop: Header=BB0_53 Depth=1
	movl	%ecx, %edx
	imulq	%rax, %rdx
	shrq	$45, %rdx
	addl	$4, %r12d
	cmpl	$99999, %ecx                    # imm = 0x1869F
	movl	%edx, %ecx
	ja	.LBB0_53
# %bb.57:                               # %_ZNSt8__detail14__to_chars_lenIjEEjT_i.exit.i87.loopexit
	addl	$-3, %r12d
	jmp	.LBB0_60
.LBB0_58:
	addl	$-2, %r12d
	jmp	.LBB0_60
.LBB0_59:
	decl	%r12d
.LBB0_60:                               # %_ZNSt8__detail14__to_chars_lenIjEEjT_i.exit.i87
	xorl	%esi, %esi
	cmpl	$-31, %r15d
	setl	%sil
	addl	%r12d, %esi
	leaq	-336(%rbp), %r14
	movq	%r14, -16(%r14)
.Ltmp28:
	leaq	-352(%rbp), %rdi
	movl	$45, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructEmc
.Ltmp29:
# %bb.61:                               # %_ZNSt7__cxx119to_stringEi.exit90
	xorl	%edi, %edi
	cmpl	$-31, %r15d
	setl	%dil
	addq	-352(%rbp), %rdi
	movl	%r12d, %esi
	movl	%r13d, %edx
	callq	_ZNSt8__detail18__to_chars_10_implIjEEvPcjT_
	movq	-120(%rbp), %rcx
	movq	-112(%rbp), %r8
	movq	-344(%rbp), %rdx
	leaq	(%rdx,%r8), %rax
	movl	$15, %edi
	leaq	-104(%rbp), %rsi
	cmpq	%rsi, %rcx
	je	.LBB0_63
# %bb.62:                               # %_ZNSt7__cxx119to_stringEi.exit90
	movq	-104(%rbp), %rdi
.LBB0_63:                               # %_ZNSt7__cxx119to_stringEi.exit90
	movq	-352(%rbp), %rsi
	cmpq	%rdi, %rax
	movq	-360(%rbp), %r13                # 8-byte Reload
	jbe	.LBB0_67
# %bb.64:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv.exit12.i97
	movl	$15, %edi
	cmpq	%r14, %rsi
	je	.LBB0_66
# %bb.65:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv.exit12.i97
	movq	-336(%rbp), %rdi
.LBB0_66:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8capacityEv.exit12.i97
	cmpq	%rdi, %rax
	jbe	.LBB0_68
.LBB0_67:
.Ltmp33:
	leaq	-120(%rbp), %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKcm
.Ltmp34:
	jmp	.LBB0_69
.LBB0_68:                               # %.critedge.i99
.Ltmp31:
	leaq	-352(%rbp), %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7replaceEmmPKcm
.Ltmp32:
.LBB0_69:                               # %.noexc102
	movq	%rax, %rbx
	leaq	-304(%rbp), %rdi
	movq	%rdi, -16(%rdi)
	movq	(%rax), %rsi
	leaq	16(%rax), %r15
	cmpq	%r15, %rsi
	je	.LBB0_71
# %bb.70:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i13.i93
	movq	%rsi, -320(%rbp)
	movq	(%r15), %rax
	movq	%rax, -304(%rbp)
	jmp	.LBB0_72
.LBB0_71:
	movq	8(%rbx), %rdx
	incq	%rdx
	callq	memcpy@PLT
.LBB0_72:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2EOS4_.exit14.i94
	movq	%rbx, %rax
	addq	$8, %rax
	movq	8(%rbx), %rcx
	movq	%rcx, -312(%rbp)
	movq	%r15, (%rbx)
	movq	$0, (%rax)
	movb	$0, (%r15)
.Ltmp36:
	leaq	-320(%rbp), %rdi
	movl	$.L.str.4, %esi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc
.Ltmp37:
# %bb.73:                               # %.noexc109
	movq	%rax, %rbx
	leaq	16(%r13), %rdi
	movq	%rdi, (%r13)
	movq	(%rax), %rsi
	movq	%rax, %r15
	addq	$16, %r15
	cmpq	%r15, %rsi
	je	.LBB0_75
# %bb.74:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i105
	movq	%rsi, (%r13)
	movq	16(%rbx), %rax
	movq	%rax, 16(%r13)
	movq	8(%rbx), %r12
	jmp	.LBB0_76
.LBB0_75:
	movq	8(%rbx), %r12
	leaq	1(%r12), %rdx
	callq	memcpy@PLT
.LBB0_76:
	movq	%r12, 8(%r13)
	movq	%r15, (%rbx)
	movq	$0, 8(%rbx)
	movb	$0, 16(%rbx)
	leaq	-304(%rbp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB0_78
# %bb.77:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i111
	callq	_ZdlPv
.LBB0_78:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
	movq	-352(%rbp), %rdi
	cmpq	%r14, %rdi
	leaq	-416(%rbp), %rbx
	leaq	-144(%rbp), %r14
	je	.LBB0_80
# %bb.79:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i112
	callq	_ZdlPv
.LBB0_80:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit114
	movq	-120(%rbp), %rdi
	leaq	-104(%rbp), %rax
	cmpq	%rax, %rdi
	je	.LBB0_82
# %bb.81:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i115
	callq	_ZdlPv
.LBB0_82:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit117
	leaq	-272(%rbp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB0_84
# %bb.83:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i118
	callq	_ZdlPv
.LBB0_84:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit120
	movq	-224(%rbp), %rdi
	leaq	-208(%rbp), %rax
	cmpq	%rax, %rdi
	je	.LBB0_86
# %bb.85:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i121
	callq	_ZdlPv
.LBB0_86:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit123
	movq	-88(%rbp), %rdi
	leaq	-72(%rbp), %rax
	cmpq	%rax, %rdi
	je	.LBB0_88
# %bb.87:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i124
	callq	_ZdlPv
.LBB0_88:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit126
	leaq	-240(%rbp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB0_90
# %bb.89:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i127
	callq	_ZdlPv
.LBB0_90:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit129
	leaq	-376(%rbp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB0_92
# %bb.91:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i130
	callq	_ZdlPv
.LBB0_92:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit132
	movq	-160(%rbp), %rdi
	cmpq	%r14, %rdi
	je	.LBB0_94
# %bb.93:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i133
	callq	_ZdlPv
.LBB0_94:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit135
	movq	-432(%rbp), %rdi
	cmpq	%rbx, %rdi
	je	.LBB0_96
# %bb.95:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i136
	callq	_ZdlPv
.LBB0_96:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit138
	movq	%r13, %rax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.LBB0_97:
	.cfi_def_cfa %rbp, 16
.Ltmp38:
	movq	%rax, %rbx
	leaq	-304(%rbp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB0_100
# %bb.98:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i139
	callq	_ZdlPv
	jmp	.LBB0_100
.LBB0_99:
.Ltmp35:
	movq	%rax, %rbx
.LBB0_100:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit141
	movq	-352(%rbp), %rdi
	cmpq	%r14, %rdi
	je	.LBB0_102
# %bb.101:                              # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i142
	callq	_ZdlPv
.LBB0_102:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit144
	movq	-120(%rbp), %rdi
	leaq	-104(%rbp), %rax
	cmpq	%rax, %rdi
	je	.LBB0_106
# %bb.103:                              # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i145
	callq	_ZdlPv
	jmp	.LBB0_106
.LBB0_104:
.Ltmp30:
	jmp	.LBB0_128
.LBB0_105:
.Ltmp27:
	movq	%rax, %rbx
.LBB0_106:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit147
	leaq	-272(%rbp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB0_109
# %bb.107:                              # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i148
	callq	_ZdlPv
	jmp	.LBB0_109
.LBB0_108:
.Ltmp24:
	movq	%rax, %rbx
.LBB0_109:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit150
	movq	-224(%rbp), %rdi
	leaq	-208(%rbp), %rax
	cmpq	%rax, %rdi
	je	.LBB0_111
# %bb.110:                              # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i151
	callq	_ZdlPv
.LBB0_111:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit153
	movq	-88(%rbp), %rdi
	leaq	-72(%rbp), %rax
	cmpq	%rax, %rdi
	je	.LBB0_115
# %bb.112:                              # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i154
	callq	_ZdlPv
	jmp	.LBB0_115
.LBB0_113:
.Ltmp19:
	jmp	.LBB0_128
.LBB0_114:
.Ltmp16:
	movq	%rax, %rbx
.LBB0_115:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit156
	leaq	-240(%rbp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB0_118
# %bb.116:                              # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i157
	callq	_ZdlPv
	jmp	.LBB0_118
.LBB0_117:
.Ltmp13:
	movq	%rax, %rbx
.LBB0_118:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit159
	leaq	-376(%rbp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB0_121
# %bb.119:                              # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i160
	callq	_ZdlPv
	jmp	.LBB0_121
.LBB0_120:
.Ltmp8:
	movq	%rax, %rbx
.LBB0_121:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit162
	movq	-160(%rbp), %rdi
	leaq	-144(%rbp), %rax
	cmpq	%rax, %rdi
	je	.LBB0_124
# %bb.122:                              # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i163
	callq	_ZdlPv
	jmp	.LBB0_124
.LBB0_123:
.Ltmp5:
	movq	%rax, %rbx
.LBB0_124:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit165
	movq	-432(%rbp), %rdi
	leaq	-416(%rbp), %rax
	cmpq	%rax, %rdi
	je	.LBB0_126
# %bb.125:                              # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i166
	callq	_ZdlPv
.LBB0_126:                              # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit168
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.LBB0_127:
.Ltmp2:
.LBB0_128:
	movq	%rax, %rdi
	callq	__clang_call_terminate
.Lfunc_end0:
	.size	_Z13reduceInvokerB5cxx11i, .Lfunc_end0-_Z13reduceInvokerB5cxx11i
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table0:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	3                               # @TType Encoding = udata4
	.uleb128 .Lttbase0-.Lttbaseref0
.Lttbaseref0:
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	1                               #   On action: 1
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp4-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp4
	.uleb128 .Ltmp5-.Lfunc_begin0           #     jumps to .Ltmp5
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp4-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp6-.Ltmp4                  #   Call between .Ltmp4 and .Ltmp6
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin0           # >> Call Site 5 <<
	.uleb128 .Ltmp7-.Ltmp6                  #   Call between .Ltmp6 and .Ltmp7
	.uleb128 .Ltmp8-.Lfunc_begin0           #     jumps to .Ltmp8
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp11-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp10-.Ltmp11                #   Call between .Ltmp11 and .Ltmp10
	.uleb128 .Ltmp13-.Lfunc_begin0          #     jumps to .Ltmp13
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp10-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp14-.Ltmp10                #   Call between .Ltmp10 and .Ltmp14
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp14-.Lfunc_begin0          # >> Call Site 8 <<
	.uleb128 .Ltmp15-.Ltmp14                #   Call between .Ltmp14 and .Ltmp15
	.uleb128 .Ltmp16-.Lfunc_begin0          #     jumps to .Ltmp16
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp15-.Lfunc_begin0          # >> Call Site 9 <<
	.uleb128 .Ltmp17-.Ltmp15                #   Call between .Ltmp15 and .Ltmp17
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp17-.Lfunc_begin0          # >> Call Site 10 <<
	.uleb128 .Ltmp18-.Ltmp17                #   Call between .Ltmp17 and .Ltmp18
	.uleb128 .Ltmp19-.Lfunc_begin0          #     jumps to .Ltmp19
	.byte	1                               #   On action: 1
	.uleb128 .Ltmp22-.Lfunc_begin0          # >> Call Site 11 <<
	.uleb128 .Ltmp21-.Ltmp22                #   Call between .Ltmp22 and .Ltmp21
	.uleb128 .Ltmp24-.Lfunc_begin0          #     jumps to .Ltmp24
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp21-.Lfunc_begin0          # >> Call Site 12 <<
	.uleb128 .Ltmp25-.Ltmp21                #   Call between .Ltmp21 and .Ltmp25
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp25-.Lfunc_begin0          # >> Call Site 13 <<
	.uleb128 .Ltmp26-.Ltmp25                #   Call between .Ltmp25 and .Ltmp26
	.uleb128 .Ltmp27-.Lfunc_begin0          #     jumps to .Ltmp27
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp26-.Lfunc_begin0          # >> Call Site 14 <<
	.uleb128 .Ltmp28-.Ltmp26                #   Call between .Ltmp26 and .Ltmp28
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp28-.Lfunc_begin0          # >> Call Site 15 <<
	.uleb128 .Ltmp29-.Ltmp28                #   Call between .Ltmp28 and .Ltmp29
	.uleb128 .Ltmp30-.Lfunc_begin0          #     jumps to .Ltmp30
	.byte	1                               #   On action: 1
	.uleb128 .Ltmp33-.Lfunc_begin0          # >> Call Site 16 <<
	.uleb128 .Ltmp32-.Ltmp33                #   Call between .Ltmp33 and .Ltmp32
	.uleb128 .Ltmp35-.Lfunc_begin0          #     jumps to .Ltmp35
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp32-.Lfunc_begin0          # >> Call Site 17 <<
	.uleb128 .Ltmp36-.Ltmp32                #   Call between .Ltmp32 and .Ltmp36
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp36-.Lfunc_begin0          # >> Call Site 18 <<
	.uleb128 .Ltmp37-.Ltmp36                #   Call between .Ltmp36 and .Ltmp37
	.uleb128 .Ltmp38-.Lfunc_begin0          #     jumps to .Ltmp38
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp37-.Lfunc_begin0          # >> Call Site 19 <<
	.uleb128 .Lfunc_end0-.Ltmp37            #   Call between .Ltmp37 and .Lfunc_end0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.byte	1                               # >> Action Record 1 <<
                                        #   Catch TypeInfo 1
	.byte	0                               #   No further actions
	.p2align	2, 0x0
                                        # >> Catch TypeInfos <<
	.long	0                               # TypeInfo 1
.Lttbase0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.globl	_Z27__device_stub__reduceKernelPfS_S_ # -- Begin function _Z27__device_stub__reduceKernelPfS_S_
	.type	_Z27__device_stub__reduceKernelPfS_S_,@function
_Z27__device_stub__reduceKernelPfS_S_:  # @_Z27__device_stub__reduceKernelPfS_S_
	.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	24(%rsp), %rsi
	movq	%rdx, (%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	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	$_Z12reduceKernelPfS_S_, %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	_Z27__device_stub__reduceKernelPfS_S_, .Lfunc_end1-_Z27__device_stub__reduceKernelPfS_S_
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin1:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception1
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$552, %rsp                      # imm = 0x228
	.cfi_def_cfa_offset 592
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rbx
	movq	%rbx, %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev
.Ltmp39:
	movl	$.L.str.9, %esi
	movq	%rbx, %rdi
	movl	$32, %edx
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode
.Ltmp40:
# %bb.1:
.Ltmp41:
	leaq	40(%rsp), %rdi
	movl	$.L.str.10, %esi
	movl	$45, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp42:
# %bb.2:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit.preheader
	movl	$1, %ebx
	leaq	24(%rsp), %r12
	leaq	8(%rsp), %r14
	leaq	40(%rsp), %r15
.LBB2_3:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
.Ltmp43:
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_Z13reduceInvokerB5cxx11i
.Ltmp44:
# %bb.4:                                #   in Loop: Header=BB2_3 Depth=1
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdx
.Ltmp46:
	movq	%r15, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp47:
# %bb.5:                                # %_ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKNSt7__cxx1112basic_stringIS4_S5_T1_EE.exit
                                        #   in Loop: Header=BB2_3 Depth=1
	movq	8(%rsp), %rdi
	cmpq	%r12, %rdi
	je	.LBB2_7
# %bb.6:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
                                        #   in Loop: Header=BB2_3 Depth=1
	callq	_ZdlPv
.LBB2_7:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
                                        #   in Loop: Header=BB2_3 Depth=1
	leal	(%rbx,%rbx), %eax
	cmpl	$524289, %ebx                   # imm = 0x80001
	movl	%eax, %ebx
	jb	.LBB2_3
# %bb.8:
.Ltmp49:
	leaq	40(%rsp), %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv
.Ltmp50:
# %bb.9:
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE(%rip), %rax
	leaq	48(%rsp), %rdi
	movq	%rax, -8(%rdi)
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE+24(%rip), %rcx
	movq	-24(%rax), %rax
	movq	%rcx, 40(%rsp,%rax)
	callq	_ZNSt13basic_filebufIcSt11char_traitsIcEED2Ev
	leaq	288(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	xorl	%eax, %eax
	addq	$552, %rsp                      # imm = 0x228
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB2_13:
	.cfi_def_cfa_offset 592
.Ltmp51:
	jmp	.LBB2_14
.LBB2_10:
.Ltmp45:
.LBB2_14:
	movq	%rax, %rbx
	jmp	.LBB2_15
.LBB2_11:
.Ltmp48:
	movq	%rax, %rbx
	movq	8(%rsp), %rdi
	cmpq	%r12, %rdi
	je	.LBB2_15
# %bb.12:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i11
	callq	_ZdlPv
.LBB2_15:
	leaq	40(%rsp), %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table2:
.Lexception1:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end1-.Lcst_begin1
.Lcst_begin1:
	.uleb128 .Lfunc_begin1-.Lfunc_begin1    # >> Call Site 1 <<
	.uleb128 .Ltmp39-.Lfunc_begin1          #   Call between .Lfunc_begin1 and .Ltmp39
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp39-.Lfunc_begin1          # >> Call Site 2 <<
	.uleb128 .Ltmp42-.Ltmp39                #   Call between .Ltmp39 and .Ltmp42
	.uleb128 .Ltmp51-.Lfunc_begin1          #     jumps to .Ltmp51
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp43-.Lfunc_begin1          # >> Call Site 3 <<
	.uleb128 .Ltmp44-.Ltmp43                #   Call between .Ltmp43 and .Ltmp44
	.uleb128 .Ltmp45-.Lfunc_begin1          #     jumps to .Ltmp45
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp46-.Lfunc_begin1          # >> Call Site 4 <<
	.uleb128 .Ltmp47-.Ltmp46                #   Call between .Ltmp46 and .Ltmp47
	.uleb128 .Ltmp48-.Lfunc_begin1          #     jumps to .Ltmp48
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp49-.Lfunc_begin1          # >> Call Site 5 <<
	.uleb128 .Ltmp50-.Ltmp49                #   Call between .Ltmp49 and .Ltmp50
	.uleb128 .Ltmp51-.Lfunc_begin1          #     jumps to .Ltmp51
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp50-.Lfunc_begin1          # >> Call Site 6 <<
	.uleb128 .Lfunc_end2-.Ltmp50            #   Call between .Ltmp50 and .Lfunc_end2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end1:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text.__clang_call_terminate,"axG",@progbits,__clang_call_terminate,comdat
	.hidden	__clang_call_terminate          # -- Begin function __clang_call_terminate
	.weak	__clang_call_terminate
	.type	__clang_call_terminate,@function
__clang_call_terminate:                 # @__clang_call_terminate
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__cxa_begin_catch
	callq	_ZSt9terminatev
.Lfunc_end3:
	.size	__clang_call_terminate, .Lfunc_end3-__clang_call_terminate
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt8__detail18__to_chars_10_implIjEEvPcjT_,"axG",@progbits,_ZNSt8__detail18__to_chars_10_implIjEEvPcjT_,comdat
	.weak	_ZNSt8__detail18__to_chars_10_implIjEEvPcjT_ # -- Begin function _ZNSt8__detail18__to_chars_10_implIjEEvPcjT_
	.type	_ZNSt8__detail18__to_chars_10_implIjEEvPcjT_,@function
_ZNSt8__detail18__to_chars_10_implIjEEvPcjT_: # @_ZNSt8__detail18__to_chars_10_implIjEEvPcjT_
	.cfi_startproc
# %bb.0:
                                        # kill: def $esi killed $esi def $rsi
	cmpl	$100, %edx
	jb	.LBB4_1
# %bb.2:                                # %.lr.ph.preheader
	decl	%esi
.LBB4_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%edx, %eax
	imulq	$1374389535, %rax, %rax         # imm = 0x51EB851F
	shrq	$37, %rax
	imull	$100, %eax, %ecx
	movl	%edx, %r8d
	subl	%ecx, %r8d
	movb	.L__const._ZNSt8__detail18__to_chars_10_implIjEEvPcjT_.__digits+1(%r8,%r8), %cl
	movl	%esi, %r9d
	movb	%cl, (%rdi,%r9)
	movb	.L__const._ZNSt8__detail18__to_chars_10_implIjEEvPcjT_.__digits(%r8,%r8), %cl
	leal	-1(%rsi), %r8d
	movb	%cl, (%rdi,%r8)
	addl	$-2, %esi
	cmpl	$9999, %edx                     # imm = 0x270F
	movl	%eax, %edx
	ja	.LBB4_3
	jmp	.LBB4_4
.LBB4_1:
	movl	%edx, %eax
.LBB4_4:                                # %._crit_edge
	cmpl	$10, %eax
	jb	.LBB4_6
# %bb.5:
	movl	%eax, %eax
	leaq	(%rax,%rax), %rcx
	movl	%ecx, %ecx
	movb	.L__const._ZNSt8__detail18__to_chars_10_implIjEEvPcjT_.__digits+1(%rcx), %cl
	movb	%cl, 1(%rdi)
	movb	.L__const._ZNSt8__detail18__to_chars_10_implIjEEvPcjT_.__digits(%rax,%rax), %al
	jmp	.LBB4_7
.LBB4_6:
	orb	$48, %al
.LBB4_7:
	movb	%al, (%rdi)
	retq
.Lfunc_end4:
	.size	_ZNSt8__detail18__to_chars_10_implIjEEvPcjT_, .Lfunc_end4-_ZNSt8__detail18__to_chars_10_implIjEEvPcjT_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z,"axG",@progbits,_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z,comdat
	.weak	_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z # -- Begin function _ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z
	.type	_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z,@function
_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z: # @_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z
	.cfi_startproc
# %bb.0:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IPcvEET_S7_RKS3_.exit
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r14
	pushq	%rbx
	subq	$208, %rsp
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	movq	%rsi, %r10
	movq	%rdi, %rbx
	leaq	-224(%rbp), %rsi
	movq	%r8, 32(%rsi)
	movq	%r9, 40(%rsi)
	testb	%al, %al
	je	.LBB5_2
# %bb.1:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IPcvEET_S7_RKS3_.exit
	movaps	%xmm0, -176(%rbp)
	movaps	%xmm1, -160(%rbp)
	movaps	%xmm2, -144(%rbp)
	movaps	%xmm3, -128(%rbp)
	movaps	%xmm4, -112(%rbp)
	movaps	%xmm5, -96(%rbp)
	movaps	%xmm6, -80(%rbp)
	movaps	%xmm7, -64(%rbp)
.LBB5_2:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IPcvEET_S7_RKS3_.exit
	movq	%rsp, %r14
	leaq	15(%rdx), %rax
	andq	$-16, %rax
	subq	%rax, %r14
	movq	%r14, %rsp
	leaq	-48(%rbp), %rax
	movq	%rsi, 16(%rax)
	leaq	16(%rbp), %rsi
	movq	%rsi, 8(%rax)
	movabsq	$206158430240, %rsi             # imm = 0x3000000020
	movq	%rsi, (%rax)
	movq	%r14, %rdi
	movq	%rdx, %rsi
	movq	%rcx, %rdx
	movq	%rax, %rcx
	callq	*%r10
	movslq	%eax, %rdx
	addq	%r14, %rdx
	leaq	16(%rbx), %rax
	movq	%rax, (%rbx)
	movq	$0, 8(%rbx)
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
	movq	%rbx, %rax
	leaq	-16(%rbp), %rsp
	popq	%rbx
	popq	%r14
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end5:
	.size	_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z, .Lfunc_end5-_ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %rbx
	subq	%rsi, %r14
	movq	%r14, (%rsp)
	cmpq	$15, %r14
	jbe	.LBB6_1
# %bb.2:
	movq	%rsp, %r12
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm
	movq	%rax, (%rbx)
	movq	(%r12), %rcx
	movq	%rcx, 16(%rbx)
	jmp	.LBB6_3
.LBB6_1:                                # %._crit_edge
	movq	(%rbx), %rax
.LBB6_3:
	testq	%r14, %r14
	je	.LBB6_7
# %bb.4:
	cmpq	$1, %r14
	jne	.LBB6_6
# %bb.5:
	movb	(%r15), %cl
	movb	%cl, (%rax)
	jmp	.LBB6_7
.LBB6_6:
	movq	%rax, %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	callq	memcpy@PLT
.LBB6_7:                                # %_ZZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tagEN6_GuardD2Ev.exit
	movq	(%rsp), %rax
	movq	%rax, 8(%rbx)
	movq	(%rbx), %rcx
	movb	$0, (%rcx,%rax)
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag, .Lfunc_end6-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
	.cfi_endproc
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12reduceKernelPfS_S_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%i\n"
	.size	.L.str, 4

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Grid Size is: %d\n"
	.size	.L.str.1, 18

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Block Size is: %d\n"
	.size	.L.str.2, 19

	.type	_Z12reduceKernelPfS_S_,@object  # @_Z12reduceKernelPfS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z12reduceKernelPfS_S_
	.p2align	3, 0x0
_Z12reduceKernelPfS_S_:
	.quad	_Z27__device_stub__reduceKernelPfS_S_
	.size	_Z12reduceKernelPfS_S_, 8

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"Run kernel: %s\n"
	.size	.L.str.3, 16

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Copy host_output off device: %s\n"
	.size	.L.str.5, 33

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Elapsed time was: %f\n"
	.size	.L.str.6, 22

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"And the final reduction is: %f\n"
	.size	.L.str.7, 32

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"times.csv"
	.size	.L.str.9, 10

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Array Size,Elapsed Time,Block Size,Grid Size\n"
	.size	.L.str.10, 46

	.type	.L__const._ZNSt8__detail18__to_chars_10_implIjEEvPcjT_.__digits,@object # @__const._ZNSt8__detail18__to_chars_10_implIjEEvPcjT_.__digits
	.section	.rodata.str1.16,"aMS",@progbits,1
	.p2align	4, 0x0
.L__const._ZNSt8__detail18__to_chars_10_implIjEEvPcjT_.__digits:
	.asciz	"00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899"
	.size	.L__const._ZNSt8__detail18__to_chars_10_implIjEEvPcjT_.__digits, 201

	.type	.L.str.11,@object               # @.str.11
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.11:
	.asciz	"%f"
	.size	.L.str.11, 3

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

	.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 _Z27__device_stub__reduceKernelPfS_S_
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym vsnprintf
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z12reduceKernelPfS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12reduceKernelPfS_S_  ; -- Begin function _Z12reduceKernelPfS_S_
	.globl	_Z12reduceKernelPfS_S_
	.p2align	8
	.type	_Z12reduceKernelPfS_S_,@function
_Z12reduceKernelPfS_S_:                 ; @_Z12reduceKernelPfS_S_
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_mov_b32 s2, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s2, s3, v[0:1]
	s_cmp_lt_u32 s3, 2
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s6, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v2, vcc_lo
	global_load_b32 v2, v[1:2], off
	v_lshlrev_b32_e32 v1, 2, v0
	s_waitcnt vmcnt(0)
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_5
; %bb.2:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_lshr_b32 s6, s3, 1
	s_mov_b32 s7, exec_lo
	v_cmpx_gt_u32_e64 s6, v0
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_1 Depth=1
	v_lshl_add_u32 v2, s6, 2, v1
	ds_load_b32 v2, v2
	ds_load_b32 v3, v1
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v2, v2, v3
	ds_store_b32 v1, v2
.LBB0_4:                                ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s7
	s_waitcnt lgkmcnt(0)
	s_barrier
	s_cmp_lt_u32 s3, 4
	s_mov_b32 s3, s6
	s_branch .LBB0_1
.LBB0_5:                                ; %._crit_edge
	s_mov_b32 s3, 0
	s_mov_b32 s6, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_11
; %bb.6:
	ds_load_b32 v0, v1
	s_load_b64 s[0:1], s[0:1], 0x10
	s_lshl_b64 s[2:3], s[2:3], 2
	v_mov_b32_e32 v1, 0
	v_bfrev_b32_e32 v2, 1
	s_add_u32 s2, s4, s2
	s_mov_b32 s6, exec_lo
	s_addc_u32 s3, s5, s3
	s_waitcnt lgkmcnt(0)
	global_store_b32 v1, v0, s[2:3]
.LBB0_7:                                ; %ComputeLoop
                                        ; =>This Inner Loop Header: Depth=1
	s_ctz_i32_b32 s2, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_readlane_b32 s3, v0, s2
	s_lshl_b32 s2, 1, s2
	s_and_not1_b32 s6, s6, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_cmp_lg_u32 s6, 0
	v_add_f32_e32 v2, s3, v2
	s_cbranch_scc1 .LBB0_7
; %bb.8:                                ; %ComputeEnd
	v_mbcnt_lo_u32_b32 v0, exec_lo, 0
	s_mov_b32 s2, 0
	s_mov_b32 s3, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v0
	s_xor_b32 s3, exec_lo, s3
	s_cbranch_execz .LBB0_11
; %bb.9:
	v_mov_b32_e32 v3, 0
	global_load_b32 v1, v3, s[0:1]
.LBB0_10:                               ; %atomicrmw.start
                                        ; =>This Inner Loop Header: Depth=1
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v0, v1, v2
	global_atomic_cmpswap_b32 v0, v3, v[0:1], s[0:1] glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, v0, v1
	v_mov_b32_e32 v1, v0
	s_or_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s2
	s_cbranch_execnz .LBB0_10
.LBB0_11:                               ; %Flow30
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12reduceKernelPfS_S_
		.amdhsa_group_segment_fixed_size 128
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 4
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z12reduceKernelPfS_S_, .Lfunc_end0-_Z12reduceKernelPfS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 420
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 128 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .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:     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: 128
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z12reduceKernelPfS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12reduceKernelPfS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
