#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <chrono>

const uint32_t MAX_DATA_SET_SIZE_PER_BLOCK = 1024;
const uint32_t DEFAULT_DATA_SIZE = 8192;

typedef uint32_t (*operation_function)(uint32_t operand1, uint32_t operand2);

// Reduction adapted from http://developer.download.nvidia.com/compute/cuda/1.1-Beta/x86_website/projects/reduction/doc/reduction.pdf
__device__ void reduce(uint32_t *dataSet, uint32_t* sharedData, uint32_t *result, operation_function op)
{
    // Calculate indecies
    unsigned int threadId = threadIdx.x;
    unsigned int globalThreadId = blockIdx.x*(blockDim.x*2) + threadIdx.x;
    
    // Perform the first reduction to get memory from global to shared
    sharedData[threadId] = op(dataSet[globalThreadId], dataSet[globalThreadId + blockDim.x]);
    __syncthreads();

    // Perform reduction using the provided operation_function
    for (unsigned int i=blockDim.x/2; i>0; i >>= 1)
    {
        if (threadId < i)
        {
            sharedData[threadId] = op(sharedData[threadId], sharedData[threadId + i]);
        }
        __syncthreads();
    }

    // Copy result back to global memory
    if (threadId == 0)
    {
        result[blockIdx.x] = sharedData[0];
    }
}

// Add two operands and return the result
__device__ uint32_t add(uint32_t operand1, uint32_t operand2)
{
    return operand1 + operand2;
}

// Return the max of 2 elements without blocking (using a conditional)
__device__ uint32_t maximum(uint32_t element1, uint32_t element2)
{
    uint32_t findMax[2];
    findMax[0] = element1;
    findMax[1] = element2;

    return findMax[element1 < element2];
}

// Return the min of 2 elements without blocking (using a conditional)
__device__ uint32_t minimum(uint32_t element1, uint32_t element2)
{
    uint32_t findMax[2];
    findMax[0] = element1;
    findMax[1] = element2;

    return findMax[element1 > element2];
}

// Get the sum of all elements in dataSet
__global__ void sum(uint32_t* dataSet, uint32_t *result)
{
    extern __shared__ uint32_t sharedData[];
    reduce(dataSet, sharedData, result, &add);
}

// Get the max of all elements in dataSet
__global__ void getMax(uint32_t* dataSet, uint32_t *result)
{
    extern __shared__ uint32_t sharedData[];
    reduce(dataSet, sharedData, result, &maximum);
}

// Get the min of all elements in dataSet
__global__ void getMin(uint32_t* dataSet, uint32_t *result)
{
    extern __shared__ uint32_t sharedData[];
    reduce(dataSet, sharedData, result, &minimum);
}

// Get tha max, min, and average of all values in dataSet
void getMaxMinAvg(uint32_t dataSize, uint32_t numBlocks, uint32_t * data, uint32_t *max, uint32_t *min, double *avg)
{
    // Allocate CPU memory
    int32_t numThreads = dataSize / (numBlocks * 2);
    uint32_t *cpuMaxResult = (uint32_t *)malloc(numBlocks * sizeof(uint32_t));
    uint32_t *cpuMinResult = (uint32_t *)malloc(numBlocks * sizeof(uint32_t));
    uint32_t *cpuSumResult = (uint32_t *)malloc(numBlocks * sizeof(uint32_t));

    // Allocate GPU memory
    uint32_t *gpuMaxResult;
    cudaMalloc((void **)&gpuMaxResult, numBlocks * sizeof(uint32_t));
    uint32_t *gpuMinResult;
    cudaMalloc((void **)&gpuMinResult, numBlocks * sizeof(uint32_t));
    uint32_t *gpuSumResult;
    cudaMalloc((void **)&gpuSumResult, numBlocks * sizeof(uint32_t));

    // Create CUDA Event for each operation
    cudaEvent_t gotMax, gotMin, gotSum;
    cudaEventCreate(&gotMax);
    cudaEventCreate(&gotMin);
    cudaEventCreate(&gotSum);

    // Create cuda stream for each operation
    cudaStream_t maxStream, minStream, sumStream;
    cudaStreamCreate(&maxStream);
    cudaStreamCreate(&minStream);
    cudaStreamCreate(&sumStream);

    // Mark when processing starts.
    auto start = std::chrono::high_resolution_clock::now();

    // Run async kernel to get maximum
    getMax<<<numBlocks, numThreads, numThreads * sizeof(uint32_t), maxStream>>>(data, gpuMaxResult);
    cudaMemcpyAsync(cpuMaxResult, gpuMaxResult, numBlocks * sizeof(uint32_t), cudaMemcpyDeviceToHost, maxStream);
    cudaEventRecord(gotMax, maxStream);

    // Run async kernel to get minimum
    getMin<<<numBlocks, numThreads, numThreads * sizeof(uint32_t), minStream>>>(data, gpuMinResult);
    cudaMemcpyAsync(cpuMinResult, gpuMinResult, numBlocks * sizeof(uint32_t), cudaMemcpyDeviceToHost, minStream);
    cudaEventRecord(gotMin, minStream);

    // Run async kernel to get average
    sum<<<numBlocks, numThreads, numThreads * sizeof(uint32_t), sumStream>>>(data, gpuSumResult);
    cudaMemcpyAsync(cpuSumResult, gpuSumResult, numBlocks * sizeof(uint32_t), cudaMemcpyDeviceToHost, sumStream);
    cudaEventRecord(gotSum, sumStream);

    bool maxFinished = false;
    bool minFinished = false;
    bool sumFinished = false;

    // Check the event for each operation and measure total time to completion
    while (!maxFinished || !minFinished || !sumFinished)
    {
        if (!maxFinished && (cudaEventQuery(gotMax) == cudaSuccess))
        {
            auto now = std::chrono::high_resolution_clock::now();
            printf("Get Maximum finished after %dus\n", std::chrono::duration_cast<std::chrono::microseconds>(now - start).count());
            maxFinished = true;
        }
        if (!minFinished && (cudaEventQuery(gotMin) == cudaSuccess))
        {
            auto now = std::chrono::high_resolution_clock::now();
            printf("Get Minimum finished after %dus\n", std::chrono::duration_cast<std::chrono::microseconds>(now - start).count());
            minFinished = true;
        }
        if (!sumFinished && (cudaEventQuery(gotSum) == cudaSuccess))
        {
            auto now = std::chrono::high_resolution_clock::now();
            printf("Get Sum finished after %dus\n", std::chrono::duration_cast<std::chrono::microseconds>(now - start).count());
            sumFinished = true;
        }
    }
    cudaDeviceSynchronize();

    // Aggregate results for max, min, avg
    *max = 0;
    *min = UINT_MAX;
    double sum = 0;

    for (size_t i = 0; i < numBlocks; i++)
    {
        sum += cpuSumResult[i];

        if (cpuMaxResult[i] > *max) {
            *max = cpuMaxResult[i];
        }
        if (cpuMinResult[i] < *min) {
            *min = cpuMinResult[i];
        }
    }

    // Calculate average
    *avg = sum / dataSize;

    // Destroy CUDA events
    cudaEventDestroy(gotMax);
    cudaEventDestroy(gotMin);
    cudaEventDestroy(gotSum);

    // Destroy CUDA streams
    cudaStreamDestroy(maxStream);
    cudaStreamDestroy(minStream);
    cudaStreamDestroy(sumStream);

    // Free GPU memory
    cudaFree(gpuMaxResult);
    cudaFree(gpuMinResult);
    cudaFree(gpuSumResult);

    // Free CPU memory
    free(cpuMaxResult);
    free(cpuMinResult);
    free(cpuSumResult);
}

