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

/*
reduction.cu
A demonstration of array reduction using CUDA

Created for GPU Architecture and Programming
Spring 2012, New York University

Copyright 2012 Guy Dickinson <guy.dickinson@nyu.edu>
*/

// Vanilla, sequential reduction on host
// This *would* have a divergence problem if it were multithreaded
int findMaxOnHost(int* A, int length) {
    for (int step = 1; step < length; step *= 2) {
        for (int i = 0; i < length; i += (2 * step)) {
            int candidate = A[i + step];
            if (A[i] < candidate) {
                A[i] = candidate;
            }
        }
    }
    return A[0];
}

__global__ void findMaxNaivelyKernel(int* A) {
    unsigned int tid = (blockIdx.x * blockDim.x) + threadIdx.x;
    for (unsigned int step = 1; step < (blockDim.x * gridDim.x); step *= 2) {
        __syncthreads();
        if (tid % (2 * step) == 0) {
            int candidate = A[tid + step];
            if (A[tid] < candidate) {
                A[tid] = candidate;
            }
        }
    }
}

// Naively find the maximum element, without taking into account thread
// diversion or memory efficiency
int cudaFindMaxOnDeviceNaively(int* A, int length) {
    int size = length * sizeof(int);
    int ret;
    int* cudaArray;
    cudaMalloc(&cudaArray, size);
    cudaMemcpy(cudaArray, A, size, cudaMemcpyHostToDevice);
    
    dim3 dimBlock(512);
    dim3 dimGrid(length/512, 1);
    
    findMaxNaivelyKernel<<<dimGrid, dimBlock>>>(cudaArray);
    
    
    // Recover just the first element from the device to save time.
    cudaMemcpy(&ret, cudaArray, sizeof(int), cudaMemcpyDeviceToHost);
    cudaFree(cudaArray);
    return ret;
}

__global__ void findMaxWithoutDivergenceKernel(int* A) {
    unsigned int tid = (blockIdx.x * blockDim.x) + threadIdx.x;
    for (unsigned int step = blockDim.x * gridDim.x >> 1; step > 0; step >>= 1) {
        __syncthreads();
        if (tid < step) {
            int candidate = A[tid + step];
            if (A[tid] < candidate) {
                A[tid] = candidate;
            }
        }
    }
}

int cudaFindMaxWithoutDivergence(int* A, int length) {
    int size = length * sizeof(int);
    int ret;
    int* cudaArray;
    cudaMalloc(&cudaArray, size);
    cudaMemcpy(cudaArray, A, size, cudaMemcpyHostToDevice);
    
    dim3 dimBlock(512);
    dim3 dimGrid(length / 512, 1);
    
    findMaxWithoutDivergenceKernel<<<dimGrid, dimBlock>>>(cudaArray);
    
    // Recover just the first element from the device to save time.
    cudaMemcpy(&ret, cudaArray, sizeof(int), cudaMemcpyDeviceToHost);
    cudaFree(cudaArray);
    return ret;
}

__global__ void findMaxWithSharedMemoryKernel(int* A) {
    //Static allocation like this is pretty lame but good enough for testing.
    __shared__ int sharedmem[512];
    
    // copy this chunk into shared memory from global
    unsigned int threadIndex = threadIdx.x;
    unsigned int globalThreadId = (blockIdx.x * blockDim.x) + threadIdx.x;
    unsigned int nThreads = (blockDim.x * gridDim.x);
    
    sharedmem[threadIndex] = (globalThreadId < nThreads) ?
        A[globalThreadId] : 0;
        
    
    // Do the reduction in shared memory
    for (unsigned int step = blockDim.x >> 1; step > 0; step >>= 1) {
        __syncthreads();
        if (threadIndex < step) {
            int candidate = sharedmem[threadIndex + step];
            if (sharedmem[threadIndex] < candidate) {
                sharedmem[threadIndex] = candidate;
            }
        }
    }
    __syncthreads();
    
    // Thread 0 within a block writes the result back to global memory
    if (threadIndex == 0) {
        A[blockIdx.x] = sharedmem[0];
    }
    __syncthreads();
    
    // Now the global data structure has as elements 0-gridDim.x filled with
    // the results which we need to reduce again. 
    if (globalThreadId < gridDim.x) {
        for (unsigned int step = gridDim.x >> 1; step > 0; step >>= 1) {
            int candidate = A[globalThreadId + step];
            if (A[globalThreadId] < candidate) {
                A[globalThreadId] = candidate;
            }
        }
    }
}

int cudaFindMaxWithSharedMemory(int* A, int length) {
    int size = length * sizeof(int);
    int ret;
    int* cudaArray;
    cudaMalloc(&cudaArray, size);
    cudaMemcpy(cudaArray, A, size, cudaMemcpyHostToDevice);
    
    dim3 dimBlock(512);
    dim3 dimGrid(length / 512, 1);
    
    findMaxWithSharedMemoryKernel<<<dimGrid, dimBlock>>>(cudaArray);
    
    // Recover just the first element from the device to save time.
    cudaMemcpy(&ret, cudaArray, sizeof(int), cudaMemcpyDeviceToHost);
    cudaFree(cudaArray);
    return ret;
}



// Returns a pointer to an array of ints of size length.
// For verification purposes, the biggest int will be at the end.
int* initializeArray(int length) {
    // Set up an array of ints of the right length
    void *ptr;
    ptr = malloc(length * sizeof(int));
    if (ptr == NULL) {
        // Handle allocation error
    }
    int* A = (int*) ptr;
    
    // Fill it with ints
    int j = 1;
    for (int i = 0; i < length; i++) {
        A[i] = j;
        j += 2;
    }
    return A;
}

void printTiming(timeval start, timeval end, char* desc, int length) {
    double elapsed =
        (end.tv_usec - start.tv_usec);
    printf("%s length %d: %g usec\n", desc, elapsed, length);
}

void checkAndPrintResult(int expected, int actual, char* desc) {
    if (expected == actual) {
        printf("%s passed check ", desc);
    } else {
        printf("%s failed check " , desc);
    }
    printf("(expected %d, got %d)\n", expected, actual);
}

// Wrapper function for launching each test component.
void launchTestWithTiming(
        int testType,
        int length) {
            
    int actual;
    char* desc;
    
    timeval start, end;
    int* array = initializeArray(length);
    int expected = array[length - 1];
    gettimeofday(&start, NULL);
    switch (testType) {
        // CPU
        case 0:
        desc = "Serial";
        actual = findMaxOnHost(array, length);
        break;
        
        // Naive Parallel
        case 1:
        desc = "Naive Parallel";
        actual = cudaFindMaxOnDeviceNaively(array, length);
        break;
        
        // Non Divergent Parallel
        case 2:
        desc = "Non Divergent Parallel";
        actual = cudaFindMaxWithoutDivergence(array, length);
        break;
        
        // Shared Memory Parallel
        case 3:
        desc = "Shared Memory Parallel";
        actual = cudaFindMaxWithSharedMemory(array, length);
        break;
        
        default:
        desc = "Unrecognized!";
        break;
        
    }
    gettimeofday(&end, NULL);
    free(array);
    
    checkAndPrintResult(expected, actual, desc);
    printTiming(start, end, desc, length);
    
}


