#ifndef __CUDACC__
#define __CUDACC__
#endif
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <cuda.h>
#include <device_functions.h>
#include <cuda_runtime_api.h>
#include <curand.h>
#include <curand_kernel.h>

#include <math.h>
#include <stdio.h>
#include <random>
#include <iomanip>
#include <iostream>

#define N 256
#define BLOCKSIZE 16

cudaError_t histogramCuda(int *freq, int *freq2, const int *vals, int bin, float &time, float &shared_time);

__global__ void naivehistKernel(int *freq, const int *vals) {
    unsigned int id = blockIdx.x * blockDim.x + threadIdx.x;
    atomicAdd(&freq[vals[id]], 1);
}

__global__ void sharedhistKernel(int *freq, const int *vals) {
    __shared__ int temp[BLOCKSIZE];
	unsigned int tid = threadIdx.x;
    temp[tid] = 0;
    __syncthreads();

    unsigned int id = blockIdx.x * blockDim.x + threadIdx.x;
    atomicAdd(&temp[vals[id]], 1);
    __syncthreads();

    atomicAdd(&(freq[tid]), temp[tid]);
}

int main() {
    const int bin = 10 + 1;
	const int vals[N] = {1,9,0,6,10,1,2,4,6,9,9,5,10,10,8,3,
							7,7,5,0,4,8,5,10,0,8,9,10,10,5,1,0,
							0,3,10,5,4,3,5,1,4,4,1,8,1,6,10,3,
							0,2,5,7,10,4,1,6,6,5,4,0,5,0,4,4,
							4,1,4,6,8,9,0,0,9,4,10,10,10,1,4,9,
							0,1,7,9,7,10,10,0,5,9,1,6,7,0,3,9,
							8,5,4,8,4,1,0,6,9,2,1,2,3,6,10,6,
							4,9,6,0,2,6,2,6,3,8,6,0,2,2,1,1,
							3,10,6,7,4,5,3,8,4,9,5,9,7,9,5,8,
							9,6,8,8,7,10,10,7,9,6,3,7,5,3,8,10,
							2,5,8,6,9,1,1,2,3,7,7,8,2,2,10,5,
							7,3,9,4,1,9,7,7,6,9,3,5,8,8,8,2,
							7,2,7,6,1,6,8,7,10,1,2,6,5,6,1,0,
							6,8,9,6,1,9,10,4,1,7,1,8,5,0,9,10,
							5,6,2,9,6,3,10,0,0,6,1,8,7,0,6,2,
							3,10,1,1,10,10,5,6,9,0,2,8,5,5,10,4};
	int freq[bin] = { 0 };
	int freq2[bin] = { 0 };
	float time = 0.0f;
	float shared_time = 0.0f;

    cudaError_t cudaStatus = histogramCuda(freq, freq2, vals, bin, time, shared_time);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "histogramCuda failed!");
        return 1;
    }

	for(int i = 0; i < bin; i++) {
       std::cout << std::left;
       std::cout << std::setw(5) << i;
       std::cout << std::setw(5) << freq[i];
       std::cout << std::endl;
	}

	std::cout << "Histogram GPU Implementation" << std::endl;
	std::cout << "Execution Time : " << time / 1000 << " seconds" << std::endl;
	std::cout << "Effective Bandwidth : " << (N*sizeof(int)*2) / (time / 1000) << " GB/s" << std::endl;
	std::cout << std::endl;

	for(int i = 0; i < bin; i++) {
       std::cout << std::left;
       std::cout << std::setw(5) << i;
       std::cout << std::setw(5) << freq2[i];
       std::cout << std::endl;
	}

	std::cout << "Histogram Shared Memory GPU Implementation" << std::endl;
	std::cout << "Execution Time : " << shared_time / 1000 << " seconds" << std::endl;
	std::cout << "Effective Bandwidth : " << (N*sizeof(int)*2) / (shared_time / 1000) << " GB/s" << std::endl;
	std::cout << std::endl;

	cudaStatus = cudaDeviceReset();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceReset failed!");
        return 1;
    }

    return 0;
}

cudaError_t histogramCuda(int *freq, int *freq2, const int *vals, int bin, float &time, float &shared_time) {
    int *dev_vals = 0;
    int *dev_freq = 0;
	int *dev_freq2 = 0;
	float milliseconds = 0.0f;
	float milliseconds1 = 0.0f;
    cudaError_t cudaStatus;
	dim3 dimBlock(BLOCKSIZE);
    dim3 dimGrid(N/BLOCKSIZE);
	cudaEvent_t start, stop;
	cudaEvent_t start1, stop1;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	cudaEventCreate(&start1);
	cudaEventCreate(&stop1);

    cudaStatus = cudaSetDevice(0);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?");
        goto Error;
    }

    cudaStatus = cudaMalloc((void**)&dev_freq, bin * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

	cudaStatus = cudaMemset(dev_freq, 0, bin * sizeof(int));
	if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemset failed!");
        goto Error;
    }

	cudaStatus = cudaMalloc((void**)&dev_freq2, bin * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

	cudaStatus = cudaMemset(dev_freq2, 0, bin * sizeof(int));
	if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemset failed!");
        goto Error;
    }

    cudaStatus = cudaMalloc((void**)&dev_vals, N * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

    cudaStatus = cudaMemcpy(dev_vals, vals, N * sizeof(int), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

	cudaEventRecord(start);
    naivehistKernel<<<dimGrid, dimBlock>>>(dev_freq, dev_vals);
	cudaEventRecord(stop);
	cudaEventSynchronize(stop);

	cudaThreadSynchronize();

	cudaEventRecord(start1);
    sharedhistKernel<<<dimGrid, dimBlock>>>(dev_freq2, dev_vals);
	cudaEventRecord(stop1);
	cudaEventSynchronize(stop1);

    cudaStatus = cudaGetLastError();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "histKernel launch failed: %s\n", cudaGetErrorString(cudaStatus));
        goto Error;
    }
    
    cudaStatus = cudaDeviceSynchronize();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching histKernel!\n", cudaStatus);
        goto Error;
    }

    cudaStatus = cudaMemcpy(freq, dev_freq, bin * sizeof(int), cudaMemcpyDeviceToHost);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

	cudaStatus = cudaMemcpy(freq2, dev_freq2, bin * sizeof(int), cudaMemcpyDeviceToHost);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

	cudaEventElapsedTime(&milliseconds, start, stop);
	cudaEventElapsedTime(&milliseconds1, start1, stop1);
	time = milliseconds;
	shared_time = milliseconds1;