// Main function
int main(int argc, char* argv[])
{
    // Set number of blocks to default and runs
    uint32_t dataSize = DEFAULT_DATA_SIZE;
    uint32_t numBlocks = 8;
    uint32_t numRuns = 2;
    
    // Check command line for number of blocks argument
    if (argc > 1) {
        numBlocks = atoi(argv[1]);

        if ((numBlocks % 2) != 0) {
            printf("Must enter a multiple of 2\n");
            return 1;
        }
        dataSize = numBlocks * MAX_DATA_SET_SIZE_PER_BLOCK ;
    }

    // Check command line for number of runs argument
    if (argc > 2) {
        numRuns = atoi(argv[2]);
    }

    // Allocate pinned memory for data set
    uint32_t * data;
    cudaMallocHost((void**)&data, dataSize * sizeof(uint32_t));

    // Allocate device memory for data set
    uint32_t *gpuData;
    cudaMalloc((void **)&gpuData, dataSize * sizeof(uint32_t));

    srand((unsigned)time(NULL)); 
    for (uint32_t x = 0; x < numRuns; x++)
    {
        printf("Run %d\n--------------------------------------------------\n", x);

        // Populate data set with random values
        uint32_t range = dataSize * 4;
        for(size_t i = 0; i < dataSize; i++){ 
            data[i] = rand() % range + 1;
        }

        // Copy data set to device
        cudaMemcpy(gpuData, data, dataSize * sizeof(uint32_t), cudaMemcpyHostToDevice);

        // Calculate values
        double avg;
        uint32_t max;
        uint32_t min;
        getMaxMinAvg(dataSize, numBlocks, gpuData, &max, &min, &avg);

        // Print results
        printf("\n\n");
        printf("Average is %f\n", avg);
        printf ("Max is %d\n", max);
        printf ("Min is %d\n", min);
        printf("\n\n\n");
    }

    // Free allocated memory
    cudaFreeHost(data);
    cudaFree(gpuData);
}

	.file	"tmpxft_002c3930_00000000-6_streams.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3744:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3744:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z6reducePjS_S_PFjjjE
	.type	_Z6reducePjS_S_PFjjjE, @function
_Z6reducePjS_S_PFjjjE:
.LFB3734:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE3734:
	.size	_Z6reducePjS_S_PFjjjE, .-_Z6reducePjS_S_PFjjjE
	.globl	_Z3addjj
	.type	_Z3addjj, @function
_Z3addjj:
.LFB3735:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE3735:
	.size	_Z3addjj, .-_Z3addjj
	.globl	_Z7maximumjj
	.type	_Z7maximumjj, @function
_Z7maximumjj:
.LFB4445:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	_Z3addjj
	.cfi_endproc
.LFE4445:
	.size	_Z7maximumjj, .-_Z7maximumjj
	.globl	_Z7minimumjj
	.type	_Z7minimumjj, @function
_Z7minimumjj:
.LFB4447:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	_Z3addjj
	.cfi_endproc
.LFE4447:
	.size	_Z7minimumjj, .-_Z7minimumjj
	.globl	_Z24__device_stub__Z3sumPjS_PjS_
	.type	_Z24__device_stub__Z3sumPjS_PjS_, @function
_Z24__device_stub__Z3sumPjS_PjS_:
.LFB3766:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L10
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z3sumPjS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L10:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3766:
	.size	_Z24__device_stub__Z3sumPjS_PjS_, .-_Z24__device_stub__Z3sumPjS_PjS_
	.globl	_Z3sumPjS_
	.type	_Z3sumPjS_, @function
_Z3sumPjS_:
.LFB3767:
	.cfi_startproc
	endbr64
	jmp	_Z24__device_stub__Z3sumPjS_PjS_
	.cfi_endproc
.LFE3767:
	.size	_Z3sumPjS_, .-_Z3sumPjS_
	.globl	_Z27__device_stub__Z6getMaxPjS_PjS_
	.type	_Z27__device_stub__Z6getMaxPjS_PjS_, @function
_Z27__device_stub__Z6getMaxPjS_PjS_:
.LFB3768:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L16
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z6getMaxPjS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L16:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3768:
	.size	_Z27__device_stub__Z6getMaxPjS_PjS_, .-_Z27__device_stub__Z6getMaxPjS_PjS_
	.globl	_Z6getMaxPjS_
	.type	_Z6getMaxPjS_, @function
_Z6getMaxPjS_:
.LFB3769:
	.cfi_startproc
	endbr64
	jmp	_Z27__device_stub__Z6getMaxPjS_PjS_
	.cfi_endproc
.LFE3769:
	.size	_Z6getMaxPjS_, .-_Z6getMaxPjS_
	.globl	_Z27__device_stub__Z6getMinPjS_PjS_
	.type	_Z27__device_stub__Z6getMinPjS_PjS_, @function
_Z27__device_stub__Z6getMinPjS_PjS_:
.LFB3770:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z6getMinPjS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L21:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3770:
	.size	_Z27__device_stub__Z6getMinPjS_PjS_, .-_Z27__device_stub__Z6getMinPjS_PjS_
	.globl	_Z6getMinPjS_
	.type	_Z6getMinPjS_, @function
_Z6getMinPjS_:
.LFB3771:
	.cfi_startproc
	endbr64
	jmp	_Z27__device_stub__Z6getMinPjS_PjS_
	.cfi_endproc
.LFE3771:
	.size	_Z6getMinPjS_, .-_Z6getMinPjS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Get Maximum finished after %dus\n"
.LC2:
	.string	"Get Minimum finished after %dus\n"
.LC3:
	.string	"Get Sum finished after %dus\n"
	.text
	.globl	_Z12getMaxMinAvgjjPjS_S_Pd
	.type	_Z12getMaxMinAvgjjPjS_S_Pd, @function