void runTest(int length) {
    launchTestWithTiming(0, length);
    launchTestWithTiming(1, length);
    launchTestWithTiming(1, length);
    
    launchTestWithTiming(2, length);
    launchTestWithTiming(3, length);
    }

int main(void) {
    runTest(1024);
    runTest(4096);
    return 0;
}
	.file	"tmpxft_002e7b81_00000000-6_reduction.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2039:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2039:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z13findMaxOnHostPii
	.type	_Z13findMaxOnHostPii, @function
_Z13findMaxOnHostPii:
.LFB2027:
	.cfi_startproc
	endbr64
	movl	$1, %eax
.L3:
	cmpl	%esi, %eax
	jge	.L6
	leal	(%rax,%rax), %r9d
	movq	%rdi, %rdx
	xorl	%ecx, %ecx
	movslq	%r9d, %r8
	salq	$2, %r8
.L7:
	cmpl	%esi, %ecx
	jge	.L9
	movl	(%rdx,%rax,4), %r10d
	cmpl	%r10d, (%rdx)
	jge	.L4
	movl	%r10d, (%rdx)
.L4:
	addl	%r9d, %ecx
	addq	%r8, %rdx
	jmp	.L7
.L9:
	movslq	%r9d, %rax
	jmp	.L3
.L6:
	movl	(%rdi), %eax
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z13findMaxOnHostPii, .-_Z13findMaxOnHostPii
	.globl	_Z15initializeArrayi
	.type	_Z15initializeArrayi, @function
_Z15initializeArrayi:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movslq	%edi, %rdi
	movq	%rdi, %rbx
	salq	$2, %rdi
	call	malloc@PLT
	xorl	%edx, %edx
.L11:
	leal	1(%rdx,%rdx), %ecx
	cmpl	%edx, %ebx
	jle	.L14
	movl	%ecx, (%rax,%rdx,4)
	incq	%rdx
	jmp	.L11
.L14:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z15initializeArrayi, .-_Z15initializeArrayi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s length %d: %g usec\n"
	.text
	.globl	_Z11printTiming7timevalS_Pci
	.type	_Z11printTiming7timevalS_Pci, @function
_Z11printTiming7timevalS_Pci:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	%rcx, %rax
	movq	%r8, %rdx
	movl	%r9d, %ecx
	movl	$2, %edi
	subq	%rsi, %rax
	leaq	.LC0(%rip), %rsi
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2032:
	.size	_Z11printTiming7timevalS_Pci, .-_Z11printTiming7timevalS_Pci
	.section	.rodata.str1.1
.LC1:
	.string	"%s passed check "
.LC2:
	.string	"%s failed check "
.LC3:
	.string	"(expected %d, got %d)\n"
	.text
	.globl	_Z19checkAndPrintResultiiPc
	.type	_Z19checkAndPrintResultiiPc, @function
_Z19checkAndPrintResultiiPc:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	pushq	%r9
	.cfi_def_cfa_offset 32
	cmpl	%esi, %edi
	jne	.L17
	leaq	.LC1(%rip), %rsi
	jmp	.L20
.L17:
	leaq	.LC2(%rip), %rsi