Error:
    cudaFree(dev_freq);
	cudaFree(dev_freq2);
    cudaFree(dev_vals);
    
    return cudaStatus;
}

	.file	"tmpxft_002aeba0_00000000-6_kernel.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB5217:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE5217:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB5926:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE5926:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.section	.text._ZSt4leftRSt8ios_base,"axG",@progbits,_ZSt4leftRSt8ios_base,comdat
	.weak	_ZSt4leftRSt8ios_base
	.type	_ZSt4leftRSt8ios_base, @function
_ZSt4leftRSt8ios_base:
.LFB4579:
	.cfi_startproc
	endbr64
	movl	24(%rdi), %edx
	movq	%rdi, %rax
	andb	$79, %dl
	orl	$32, %edx
	movl	%edx, 24(%rdi)
	ret
	.cfi_endproc
.LFE4579:
	.size	_ZSt4leftRSt8ios_base, .-_ZSt4leftRSt8ios_base
	.text
	.globl	_Z38__device_stub__Z15naivehistKernelPiPKiPiPKi
	.type	_Z38__device_stub__Z15naivehistKernelPiPKiPiPKi, @function
_Z38__device_stub__Z15naivehistKernelPiPKiPiPKi:
.LFB5239:
	.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	.L4
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z15naivehistKernelPiPKi(%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
.L4:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5239:
	.size	_Z38__device_stub__Z15naivehistKernelPiPKiPiPKi, .-_Z38__device_stub__Z15naivehistKernelPiPKiPiPKi
	.globl	_Z15naivehistKernelPiPKi
	.type	_Z15naivehistKernelPiPKi, @function
_Z15naivehistKernelPiPKi:
.LFB5240:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z15naivehistKernelPiPKiPiPKi
	.cfi_endproc
.LFE5240:
	.size	_Z15naivehistKernelPiPKi, .-_Z15naivehistKernelPiPKi
	.globl	_Z39__device_stub__Z16sharedhistKernelPiPKiPiPKi
	.type	_Z39__device_stub__Z16sharedhistKernelPiPKiPiPKi, @function
_Z39__device_stub__Z16sharedhistKernelPiPKiPiPKi:
.LFB5241:
	.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	_Z16sharedhistKernelPiPKi(%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
.LFE5241:
	.size	_Z39__device_stub__Z16sharedhistKernelPiPKiPiPKi, .-_Z39__device_stub__Z16sharedhistKernelPiPKiPiPKi
	.globl	_Z16sharedhistKernelPiPKi
	.type	_Z16sharedhistKernelPiPKi, @function
_Z16sharedhistKernelPiPKi:
.LFB5242:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z16sharedhistKernelPiPKiPiPKi
	.cfi_endproc
.LFE5242:
	.size	_Z16sharedhistKernelPiPKi, .-_Z16sharedhistKernelPiPKi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?"
.LC3:
	.string	"cudaMalloc failed!"
.LC4:
	.string	"cudaMemset failed!"
.LC5:
	.string	"cudaMemcpy failed!"
.LC6:
	.string	"histKernel launch failed: %s\n"
.LC7:
	.string	"cudaDeviceSynchronize returned error code %d after launching histKernel!\n"
	.text
	.globl	_Z13histogramCudaPiS_PKiiRfS2_
	.type	_Z13histogramCudaPiS_PKiiRfS2_, @function
_Z13histogramCudaPiS_PKiiRfS2_:
.LFB5214:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdx, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%r8, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r9, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movslq	%ecx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%rsi, 8(%rsp)
	leaq	48(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	xorl	%eax, %eax
	movl	$0x00000000, 16(%rsp)
	movq	%rax, 24(%rsp)
	movq	%rax, 32(%rsp)
	movq	%rax, 40(%rsp)
	movl	$268435457, %eax
	salq	$4, %rax
	movl	$0x00000000, 20(%rsp)
	movq	%rax, 80(%rsp)
	movl	$1, 88(%rsp)
	movq	%rax, 92(%rsp)
	movl	$1, 100(%rsp)
	call	cudaEventCreate@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	72(%rsp), %rdi
	call	cudaEventCreate@PLT
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	leaq	.LC2(%rip), %rdx
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L32
	salq	$2, %rbp
	leaq	32(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L18
.L33:
	leaq	.LC3(%rip), %rdx
.L32:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L17
.L18:
	movq	32(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L35
	leaq	40(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L33
	movq	40(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L21
.L35:
	leaq	.LC4(%rip), %rdx
	jmp	.L32
.L21:
	leaq	24(%rsp), %rdi
	movl	$1024, %esi
	call	cudaMalloc@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L33
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movl	$1024, %edx
	movq	%r15, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L34
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	88(%rsp), %ecx
	movl	100(%rsp), %esi
	xorl	%r9d, %r9d
	movq	80(%rsp), %rdx
	movq	92(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z38__device_stub__Z15naivehistKernelPiPKiPiPKi
.L24:
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	call	cudaThreadSynchronize@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	88(%rsp), %ecx
	movl	100(%rsp), %esi
	xorl	%r9d, %r9d
	movq	80(%rsp), %rdx
	movq	92(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	24(%rsp), %rsi
	movq	40(%rsp), %rdi
	call	_Z39__device_stub__Z16sharedhistKernelPiPKiPiPKi
.L25:
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L26
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC6(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L17
.L26:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L27
	movq	stderr(%rip), %rdi
	movl	%eax, %ecx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC7(%rip), %rdx
	call	__fprintf_chk@PLT
	jmp	.L17
.L27:
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdx
	movq	%r14, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L34
	movq	40(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	$2, %ecx
	movq	%rbp, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L29
.L34:
	leaq	.LC5(%rip), %rdx
	jmp	.L32
.L29:
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	16(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	leaq	20(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movss	16(%rsp), %xmm0
	movss	%xmm0, 0(%r13)
	movss	20(%rsp), %xmm0
	movss	%xmm0, (%r12)
.L17:
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebx, %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
.LFE5214:
	.size	_Z13histogramCudaPiS_PKiiRfS2_, .-_Z13histogramCudaPiS_PKiiRfS2_
	.section	.rodata.str1.1
.LC8:
	.string	"histogramCuda failed!"
.LC9:
	.string	"Histogram GPU Implementation"
.LC10:
	.string	"Execution Time : "
.LC12:
	.string	" seconds"
.LC13:
	.string	"Effective Bandwidth : "
.LC15:
	.string	" GB/s"
.LC16:
	.string	"Histogram Shared Memory GPU Implementation"
.LC17:
	.string	"cudaDeviceReset failed!"
	.section	.rodata
	.align 32
.LC0:
	.long	1
	.long	9
	.long	0
	.long	6
	.long	10
	.long	1
	.long	2
	.long	4
	.long	6
	.long	9
	.long	9
	.long	5
	.long	10
	.long	10
	.long	8
	.long	3
	.long	7
	.long	7
	.long	5
	.long	0
	.long	4
	.long	8
	.long	5
	.long	10
	.long	0
	.long	8
	.long	9
	.long	10
	.long	10
	.long	5
	.long	1
	.long	0
	.long	0
	.long	3
	.long	10
	.long	5
	.long	4
	.long	3
	.long	5
	.long	1
	.long	4
	.long	4
	.long	1
	.long	8
	.long	1
	.long	6
	.long	10
	.long	3
	.long	0
	.long	2
	.long	5
	.long	7
	.long	10
	.long	4
	.long	1
	.long	6
	.long	6
	.long	5
	.long	4
	.long	0
	.long	5
	.long	0
	.long	4
	.long	4
	.long	4
	.long	1
	.long	4
	.long	6
	.long	8
	.long	9
	.long	0
	.long	0
	.long	9
	.long	4
	.long	10
	.long	10
	.long	10
	.long	1
	.long	4
	.long	9
	.long	0
	.long	1
	.long	7
	.long	9
	.long	7
	.long	10
	.long	10
	.long	0
	.long	5
	.long	9
	.long	1
	.long	6
	.long	7
	.long	0
	.long	3
	.long	9
	.long	8
	.long	5
	.long	4
	.long	8
	.long	4
	.long	1
	.long	0
	.long	6
	.long	9
	.long	2
	.long	1
	.long	2
	.long	3
	.long	6
	.long	10
	.long	6
	.long	4
	.long	9
	.long	6
	.long	0
	.long	2
	.long	6
	.long	2
	.long	6
	.long	3
	.long	8
	.long	6
	.long	0
	.long	2
	.long	2
	.long	1
	.long	1
	.long	3
	.long	10
	.long	6
	.long	7
	.long	4
	.long	5
	.long	3
	.long	8
	.long	4
	.long	9
	.long	5
	.long	9
	.long	7
	.long	9
	.long	5
	.long	8
	.long	9
	.long	6
	.long	8
	.long	8
	.long	7
	.long	10
	.long	10
	.long	7
	.long	9
	.long	6
	.long	3
	.long	7
	.long	5
	.long	3
	.long	8
	.long	10
	.long	2
	.long	5
	.long	8
	.long	6
	.long	9
	.long	1
	.long	1
	.long	2
	.long	3
	.long	7
	.long	7
	.long	8
	.long	2
	.long	2
	.long	10
	.long	5
	.long	7
	.long	3
	.long	9
	.long	4
	.long	1
	.long	9
	.long	7
	.long	7
	.long	6
	.long	9
	.long	3
	.long	5
	.long	8
	.long	8
	.long	8
	.long	2
	.long	7
	.long	2
	.long	7
	.long	6
	.long	1
	.long	6
	.long	8
	.long	7
	.long	10
	.long	1
	.long	2
	.long	6
	.long	5
	.long	6
	.long	1
	.long	0
	.long	6
	.long	8
	.long	9
	.long	6
	.long	1
	.long	9
	.long	10
	.long	4
	.long	1
	.long	7
	.long	1
	.long	8
	.long	5
	.long	0
	.long	9
	.long	10
	.long	5
	.long	6
	.long	2
	.long	9
	.long	6
	.long	3
	.long	10
	.long	0
	.long	0
	.long	6
	.long	1
	.long	8
	.long	7
	.long	0
	.long	6
	.long	2
	.long	3
	.long	10
	.long	1
	.long	1
	.long	10
	.long	10
	.long	5
	.long	6
	.long	9
	.long	0
	.long	2
	.long	8
	.long	5
	.long	5
	.long	10
	.long	4
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB5213:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rsi
	movl	$256, %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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	_ZSt4cout(%rip), %rbx
	subq	$1160, %rsp
	.cfi_def_cfa_offset 1216
	movq	%fs:40, %rax
	movq	%rax, 1144(%rsp)
	xorl	%eax, %eax
	leaq	120(%rsp), %rdi
	leaq	76(%rsp), %r14
	movl	$0x00000000, 24(%rsp)
	rep movsl
	leaq	32(%rsp), %rdi
	movl	$11, %ecx
	leaq	32(%rsp), %r12
	leaq	120(%rsp), %rdx
	leaq	28(%rsp), %r9
	movq	%r14, %rsi
	movl	$0x00000000, 28(%rsp)
	leaq	24(%rsp), %r8
	rep stosl
	leaq	76(%rsp), %rdi
	movl	$11, %ecx
	rep stosl
	movl	$11, %ecx
	movq	%r12, %rdi
	call	_Z13histogramCudaPiS_PKiiRfS2_
	testl	%eax, %eax
	je	.L37
	movq	stderr(%rip), %rdi
	leaq	.LC8(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	jmp	.L50
.L37:
	movq	(%rbx), %rax
	movq	-24(%rax), %r13
	addq	%rbx, %r13
	movq	%r13, %rdi
	call	_ZSt4leftRSt8ios_base
	movq	$5, 16(%r13)
	movl	%ebp, %esi
	movq	%rbx, %rdi
	call	_ZNSolsEi@PLT
	movq	(%rbx), %rax
	movl	(%r12,%rbp,4), %esi
	movq	%rbx, %rdi
	incq	%rbp
	movq	-24(%rax), %rax
	movq	$5, 16(%rbx,%rax)
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	cmpq	$11, %rbp
	jne	.L37
	leaq	.LC9(%rip), %rsi
	movq	%rbx, %rdi
	leaq	.LC10(%rip), %r13
	xorl	%ebp, %ebp
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	leaq	.LC12(%rip), %r12
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%r13, %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	24(%rsp), %xmm1
	divss	.LC11(%rip), %xmm1
	cvtss2sd	%xmm1, %xmm0
	movq	%rax, %rdi
	movss	%xmm1, 12(%rsp)
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC13(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	12(%rsp), %xmm1
	movss	.LC14(%rip), %xmm0
	movq	%rax, %rdi
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC15(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L39:
	movq	(%rbx), %rax
	movq	-24(%rax), %r15
	addq	%rbx, %r15
	movq	%r15, %rdi
	call	_ZSt4leftRSt8ios_base
	movq	$5, 16(%r15)
	movl	%ebp, %esi
	movq	%rbx, %rdi
	call	_ZNSolsEi@PLT
	movq	(%rbx), %rax
	movl	(%r14,%rbp,4), %esi
	movq	%rbx, %rdi
	incq	%rbp
	movq	-24(%rax), %rax
	movq	$5, 16(%rbx,%rax)
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	cmpq	$11, %rbp
	jne	.L39
	leaq	.LC16(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%r13, %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	28(%rsp), %xmm1
	divss	.LC11(%rip), %xmm1
	cvtss2sd	%xmm1, %xmm0
	movq	%rax, %rdi
	movss	%xmm1, 12(%rsp)
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC13(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	12(%rsp), %xmm1
	movss	.LC14(%rip), %xmm0
	movq	%rax, %rdi
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC15(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	call	cudaDeviceReset@PLT
	movl	%eax, %edx
	xorl	%eax, %eax
	testl	%edx, %edx
	je	.L36
	movq	stderr(%rip), %rdi
	leaq	.LC17(%rip), %rdx
	movl	$2, %esi
.L50:
	call	__fprintf_chk@PLT
	movl	$1, %eax
.L36:
	movq	1144(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L41
	call	__stack_chk_fail@PLT
.L41:
	addq	$1160, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5213:
	.size	main, .-main
	.section	.rodata.str1.1
.LC19:
	.string	"_Z16sharedhistKernelPiPKi"
.LC20:
	.string	"_Z15naivehistKernelPiPKi"
.LC21:
	.string	"precalc_xorwow_matrix"
.LC22:
	.string	"precalc_xorwow_offset_matrix"
.LC23:
	.string	"mrg32k3aM1"
.LC24:
	.string	"mrg32k3aM2"
.LC25:
	.string	"mrg32k3aM1SubSeq"
.LC26:
	.string	"mrg32k3aM2SubSeq"
.LC27:
	.string	"mrg32k3aM1Seq"
.LC28:
	.string	"mrg32k3aM2Seq"
.LC29:
	.string	"__cr_lgamma_table"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB5244:
	.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	.LC19(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z16sharedhistKernelPiPKi(%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	.LC20(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z15naivehistKernelPiPKi(%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	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC21(%rip), %rdx
	movl	$102400, %r9d
	leaq	_ZL21precalc_xorwow_matrix(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC22(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$102400, %r9d
	leaq	_ZL28precalc_xorwow_offset_matrix(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC23(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM1(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC24(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM2(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC25(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM1SubSeq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC26(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM2SubSeq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC27(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM1Seq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC28(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM2Seq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC29(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$72, %r9d
	movq	%rdx, %rcx
	leaq	_ZL17__cr_lgamma_table(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.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
.LFE5244:
	.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
	.local	_ZL17__cr_lgamma_table
	.comm	_ZL17__cr_lgamma_table,72,32
	.local	_ZL13mrg32k3aM2Seq
	.comm	_ZL13mrg32k3aM2Seq,2304,32
	.local	_ZL13mrg32k3aM1Seq
	.comm	_ZL13mrg32k3aM1Seq,2304,32
	.local	_ZL16mrg32k3aM2SubSeq
	.comm	_ZL16mrg32k3aM2SubSeq,2016,32
	.local	_ZL16mrg32k3aM1SubSeq
	.comm	_ZL16mrg32k3aM1SubSeq,2016,32
	.local	_ZL10mrg32k3aM2
	.comm	_ZL10mrg32k3aM2,2304,32
	.local	_ZL10mrg32k3aM1
	.comm	_ZL10mrg32k3aM1,2304,32
	.local	_ZL28precalc_xorwow_offset_matrix
	.comm	_ZL28precalc_xorwow_offset_matrix,102400,32
	.local	_ZL21precalc_xorwow_matrix
	.comm	_ZL21precalc_xorwow_matrix,102400,32
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC11:
	.long	1148846080
	.align 4
.LC14:
	.long	1157627904
	.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:

#ifndef __HIPCC__
#define __HIPCC__
#endif
#include "hip/hip_runtime.h"


#include <hip/device_functions.h>
#include <hip/hip_runtime_api.h>
#include <hiprand/hiprand.h>
#include <hiprand/hiprand_kernel.h>

#include <math.h>
#include <stdio.h>
#include <random>
#include <iomanip>
#include <iostream>

#define N 256
#define BLOCKSIZE 16

hipError_t histogramCuda(int *freq, int *freq2, const int *vals, int bin, float &time, float &shared_time);

__global__ void naivehistKernel(int *freq, const int *vals) {
    unsigned int id = blockIdx.x * blockDim.x + threadIdx.x;
    atomicAdd(&freq[vals[id]], 1);
}

__global__ void sharedhistKernel(int *freq, const int *vals) {
    __shared__ int temp[BLOCKSIZE];
	unsigned int tid = threadIdx.x;
    temp[tid] = 0;
    __syncthreads();

    unsigned int id = blockIdx.x * blockDim.x + threadIdx.x;
    atomicAdd(&temp[vals[id]], 1);
    __syncthreads();

    atomicAdd(&(freq[tid]), temp[tid]);
}

int main() {
    const int bin = 10 + 1;
	const int vals[N] = {1,9,0,6,10,1,2,4,6,9,9,5,10,10,8,3,
							7,7,5,0,4,8,5,10,0,8,9,10,10,5,1,0,
							0,3,10,5,4,3,5,1,4,4,1,8,1,6,10,3,
							0,2,5,7,10,4,1,6,6,5,4,0,5,0,4,4,
							4,1,4,6,8,9,0,0,9,4,10,10,10,1,4,9,
							0,1,7,9,7,10,10,0,5,9,1,6,7,0,3,9,
							8,5,4,8,4,1,0,6,9,2,1,2,3,6,10,6,
							4,9,6,0,2,6,2,6,3,8,6,0,2,2,1,1,
							3,10,6,7,4,5,3,8,4,9,5,9,7,9,5,8,
							9,6,8,8,7,10,10,7,9,6,3,7,5,3,8,10,
							2,5,8,6,9,1,1,2,3,7,7,8,2,2,10,5,
							7,3,9,4,1,9,7,7,6,9,3,5,8,8,8,2,
							7,2,7,6,1,6,8,7,10,1,2,6,5,6,1,0,
							6,8,9,6,1,9,10,4,1,7,1,8,5,0,9,10,
							5,6,2,9,6,3,10,0,0,6,1,8,7,0,6,2,
							3,10,1,1,10,10,5,6,9,0,2,8,5,5,10,4};
	int freq[bin] = { 0 };
	int freq2[bin] = { 0 };
	float time = 0.0f;
	float shared_time = 0.0f;

    hipError_t cudaStatus = histogramCuda(freq, freq2, vals, bin, time, shared_time);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "histogramCuda failed!");
        return 1;
    }

	for(int i = 0; i < bin; i++) {
       std::cout << std::left;
       std::cout << std::setw(5) << i;
       std::cout << std::setw(5) << freq[i];
       std::cout << std::endl;
	}

	std::cout << "Histogram GPU Implementation" << std::endl;
	std::cout << "Execution Time : " << time / 1000 << " seconds" << std::endl;
	std::cout << "Effective Bandwidth : " << (N*sizeof(int)*2) / (time / 1000) << " GB/s" << std::endl;
	std::cout << std::endl;

	for(int i = 0; i < bin; i++) {
       std::cout << std::left;
       std::cout << std::setw(5) << i;
       std::cout << std::setw(5) << freq2[i];
       std::cout << std::endl;
	}

	std::cout << "Histogram Shared Memory GPU Implementation" << std::endl;
	std::cout << "Execution Time : " << shared_time / 1000 << " seconds" << std::endl;
	std::cout << "Effective Bandwidth : " << (N*sizeof(int)*2) / (shared_time / 1000) << " GB/s" << std::endl;
	std::cout << std::endl;

	cudaStatus = hipDeviceReset();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipDeviceReset failed!");
        return 1;
    }

    return 0;
}

hipError_t histogramCuda(int *freq, int *freq2, const int *vals, int bin, float &time, float &shared_time) {
    int *dev_vals = 0;
    int *dev_freq = 0;
	int *dev_freq2 = 0;
	float milliseconds = 0.0f;
	float milliseconds1 = 0.0f;
    hipError_t cudaStatus;
	dim3 dimBlock(BLOCKSIZE);
    dim3 dimGrid(N/BLOCKSIZE);
	hipEvent_t start, stop;
	hipEvent_t start1, stop1;
	hipEventCreate(&start);
	hipEventCreate(&stop);
	hipEventCreate(&start1);
	hipEventCreate(&stop1);

    cudaStatus = hipSetDevice(0);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipSetDevice failed!  Do you have a CUDA-capable GPU installed?");
        goto Error;
    }

    cudaStatus = hipMalloc((void**)&dev_freq, bin * sizeof(int));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
        goto Error;
    }

	cudaStatus = hipMemset(dev_freq, 0, bin * sizeof(int));
	if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemset failed!");
        goto Error;
    }

	cudaStatus = hipMalloc((void**)&dev_freq2, bin * sizeof(int));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
        goto Error;
    }

	cudaStatus = hipMemset(dev_freq2, 0, bin * sizeof(int));
	if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemset failed!");
        goto Error;
    }

    cudaStatus = hipMalloc((void**)&dev_vals, N * sizeof(int));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
        goto Error;
    }

    cudaStatus = hipMemcpy(dev_vals, vals, N * sizeof(int), hipMemcpyHostToDevice);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
        goto Error;
    }

	hipEventRecord(start);
    naivehistKernel<<<dimGrid, dimBlock>>>(dev_freq, dev_vals);
	hipEventRecord(stop);
	hipEventSynchronize(stop);

	hipDeviceSynchronize();

	hipEventRecord(start1);
    sharedhistKernel<<<dimGrid, dimBlock>>>(dev_freq2, dev_vals);
	hipEventRecord(stop1);
	hipEventSynchronize(stop1);

    cudaStatus = hipGetLastError();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "histKernel launch failed: %s\n", hipGetErrorString(cudaStatus));
        goto Error;
    }
    
    cudaStatus = hipDeviceSynchronize();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipDeviceSynchronize returned error code %d after launching histKernel!\n", cudaStatus);
        goto Error;
    }

    cudaStatus = hipMemcpy(freq, dev_freq, bin * sizeof(int), hipMemcpyDeviceToHost);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
        goto Error;
    }

	cudaStatus = hipMemcpy(freq2, dev_freq2, bin * sizeof(int), hipMemcpyDeviceToHost);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
        goto Error;
    }

	hipEventElapsedTime(&milliseconds, start, stop);
	hipEventElapsedTime(&milliseconds1, start1, stop1);
	time = milliseconds;
	shared_time = milliseconds1;

Error:
    hipFree(dev_freq);
	hipFree(dev_freq2);
    hipFree(dev_vals);
    
    return cudaStatus;
}

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

                                        # End of file scope inline assembly
	.globl	_Z30__device_stub__naivehistKernelPiPKi # -- Begin function _Z30__device_stub__naivehistKernelPiPKi
	.type	_Z30__device_stub__naivehistKernelPiPKi,@function
_Z30__device_stub__naivehistKernelPiPKi: # @_Z30__device_stub__naivehistKernelPiPKi
	.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	$_Z15naivehistKernelPiPKi, %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	_Z30__device_stub__naivehistKernelPiPKi, .Lfunc_end0-_Z30__device_stub__naivehistKernelPiPKi
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__sharedhistKernelPiPKi # -- Begin function _Z31__device_stub__sharedhistKernelPiPKi
	.type	_Z31__device_stub__sharedhistKernelPiPKi,@function
_Z31__device_stub__sharedhistKernelPiPKi: # @_Z31__device_stub__sharedhistKernelPiPKi
	.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	$_Z16sharedhistKernelPiPKi, %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	_Z31__device_stub__sharedhistKernelPiPKi, .Lfunc_end1-_Z31__device_stub__sharedhistKernelPiPKi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x447a0000                      # float 1000
.LCPI2_1:
	.long	0x45000000                      # float 2048
	.text
	.globl	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	%rbx
	.cfi_def_cfa_offset 40
	subq	$1144, %rsp                     # imm = 0x478
	.cfi_def_cfa_offset 1184
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	112(%rsp), %rbx
	movl	$.L__const.main.vals, %esi
	movl	$1024, %edx                     # imm = 0x400
	movq	%rbx, %rdi
	callq	memcpy@PLT
	xorps	%xmm0, %xmm0
	leaq	64(%rsp), %rdi
	movups	%xmm0, 28(%rdi)
	movaps	%xmm0, 16(%rdi)
	movaps	%xmm0, (%rdi)
	leaq	16(%rsp), %rsi
	movups	%xmm0, 28(%rsi)
	movaps	%xmm0, 16(%rsi)
	movaps	%xmm0, (%rsi)
	xorl	%eax, %eax
	leaq	12(%rsp), %r8
	movl	%eax, (%r8)
	leaq	8(%rsp), %r9
	movl	%eax, (%r9)
	movq	%rbx, %rdx
	movl	$11, %ecx
	callq	_Z13histogramCudaPiS_PKiiRfS2_
	testl	%eax, %eax
	jne	.LBB2_9
# %bb.1:                                # %.preheader.preheader
	xorl	%ebx, %ebx
	movl	$_ZSt4cout, %r14d
	movl	$-177, %ebp
	movl	$5, %r15d
.LBB2_2:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rcx
	movl	_ZSt4cout+24(%rcx), %edx
	andl	%ebp, %edx
	orl	$32, %edx
	movl	%edx, _ZSt4cout+24(%rcx)
	movq	-24(%rax), %rax
	movq	%r15, _ZSt4cout+16(%rax)
	movl	$_ZSt4cout, %edi
	movl	%ebx, %esi
	callq	_ZNSolsEi
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	movq	%r15, _ZSt4cout+16(%rax)
	movl	64(%rsp,%rbx,4), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	incq	%rbx
	cmpq	$11, %rbx
	jne	.LBB2_2
# %bb.3:
	movl	$_ZSt4cout, %r14d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$28, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$17, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	divss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.3, %esi
	movl	$8, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$22, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movss	.LCPI2_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	4(%rsp), %xmm0                  # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$5, %r15d
	movl	$.L.str.5, %esi
	movl	$5, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorl	%ebx, %ebx
	movl	$-177, %ebp
.LBB2_4:                                # =>This Inner Loop Header: Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rcx
	movl	_ZSt4cout+24(%rcx), %edx
	andl	%ebp, %edx
	orl	$32, %edx
	movl	%edx, _ZSt4cout+24(%rcx)
	movq	-24(%rax), %rax
	movq	%r15, _ZSt4cout+16(%rax)
	movl	$_ZSt4cout, %edi
	movl	%ebx, %esi
	callq	_ZNSolsEi
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	movq	%r15, _ZSt4cout+16(%rax)
	movl	16(%rsp,%rbx,4), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	incq	%rbx
	cmpq	$11, %rbx
	jne	.LBB2_4
# %bb.5:
	movl	$_ZSt4cout, %r14d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$42, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$17, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movss	8(%rsp), %xmm0                  # xmm0 = mem[0],zero,zero,zero
	divss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.3, %esi
	movl	$8, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$22, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movss	.LCPI2_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	4(%rsp), %xmm0                  # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.5, %esi
	movl	$5, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	callq	hipDeviceReset
	movl	%eax, %ecx
	xorl	%eax, %eax
	testl	%ecx, %ecx
	jne	.LBB2_6
.LBB2_8:
	addq	$1144, %rsp                     # imm = 0x478
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
.LBB2_9:
	.cfi_def_cfa_offset 1184
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$21, %esi
	jmp	.LBB2_7
.LBB2_6:
	movq	stderr(%rip), %rcx
	movl	$.L.str.7, %edi
	movl	$22, %esi
.LBB2_7:
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %eax
	jmp	.LBB2_8
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z13histogramCudaPiS_PKiiRfS2_  # -- Begin function _Z13histogramCudaPiS_PKiiRfS2_
	.type	_Z13histogramCudaPiS_PKiiRfS2_,@function
_Z13histogramCudaPiS_PKiiRfS2_:         # @_Z13histogramCudaPiS_PKiiRfS2_
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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, 64(%rsp)                   # 8-byte Spill
	movq	%r8, %r14
	movl	%ecx, %r13d
	movq	%rdx, %rbx
	movq	%rsi, %r15
	movq	%rdi, %r12
	xorl	%eax, %eax
	movq	%rax, 16(%rsp)
	movq	%rax, 8(%rsp)
	movq	%rax, (%rsp)
	movl	%eax, 44(%rsp)
	movl	%eax, 40(%rsp)
	leaq	56(%rsp), %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	leaq	48(%rsp), %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB3_1
# %bb.2:
	movslq	%r13d, %r13
	shlq	$2, %r13
	leaq	8(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_3
# %bb.6:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	movq	%r13, %rdx
	callq	hipMemset
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.8:
	movq	%rsp, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_3
# %bb.9:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	movq	%r13, %rdx
	callq	hipMemset
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.10:
	leaq	16(%rsp), %rdi
	movl	$1024, %esi                     # imm = 0x400
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_3
# %bb.11:
	movq	16(%rsp), %rdi
	movl	$1024, %edx                     # imm = 0x400
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_12
# %bb.13:
	movabsq	$4294967312, %rbx               # imm = 0x100000010
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_15
# %bb.14:
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	callq	_Z30__device_stub__naivehistKernelPiPKi
.LBB3_15:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	callq	hipDeviceSynchronize
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_17
# %bb.16:
	movq	(%rsp), %rdi
	movq	16(%rsp), %rsi
	callq	_Z31__device_stub__sharedhistKernelPiPKi
.LBB3_17:
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	24(%rsp), %rdi
	callq	hipEventSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB3_18
# %bb.19:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_20
# %bb.21:
	movq	8(%rsp), %rsi
	movq	%r12, %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_12
# %bb.22:
	movq	(%rsp), %rsi
	movq	%r15, %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_12
# %bb.23:
	movq	56(%rsp), %rsi
	movq	32(%rsp), %rdx
	leaq	44(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	movq	48(%rsp), %rsi
	movq	24(%rsp), %rdx
	leaq	40(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movss	(%rbx), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%r14)
	movss	(%r15), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movq	64(%rsp), %rax                  # 8-byte Reload
	movss	%xmm0, (%rax)
	xorl	%ebp, %ebp
	jmp	.LBB3_24
.LBB3_3:
	movl	%eax, %ebp
	movq	stderr(%rip), %rcx
	movl	$.L.str.9, %edi
	jmp	.LBB3_4
.LBB3_12:
	movl	%eax, %ebp
	movq	stderr(%rip), %rcx
	movl	$.L.str.11, %edi
	jmp	.LBB3_4
.LBB3_7:
	movl	%eax, %ebp
	movq	stderr(%rip), %rcx
	movl	$.L.str.10, %edi
.LBB3_4:
	movl	$17, %esi
.LBB3_5:
	movl	$1, %edx
	callq	fwrite@PLT
.LBB3_24:
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	%ebp, %eax
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_1:
	.cfi_def_cfa_offset 128
	movl	%eax, %ebp
	movq	stderr(%rip), %rcx
	movl	$.L.str.8, %edi
	movl	$63, %esi
	jmp	.LBB3_5
.LBB3_18:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_24
.LBB3_20:
	movl	%eax, %ebp
	movq	stderr(%rip), %rdi
	movl	$.L.str.13, %esi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_24
.Lfunc_end3:
	.size	_Z13histogramCudaPiS_PKiiRfS2_, .Lfunc_end3-_Z13histogramCudaPiS_PKiiRfS2_
	.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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15naivehistKernelPiPKi, %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	$_Z16sharedhistKernelPiPKi, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z15naivehistKernelPiPKi,@object # @_Z15naivehistKernelPiPKi
	.section	.rodata,"a",@progbits
	.globl	_Z15naivehistKernelPiPKi
	.p2align	3, 0x0
_Z15naivehistKernelPiPKi:
	.quad	_Z30__device_stub__naivehistKernelPiPKi
	.size	_Z15naivehistKernelPiPKi, 8

	.type	_Z16sharedhistKernelPiPKi,@object # @_Z16sharedhistKernelPiPKi
	.globl	_Z16sharedhistKernelPiPKi
	.p2align	3, 0x0
_Z16sharedhistKernelPiPKi:
	.quad	_Z31__device_stub__sharedhistKernelPiPKi
	.size	_Z16sharedhistKernelPiPKi, 8

	.type	.L__const.main.vals,@object     # @__const.main.vals
	.p2align	4, 0x0
.L__const.main.vals:
	.long	1                               # 0x1
	.long	9                               # 0x9
	.long	0                               # 0x0
	.long	6                               # 0x6
	.long	10                              # 0xa
	.long	1                               # 0x1
	.long	2                               # 0x2
	.long	4                               # 0x4
	.long	6                               # 0x6
	.long	9                               # 0x9
	.long	9                               # 0x9
	.long	5                               # 0x5
	.long	10                              # 0xa
	.long	10                              # 0xa
	.long	8                               # 0x8
	.long	3                               # 0x3
	.long	7                               # 0x7
	.long	7                               # 0x7
	.long	5                               # 0x5
	.long	0                               # 0x0
	.long	4                               # 0x4
	.long	8                               # 0x8
	.long	5                               # 0x5
	.long	10                              # 0xa
	.long	0                               # 0x0
	.long	8                               # 0x8
	.long	9                               # 0x9
	.long	10                              # 0xa
	.long	10                              # 0xa
	.long	5                               # 0x5
	.long	1                               # 0x1
	.long	0                               # 0x0
	.long	0                               # 0x0
	.long	3                               # 0x3
	.long	10                              # 0xa
	.long	5                               # 0x5
	.long	4                               # 0x4
	.long	3                               # 0x3
	.long	5                               # 0x5
	.long	1                               # 0x1
	.long	4                               # 0x4
	.long	4                               # 0x4
	.long	1                               # 0x1
	.long	8                               # 0x8
	.long	1                               # 0x1
	.long	6                               # 0x6
	.long	10                              # 0xa
	.long	3                               # 0x3
	.long	0                               # 0x0
	.long	2                               # 0x2
	.long	5                               # 0x5
	.long	7                               # 0x7
	.long	10                              # 0xa
	.long	4                               # 0x4
	.long	1                               # 0x1
	.long	6                               # 0x6
	.long	6                               # 0x6
	.long	5                               # 0x5
	.long	4                               # 0x4
	.long	0                               # 0x0
	.long	5                               # 0x5
	.long	0                               # 0x0
	.long	4                               # 0x4
	.long	4                               # 0x4
	.long	4                               # 0x4
	.long	1                               # 0x1
	.long	4                               # 0x4
	.long	6                               # 0x6
	.long	8                               # 0x8
	.long	9                               # 0x9
	.long	0                               # 0x0
	.long	0                               # 0x0
	.long	9                               # 0x9
	.long	4                               # 0x4
	.long	10                              # 0xa
	.long	10                              # 0xa
	.long	10                              # 0xa
	.long	1                               # 0x1
	.long	4                               # 0x4
	.long	9                               # 0x9
	.long	0                               # 0x0
	.long	1                               # 0x1
	.long	7                               # 0x7
	.long	9                               # 0x9
	.long	7                               # 0x7
	.long	10                              # 0xa
	.long	10                              # 0xa
	.long	0                               # 0x0
	.long	5                               # 0x5
	.long	9                               # 0x9
	.long	1                               # 0x1
	.long	6                               # 0x6
	.long	7                               # 0x7
	.long	0                               # 0x0
	.long	3                               # 0x3
	.long	9                               # 0x9
	.long	8                               # 0x8
	.long	5                               # 0x5
	.long	4                               # 0x4
	.long	8                               # 0x8
	.long	4                               # 0x4
	.long	1                               # 0x1
	.long	0                               # 0x0
	.long	6                               # 0x6
	.long	9                               # 0x9
	.long	2                               # 0x2
	.long	1                               # 0x1
	.long	2                               # 0x2
	.long	3                               # 0x3
	.long	6                               # 0x6
	.long	10                              # 0xa
	.long	6                               # 0x6
	.long	4                               # 0x4
	.long	9                               # 0x9
	.long	6                               # 0x6
	.long	0                               # 0x0
	.long	2                               # 0x2
	.long	6                               # 0x6
	.long	2                               # 0x2
	.long	6                               # 0x6
	.long	3                               # 0x3
	.long	8                               # 0x8
	.long	6                               # 0x6
	.long	0                               # 0x0
	.long	2                               # 0x2
	.long	2                               # 0x2
	.long	1                               # 0x1
	.long	1                               # 0x1
	.long	3                               # 0x3
	.long	10                              # 0xa
	.long	6                               # 0x6
	.long	7                               # 0x7
	.long	4                               # 0x4
	.long	5                               # 0x5
	.long	3                               # 0x3
	.long	8                               # 0x8
	.long	4                               # 0x4
	.long	9                               # 0x9
	.long	5                               # 0x5
	.long	9                               # 0x9
	.long	7                               # 0x7
	.long	9                               # 0x9
	.long	5                               # 0x5
	.long	8                               # 0x8
	.long	9                               # 0x9
	.long	6                               # 0x6
	.long	8                               # 0x8
	.long	8                               # 0x8
	.long	7                               # 0x7
	.long	10                              # 0xa
	.long	10                              # 0xa
	.long	7                               # 0x7
	.long	9                               # 0x9
	.long	6                               # 0x6
	.long	3                               # 0x3
	.long	7                               # 0x7
	.long	5                               # 0x5
	.long	3                               # 0x3
	.long	8                               # 0x8
	.long	10                              # 0xa
	.long	2                               # 0x2
	.long	5                               # 0x5
	.long	8                               # 0x8
	.long	6                               # 0x6
	.long	9                               # 0x9
	.long	1                               # 0x1
	.long	1                               # 0x1
	.long	2                               # 0x2
	.long	3                               # 0x3
	.long	7                               # 0x7
	.long	7                               # 0x7
	.long	8                               # 0x8
	.long	2                               # 0x2
	.long	2                               # 0x2
	.long	10                              # 0xa
	.long	5                               # 0x5
	.long	7                               # 0x7
	.long	3                               # 0x3
	.long	9                               # 0x9
	.long	4                               # 0x4
	.long	1                               # 0x1
	.long	9                               # 0x9
	.long	7                               # 0x7
	.long	7                               # 0x7
	.long	6                               # 0x6
	.long	9                               # 0x9
	.long	3                               # 0x3
	.long	5                               # 0x5
	.long	8                               # 0x8
	.long	8                               # 0x8
	.long	8                               # 0x8
	.long	2                               # 0x2
	.long	7                               # 0x7
	.long	2                               # 0x2
	.long	7                               # 0x7
	.long	6                               # 0x6
	.long	1                               # 0x1
	.long	6                               # 0x6
	.long	8                               # 0x8
	.long	7                               # 0x7
	.long	10                              # 0xa
	.long	1                               # 0x1
	.long	2                               # 0x2
	.long	6                               # 0x6
	.long	5                               # 0x5
	.long	6                               # 0x6
	.long	1                               # 0x1
	.long	0                               # 0x0
	.long	6                               # 0x6
	.long	8                               # 0x8
	.long	9                               # 0x9
	.long	6                               # 0x6
	.long	1                               # 0x1
	.long	9                               # 0x9
	.long	10                              # 0xa
	.long	4                               # 0x4
	.long	1                               # 0x1
	.long	7                               # 0x7
	.long	1                               # 0x1
	.long	8                               # 0x8
	.long	5                               # 0x5
	.long	0                               # 0x0
	.long	9                               # 0x9
	.long	10                              # 0xa
	.long	5                               # 0x5
	.long	6                               # 0x6
	.long	2                               # 0x2
	.long	9                               # 0x9
	.long	6                               # 0x6
	.long	3                               # 0x3
	.long	10                              # 0xa
	.long	0                               # 0x0
	.long	0                               # 0x0
	.long	6                               # 0x6
	.long	1                               # 0x1
	.long	8                               # 0x8
	.long	7                               # 0x7
	.long	0                               # 0x0
	.long	6                               # 0x6
	.long	2                               # 0x2
	.long	3                               # 0x3
	.long	10                              # 0xa
	.long	1                               # 0x1
	.long	1                               # 0x1
	.long	10                              # 0xa
	.long	10                              # 0xa
	.long	5                               # 0x5
	.long	6                               # 0x6
	.long	9                               # 0x9
	.long	0                               # 0x0
	.long	2                               # 0x2
	.long	8                               # 0x8
	.long	5                               # 0x5
	.long	5                               # 0x5
	.long	10                              # 0xa
	.long	4                               # 0x4
	.size	.L__const.main.vals, 1024

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"histogramCuda failed!"
	.size	.L.str, 22

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Histogram GPU Implementation"
	.size	.L.str.1, 29

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Execution Time : "
	.size	.L.str.2, 18

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	" seconds"
	.size	.L.str.3, 9

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Effective Bandwidth : "
	.size	.L.str.4, 23

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	" GB/s"
	.size	.L.str.5, 6

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Histogram Shared Memory GPU Implementation"
	.size	.L.str.6, 43

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"hipDeviceReset failed!"
	.size	.L.str.7, 23

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"hipSetDevice failed!  Do you have a CUDA-capable GPU installed?"
	.size	.L.str.8, 64

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"hipMalloc failed!"
	.size	.L.str.9, 18

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"hipMemset failed!"
	.size	.L.str.10, 18

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"hipMemcpy failed!"
	.size	.L.str.11, 18

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"histKernel launch failed: %s\n"
	.size	.L.str.12, 30

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"hipDeviceSynchronize returned error code %d after launching histKernel!\n"
	.size	.L.str.13, 73

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z15naivehistKernelPiPKi"
	.size	.L__unnamed_1, 25

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z16sharedhistKernelPiPKi"
	.size	.L__unnamed_2, 26

	.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 _Z30__device_stub__naivehistKernelPiPKi
	.addrsig_sym _Z31__device_stub__sharedhistKernelPiPKi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z15naivehistKernelPiPKi
	.addrsig_sym _Z16sharedhistKernelPiPKi
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z15naivehistKernelPiPKi ; -- Begin function _Z15naivehistKernelPiPKi
	.globl	_Z15naivehistKernelPiPKi
	.p2align	8
	.type	_Z15naivehistKernelPiPKi,@function
_Z15naivehistKernelPiPKi:               ; @_Z15naivehistKernelPiPKi
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_mov_b32_e32 v2, 0
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_mov_b32_e32 v2, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_atomic_add_u32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15naivehistKernelPiPKi
		.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 3
		.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	_Z15naivehistKernelPiPKi, .Lfunc_end0-_Z15naivehistKernelPiPKi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 140
; NumSgprs: 18
; NumVgprs: 3
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 3
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z16sharedhistKernelPiPKi ; -- Begin function _Z16sharedhistKernelPiPKi
	.globl	_Z16sharedhistKernelPiPKi
	.p2align	8
	.type	_Z16sharedhistKernelPiPKi,@function
_Z16sharedhistKernelPiPKi:              ; @_Z16sharedhistKernelPiPKi
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	v_dual_mov_b32 v3, 0 :: v_dual_lshlrev_b32 v4, 2, v0
	ds_store_b32 v4, v3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_mov_b32_e32 v2, v3
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s2, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v2, vcc_lo
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(0)
	v_dual_mov_b32 v1, 1 :: v_dual_lshlrev_b32 v0, 2, v0
	ds_add_u32 v0, v1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b32 v0, v4
	s_waitcnt lgkmcnt(0)
	global_atomic_add_u32 v4, v0, s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16sharedhistKernelPiPKi
		.amdhsa_group_segment_fixed_size 64
		.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	_Z16sharedhistKernelPiPKi, .Lfunc_end1-_Z16sharedhistKernelPiPKi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 176
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 64 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
    .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:           _Z15naivehistKernelPiPKi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z15naivehistKernelPiPKi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     3
    .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
    .group_segment_fixed_size: 64
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16sharedhistKernelPiPKi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16sharedhistKernelPiPKi.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