_Z12getMaxMinAvgjjPjS_S_Pd:
.LFB3738:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rcx, %r15
	leal	(%rsi,%rsi), %ecx
	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
	movq	%r8, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	subq	$184, %rsp
	.cfi_def_cfa_offset 240
	movq	%r9, 56(%rsp)
	movl	%edi, 44(%rsp)
	movq	%rdx, 32(%rsp)
	xorl	%edx, %edx
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	movl	%edi, %eax
	divl	%ecx
	movl	%eax, %ebp
	movl	%esi, %eax
	movq	%rax, 48(%rsp)
	salq	$2, %rax
	movq	%rbp, %r14
	salq	$2, %rbp
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	(%rsp), %rsi
	leaq	72(%rsp), %rdi
	movq	%rax, 24(%rsp)
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	88(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	96(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	104(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	112(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	120(%rsp), %rdi
	call	cudaStreamCreate@PLT
	leaq	128(%rsp), %rdi
	call	cudaStreamCreate@PLT
	leaq	136(%rsp), %rdi
	call	cudaStreamCreate@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	%r14d, 156(%rsp)
	movq	120(%rsp), %r9
	movq	%rbp, %r8
	movq	%rax, %r13
	movl	%ebx, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 160(%rsp)
	movl	164(%rsp), %ecx
	movq	%rax, 148(%rsp)
	movq	156(%rsp), %rdx
	movq	144(%rsp), %rdi
	movl	152(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	72(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z27__device_stub__Z6getMaxPjS_PjS_
.L27:
	movq	120(%rsp), %r8
	movq	(%rsp), %rdx
	movl	$2, %ecx
	movq	72(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	cudaMemcpyAsync@PLT
	movq	120(%rsp), %rsi
	movq	96(%rsp), %rdi
	call	cudaEventRecord@PLT
	movl	%r14d, 156(%rsp)
	movq	128(%rsp), %r9
	movq	%rbp, %r8
	movabsq	$4294967297, %rax
	movl	%ebx, 144(%rsp)
	movq	%rax, 160(%rsp)
	movl	164(%rsp), %ecx
	movq	%rax, 148(%rsp)
	movq	156(%rsp), %rdx
	movq	144(%rsp), %rdi
	movl	152(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L28
	movq	80(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z27__device_stub__Z6getMinPjS_PjS_
.L28:
	movq	(%rsp), %rdx
	movq	80(%rsp), %rsi
	movl	$2, %ecx
	movq	128(%rsp), %r8
	movq	16(%rsp), %rdi
	call	cudaMemcpyAsync@PLT
	movq	128(%rsp), %rsi
	movq	104(%rsp), %rdi
	call	cudaEventRecord@PLT
	movl	%r14d, 156(%rsp)
	movq	136(%rsp), %r9
	movq	%rbp, %r8
	movabsq	$4294967297, %rax
	movl	%ebx, 144(%rsp)
	movq	%rax, 160(%rsp)
	movl	164(%rsp), %ecx
	movq	%rax, 148(%rsp)
	movq	156(%rsp), %rdx
	movq	144(%rsp), %rdi
	movl	152(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	movq	88(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z24__device_stub__Z3sumPjS_PjS_
.L29:
	movq	136(%rsp), %r8
	movq	(%rsp), %rdx
	xorl	%ebx, %ebx
	xorl	%ebp, %ebp
	movq	88(%rsp), %rsi
	movq	24(%rsp), %rdi
	movl	$2, %ecx
	xorl	%r14d, %r14d
	call	cudaMemcpyAsync@PLT
	movq	136(%rsp), %rsi
	movq	112(%rsp), %rdi
	call	cudaEventRecord@PLT
.L30:
	movl	%ebp, %eax
	andb	%bl, %al
	jne	.L55
	testb	%bpl, %bpl
	jne	.L31
	movq	96(%rsp), %rdi
	call	cudaEventQuery@PLT
	testl	%eax, %eax
	jne	.L32
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$1000, %ecx
	movl	$2, %edi
	movb	$1, %bpl
	subq	%r13, %rax
	leaq	.LC1(%rip), %rsi
	cqto
	idivq	%rcx
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L32:
	testb	%bl, %bl
	jne	.L33
.L31:
	movq	104(%rsp), %rdi
	xorl	%ebx, %ebx
	call	cudaEventQuery@PLT
	testl	%eax, %eax
	jne	.L33
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$1000, %ecx
	leaq	.LC2(%rip), %rsi
	movb	$1, %bl
	subq	%r13, %rax
	movl	$2, %edi
	cqto
	idivq	%rcx
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L33:
	testb	%r14b, %r14b
	je	.L34
.L36:
	movb	$1, %r14b
	jmp	.L30
.L55:
	testb	%r14b, %r14b
	jne	.L56
	movl	%eax, %ebp
	movl	%eax, %ebx
.L34:
	movq	112(%rsp), %rdi
	xorl	%r14d, %r14d
	call	cudaEventQuery@PLT
	testl	%eax, %eax
	jne	.L30
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$1000, %ecx
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	subq	%r13, %rax
	cqto
	idivq	%rcx
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L36
.L56:
	call	cudaDeviceSynchronize@PLT
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
	movl	%eax, (%r15)
	xorl	%eax, %eax
	movl	$-1, (%r12)
.L38:
	movq	48(%rsp), %rbx
	cmpq	%rbx, %rax
	jnb	.L57
	movq	24(%rsp), %rbx
	movl	(%rbx,%rax,4), %edx
	movq	8(%rsp), %rbx
	cvtsi2sdq	%rdx, %xmm1
	movl	(%rbx,%rax,4), %edx
	addsd	%xmm1, %xmm0
	cmpl	%edx, (%r15)
	jnb	.L41
	movl	%edx, (%r15)
.L41:
	movq	16(%rsp), %rbx
	movl	(%rbx,%rax,4), %edx
	cmpl	(%r12), %edx
	jnb	.L42
	movl	%edx, (%r12)
.L42:
	incq	%rax
	jmp	.L38
.L57:
	movl	44(%rsp), %eax
	movq	96(%rsp), %rdi
	cvtsi2sdq	%rax, %xmm1
	movq	56(%rsp), %rax
	divsd	%xmm1, %xmm0
	movsd	%xmm0, (%rax)
	call	cudaEventDestroy@PLT
	movq	104(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	112(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	120(%rsp), %rdi
	call	cudaStreamDestroy@PLT
	movq	128(%rsp), %rdi
	call	cudaStreamDestroy@PLT
	movq	136(%rsp), %rdi
	call	cudaStreamDestroy@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L46
	call	__stack_chk_fail@PLT
.L46:
	movq	24(%rsp), %rdi
	addq	$184, %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
	jmp	free@PLT
	.cfi_endproc
.LFE3738:
	.size	_Z12getMaxMinAvgjjPjS_S_Pd, .-_Z12getMaxMinAvgjjPjS_S_Pd
	.section	.rodata.str1.1
.LC4:
	.string	"Must enter a multiple of 2\n"
.LC5:
	.string	"Run %d\n--------------------------------------------------\n"
.LC6:
	.string	"\n\n"
.LC7:
	.string	"Average is %f\n"
.LC8:
	.string	"Max is %d\n"
.LC9:
	.string	"Min is %d\n"
.LC10:
	.string	"\n\n\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3741:
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	cmpl	$1, %edi
	jle	.L67
	movl	%edi, %r14d
	movq	8(%rsi), %rdi
	movq	%rsi, %r12
	call	atoi@PLT
	movl	%eax, %ebp
	movl	%eax, %ebx
	andl	$1, %ebp
	je	.L60
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L58
.L60:
	movl	%eax, %r13d
	movl	$2, %ebp
	sall	$10, %r13d
	cmpl	$2, %r14d
	je	.L59
	movq	16(%r12), %rdi
	call	atoi@PLT
	movl	%eax, %ebp
	jmp	.L59
.L67:
	movl	$8, %ebx
	movl	$8192, %r13d
	movl	$2, %ebp
.L59:
	movl	%r13d, %r14d
	leaq	32(%rsp), %rdi
	xorl	%r12d, %r12d
	leaq	0(,%r14,4), %rax
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	cudaMallocHost@PLT
	movq	(%rsp), %rsi
	leaq	40(%rsp), %rdi
	call	cudaMalloc@PLT
	xorl	%edi, %edi
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	leal	0(,%r13,4), %eax
	movl	%eax, 12(%rsp)
.L62:
	cmpl	%r12d, %ebp
	je	.L70
	movl	%r12d, %edx
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	movl	$2, %edi
	call	__printf_chk@PLT
.L63:
	cmpq	%r14, %r15
	jnb	.L71
	call	rand@PLT
	xorl	%edx, %edx
	divl	12(%rsp)
	movq	32(%rsp), %rax
	incl	%edx
	movl	%edx, (%rax,%r15,4)
	incq	%r15
	jmp	.L63
.L71:
	movq	(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$1, %ecx
	incl	%r12d
	movq	40(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdx
	movl	%ebx, %esi
	movl	%r13d, %edi
	leaq	24(%rsp), %rcx
	leaq	48(%rsp), %r9
	leaq	28(%rsp), %r8
	call	_Z12getMaxMinAvgjjPjS_S_Pd
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movsd	48(%rsp), %xmm0
	leaq	.LC7(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	24(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC8(%rip), %rsi
	call	__printf_chk@PLT
	movl	28(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC9(%rip), %rsi
	call	__printf_chk@PLT
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L62
.L70:
	movq	32(%rsp), %rdi
	xorl	%ebp, %ebp
	call	cudaFreeHost@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
.L58:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L66
	call	__stack_chk_fail@PLT
.L66:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebp, %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
.LFE3741:
	.size	main, .-main
	.section	.rodata.str1.1
.LC11:
	.string	"_Z6getMinPjS_"
.LC12:
	.string	"_Z6getMaxPjS_"
.LC13:
	.string	"_Z3sumPjS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3773:
	.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	.LC11(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z6getMinPjS_(%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	.LC12(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z6getMaxPjS_(%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	.LC13(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z3sumPjS_(%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
.LFE3773:
	.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 <hip/hip_runtime.h>
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <chrono>

const uint32_t MAX_DATA_SET_SIZE_PER_BLOCK = 1024;
const uint32_t DEFAULT_DATA_SIZE = 8192;

typedef uint32_t (*operation_function)(uint32_t operand1, uint32_t operand2);

// Reduction adapted from http://developer.download.nvidia.com/compute/cuda/1.1-Beta/x86_website/projects/reduction/doc/reduction.pdf
__device__ void reduce(uint32_t *dataSet, uint32_t* sharedData, uint32_t *result, operation_function op)
{
    // Calculate indecies
    unsigned int threadId = threadIdx.x;
    unsigned int globalThreadId = blockIdx.x*(blockDim.x*2) + threadIdx.x;
    
    // Perform the first reduction to get memory from global to shared
    sharedData[threadId] = op(dataSet[globalThreadId], dataSet[globalThreadId + blockDim.x]);
    __syncthreads();

    // Perform reduction using the provided operation_function
    for (unsigned int i=blockDim.x/2; i>0; i >>= 1)
    {
        if (threadId < i)
        {
            sharedData[threadId] = op(sharedData[threadId], sharedData[threadId + i]);
        }
        __syncthreads();
    }

    // Copy result back to global memory
    if (threadId == 0)
    {
        result[blockIdx.x] = sharedData[0];
    }
}

// Add two operands and return the result
__device__ uint32_t add(uint32_t operand1, uint32_t operand2)
{
    return operand1 + operand2;
}

// Return the max of 2 elements without blocking (using a conditional)
__device__ uint32_t maximum(uint32_t element1, uint32_t element2)
{
    uint32_t findMax[2];
    findMax[0] = element1;
    findMax[1] = element2;

    return findMax[element1 < element2];
}

// Return the min of 2 elements without blocking (using a conditional)
__device__ uint32_t minimum(uint32_t element1, uint32_t element2)
{
    uint32_t findMax[2];
    findMax[0] = element1;
    findMax[1] = element2;

    return findMax[element1 > element2];
}

// Get the sum of all elements in dataSet
__global__ void sum(uint32_t* dataSet, uint32_t *result)
{
    extern __shared__ uint32_t sharedData[];
    reduce(dataSet, sharedData, result, &add);
}

// Get the max of all elements in dataSet
__global__ void getMax(uint32_t* dataSet, uint32_t *result)
{
    extern __shared__ uint32_t sharedData[];
    reduce(dataSet, sharedData, result, &maximum);
}

// Get the min of all elements in dataSet
__global__ void getMin(uint32_t* dataSet, uint32_t *result)
{
    extern __shared__ uint32_t sharedData[];
    reduce(dataSet, sharedData, result, &minimum);
}

// Get tha max, min, and average of all values in dataSet
void getMaxMinAvg(uint32_t dataSize, uint32_t numBlocks, uint32_t * data, uint32_t *max, uint32_t *min, double *avg)
{
    // Allocate CPU memory
    int32_t numThreads = dataSize / (numBlocks * 2);
    uint32_t *cpuMaxResult = (uint32_t *)malloc(numBlocks * sizeof(uint32_t));
    uint32_t *cpuMinResult = (uint32_t *)malloc(numBlocks * sizeof(uint32_t));
    uint32_t *cpuSumResult = (uint32_t *)malloc(numBlocks * sizeof(uint32_t));

    // Allocate GPU memory
    uint32_t *gpuMaxResult;
    hipMalloc((void **)&gpuMaxResult, numBlocks * sizeof(uint32_t));
    uint32_t *gpuMinResult;
    hipMalloc((void **)&gpuMinResult, numBlocks * sizeof(uint32_t));
    uint32_t *gpuSumResult;
    hipMalloc((void **)&gpuSumResult, numBlocks * sizeof(uint32_t));

    // Create CUDA Event for each operation
    hipEvent_t gotMax, gotMin, gotSum;
    hipEventCreate(&gotMax);
    hipEventCreate(&gotMin);
    hipEventCreate(&gotSum);

    // Create cuda stream for each operation
    hipStream_t maxStream, minStream, sumStream;
    hipStreamCreate(&maxStream);
    hipStreamCreate(&minStream);
    hipStreamCreate(&sumStream);

    // Mark when processing starts.
    auto start = std::chrono::high_resolution_clock::now();

    // Run async kernel to get maximum
    getMax<<<numBlocks, numThreads, numThreads * sizeof(uint32_t), maxStream>>>(data, gpuMaxResult);
    hipMemcpyAsync(cpuMaxResult, gpuMaxResult, numBlocks * sizeof(uint32_t), hipMemcpyDeviceToHost, maxStream);
    hipEventRecord(gotMax, maxStream);

    // Run async kernel to get minimum
    getMin<<<numBlocks, numThreads, numThreads * sizeof(uint32_t), minStream>>>(data, gpuMinResult);
    hipMemcpyAsync(cpuMinResult, gpuMinResult, numBlocks * sizeof(uint32_t), hipMemcpyDeviceToHost, minStream);
    hipEventRecord(gotMin, minStream);

    // Run async kernel to get average
    sum<<<numBlocks, numThreads, numThreads * sizeof(uint32_t), sumStream>>>(data, gpuSumResult);
    hipMemcpyAsync(cpuSumResult, gpuSumResult, numBlocks * sizeof(uint32_t), hipMemcpyDeviceToHost, sumStream);
    hipEventRecord(gotSum, sumStream);

    bool maxFinished = false;
    bool minFinished = false;
    bool sumFinished = false;

    // Check the event for each operation and measure total time to completion
    while (!maxFinished || !minFinished || !sumFinished)
    {
        if (!maxFinished && (hipEventQuery(gotMax) == hipSuccess))
        {
            auto now = std::chrono::high_resolution_clock::now();
            printf("Get Maximum finished after %dus\n", std::chrono::duration_cast<std::chrono::microseconds>(now - start).count());
            maxFinished = true;
        }
        if (!minFinished && (hipEventQuery(gotMin) == hipSuccess))
        {
            auto now = std::chrono::high_resolution_clock::now();
            printf("Get Minimum finished after %dus\n", std::chrono::duration_cast<std::chrono::microseconds>(now - start).count());
            minFinished = true;
        }
        if (!sumFinished && (hipEventQuery(gotSum) == hipSuccess))
        {
            auto now = std::chrono::high_resolution_clock::now();
            printf("Get Sum finished after %dus\n", std::chrono::duration_cast<std::chrono::microseconds>(now - start).count());
            sumFinished = true;
        }
    }
    hipDeviceSynchronize();

    // Aggregate results for max, min, avg
    *max = 0;
    *min = UINT_MAX;
    double sum = 0;

    for (size_t i = 0; i < numBlocks; i++)
    {
        sum += cpuSumResult[i];

        if (cpuMaxResult[i] > *max) {
            *max = cpuMaxResult[i];
        }
        if (cpuMinResult[i] < *min) {
            *min = cpuMinResult[i];
        }
    }

    // Calculate average
    *avg = sum / dataSize;

    // Destroy CUDA events
    hipEventDestroy(gotMax);
    hipEventDestroy(gotMin);
    hipEventDestroy(gotSum);

    // Destroy CUDA streams
    hipStreamDestroy(maxStream);
    hipStreamDestroy(minStream);
    hipStreamDestroy(sumStream);

    // Free GPU memory
    hipFree(gpuMaxResult);
    hipFree(gpuMinResult);
    hipFree(gpuSumResult);

    // Free CPU memory
    free(cpuMaxResult);
    free(cpuMinResult);
    free(cpuSumResult);
}

// Main function
int main(int argc, char* argv[])
{
    // Set number of blocks to default and runs
    uint32_t dataSize = DEFAULT_DATA_SIZE;
    uint32_t numBlocks = 8;
    uint32_t numRuns = 2;
    
    // Check command line for number of blocks argument
    if (argc > 1) {
        numBlocks = atoi(argv[1]);

        if ((numBlocks % 2) != 0) {
            printf("Must enter a multiple of 2\n");
            return 1;
        }
        dataSize = numBlocks * MAX_DATA_SET_SIZE_PER_BLOCK ;
    }

    // Check command line for number of runs argument
    if (argc > 2) {
        numRuns = atoi(argv[2]);
    }

    // Allocate pinned memory for data set
    uint32_t * data;
    hipHostMalloc((void**)&data, dataSize * sizeof(uint32_t), hipHostMallocDefault);

    // Allocate device memory for data set
    uint32_t *gpuData;
    hipMalloc((void **)&gpuData, dataSize * sizeof(uint32_t));

    srand((unsigned)time(NULL)); 
    for (uint32_t x = 0; x < numRuns; x++)
    {
        printf("Run %d\n--------------------------------------------------\n", x);

        // Populate data set with random values
        uint32_t range = dataSize * 4;
        for(size_t i = 0; i < dataSize; i++){ 
            data[i] = rand() % range + 1;
        }

        // Copy data set to device
        hipMemcpy(gpuData, data, dataSize * sizeof(uint32_t), hipMemcpyHostToDevice);

        // Calculate values
        double avg;
        uint32_t max;
        uint32_t min;
        getMaxMinAvg(dataSize, numBlocks, gpuData, &max, &min, &avg);

        // Print results
        printf("\n\n");
        printf("Average is %f\n", avg);
        printf ("Max is %d\n", max);
        printf ("Min is %d\n", min);
        printf("\n\n\n");
    }

    // Free allocated memory
    hipHostFree(data);
    hipFree(gpuData);
}

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

                                        # End of file scope inline assembly
	.globl	_Z18__device_stub__sumPjS_      # -- Begin function _Z18__device_stub__sumPjS_
	.type	_Z18__device_stub__sumPjS_,@function
_Z18__device_stub__sumPjS_:             # @_Z18__device_stub__sumPjS_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z3sumPjS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z18__device_stub__sumPjS_, .Lfunc_end0-_Z18__device_stub__sumPjS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z21__device_stub__getMaxPjS_   # -- Begin function _Z21__device_stub__getMaxPjS_
	.type	_Z21__device_stub__getMaxPjS_,@function
_Z21__device_stub__getMaxPjS_:          # @_Z21__device_stub__getMaxPjS_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z6getMaxPjS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z21__device_stub__getMaxPjS_, .Lfunc_end1-_Z21__device_stub__getMaxPjS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z21__device_stub__getMinPjS_   # -- Begin function _Z21__device_stub__getMinPjS_
	.type	_Z21__device_stub__getMinPjS_,@function
_Z21__device_stub__getMinPjS_:          # @_Z21__device_stub__getMinPjS_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z6getMinPjS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z21__device_stub__getMinPjS_, .Lfunc_end2-_Z21__device_stub__getMinPjS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z12getMaxMinAvgjjPjS_S_Pd      # -- Begin function _Z12getMaxMinAvgjjPjS_S_Pd
	.type	_Z12getMaxMinAvgjjPjS_S_Pd,@function
_Z12getMaxMinAvgjjPjS_S_Pd:             # @_Z12getMaxMinAvgjjPjS_S_Pd
	.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	$152, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%r9, 144(%rsp)                  # 8-byte Spill
	movq	%r8, 136(%rsp)                  # 8-byte Spill
	movq	%rcx, %r12
	movq	%rdx, 32(%rsp)                  # 8-byte Spill
                                        # kill: def $esi killed $esi def $rsi
	movl	%edi, %eax
	leal	(%rsi,%rsi), %ecx
	movl	%edi, 116(%rsp)                 # 4-byte Spill
	xorl	%edx, %edx
	divl	%ecx
	movl	%eax, %r15d
	movq	%rsi, 128(%rsp)                 # 8-byte Spill
	movl	%esi, %r14d
	leaq	(,%r14,4), %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	leaq	104(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	96(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	88(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	80(%rsp), %rdi
	callq	hipEventCreate
	leaq	72(%rsp), %rdi
	callq	hipEventCreate
	leaq	64(%rsp), %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipStreamCreate
	leaq	16(%rsp), %rdi
	callq	hipStreamCreate
	leaq	8(%rsp), %rdi
	callq	hipStreamCreate
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %rbp
	movslq	%r15d, %rbx
	shlq	$2, %rbx
	leaq	24(%rsp), %rax
	movq	(%rax), %r9
	movq	%r14, 120(%rsp)                 # 8-byte Spill
	btsq	$32, %r14
	btsq	$32, %r15
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	movq	%rbx, %r8
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_2
# %bb.1:
	movq	104(%rsp), %rsi
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	_Z21__device_stub__getMaxPjS_
.LBB3_2:
	movq	104(%rsp), %rsi
	movq	24(%rsp), %r8
	movq	56(%rsp), %rdi                  # 8-byte Reload
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpyAsync
	movq	80(%rsp), %rdi
	movq	24(%rsp), %rsi
	callq	hipEventRecord
	movq	16(%rsp), %r9
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	movq	%rbx, %r8
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_4
# %bb.3:
	movq	96(%rsp), %rsi
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	_Z21__device_stub__getMinPjS_
.LBB3_4:
	movq	96(%rsp), %rsi
	movq	16(%rsp), %r8
	movq	48(%rsp), %rdi                  # 8-byte Reload
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpyAsync
	movq	72(%rsp), %rdi
	movq	16(%rsp), %rsi
	callq	hipEventRecord
	movq	8(%rsp), %r9
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	movq	%rbx, %r8
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_6
# %bb.5:
	movq	88(%rsp), %rsi
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	_Z18__device_stub__sumPjS_
.LBB3_6:
	movq	88(%rsp), %rsi
	movq	8(%rsp), %r8
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpyAsync
	movq	64(%rsp), %rdi
	movq	8(%rsp), %rsi
	callq	hipEventRecord
	movb	$1, %r14b
	xorl	%r13d, %r13d
	movabsq	$2361183241434822607, %rbx      # imm = 0x20C49BA5E353F7CF
	xorl	%r15d, %r15d
.LBB3_7:                                # =>This Inner Loop Header: Depth=1
	testb	$1, %r13b
	jne	.LBB3_8
# %bb.11:                               # %.critedge84
                                        #   in Loop: Header=BB3_7 Depth=1
	movq	80(%rsp), %rdi
	callq	hipEventQuery
	testl	%eax, %eax
	jne	.LBB3_13
# %bb.12:                               #   in Loop: Header=BB3_7 Depth=1
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%rbp, %rax
	imulq	%rbx
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$7, %rdx
	addq	%rdx, %rsi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movb	$1, %r13b
	jmp	.LBB3_13
.LBB3_8:                                #   in Loop: Header=BB3_7 Depth=1
	testb	$1, %r15b
	sete	%al
	orb	%r14b, %al
	testb	$1, %al
	je	.LBB3_9
.LBB3_13:                               # %.critedge
                                        #   in Loop: Header=BB3_7 Depth=1
	testb	$1, %r15b
	jne	.LBB3_16
# %bb.14:                               #   in Loop: Header=BB3_7 Depth=1
	movq	72(%rsp), %rdi
	callq	hipEventQuery
	testl	%eax, %eax
	jne	.LBB3_16
# %bb.15:                               #   in Loop: Header=BB3_7 Depth=1
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%rbp, %rax
	imulq	%rbx
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$7, %rdx
	addq	%rdx, %rsi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	movb	$1, %r15b
.LBB3_16:                               #   in Loop: Header=BB3_7 Depth=1
	testb	$1, %r14b
	je	.LBB3_7
# %bb.17:                               #   in Loop: Header=BB3_7 Depth=1
	movq	64(%rsp), %rdi
	callq	hipEventQuery
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.18:                               #   in Loop: Header=BB3_7 Depth=1
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%rbp, %rax
	imulq	%rbx
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$7, %rdx
	addq	%rdx, %rsi
	xorl	%r14d, %r14d
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB3_7
.LBB3_9:
	callq	hipDeviceSynchronize
	movl	$0, (%r12)
	movq	136(%rsp), %rsi                 # 8-byte Reload
	movl	$-1, (%rsi)
	cmpl	$0, 128(%rsp)                   # 4-byte Folded Reload
	je	.LBB3_10
# %bb.19:                               # %.lr.ph.preheader
	xorpd	%xmm0, %xmm0
	movl	$-1, %ecx
	xorl	%eax, %eax
	movq	56(%rsp), %rbx                  # 8-byte Reload
	movq	48(%rsp), %r14                  # 8-byte Reload
	movq	40(%rsp), %r15                  # 8-byte Reload
	movq	120(%rsp), %rdi                 # 8-byte Reload
.LBB3_20:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%rax,4), %edx
	cmpl	(%r12), %edx
	jbe	.LBB3_22
# %bb.21:                               #   in Loop: Header=BB3_20 Depth=1
	movl	%edx, (%r12)
	movl	(%rsi), %ecx
.LBB3_22:                               #   in Loop: Header=BB3_20 Depth=1
	movl	(%r14,%rax,4), %edx
	cmpl	%ecx, %edx
	jae	.LBB3_24
# %bb.23:                               #   in Loop: Header=BB3_20 Depth=1
	movl	%edx, (%rsi)
	movl	%edx, %ecx
.LBB3_24:                               #   in Loop: Header=BB3_20 Depth=1
	movl	(%r15,%rax,4), %edx
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rdx, %xmm1
	addsd	%xmm1, %xmm0
	incq	%rax
	cmpq	%rax, %rdi
	jne	.LBB3_20
	jmp	.LBB3_25
.LBB3_10:
	xorpd	%xmm0, %xmm0
	movq	56(%rsp), %rbx                  # 8-byte Reload
	movq	48(%rsp), %r14                  # 8-byte Reload
	movq	40(%rsp), %r15                  # 8-byte Reload
.LBB3_25:                               # %._crit_edge
	movl	116(%rsp), %eax                 # 4-byte Reload
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	divsd	%xmm1, %xmm0
	movq	144(%rsp), %rax                 # 8-byte Reload
	movsd	%xmm0, (%rax)
	movq	80(%rsp), %rdi
	callq	hipEventDestroy
	movq	72(%rsp), %rdi
	callq	hipEventDestroy
	movq	64(%rsp), %rdi
	callq	hipEventDestroy
	movq	24(%rsp), %rdi
	callq	hipStreamDestroy
	movq	16(%rsp), %rdi
	callq	hipStreamDestroy
	movq	8(%rsp), %rdi
	callq	hipStreamDestroy
	movq	104(%rsp), %rdi
	callq	hipFree
	movq	96(%rsp), %rdi
	callq	hipFree
	movq	88(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	addq	$152, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z12getMaxMinAvgjjPjS_S_Pd, .Lfunc_end3-_Z12getMaxMinAvgjjPjS_S_Pd
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$2, 4(%rsp)                     # 4-byte Folded Spill
	cmpl	$2, %edi
	jl	.LBB4_1
# %bb.2:
	movq	%rsi, %r14
	movl	%edi, %r15d
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	testb	$1, %bpl
	jne	.LBB4_3
# %bb.4:
	movl	%ebp, %r12d
	shll	$10, %r12d
	cmpl	$2, %r15d
	je	.LBB4_6
# %bb.5:
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	jmp	.LBB4_6
.LBB4_1:
	movl	$8192, %r12d                    # imm = 0x2000
	movl	$8, %ebp
.LBB4_6:                                # %.thread
	movl	%r12d, %r14d
	leaq	(,%r14,4), %r15
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	leaq	8(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	cmpl	$0, 4(%rsp)                     # 4-byte Folded Reload
	je	.LBB4_13
# %bb.7:                                # %.lr.ph35
	leal	(,%r14,4), %r12d
	xorl	%r13d, %r13d
.LBB4_8:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_10 Depth 2
	movl	$.L.str.4, %edi
	movl	%r13d, %esi
	xorl	%eax, %eax
	callq	printf
	testl	%r14d, %r14d
	je	.LBB4_11
# %bb.9:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB4_8 Depth=1
	xorl	%ebx, %ebx
.LBB4_10:                               # %.lr.ph
                                        #   Parent Loop BB4_8 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorl	%edx, %edx
	divl	%r12d
	incl	%edx
	movq	16(%rsp), %rsi
	movl	%edx, (%rsi,%rbx,4)
	incq	%rbx
	cmpq	%rbx, %r14
	jne	.LBB4_10
	jmp	.LBB4_12
.LBB4_11:                               # %.._crit_edge_crit_edge
                                        #   in Loop: Header=BB4_8 Depth=1
	movq	16(%rsp), %rsi
.LBB4_12:                               # %._crit_edge
                                        #   in Loop: Header=BB4_8 Depth=1
	movq	8(%rsp), %rdi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdx
	movl	%r14d, %edi
	movl	%ebp, %esi
	leaq	28(%rsp), %rcx
	leaq	24(%rsp), %r8
	leaq	32(%rsp), %r9
	callq	_Z12getMaxMinAvgjjPjS_S_Pd
	movl	$.Lstr, %edi
	callq	puts@PLT
	movsd	32(%rsp), %xmm0                 # xmm0 = mem[0],zero
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movl	28(%rsp), %esi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	24(%rsp), %esi
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	incl	%r13d
	cmpl	4(%rsp), %r13d                  # 4-byte Folded Reload
	jne	.LBB4_8
.LBB4_13:                               # %._crit_edge36
	movq	16(%rsp), %rdi
	callq	hipHostFree
	movq	8(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	jmp	.LBB4_14
.LBB4_3:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$1, %eax
.LBB4_14:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z3sumPjS_, %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	$_Z6getMaxPjS_, %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	$_Z6getMinPjS_, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z3sumPjS_,@object              # @_Z3sumPjS_
	.section	.rodata,"a",@progbits
	.globl	_Z3sumPjS_
	.p2align	3, 0x0
_Z3sumPjS_:
	.quad	_Z18__device_stub__sumPjS_
	.size	_Z3sumPjS_, 8

	.type	_Z6getMaxPjS_,@object           # @_Z6getMaxPjS_
	.globl	_Z6getMaxPjS_
	.p2align	3, 0x0
_Z6getMaxPjS_:
	.quad	_Z21__device_stub__getMaxPjS_
	.size	_Z6getMaxPjS_, 8

	.type	_Z6getMinPjS_,@object           # @_Z6getMinPjS_
	.globl	_Z6getMinPjS_
	.p2align	3, 0x0
_Z6getMinPjS_:
	.quad	_Z21__device_stub__getMinPjS_
	.size	_Z6getMinPjS_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Get Maximum finished after %dus\n"
	.size	.L.str, 33

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Get Minimum finished after %dus\n"
	.size	.L.str.1, 33

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Get Sum finished after %dus\n"
	.size	.L.str.2, 29

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Run %d\n--------------------------------------------------\n"
	.size	.L.str.4, 59

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Average is %f\n"
	.size	.L.str.6, 15

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Max is %d\n"
	.size	.L.str.7, 11

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Min is %d\n"
	.size	.L.str.8, 11

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z3sumPjS_"
	.size	.L__unnamed_1, 11

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z6getMaxPjS_"
	.size	.L__unnamed_2, 14

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z6getMinPjS_"
	.size	.L__unnamed_3, 14

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"\n"
	.size	.Lstr, 2

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\n\n"
	.size	.Lstr.1, 3

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Must enter a multiple of 2"
	.size	.Lstr.2, 27

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z18__device_stub__sumPjS_
	.addrsig_sym _Z21__device_stub__getMaxPjS_
	.addrsig_sym _Z21__device_stub__getMinPjS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z3sumPjS_
	.addrsig_sym _Z6getMaxPjS_
	.addrsig_sym _Z6getMinPjS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z3sumPjS_              ; -- Begin function _Z3sumPjS_
	.globl	_Z3sumPjS_
	.p2align	8
	.type	_Z3sumPjS_,@function
_Z3sumPjS_:                             ; @_Z3sumPjS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s5, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_mov_b32 s4, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s5, s5, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	s_mul_i32 s6, s15, s5
	s_cmp_lt_u32 s5, 2
	v_lshl_add_u32 v1, s6, 1, v0
	v_mov_b32_e32 v2, 0
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_add_nc_u32_e32 v1, s5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v3, vcc_lo, s0, v3
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	s_clause 0x1
	global_load_b32 v3, v[3:4], off
	global_load_b32 v2, v[1:2], off
	v_lshl_add_u32 v1, v0, 2, 0
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v2, v2, v3
	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.i
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_lshr_b32 s0, s5, 1
	s_mov_b32 s1, exec_lo
	v_cmpx_gt_u32_e64 s0, v0
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_1 Depth=1
	v_lshl_add_u32 v2, s0, 2, v1
	ds_load_b32 v3, v1
	ds_load_b32 v2, v2
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_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, s1
	s_waitcnt lgkmcnt(0)
	s_barrier
	s_cmp_lt_u32 s5, 4
	s_mov_b32 s5, s0
	s_branch .LBB0_1
.LBB0_5:                                ; %._crit_edge.i
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_7
; %bb.6:
	v_mov_b32_e32 v0, 0
	s_mov_b32 s5, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[0:1], s[4:5], 2
	s_add_u32 s0, s2, s0
	ds_load_b32 v1, v0
	s_addc_u32 s1, s3, s1
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB0_7:                                ; %_Z6reducePjS_S_PFjjjE.exit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z3sumPjS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 5
		.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	_Z3sumPjS_, .Lfunc_end0-_Z3sumPjS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 332
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; 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	_Z6getMaxPjS_           ; -- Begin function _Z6getMaxPjS_
	.globl	_Z6getMaxPjS_
	.p2align	8
	.type	_Z6getMaxPjS_,@function
_Z6getMaxPjS_:                          ; @_Z6getMaxPjS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s5, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_mov_b32 s4, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s5, s5, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	s_mul_i32 s6, s15, s5
	s_cmp_lt_u32 s5, 2
	v_lshl_add_u32 v1, s6, 1, v0
	v_mov_b32_e32 v2, 0
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_add_nc_u32_e32 v1, s5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v3, vcc_lo, s0, v3
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	s_clause 0x1
	global_load_b32 v3, v[3:4], off
	global_load_b32 v2, v[1:2], off
	v_lshl_add_u32 v1, v0, 2, 0
	s_waitcnt vmcnt(0)
	v_cmp_lt_u32_e32 vcc_lo, v3, v2
	v_cndmask_b32_e32 v2, v3, v2, vcc_lo
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
.LBB1_1:                                ; =>This Inner Loop Header: Depth=1
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_5
; %bb.2:                                ; %.lr.ph.i
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_lshr_b32 s0, s5, 1
	s_mov_b32 s1, exec_lo
	v_cmpx_gt_u32_e64 s0, v0
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_1 Depth=1
	v_lshl_add_u32 v2, s0, 2, v1
	ds_load_b32 v3, v1
	ds_load_b32 v2, v2
	s_waitcnt lgkmcnt(0)
	v_cmp_lt_u32_e32 vcc_lo, v3, v2
	v_cndmask_b32_e32 v2, v3, v2, vcc_lo
	ds_store_b32 v1, v2
.LBB1_4:                                ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt lgkmcnt(0)
	s_barrier
	s_cmp_lt_u32 s5, 4
	s_mov_b32 s5, s0
	s_branch .LBB1_1
.LBB1_5:                                ; %._crit_edge.i
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB1_7
; %bb.6:
	v_mov_b32_e32 v0, 0
	s_mov_b32 s5, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[0:1], s[4:5], 2
	s_add_u32 s0, s2, s0
	ds_load_b32 v1, v0
	s_addc_u32 s1, s3, s1
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB1_7:                                ; %_Z6reducePjS_S_PFjjjE.exit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6getMaxPjS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 5
		.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	_Z6getMaxPjS_, .Lfunc_end1-_Z6getMaxPjS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 340
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; 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	_Z6getMinPjS_           ; -- Begin function _Z6getMinPjS_
	.globl	_Z6getMinPjS_
	.p2align	8
	.type	_Z6getMinPjS_,@function
_Z6getMinPjS_:                          ; @_Z6getMinPjS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s5, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_mov_b32 s4, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s5, s5, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	s_mul_i32 s6, s15, s5
	s_cmp_lt_u32 s5, 2
	v_lshl_add_u32 v1, s6, 1, v0
	v_mov_b32_e32 v2, 0
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_add_nc_u32_e32 v1, s5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v3, vcc_lo, s0, v3
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	s_clause 0x1
	global_load_b32 v3, v[3:4], off
	global_load_b32 v2, v[1:2], off
	v_lshl_add_u32 v1, v0, 2, 0
	s_waitcnt vmcnt(0)
	v_cmp_gt_u32_e32 vcc_lo, v3, v2
	v_cndmask_b32_e32 v2, v3, v2, vcc_lo
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
.LBB2_1:                                ; =>This Inner Loop Header: Depth=1
	buffer_gl0_inv
	s_cbranch_scc1 .LBB2_5
; %bb.2:                                ; %.lr.ph.i
                                        ;   in Loop: Header=BB2_1 Depth=1
	s_lshr_b32 s0, s5, 1
	s_mov_b32 s1, exec_lo
	v_cmpx_gt_u32_e64 s0, v0
	s_cbranch_execz .LBB2_4
; %bb.3:                                ;   in Loop: Header=BB2_1 Depth=1
	v_lshl_add_u32 v2, s0, 2, v1
	ds_load_b32 v3, v1
	ds_load_b32 v2, v2
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_u32_e32 vcc_lo, v3, v2
	v_cndmask_b32_e32 v2, v3, v2, vcc_lo
	ds_store_b32 v1, v2
.LBB2_4:                                ;   in Loop: Header=BB2_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt lgkmcnt(0)
	s_barrier
	s_cmp_lt_u32 s5, 4
	s_mov_b32 s5, s0
	s_branch .LBB2_1
.LBB2_5:                                ; %._crit_edge.i
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB2_7
; %bb.6:
	v_mov_b32_e32 v0, 0
	s_mov_b32 s5, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[0:1], s[4:5], 2
	s_add_u32 s0, s2, s0
	ds_load_b32 v1, v0
	s_addc_u32 s1, s3, s1
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB2_7:                                ; %_Z6reducePjS_S_PFjjjE.exit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6getMinPjS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 5
		.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	_Z6getMinPjS_, .Lfunc_end2-_Z6getMinPjS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 340
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         136
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z3sumPjS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z3sumPjS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .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:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         136
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6getMaxPjS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6getMaxPjS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .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:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         136
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6getMinPjS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6getMinPjS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