.L20:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%r8
	.cfi_def_cfa_offset 24
	movl	%ebp, %ecx
	movl	%ebx, %edx
	leaq	.LC3(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 16
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2033:
	.size	_Z19checkAndPrintResultiiPc, .-_Z19checkAndPrintResultiiPc
	.globl	_Z40__device_stub__Z20findMaxNaivelyKernelPiPi
	.type	_Z40__device_stub__Z20findMaxNaivelyKernelPiPi, @function
_Z40__device_stub__Z20findMaxNaivelyKernelPiPi:
.LFB2061:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z20findMaxNaivelyKernelPi(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L21:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2061:
	.size	_Z40__device_stub__Z20findMaxNaivelyKernelPiPi, .-_Z40__device_stub__Z20findMaxNaivelyKernelPiPi
	.globl	_Z20findMaxNaivelyKernelPi
	.type	_Z20findMaxNaivelyKernelPi, @function
_Z20findMaxNaivelyKernelPi:
.LFB2062:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z20findMaxNaivelyKernelPiPi
	.cfi_endproc
.LFE2062:
	.size	_Z20findMaxNaivelyKernelPi, .-_Z20findMaxNaivelyKernelPi
	.globl	_Z26cudaFindMaxOnDeviceNaivelyPii
	.type	_Z26cudaFindMaxOnDeviceNaivelyPii, @function
_Z26cudaFindMaxOnDeviceNaivelyPii:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leal	0(,%rsi,4), %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movslq	%ebp, %rbp
	movl	%esi, %ebx
	movq	%rbp, %rsi
	subq	$48, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movq	%rbp, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebx, %eax
	movl	$512, %ecx
	xorl	%r9d, %r9d
	cltd
	xorl	%r8d, %r8d
	idivl	%ecx
	movl	$8388609, %edx
	movl	$1, %ecx
	salq	$9, %rdx
	movl	%eax, 28(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	28(%rsp), %rdi
	movl	36(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	8(%rsp), %rdi
	call	_Z40__device_stub__Z20findMaxNaivelyKernelPiPi
.L27:
	movq	8(%rsp), %rsi
	leaq	4(%rsp), %rdi
	movl	$2, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movl	4(%rsp), %eax
	movq	40(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$48, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z26cudaFindMaxOnDeviceNaivelyPii, .-_Z26cudaFindMaxOnDeviceNaivelyPii
	.globl	_Z50__device_stub__Z30findMaxWithoutDivergenceKernelPiPi
	.type	_Z50__device_stub__Z30findMaxWithoutDivergenceKernelPiPi, @function
_Z50__device_stub__Z30findMaxWithoutDivergenceKernelPiPi:
.LFB2063:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L30
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z30findMaxWithoutDivergenceKernelPi(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L30:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L32
	call	__stack_chk_fail@PLT
.L32:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2063:
	.size	_Z50__device_stub__Z30findMaxWithoutDivergenceKernelPiPi, .-_Z50__device_stub__Z30findMaxWithoutDivergenceKernelPiPi
	.globl	_Z30findMaxWithoutDivergenceKernelPi
	.type	_Z30findMaxWithoutDivergenceKernelPi, @function
_Z30findMaxWithoutDivergenceKernelPi:
.LFB2064:
	.cfi_startproc
	endbr64
	jmp	_Z50__device_stub__Z30findMaxWithoutDivergenceKernelPiPi
	.cfi_endproc
.LFE2064:
	.size	_Z30findMaxWithoutDivergenceKernelPi, .-_Z30findMaxWithoutDivergenceKernelPi
	.globl	_Z28cudaFindMaxWithoutDivergencePii
	.type	_Z28cudaFindMaxWithoutDivergencePii, @function
_Z28cudaFindMaxWithoutDivergencePii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leal	0(,%rsi,4), %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movslq	%ebp, %rbp
	movl	%esi, %ebx
	movq	%rbp, %rsi
	subq	$48, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movq	%rbp, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebx, %eax
	movl	$512, %ecx
	xorl	%r9d, %r9d
	cltd
	xorl	%r8d, %r8d
	idivl	%ecx
	movl	$8388609, %edx
	movl	$1, %ecx
	salq	$9, %rdx
	movl	%eax, 28(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	28(%rsp), %rdi
	movl	36(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	movq	8(%rsp), %rdi
	call	_Z50__device_stub__Z30findMaxWithoutDivergenceKernelPiPi
.L36:
	movq	8(%rsp), %rsi
	leaq	4(%rsp), %rdi
	movl	$2, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movl	4(%rsp), %eax
	movq	40(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	addq	$48, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z28cudaFindMaxWithoutDivergencePii, .-_Z28cudaFindMaxWithoutDivergencePii
	.globl	_Z49__device_stub__Z29findMaxWithSharedMemoryKernelPiPi
	.type	_Z49__device_stub__Z29findMaxWithSharedMemoryKernelPiPi, @function
_Z49__device_stub__Z29findMaxWithSharedMemoryKernelPiPi:
.LFB2065:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z29findMaxWithSharedMemoryKernelPi(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L39:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L41
	call	__stack_chk_fail@PLT
.L41:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2065:
	.size	_Z49__device_stub__Z29findMaxWithSharedMemoryKernelPiPi, .-_Z49__device_stub__Z29findMaxWithSharedMemoryKernelPiPi
	.globl	_Z29findMaxWithSharedMemoryKernelPi
	.type	_Z29findMaxWithSharedMemoryKernelPi, @function
_Z29findMaxWithSharedMemoryKernelPi:
.LFB2066:
	.cfi_startproc
	endbr64
	jmp	_Z49__device_stub__Z29findMaxWithSharedMemoryKernelPiPi
	.cfi_endproc
.LFE2066:
	.size	_Z29findMaxWithSharedMemoryKernelPi, .-_Z29findMaxWithSharedMemoryKernelPi
	.globl	_Z27cudaFindMaxWithSharedMemoryPii
	.type	_Z27cudaFindMaxWithSharedMemoryPii, @function
_Z27cudaFindMaxWithSharedMemoryPii:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leal	0(,%rsi,4), %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movslq	%ebp, %rbp
	movl	%esi, %ebx
	movq	%rbp, %rsi
	subq	$48, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movq	%rbp, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebx, %eax
	movl	$512, %ecx
	xorl	%r9d, %r9d
	cltd
	xorl	%r8d, %r8d
	idivl	%ecx
	movl	$8388609, %edx
	movl	$1, %ecx
	salq	$9, %rdx
	movl	%eax, 28(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	28(%rsp), %rdi
	movl	36(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L45
	movq	8(%rsp), %rdi
	call	_Z49__device_stub__Z29findMaxWithSharedMemoryKernelPiPi
.L45:
	movq	8(%rsp), %rsi
	leaq	4(%rsp), %rdi
	movl	$2, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movl	4(%rsp), %eax
	movq	40(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L46
	call	__stack_chk_fail@PLT
.L46:
	addq	$48, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z27cudaFindMaxWithSharedMemoryPii, .-_Z27cudaFindMaxWithSharedMemoryPii
	.section	.rodata.str1.1
.LC4:
	.string	"Serial"
.LC5:
	.string	"Naive Parallel"
.LC6:
	.string	"Non Divergent Parallel"
.LC7:
	.string	"Shared Memory Parallel"
.LC8:
	.string	"Unrecognized!"
	.text
	.globl	_Z20launchTestWithTimingii
	.type	_Z20launchTestWithTimingii, @function
_Z20launchTestWithTimingii:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%edi, %r13d
	movl	%esi, %edi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	_Z15initializeArrayi
	xorl	%esi, %esi
	leaq	8(%rsp), %rdi
	movq	%rax, %r12
	movslq	%ebp, %rax
	movl	-4(%r12,%rax,4), %r14d
	call	gettimeofday@PLT
	cmpl	$2, %r13d
	je	.L49
	jg	.L50
	testl	%r13d, %r13d
	je	.L51
	decl	%r13d
	je	.L52
	jmp	.L57
.L50:
	cmpl	$3, %r13d
	je	.L54
.L57:
	leaq	.LC8(%rip), %r13
	jmp	.L53
.L51:
	movl	%ebp, %esi
	movq	%r12, %rdi
	leaq	.LC4(%rip), %r13
	call	_Z13findMaxOnHostPii
	movl	%eax, %ebx
	jmp	.L53
.L52:
	movl	%ebp, %esi
	movq	%r12, %rdi
	leaq	.LC5(%rip), %r13
	call	_Z26cudaFindMaxOnDeviceNaivelyPii
	movl	%eax, %ebx
	jmp	.L53
.L49:
	movl	%ebp, %esi
	movq	%r12, %rdi
	leaq	.LC6(%rip), %r13
	call	_Z28cudaFindMaxWithoutDivergencePii
	movl	%eax, %ebx
	jmp	.L53
.L54:
	movl	%ebp, %esi
	movq	%r12, %rdi
	leaq	.LC7(%rip), %r13
	call	_Z27cudaFindMaxWithSharedMemoryPii
	movl	%eax, %ebx
.L53:
	xorl	%esi, %esi
	leaq	24(%rsp), %rdi
	call	gettimeofday@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%r13, %rdx
	movl	%ebx, %esi
	movl	%r14d, %edi
	call	_Z19checkAndPrintResultiiPc
	movq	24(%rsp), %rdx
	movl	%ebp, %r9d
	movq	%r13, %r8
	movq	32(%rsp), %rcx
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	call	_Z11printTiming7timevalS_Pci
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L55
	call	__stack_chk_fail@PLT
.L55:
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z20launchTestWithTimingii, .-_Z20launchTestWithTimingii
	.globl	_Z7runTesti
	.type	_Z7runTesti, @function
_Z7runTesti:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %esi
	movl	%edi, %ebx
	xorl	%edi, %edi
	call	_Z20launchTestWithTimingii
	movl	%ebx, %esi
	movl	$1, %edi
	call	_Z20launchTestWithTimingii
	movl	%ebx, %esi
	movl	$1, %edi
	call	_Z20launchTestWithTimingii
	movl	%ebx, %esi
	movl	$2, %edi
	call	_Z20launchTestWithTimingii
	movl	%ebx, %esi
	movl	$3, %edi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	_Z20launchTestWithTimingii
	.cfi_endproc
.LFE2035:
	.size	_Z7runTesti, .-_Z7runTesti
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$1024, %edi
	call	_Z7runTesti
	movl	$4096, %edi
	call	_Z7runTesti
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z29findMaxWithSharedMemoryKernelPi"
.LC10:
	.string	"_Z30findMaxWithoutDivergenceKernelPi"
.LC11:
	.string	"_Z20findMaxNaivelyKernelPi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2068:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC9(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z29findMaxWithSharedMemoryKernelPi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC10(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z30findMaxWithoutDivergenceKernelPi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC11(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z20findMaxNaivelyKernelPi(%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
.LFE2068:
	.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 <stdlib.h>
#include <stdio.h>
#include <sys/time.h>

/*
reduction.cu
A demonstration of array reduction using CUDA

Created for GPU Architecture and Programming
Spring 2012, New York University

Copyright 2012 Guy Dickinson <guy.dickinson@nyu.edu>
*/

// Vanilla, sequential reduction on host
// This *would* have a divergence problem if it were multithreaded
int findMaxOnHost(int* A, int length) {
    for (int step = 1; step < length; step *= 2) {
        for (int i = 0; i < length; i += (2 * step)) {
            int candidate = A[i + step];
            if (A[i] < candidate) {
                A[i] = candidate;
            }
        }
    }
    return A[0];
}

__global__ void findMaxNaivelyKernel(int* A) {
    unsigned int tid = (blockIdx.x * blockDim.x) + threadIdx.x;
    for (unsigned int step = 1; step < (blockDim.x * gridDim.x); step *= 2) {
        __syncthreads();
        if (tid % (2 * step) == 0) {
            int candidate = A[tid + step];
            if (A[tid] < candidate) {
                A[tid] = candidate;
            }
        }
    }
}

// Naively find the maximum element, without taking into account thread
// diversion or memory efficiency
int cudaFindMaxOnDeviceNaively(int* A, int length) {
    int size = length * sizeof(int);
    int ret;
    int* hipArray;
    hipMalloc(&hipArray, size);
    hipMemcpy(hipArray, A, size, hipMemcpyHostToDevice);
    
    dim3 dimBlock(512);
    dim3 dimGrid(length/512, 1);
    
    findMaxNaivelyKernel<<<dimGrid, dimBlock>>>(hipArray);
    
    
    // Recover just the first element from the device to save time.
    hipMemcpy(&ret, hipArray, sizeof(int), hipMemcpyDeviceToHost);
    hipFree(hipArray);
    return ret;
}

__global__ void findMaxWithoutDivergenceKernel(int* A) {
    unsigned int tid = (blockIdx.x * blockDim.x) + threadIdx.x;
    for (unsigned int step = blockDim.x * gridDim.x >> 1; step > 0; step >>= 1) {
        __syncthreads();
        if (tid < step) {
            int candidate = A[tid + step];
            if (A[tid] < candidate) {
                A[tid] = candidate;
            }
        }
    }
}

int cudaFindMaxWithoutDivergence(int* A, int length) {
    int size = length * sizeof(int);
    int ret;
    int* hipArray;
    hipMalloc(&hipArray, size);
    hipMemcpy(hipArray, A, size, hipMemcpyHostToDevice);
    
    dim3 dimBlock(512);
    dim3 dimGrid(length / 512, 1);
    
    findMaxWithoutDivergenceKernel<<<dimGrid, dimBlock>>>(hipArray);
    
    // Recover just the first element from the device to save time.
    hipMemcpy(&ret, hipArray, sizeof(int), hipMemcpyDeviceToHost);
    hipFree(hipArray);
    return ret;
}

__global__ void findMaxWithSharedMemoryKernel(int* A) {
    //Static allocation like this is pretty lame but good enough for testing.
    __shared__ int sharedmem[512];
    
    // copy this chunk into shared memory from global
    unsigned int threadIndex = threadIdx.x;
    unsigned int globalThreadId = (blockIdx.x * blockDim.x) + threadIdx.x;
    unsigned int nThreads = (blockDim.x * gridDim.x);
    
    sharedmem[threadIndex] = (globalThreadId < nThreads) ?
        A[globalThreadId] : 0;
        
    
    // Do the reduction in shared memory
    for (unsigned int step = blockDim.x >> 1; step > 0; step >>= 1) {
        __syncthreads();
        if (threadIndex < step) {
            int candidate = sharedmem[threadIndex + step];
            if (sharedmem[threadIndex] < candidate) {
                sharedmem[threadIndex] = candidate;
            }
        }
    }
    __syncthreads();
    
    // Thread 0 within a block writes the result back to global memory
    if (threadIndex == 0) {
        A[blockIdx.x] = sharedmem[0];
    }
    __syncthreads();
    
    // Now the global data structure has as elements 0-gridDim.x filled with
    // the results which we need to reduce again. 
    if (globalThreadId < gridDim.x) {
        for (unsigned int step = gridDim.x >> 1; step > 0; step >>= 1) {
            int candidate = A[globalThreadId + step];
            if (A[globalThreadId] < candidate) {
                A[globalThreadId] = candidate;
            }
        }
    }
}

int cudaFindMaxWithSharedMemory(int* A, int length) {
    int size = length * sizeof(int);
    int ret;
    int* hipArray;
    hipMalloc(&hipArray, size);
    hipMemcpy(hipArray, A, size, hipMemcpyHostToDevice);
    
    dim3 dimBlock(512);
    dim3 dimGrid(length / 512, 1);
    
    findMaxWithSharedMemoryKernel<<<dimGrid, dimBlock>>>(hipArray);
    
    // Recover just the first element from the device to save time.
    hipMemcpy(&ret, hipArray, sizeof(int), hipMemcpyDeviceToHost);
    hipFree(hipArray);
    return ret;
}



// Returns a pointer to an array of ints of size length.
// For verification purposes, the biggest int will be at the end.
int* initializeArray(int length) {
    // Set up an array of ints of the right length
    void *ptr;
    ptr = malloc(length * sizeof(int));
    if (ptr == NULL) {
        // Handle allocation error
    }
    int* A = (int*) ptr;
    
    // Fill it with ints
    int j = 1;
    for (int i = 0; i < length; i++) {
        A[i] = j;
        j += 2;
    }
    return A;
}

void printTiming(timeval start, timeval end, char* desc, int length) {
    double elapsed =
        (end.tv_usec - start.tv_usec);
    printf("%s length %d: %g usec\n", desc, elapsed, length);
}

void checkAndPrintResult(int expected, int actual, char* desc) {
    if (expected == actual) {
        printf("%s passed check ", desc);
    } else {
        printf("%s failed check " , desc);
    }
    printf("(expected %d, got %d)\n", expected, actual);
}

// Wrapper function for launching each test component.
void launchTestWithTiming(
        int testType,
        int length) {
            
    int actual;
    char* desc;
    
    timeval start, end;
    int* array = initializeArray(length);
    int expected = array[length - 1];
    gettimeofday(&start, NULL);
    switch (testType) {
        // CPU
        case 0:
        desc = "Serial";
        actual = findMaxOnHost(array, length);
        break;
        
        // Naive Parallel
        case 1:
        desc = "Naive Parallel";
        actual = cudaFindMaxOnDeviceNaively(array, length);
        break;
        
        // Non Divergent Parallel
        case 2:
        desc = "Non Divergent Parallel";
        actual = cudaFindMaxWithoutDivergence(array, length);
        break;
        
        // Shared Memory Parallel
        case 3:
        desc = "Shared Memory Parallel";
        actual = cudaFindMaxWithSharedMemory(array, length);
        break;
        
        default:
        desc = "Unrecognized!";
        break;
        
    }
    gettimeofday(&end, NULL);
    free(array);
    
    checkAndPrintResult(expected, actual, desc);
    printTiming(start, end, desc, length);
    
}


void runTest(int length) {
    launchTestWithTiming(0, length);
    launchTestWithTiming(1, length);
    launchTestWithTiming(1, length);
    
    launchTestWithTiming(2, length);
    launchTestWithTiming(3, length);
    }

int main(void) {
    runTest(1024);
    runTest(4096);
    return 0;
}
	.text
	.file	"reduction.hip"
	.globl	_Z13findMaxOnHostPii            # -- Begin function _Z13findMaxOnHostPii
	.type	_Z13findMaxOnHostPii,@function
_Z13findMaxOnHostPii:                   # @_Z13findMaxOnHostPii
	.cfi_startproc
# %bb.0:
	cmpl	$2, %esi
	jl	.LBB0_7
# %bb.1:                                # %.preheader.lr.ph
	movl	%esi, %eax
	movl	$1, %ecx
.LBB0_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_3 Depth 2
                                        # kill: def $ecx killed $ecx def $rcx
	movslq	%ecx, %r8
	addl	%ecx, %ecx
	movslq	%ecx, %rdx
	leaq	(%rdi,%r8,4), %r8
	xorl	%r9d, %r9d
.LBB0_3:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r8,%r9,4), %r10d
	cmpl	%r10d, (%rdi,%r9,4)
	jge	.LBB0_5
# %bb.4:                                #   in Loop: Header=BB0_3 Depth=2
	movl	%r10d, (%rdi,%r9,4)
.LBB0_5:                                #   in Loop: Header=BB0_3 Depth=2
	addq	%rdx, %r9
	cmpq	%rax, %r9
	jl	.LBB0_3
# %bb.6:                                # %._crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	cmpl	%esi, %ecx
	jl	.LBB0_2
.LBB0_7:                                # %._crit_edge21
	movl	(%rdi), %eax
	retq
.Lfunc_end0:
	.size	_Z13findMaxOnHostPii, .Lfunc_end0-_Z13findMaxOnHostPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z35__device_stub__findMaxNaivelyKernelPi # -- Begin function _Z35__device_stub__findMaxNaivelyKernelPi
	.type	_Z35__device_stub__findMaxNaivelyKernelPi,@function
_Z35__device_stub__findMaxNaivelyKernelPi: # @_Z35__device_stub__findMaxNaivelyKernelPi
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.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)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z20findMaxNaivelyKernelPi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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	_Z35__device_stub__findMaxNaivelyKernelPi, .Lfunc_end1-_Z35__device_stub__findMaxNaivelyKernelPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z26cudaFindMaxOnDeviceNaivelyPii # -- Begin function _Z26cudaFindMaxOnDeviceNaivelyPii
	.type	_Z26cudaFindMaxOnDeviceNaivelyPii,@function
_Z26cudaFindMaxOnDeviceNaivelyPii:      # @_Z26cudaFindMaxOnDeviceNaivelyPii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%esi, %ebx
	movq	%rdi, %r14
	leal	(,%rbx,4), %eax
	movslq	%eax, %r15
	leaq	8(%rsp), %r12
	movq	%r12, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%r12), %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leal	511(%rbx), %edi
	testl	%ebx, %ebx
	cmovnsl	%ebx, %edi
	sarl	$9, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$512, %rdx                      # imm = 0x200
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	movq	8(%rsp), %rdi
	callq	_Z35__device_stub__findMaxNaivelyKernelPi
.LBB2_2:
	movq	8(%rsp), %rsi
	leaq	20(%rsp), %rbx
	movl	$4, %edx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	callq	hipFree
	movl	(%rbx), %eax
	addq	$24, %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_end2:
	.size	_Z26cudaFindMaxOnDeviceNaivelyPii, .Lfunc_end2-_Z26cudaFindMaxOnDeviceNaivelyPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z45__device_stub__findMaxWithoutDivergenceKernelPi # -- Begin function _Z45__device_stub__findMaxWithoutDivergenceKernelPi
	.type	_Z45__device_stub__findMaxWithoutDivergenceKernelPi,@function
_Z45__device_stub__findMaxWithoutDivergenceKernelPi: # @_Z45__device_stub__findMaxWithoutDivergenceKernelPi
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.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)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z30findMaxWithoutDivergenceKernelPi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end3:
	.size	_Z45__device_stub__findMaxWithoutDivergenceKernelPi, .Lfunc_end3-_Z45__device_stub__findMaxWithoutDivergenceKernelPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z28cudaFindMaxWithoutDivergencePii # -- Begin function _Z28cudaFindMaxWithoutDivergencePii
	.type	_Z28cudaFindMaxWithoutDivergencePii,@function
_Z28cudaFindMaxWithoutDivergencePii:    # @_Z28cudaFindMaxWithoutDivergencePii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%esi, %ebx
	movq	%rdi, %r14
	leal	(,%rbx,4), %eax
	movslq	%eax, %r15
	leaq	8(%rsp), %r12
	movq	%r12, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%r12), %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leal	511(%rbx), %edi
	testl	%ebx, %ebx
	cmovnsl	%ebx, %edi
	sarl	$9, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$512, %rdx                      # imm = 0x200
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_2
# %bb.1:
	movq	8(%rsp), %rdi
	callq	_Z45__device_stub__findMaxWithoutDivergenceKernelPi
.LBB4_2:
	movq	8(%rsp), %rsi
	leaq	20(%rsp), %rbx
	movl	$4, %edx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	callq	hipFree
	movl	(%rbx), %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z28cudaFindMaxWithoutDivergencePii, .Lfunc_end4-_Z28cudaFindMaxWithoutDivergencePii
	.cfi_endproc
                                        # -- End function
	.globl	_Z44__device_stub__findMaxWithSharedMemoryKernelPi # -- Begin function _Z44__device_stub__findMaxWithSharedMemoryKernelPi
	.type	_Z44__device_stub__findMaxWithSharedMemoryKernelPi,@function
_Z44__device_stub__findMaxWithSharedMemoryKernelPi: # @_Z44__device_stub__findMaxWithSharedMemoryKernelPi
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.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)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z29findMaxWithSharedMemoryKernelPi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end5:
	.size	_Z44__device_stub__findMaxWithSharedMemoryKernelPi, .Lfunc_end5-_Z44__device_stub__findMaxWithSharedMemoryKernelPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z27cudaFindMaxWithSharedMemoryPii # -- Begin function _Z27cudaFindMaxWithSharedMemoryPii
	.type	_Z27cudaFindMaxWithSharedMemoryPii,@function
_Z27cudaFindMaxWithSharedMemoryPii:     # @_Z27cudaFindMaxWithSharedMemoryPii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%esi, %ebx
	movq	%rdi, %r14
	leal	(,%rbx,4), %eax
	movslq	%eax, %r15
	leaq	8(%rsp), %r12
	movq	%r12, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%r12), %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leal	511(%rbx), %edi
	testl	%ebx, %ebx
	cmovnsl	%ebx, %edi
	sarl	$9, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$512, %rdx                      # imm = 0x200
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_2
# %bb.1:
	movq	8(%rsp), %rdi
	callq	_Z44__device_stub__findMaxWithSharedMemoryKernelPi
.LBB6_2:
	movq	8(%rsp), %rsi
	leaq	20(%rsp), %rbx
	movl	$4, %edx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	callq	hipFree
	movl	(%rbx), %eax
	addq	$24, %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	_Z27cudaFindMaxWithSharedMemoryPii, .Lfunc_end6-_Z27cudaFindMaxWithSharedMemoryPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z15initializeArrayi            # -- Begin function _Z15initializeArrayi
	.type	_Z15initializeArrayi,@function
_Z15initializeArrayi:                   # @_Z15initializeArrayi
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%edi, %ebx
	movslq	%edi, %r14
	leaq	(,%r14,4), %rdi
	callq	malloc
	testl	%r14d, %r14d
	jle	.LBB7_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebx, %ecx
	addq	%rcx, %rcx
	xorl	%edx, %edx
.LBB7_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	leal	1(%rdx), %esi
	movl	%esi, (%rax,%rdx,2)
	addq	$2, %rdx
	cmpq	%rdx, %rcx
	jne	.LBB7_2
.LBB7_3:                                # %._crit_edge
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	_Z15initializeArrayi, .Lfunc_end7-_Z15initializeArrayi
	.cfi_endproc
                                        # -- End function
	.globl	_Z11printTiming7timevalS_Pci    # -- Begin function _Z11printTiming7timevalS_Pci
	.type	_Z11printTiming7timevalS_Pci,@function
_Z11printTiming7timevalS_Pci:           # @_Z11printTiming7timevalS_Pci
	.cfi_startproc
# %bb.0:
	movl	%r9d, %edx
	subq	%rsi, %rcx
	cvtsi2sd	%rcx, %xmm0
	movl	$.L.str, %edi
	movq	%r8, %rsi
	movb	$1, %al
	jmp	printf                          # TAILCALL
.Lfunc_end8:
	.size	_Z11printTiming7timevalS_Pci, .Lfunc_end8-_Z11printTiming7timevalS_Pci
	.cfi_endproc
                                        # -- End function
	.globl	_Z19checkAndPrintResultiiPc     # -- Begin function _Z19checkAndPrintResultiiPc
	.type	_Z19checkAndPrintResultiiPc,@function
_Z19checkAndPrintResultiiPc:            # @_Z19checkAndPrintResultiiPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movl	%edi, %ebp
	cmpl	%esi, %edi
	movl	$.L.str.1, %eax
	movl	$.L.str.2, %edi
	cmoveq	%rax, %rdi
	movq	%rdx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.3, %edi
	movl	%ebp, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.Lfunc_end9:
	.size	_Z19checkAndPrintResultiiPc, .Lfunc_end9-_Z19checkAndPrintResultiiPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z20launchTestWithTimingii      # -- Begin function _Z20launchTestWithTimingii
	.type	_Z20launchTestWithTimingii,@function
_Z20launchTestWithTimingii:             # @_Z20launchTestWithTimingii
	.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	%esi, %ebx
	movl	%edi, %r15d
	movslq	%esi, %r12
	leaq	(,%r12,4), %rdi
	callq	malloc
	movq	%rax, %r14
	testl	%r12d, %r12d
	jle	.LBB10_1
# %bb.2:                                # %.lr.ph.preheader.i
	movl	%ebx, %eax
	addq	%rax, %rax
	xorl	%ecx, %ecx
.LBB10_3:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	leal	1(%rcx), %edx
	movl	%edx, (%r14,%rcx,2)
	addq	$2, %rcx
	cmpq	%rcx, %rax
	jne	.LBB10_3
# %bb.4:                                # %_Z15initializeArrayi.exit.loopexit
	movl	-4(%r14,%r12,4), %ebp
	jmp	.LBB10_5
.LBB10_1:
                                        # implicit-def: $ebp
.LBB10_5:                               # %_Z15initializeArrayi.exit
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cmpl	$3, %r15d
	ja	.LBB10_6
# %bb.7:                                # %_Z15initializeArrayi.exit
	movl	%r15d, %eax
	jmpq	*.LJTI10_0(,%rax,8)
.LBB10_8:
	cmpl	$2, %ebx
	jl	.LBB10_15
# %bb.9:                                # %.preheader.lr.ph.i
	movl	%ebx, %eax
	movl	$1, %ecx
.LBB10_10:                              # %.lr.ph.i20
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB10_11 Depth 2
                                        # kill: def $ecx killed $ecx def $rcx
	movslq	%ecx, %rsi
	addl	%ecx, %ecx
	movslq	%ecx, %rdx
	leaq	(%r14,%rsi,4), %rsi
	xorl	%edi, %edi
.LBB10_11:                              #   Parent Loop BB10_10 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rsi,%rdi,4), %r8d
	cmpl	%r8d, (%r14,%rdi,4)
	jge	.LBB10_13
# %bb.12:                               #   in Loop: Header=BB10_11 Depth=2
	movl	%r8d, (%r14,%rdi,4)
.LBB10_13:                              #   in Loop: Header=BB10_11 Depth=2
	addq	%rdx, %rdi
	cmpq	%rax, %rdi
	jl	.LBB10_11
# %bb.14:                               # %._crit_edge.i
                                        #   in Loop: Header=BB10_10 Depth=1
	cmpl	%ebx, %ecx
	jl	.LBB10_10
.LBB10_15:                              # %_Z13findMaxOnHostPii.exit
	movl	(%r14), %r12d
	movl	$.L.str.4, %r15d
	jmp	.LBB10_19
.LBB10_17:
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_Z28cudaFindMaxWithoutDivergencePii
	movl	%eax, %r12d
	movl	$.L.str.6, %r15d
	jmp	.LBB10_19
.LBB10_18:
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_Z27cudaFindMaxWithSharedMemoryPii
	movl	%eax, %r12d
	movl	$.L.str.7, %r15d
	jmp	.LBB10_19
.LBB10_16:
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_Z26cudaFindMaxOnDeviceNaivelyPii
	movl	%eax, %r12d
	movl	$.L.str.5, %r15d
	jmp	.LBB10_19
.LBB10_6:
	movl	$.L.str.8, %r15d
                                        # implicit-def: $r12d
.LBB10_19:
	leaq	24(%rsp), %r13
	movq	%r13, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	%r14, %rdi
	callq	free
	cmpl	%r12d, %ebp
	movl	$.L.str.1, %eax
	movl	$.L.str.2, %edi
	cmoveq	%rax, %rdi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.3, %edi
	movl	%ebp, %esi
	movl	%r12d, %edx
	xorl	%eax, %eax
	callq	printf
	movq	8(%r13), %rax
	subq	16(%rsp), %rax
	cvtsi2sd	%rax, %xmm0
	movl	$.L.str, %edi
	movq	%r15, %rsi
	movl	%ebx, %edx
	movb	$1, %al
	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
	jmp	printf                          # TAILCALL
.Lfunc_end10:
	.size	_Z20launchTestWithTimingii, .Lfunc_end10-_Z20launchTestWithTimingii
	.cfi_endproc
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
.LJTI10_0:
	.quad	.LBB10_8
	.quad	.LBB10_16
	.quad	.LBB10_17
	.quad	.LBB10_18
                                        # -- End function
	.text
	.globl	_Z7runTesti                     # -- Begin function _Z7runTesti
	.type	_Z7runTesti,@function
_Z7runTesti:                            # @_Z7runTesti
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edi, %ebx
	xorl	%edi, %edi
	movl	%ebx, %esi
	callq	_Z20launchTestWithTimingii
	movl	$1, %edi
	movl	%ebx, %esi
	callq	_Z20launchTestWithTimingii
	movl	$1, %edi
	movl	%ebx, %esi
	callq	_Z20launchTestWithTimingii
	movl	$2, %edi
	movl	%ebx, %esi
	callq	_Z20launchTestWithTimingii
	movl	$3, %edi
	movl	%ebx, %esi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	_Z20launchTestWithTimingii      # TAILCALL
.Lfunc_end11:
	.size	_Z7runTesti, .Lfunc_end11-_Z7runTesti
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$1024, %edi                     # imm = 0x400
	callq	_Z7runTesti
	movl	$4096, %edi                     # imm = 0x1000
	callq	_Z7runTesti
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end12:
	.size	main, .Lfunc_end12-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	.LBB13_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB13_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z20findMaxNaivelyKernelPi, %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	$_Z30findMaxWithoutDivergenceKernelPi, %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	$_Z29findMaxWithSharedMemoryKernelPi, %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_end13:
	.size	__hip_module_ctor, .Lfunc_end13-__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	.LBB14_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
.LBB14_2:
	retq
.Lfunc_end14:
	.size	__hip_module_dtor, .Lfunc_end14-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z20findMaxNaivelyKernelPi,@object # @_Z20findMaxNaivelyKernelPi
	.section	.rodata,"a",@progbits
	.globl	_Z20findMaxNaivelyKernelPi
	.p2align	3, 0x0
_Z20findMaxNaivelyKernelPi:
	.quad	_Z35__device_stub__findMaxNaivelyKernelPi
	.size	_Z20findMaxNaivelyKernelPi, 8

	.type	_Z30findMaxWithoutDivergenceKernelPi,@object # @_Z30findMaxWithoutDivergenceKernelPi
	.globl	_Z30findMaxWithoutDivergenceKernelPi
	.p2align	3, 0x0
_Z30findMaxWithoutDivergenceKernelPi:
	.quad	_Z45__device_stub__findMaxWithoutDivergenceKernelPi
	.size	_Z30findMaxWithoutDivergenceKernelPi, 8

	.type	_Z29findMaxWithSharedMemoryKernelPi,@object # @_Z29findMaxWithSharedMemoryKernelPi
	.globl	_Z29findMaxWithSharedMemoryKernelPi
	.p2align	3, 0x0
_Z29findMaxWithSharedMemoryKernelPi:
	.quad	_Z44__device_stub__findMaxWithSharedMemoryKernelPi
	.size	_Z29findMaxWithSharedMemoryKernelPi, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%s length %d: %g usec\n"
	.size	.L.str, 23

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%s passed check "
	.size	.L.str.1, 17

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%s failed check "
	.size	.L.str.2, 17

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"(expected %d, got %d)\n"
	.size	.L.str.3, 23

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Naive Parallel"
	.size	.L.str.5, 15

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Non Divergent Parallel"
	.size	.L.str.6, 23

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Shared Memory Parallel"
	.size	.L.str.7, 23

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Unrecognized!"
	.size	.L.str.8, 14

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z20findMaxNaivelyKernelPi"
	.size	.L__unnamed_1, 27

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z30findMaxWithoutDivergenceKernelPi"
	.size	.L__unnamed_2, 37

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z29findMaxWithSharedMemoryKernelPi"
	.size	.L__unnamed_3, 36

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

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z35__device_stub__findMaxNaivelyKernelPi
	.addrsig_sym _Z45__device_stub__findMaxWithoutDivergenceKernelPi
	.addrsig_sym _Z44__device_stub__findMaxWithSharedMemoryKernelPi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z20findMaxNaivelyKernelPi
	.addrsig_sym _Z30findMaxWithoutDivergenceKernelPi
	.addrsig_sym _Z29findMaxWithSharedMemoryKernelPi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z20findMaxNaivelyKernelPi ; -- Begin function _Z20findMaxNaivelyKernelPi
	.globl	_Z20findMaxNaivelyKernelPi
	.p2align	8
	.type	_Z20findMaxNaivelyKernelPi,@function
_Z20findMaxNaivelyKernelPi:             ; @_Z20findMaxNaivelyKernelPi
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x14
	s_load_b32 s4, s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s2, s4, s3
	s_cmp_lt_u32 s2, 2
	s_cbranch_scc1 .LBB0_6
; %bb.1:                                ; %.lr.ph
	s_load_b64 s[0:1], s[0:1], 0x0
	v_mov_b32_e32 v1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s15, s3, v[0:1]
	v_mov_b32_e32 v3, v1
	s_mov_b32 s3, 1
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s0, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s5, s3
	s_lshl_b32 s3, s3, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_i32 s4, s3, -1
	s_waitcnt_vscnt null, 0x0
	s_barrier
	v_and_b32_e32 v0, s4, v2
	s_mov_b32 s4, exec_lo
	buffer_gl0_inv
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_5
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	v_add_nc_u32_e32 v0, s5, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	v_add_co_u32 v5, vcc_lo, s0, v5
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v6, vcc_lo
	s_clause 0x1
	global_load_b32 v0, v[5:6], off
	global_load_b32 v5, v[3:4], off
	s_waitcnt vmcnt(0)
	v_cmp_lt_i32_e32 vcc_lo, v5, v0
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	global_store_b32 v[3:4], v0, off
.LBB0_5:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s4
	s_cmp_ge_u32 s3, s2
	s_cbranch_scc0 .LBB0_2
.LBB0_6:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z20findMaxNaivelyKernelPi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 7
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z20findMaxNaivelyKernelPi, .Lfunc_end0-_Z20findMaxNaivelyKernelPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 256
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z30findMaxWithoutDivergenceKernelPi ; -- Begin function _Z30findMaxWithoutDivergenceKernelPi
	.globl	_Z30findMaxWithoutDivergenceKernelPi
	.p2align	8
	.type	_Z30findMaxWithoutDivergenceKernelPi,@function
_Z30findMaxWithoutDivergenceKernelPi:   ; @_Z30findMaxWithoutDivergenceKernelPi
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x14
	s_load_b32 s4, s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s2, s4, s3
	s_cmp_lt_u32 s2, 2
	s_cbranch_scc1 .LBB1_6
; %bb.1:                                ; %.lr.ph
	s_load_b64 s[0:1], s[0:1], 0x0
	v_mov_b32_e32 v1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s15, s3, v[0:1]
	v_mov_b32_e32 v3, v1
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s0, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s3, s2
	s_lshr_b32 s2, s2, 1
	s_mov_b32 s4, exec_lo
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u32_e64 s2, v2
	s_cbranch_execz .LBB1_5
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_nc_u32_e32 v0, s2, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	v_add_co_u32 v5, vcc_lo, s0, v5
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v6, vcc_lo
	s_clause 0x1
	global_load_b32 v0, v[5:6], off
	global_load_b32 v5, v[3:4], off
	s_waitcnt vmcnt(0)
	v_cmp_lt_i32_e32 vcc_lo, v5, v0
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_5
; %bb.4:                                ;   in Loop: Header=BB1_2 Depth=1
	global_store_b32 v[3:4], v0, off
.LBB1_5:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s4
	s_cmp_lt_u32 s3, 4
	s_cbranch_scc0 .LBB1_2
.LBB1_6:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z30findMaxWithoutDivergenceKernelPi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 7
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z30findMaxWithoutDivergenceKernelPi, .Lfunc_end1-_Z30findMaxWithoutDivergenceKernelPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 244
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z29findMaxWithSharedMemoryKernelPi ; -- Begin function _Z29findMaxWithSharedMemoryKernelPi
	.globl	_Z29findMaxWithSharedMemoryKernelPi
	.p2align	8
	.type	_Z29findMaxWithSharedMemoryKernelPi,@function
_Z29findMaxWithSharedMemoryKernelPi:    ; @_Z29findMaxWithSharedMemoryKernelPi
; %bb.0:
	s_clause 0x2
	s_load_b32 s3, s[0:1], 0x14
	s_load_b32 s4, s[0:1], 0x8
	s_load_b64 s[0:1], s[0:1], 0x0
	s_mov_b32 s2, s15
	v_mov_b32_e32 v3, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mad_u64_u32 v[1:2], null, s2, s3, v[0:1]
	s_mul_i32 s5, s4, s3
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_cmp_gt_u32_e32 vcc_lo, s5, v1
	s_and_saveexec_b32 s5, vcc_lo
	s_cbranch_execz .LBB2_2
; %bb.1:
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_add_co_u32 v2, vcc_lo, s0, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	global_load_b32 v3, v[2:3], off
.LBB2_2:
	s_or_b32 exec_lo, exec_lo, s5
	v_lshlrev_b32_e32 v2, 2, v0
	s_cmp_lt_u32 s3, 2
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v3
	s_cbranch_scc1 .LBB2_7
.LBB2_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s5, s3
	s_lshr_b32 s3, s3, 1
	s_mov_b32 s6, exec_lo
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u32_e64 s3, v0
	s_cbranch_execz .LBB2_6
; %bb.4:                                ;   in Loop: Header=BB2_3 Depth=1
	v_lshl_add_u32 v3, s3, 2, v2
	ds_load_b32 v3, v3
	ds_load_b32 v4, v2
	s_waitcnt lgkmcnt(0)
	v_cmp_lt_i32_e32 vcc_lo, v4, v3
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB2_6
; %bb.5:                                ;   in Loop: Header=BB2_3 Depth=1
	ds_store_b32 v2, v3
.LBB2_6:                                ;   in Loop: Header=BB2_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s6
	s_cmp_lt_u32 s5, 4
	s_cbranch_scc0 .LBB2_3
.LBB2_7:                                ; %._crit_edge
	s_mov_b32 s3, 0
	s_mov_b32 s5, exec_lo
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB2_9
; %bb.8:
	v_mov_b32_e32 v0, 0
	s_lshl_b64 s[2:3], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s2, s0, s2
	s_addc_u32 s3, s1, s3
	ds_load_b32 v2, v0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v2, s[2:3]
.LBB2_9:
	s_or_b32 exec_lo, exec_lo, s5
	v_max_u32_e32 v0, 1, v1
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_u32_e64 s4, v0
	s_cbranch_execz .LBB2_14
; %bb.10:                               ; %.lr.ph41
	v_mov_b32_e32 v3, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mov_b32_e32 v2, v3
	v_lshlrev_b64 v[4:5], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s0, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	global_load_b32 v0, v[4:5], off
.LBB2_11:                               ; =>This Inner Loop Header: Depth=1
	s_lshr_b32 s2, s4, 1
	s_mov_b32 s3, exec_lo
	v_add_nc_u32_e32 v2, s2, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[6:7], 2, v[2:3]
	v_add_co_u32 v6, vcc_lo, s0, v6
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v7, vcc_lo, s1, v7, vcc_lo
	global_load_b32 v2, v[6:7], off
	s_waitcnt vmcnt(0)
	v_cmpx_lt_i32_e64 v0, v2
	s_cbranch_execz .LBB2_13
; %bb.12:                               ;   in Loop: Header=BB2_11 Depth=1
	v_mov_b32_e32 v0, v2
	global_store_b32 v[4:5], v2, off
.LBB2_13:                               ;   in Loop: Header=BB2_11 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_cmp_gt_u32 s4, 3
	s_mov_b32 s4, s2
	s_cbranch_scc1 .LBB2_11
.LBB2_14:                               ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z29findMaxWithSharedMemoryKernelPi
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end2:
	.size	_Z29findMaxWithSharedMemoryKernelPi, .Lfunc_end2-_Z29findMaxWithSharedMemoryKernelPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 508
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.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
      - .offset:         8
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z20findMaxNaivelyKernelPi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z20findMaxNaivelyKernelPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z30findMaxWithoutDivergenceKernelPi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z30findMaxWithoutDivergenceKernelPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z29findMaxWithSharedMemoryKernelPi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z29findMaxWithSharedMemoryKernelPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
