// To compute histogram with atomic operations */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <cuda_runtime.h>


// Variables
float* data_h;          // host vectors
unsigned int* hist_h;   // GPU solution back to the CPU 
float* data_d;          // device vectors
unsigned int* hist_d;
unsigned int* hist_c;   // CPU solution


// Functions
void RandomUniform(float*, long);
void RandomNormal(float*, long);
void RandomExpDecay(float*, long);

__global__ void hist_shmem(float *data, const long N, unsigned int *hist, 
                           const int bins, const float Rmin, const float binsize) 
{

    // use shared memory and atomic addition

    extern __shared__  unsigned int temp[];     // assume the blocksize is equal to the total # bins
    temp[threadIdx.x] = 0;
    __syncthreads();

    long i = threadIdx.x + blockIdx.x * blockDim.x;
    long stride = blockDim.x * gridDim.x;

//    if( (index > bins-1) || (index < 0)) {
//      printf("data[%d]=%f, index=%d\n",i,data[i],index);
//    }

    while (i < N) {
        int index = (int)((data[i] - Rmin) / binsize);
        atomicAdd(&temp[index], 1);
        i += stride;
    }

    __syncthreads();
    atomicAdd( &(hist[threadIdx.x]), temp[threadIdx.x] );

}


int main(void)
{

    int gid;

    // Error code to check return values for CUDA calls
    cudaError_t err = cudaSuccess;

    scanf("%d",&gid);
    err = cudaSetDevice(gid);
    if (err != cudaSuccess) {
        printf("!!! Cannot select GPU with device ID = %d\n", gid);
        exit(1);
    }
    printf("Set GPU with device ID = %d\n", gid);

    cudaSetDevice(gid);

    printf("To find the histogram of a data set (with real numbers): \n");
    long N; 
    int bins,index;
    float Rmin, Rmax, binsize;

    printf("Enter the size of the data vector: ");
    scanf("%ld",&N);
    printf("%ld\n",N);
    long size = N * sizeof(float);

    printf("Enter the data range [Rmin, Rmax] for the histogram: ");
    scanf("%f %f",&Rmin, &Rmax);
    printf("%f %f\n",Rmin, Rmax);

    printf("Enter the number of bins of the histogram: ");
    scanf("%d",&bins);
    printf("%d\n",bins);
    if(bins > 1024) {
        printf("The number of bins is set to # of threads per block < 1024 ! \n");
        exit(0);
    }
    int bsize = bins*sizeof(int);
    binsize = (Rmax - Rmin)/(float)bins;
     
    data_h = (float*)malloc(size);
    hist_h = (unsigned int*)malloc(bsize);

    // Check memory allocations
    if(data_h == NULL || hist_h == NULL)
    {
        fprintf(stderr, "Failed to allocate host vectors!\n");
        exit(EXIT_FAILURE);
    }

    for(int i=0; i<bins; i++){
        hist_h[i]=0;
    }

    // initialize the data_h vector
    // srand(time(NULL));  // initialize the seed with the current time
    srand(12345);  

//    RandomUniform(data_h, N);      // uniform deviate in (0,1)
    RandomExpDecay(data_h, N);       

    int threadsPerBlock;
    printf("Enter the number of threads per block: ");
    scanf("%d",&threadsPerBlock);
    printf("%d\n",threadsPerBlock);
    if( threadsPerBlock != bins ) {
        printf("The number of threads per block must be equal to the number of bins ! \n");
        exit(0);
    }
    fflush(stdout);

    int blocksPerGrid;
    printf("Enter the number of blocks per grid: ");
    scanf("%d",&blocksPerGrid);
    printf("%d\n",blocksPerGrid);
    if( blocksPerGrid > 2147483647 ) {
        printf("The number of blocks must be less than 2147483647 ! \n");
        exit(0);
    }
    printf("The number of blocks is %d\n", blocksPerGrid);
    fflush(stdout);

    int CPU;
    printf("To compute the histogram with CPU (1/0) ? ");
    scanf("%d",&CPU);
    printf("%d\n",CPU);
    fflush(stdout);


    // create the timer
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);

    // start the timer
    cudaEventRecord(start,0);

    // Allocate vectors in device memory

    cudaMalloc((void**)&hist_d, bsize);
    cudaMalloc((void**)&data_d, size);

    // Copy vectors from host memory to device memory

    cudaMemcpy(data_d, data_h, size, cudaMemcpyHostToDevice);
    cudaMemcpy(hist_d, hist_h, bsize, cudaMemcpyHostToDevice);

    // stop the timer
    cudaEventRecord(stop,0);
    cudaEventSynchronize(stop);

    float Intime;
    cudaEventElapsedTime( &Intime, start, stop);
    printf("Input time for GPU: %f (ms) \n",Intime);

   // start the timer
    cudaEventRecord(start,0);
    
    int sm = threadsPerBlock * sizeof(int);

    hist_shmem <<< blocksPerGrid, threadsPerBlock, sm >>> (data_d, N, hist_d, bins, Rmin, binsize);

    // stop the timer
    cudaEventRecord(stop,0);
    cudaEventSynchronize(stop);

    float gputime;
    cudaEventElapsedTime( &gputime, start, stop);
    printf("Processing time for GPU: %f (ms) \n",gputime);
    printf("GPU Gflops: %f\n",2*N/(1000000.0*gputime));

    // Copy result from device memory to host memory
    // hist_h contains the result in host memory

    // start the timer
    cudaEventRecord(start,0);

    cudaMemcpy(hist_h, hist_d, bsize, cudaMemcpyDeviceToHost);

    cudaFree(data_d);
    cudaFree(hist_d);

    // stop the timer
    cudaEventRecord(stop,0);
    cudaEventSynchronize(stop);

    float Outime;
    cudaEventElapsedTime( &Outime, start, stop);
    printf("Output time for GPU: %f (ms) \n", Outime);

    float gputime_tot;
    gputime_tot = Intime + gputime + Outime;
    printf("Total time for GPU: %f (ms) \n", gputime_tot);

    // Save histogram in file
    FILE *out;
    out = fopen("hist_shmem.dat","w");

    fprintf(out, "Histogram (GPU):\n");
    for(int i=0; i<bins; i++) {
        float x = Rmin + (i + 0.5) * binsize;         // the center of each bin
        fprintf(out,"%f %d \n",x,hist_h[i]);
    }
    fclose(out);

    // Print the histogram on screen
    printf("Histogram (GPU):\n");
    for(int i = 0; i < bins; i = i+1) {
      float x = Rmin + (i + 0.5) * binsize;         // the center of each bin
      printf("%f %d\n", x, hist_h[i]);
    }

    if(CPU==0) {
      cudaEventDestroy(start);
      cudaEventDestroy(stop);
      cudaDeviceReset();
      free(data_h);
      free(hist_h);
      return 0;
    }

    // To compute the CPU reference solution 

    hist_c = (unsigned int*)malloc(bsize);
    for(int i = 0; i < bins; i = i+1){
        hist_c[i] = 0;
    }

    // start the timer
    cudaEventRecord(start,0);

    for(int i = 0; i < N; i = i+1) {
        index = (int)((data_h[i] - Rmin) / binsize);
        if( (index > bins - 1) || (index < 0)) {
            printf("data[%d]=%f, index=%d\n",i,data_h[i],index);
            exit(0);
        } 
        hist_c[index]++;
    }

    // stop the timer
    cudaEventRecord(stop,0);
    cudaEventSynchronize(stop);

    float cputime;
    cudaEventElapsedTime( &cputime, start, stop);
    printf("Processing time for CPU: %f (ms) \n",cputime);
    printf("CPU Gflops: %f\n",2*N/(1000000.0*cputime));
    printf("Speed up of GPU = %f\n", cputime/(gputime_tot));

    // destroy the timer
    cudaEventDestroy(start);
    cudaEventDestroy(stop);

    // check histogram sum equal to the total number of data 

    int sum = 0;
    for(int i = 0; i < bins; i = i+1) {
        sum += hist_c[i];
    }
    if(sum != N) {
        printf("Error, sum = %d\n",sum);
        exit(0);
    }

    // compare histograms from CPU and GPU

    for (int i = 0; i < bins; i++) {
        if(hist_h[i] != hist_c[i]) {
            printf("i=%d, hist_h=%d, hist_c=%d \n", i, hist_h[i], hist_c[i]);
        }
    }

    // save histogram in file
    FILE *out1;            
    out1 = fopen("hist_cpu.dat","w");

    fprintf(out1, "Histogram (CPU):\n");
    for(int i=0; i<bins; i++) {
        float x=Rmin+(i+0.5)*binsize;         // the center of each bin
        fprintf(out1,"%f %d \n",x,hist_c[i]);
    }
    fclose(out1);

    printf("Histogram (CPU):\n");
    for(int i=0; i<bins; i++) {
      float x=Rmin+(i+0.5)*binsize;         // the center of each bin
      printf("%f %d \n",x,hist_c[i]);
    }

    cudaDeviceReset();

    free(data_h);
    free(hist_h);
    free(hist_c);

    return 0;
}


void RandomUniform(float* data, long n)   // RNG with uniform distribution in (0,1)
{
    for(long i = 0; i < n; i++){
        data[i] = rand()/(float)RAND_MAX;
    }
}

void RandomNormal(float* data, long n)   // RNG with normal distribution, mu=0, sigma=1
{
    const float Pi = acos(-1.0);

    for(long i = 0; i < n; i++) {
        double y = (double) rand() / (float)RAND_MAX;
        double x = -log(1.0-y);
        double z = (double) rand() / (float)RAND_MAX;
        double theta = 2*Pi*z;
        data[i] = (float) (sqrt(2.0*x)*cos(theta));   
    }
}


void RandomExpDecay(float* data, long n)   // RNG with Exponential Decay
{
    for(long i = 0; i < n; i = i+1){
        double y = (double) rand() / (float) RAND_MAX;
        data[i] = (float) -log(1.0 - y);
    }
}

	.file	"tmpxft_0032ba43_00000000-6_hist_1gpu_shmem.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z13RandomUniformPfl
	.type	_Z13RandomUniformPfl, @function
_Z13RandomUniformPfl:
.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
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L3:
	cmpq	%rbp, %rbx
	jge	.L7
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L3
.L7:
	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	_Z13RandomUniformPfl, .-_Z13RandomUniformPfl
	.globl	_Z12RandomNormalPfl
	.type	_Z12RandomNormalPfl, @function
_Z12RandomNormalPfl:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
.L9:
	cmpq	%rbp, %rbx
	jge	.L12
	call	rand@PLT
	movsd	.LC2(%rip), %xmm0
	cvtsi2sdl	%eax, %xmm1
	mulsd	.LC1(%rip), %xmm1
	subsd	%xmm1, %xmm0
	call	log@PLT
	movsd	%xmm0, 8(%rsp)
	call	rand@PLT
	movsd	8(%rsp), %xmm0
	xorps	.LC3(%rip), %xmm0
	movl	%eax, %r13d
	addsd	%xmm0, %xmm0
	call	sqrt@PLT
	movsd	%xmm0, 8(%rsp)
	cvtsi2sdl	%r13d, %xmm0
	mulsd	.LC1(%rip), %xmm0
	mulsd	.LC4(%rip), %xmm0
	call	cos@PLT
	mulsd	8(%rsp), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L9
.L12:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z12RandomNormalPfl, .-_Z12RandomNormalPfl
	.globl	_Z14RandomExpDecayPfl
	.type	_Z14RandomExpDecayPfl, @function
_Z14RandomExpDecayPfl:
.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
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L14:
	cmpq	%rbp, %rbx
	jge	.L17
	call	rand@PLT
	movsd	.LC2(%rip), %xmm0
	cvtsi2sdl	%eax, %xmm1
	mulsd	.LC1(%rip), %xmm1
	subsd	%xmm1, %xmm0
	call	log@PLT
	cvtsd2ss	%xmm0, %xmm0
	xorps	.LC5(%rip), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L14
.L17:
	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	_Z14RandomExpDecayPfl, .-_Z14RandomExpDecayPfl
	.globl	_Z36__device_stub__Z10hist_shmemPflPjiffPflPjiff
	.type	_Z36__device_stub__Z10hist_shmemPflPjiffPflPjiff, @function
_Z36__device_stub__Z10hist_shmemPflPjiffPflPjiff:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movss	%xmm0, 16(%rsp)
	movss	%xmm1, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z10hist_shmemPflPjiff(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L18:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z36__device_stub__Z10hist_shmemPflPjiffPflPjiff, .-_Z36__device_stub__Z10hist_shmemPflPjiffPflPjiff
	.globl	_Z10hist_shmemPflPjiff
	.type	_Z10hist_shmemPflPjiff, @function
_Z10hist_shmemPflPjiff:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z10hist_shmemPflPjiffPflPjiff
	.cfi_endproc
.LFE2056:
	.size	_Z10hist_shmemPflPjiff, .-_Z10hist_shmemPflPjiff
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC6:
	.string	"%d"
.LC7:
	.string	"!!! Cannot select GPU with device ID = %d\n"
.LC8:
	.string	"Set GPU with device ID = %d\n"
.LC9:
	.string	"To find the histogram of a data set (with real numbers): \n"
.LC10:
	.string	"Enter the size of the data vector: "
.LC11:
	.string	"%ld"
.LC12:
	.string	"%ld\n"
.LC13:
	.string	"Enter the data range [Rmin, Rmax] for the histogram: "
.LC14:
	.string	"%f %f"
.LC15:
	.string	"%f %f\n"
.LC16:
	.string	"Enter the number of bins of the histogram: "
.LC17:
	.string	"%d\n"
.LC18:
	.string	"The number of bins is set to # of threads per block < 1024 ! \n"
.LC19:
	.string	"Failed to allocate host vectors!\n"
.LC20:
	.string	"Enter the number of threads per block: "
.LC21:
	.string	"The number of threads per block must be equal to the number of bins ! \n"
.LC22:
	.string	"Enter the number of blocks per grid: "
.LC23:
	.string	"The number of blocks is %d\n"
.LC24:
	.string	"To compute the histogram with CPU (1/0) ? "
.LC25:
	.string	"Input time for GPU: %f (ms) \n"
.LC26:
	.string	"Processing time for GPU: %f (ms) \n"
.LC28:
	.string	"GPU Gflops: %f\n"
.LC29:
	.string	"Output time for GPU: %f (ms) \n"
.LC30:
	.string	"Total time for GPU: %f (ms) \n"
.LC31:
	.string	"w"
.LC32:
	.string	"hist_shmem.dat"
.LC33:
	.string	"Histogram (GPU):\n"
.LC35:
	.string	"%f %d \n"
.LC36:
	.string	"%f %d\n"
.LC37:
	.string	"data[%d]=%f, index=%d\n"
.LC38:
	.string	"Processing time for CPU: %f (ms) \n"
.LC39:
	.string	"CPU Gflops: %f\n"
.LC40:
	.string	"Speed up of GPU = %f\n"
.LC41:
	.string	"Error, sum = %d\n"
.LC42:
	.string	"i=%d, hist_h=%d, hist_c=%d \n"
.LC43:
	.string	"hist_cpu.dat"
.LC44:
	.string	"Histogram (CPU):\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC6(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rsi
	call	__isoc23_scanf@PLT
	movl	20(%rsp), %edi
	call	cudaSetDevice@PLT
	movl	20(%rsp), %edx
	testl	%eax, %eax
	je	.L24
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L65
.L24:
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	20(%rsp), %edi
	leaq	.LC17(%rip), %r13
	call	cudaSetDevice@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	56(%rsp), %rsi
	leaq	.LC11(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movq	56(%rsp), %rdx
	leaq	.LC12(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movq	56(%rsp), %rbp
	call	__printf_chk@PLT
	leaq	32(%rsp), %rdx
	leaq	28(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC14(%rip), %rdi
	call	__isoc23_scanf@PLT
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	movb	$2, %al
	cvtss2sd	28(%rsp), %xmm0
	cvtss2sd	32(%rsp), %xmm1
	call	__printf_chk@PLT
	xorl	%eax, %eax
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	24(%rsp), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	24(%rsp), %edx
	movq	%r13, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	24(%rsp), %r14d
	cmpl	$1024, %r14d
	jle	.L25
	leaq	.LC18(%rip), %rsi
.L64:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L63:
	xorl	%edi, %edi
.L62:
	call	exit@PLT
.L25:
	movss	32(%rsp), %xmm3
	movss	28(%rsp), %xmm4
	salq	$2, %rbp
	leal	0(,%r14,4), %ebx
	movq	%rbp, %rdi
	movslq	%ebx, %rbx
	movss	%xmm3, 8(%rsp)
	movss	%xmm4, 12(%rsp)
	call	malloc@PLT
	movq	%rbx, %rdi
	movq	%rax, data_h(%rip)
	movq	%rax, %r15
	call	malloc@PLT
	movq	%rax, hist_h(%rip)
	testq	%rax, %rax
	je	.L55
	xorl	%edx, %edx
	testq	%r15, %r15
	jne	.L26
.L55:
	movq	stderr(%rip), %rdi
	leaq	.LC19(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L65:
	movl	$1, %edi
	jmp	.L62
.L26:
	cmpl	%edx, %r14d
	jle	.L66
	xorl	%esi, %esi
	movl	%esi, (%rax,%rdx,4)
	incq	%rdx
	jmp	.L26
.L66:
	movl	$12345, %edi
	call	srand@PLT
	movq	56(%rsp), %rsi
	movq	data_h(%rip), %rdi
	call	_Z14RandomExpDecayPfl
	leaq	.LC20(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	36(%rsp), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	36(%rsp), %edx
	movq	%r13, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	24(%rsp), %eax
	leaq	.LC21(%rip), %rsi
	cmpl	%eax, 36(%rsp)
	jne	.L64
	cvtsi2ssl	%r14d, %xmm1
	movss	8(%rsp), %xmm0
	subss	12(%rsp), %xmm0
	movq	stdout(%rip), %rdi
	divss	%xmm1, %xmm0
	movss	%xmm0, 8(%rsp)
	call	fflush@PLT
	leaq	.LC22(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	40(%rsp), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	40(%rsp), %edx
	movq	%r13, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	40(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC23(%rip), %rsi
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	leaq	.LC24(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	44(%rsp), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	44(%rsp), %edx
	movq	%r13, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	72(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	%rbx, %rsi
	leaq	hist_d(%rip), %rdi
	call	cudaMalloc@PLT
	movq	%rbp, %rsi
	leaq	data_d(%rip), %rdi
	call	cudaMalloc@PLT
	movq	data_h(%rip), %rsi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	data_d(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	hist_h(%rip), %rsi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	hist_d(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	leaq	48(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC25(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	48(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	36(%rsp), %r8d
	movl	40(%rsp), %edx
	movabsq	$4294967297, %rax
	movq	%rax, 96(%rsp)
	movl	100(%rsp), %ecx
	movl	%r8d, 92(%rsp)
	sall	$2, %r8d
	xorl	%r9d, %r9d
	movl	%edx, 80(%rsp)
	movq	92(%rsp), %rdx
	movslq	%r8d, %r8
	movq	%rax, 84(%rsp)
	movq	80(%rsp), %rdi
	movl	88(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L30
	movss	8(%rsp), %xmm1
	movss	28(%rsp), %xmm0
	movl	24(%rsp), %ecx
	movq	hist_d(%rip), %rdx
	movq	56(%rsp), %rsi
	movq	data_d(%rip), %rdi
	call	_Z36__device_stub__Z10hist_shmemPflPjiffPflPjiff
.L30:
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%r14d, %r14d
	leaq	.LC31(%rip), %rbp
	leaq	.LC33(%rip), %r13
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	leaq	52(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC26(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	52(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	56(%rsp), %rax
	cvtss2sd	52(%rsp), %xmm1
	mulsd	.LC27(%rip), %xmm1
	leaq	.LC28(%rip), %rsi
	movl	$2, %edi
	addq	%rax, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	hist_d(%rip), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	hist_h(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	data_d(%rip), %rdi
	call	cudaFree@PLT
	movq	hist_d(%rip), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	leaq	80(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC29(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	80(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	movss	48(%rsp), %xmm0
	addss	52(%rsp), %xmm0
	leaq	.LC30(%rip), %rsi
	addss	80(%rsp), %xmm0
	movss	%xmm0, 12(%rsp)
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	leaq	.LC32(%rip), %rdi
	call	fopen@PLT
	movq	%r13, %rdx
	movl	$2, %esi
	movq	%rax, %rdi
	movq	%rax, %r12
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L31:
	cmpl	%r14d, 24(%rsp)
	jle	.L67
	cvtsi2sdl	%r14d, %xmm0
	cvtss2sd	8(%rsp), %xmm1
	addsd	.LC34(%rip), %xmm0
	movq	hist_h(%rip), %rax
	leaq	.LC35(%rip), %rdx
	movl	$2, %esi
	movq	%r12, %rdi
	movl	(%rax,%r14,4), %ecx
	movb	$1, %al
	incq	%r14
	mulsd	%xmm1, %xmm0
	cvtss2sd	28(%rsp), %xmm1
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__fprintf_chk@PLT
	jmp	.L31
.L67:
	movq	%r12, %rdi
	xorl	%r12d, %r12d
	call	fclose@PLT
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L33:
	movl	24(%rsp), %r13d
	cmpl	%r12d, %r13d
	jle	.L68
	cvtsi2sdl	%r12d, %xmm0
	addsd	.LC34(%rip), %xmm0
	cvtss2sd	8(%rsp), %xmm1
	movq	hist_h(%rip), %rax
	leaq	.LC36(%rip), %rsi
	movl	$2, %edi
	movl	(%rax,%r12,4), %edx
	movb	$1, %al
	incq	%r12
	mulsd	%xmm1, %xmm0
	cvtss2sd	28(%rsp), %xmm1
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	jmp	.L33
.L68:
	cmpl	$0, 44(%rsp)
	movq	64(%rsp), %r12
	jne	.L35
	movq	%r12, %rdi
	call	cudaEventDestroy@PLT
	movq	72(%rsp), %rdi
	call	cudaEventDestroy@PLT
	call	cudaDeviceReset@PLT
	movq	data_h(%rip), %rdi
	call	free@PLT
	movq	hist_h(%rip), %rdi
	jmp	.L61
.L35:
	movq	%rbx, %rdi
	call	malloc@PLT
	xorl	%edx, %edx
	movq	%rax, hist_c(%rip)
.L37:
	cmpl	%edx, %r13d
	jle	.L69
	xorl	%ecx, %ecx
	movl	%ecx, (%rax,%rdx,4)
	incq	%rdx
	jmp	.L37
.L69:
	xorl	%esi, %esi
	movq	%r12, %rdi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rsi
	xorl	%edx, %edx
	movq	data_h(%rip), %rdi
	movss	28(%rsp), %xmm2
	movq	hist_c(%rip), %rax
.L39:
	cmpq	%rdx, %rsi
	jle	.L70
	movss	(%rdi,%rdx,4), %xmm0
	leaq	1(%rdx), %r8
	movaps	%xmm0, %xmm1
	subss	%xmm2, %xmm1
	divss	8(%rsp), %xmm1
	cvttss2sil	%xmm1, %ecx
	cmpl	%ecx, 24(%rsp)
	jle	.L56
	testl	%ecx, %ecx
	jns	.L40
.L56:
	leaq	.LC37(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	jmp	.L63
.L40:
	movslq	%ecx, %rcx
	movq	%r8, %rdx
	incl	(%rax,%rcx,4)
	jmp	.L39
.L70:
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	leaq	92(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC38(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	92(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	56(%rsp), %rax
	cvtss2sd	92(%rsp), %xmm1
	mulsd	.LC27(%rip), %xmm1
	leaq	.LC39(%rip), %rsi
	movl	$2, %edi
	addq	%rax, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	leaq	.LC40(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movss	92(%rsp), %xmm0
	divss	12(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	64(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	72(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	24(%rsp), %ecx
	xorl	%eax, %eax
	xorl	%edx, %edx
	movq	hist_c(%rip), %rsi
.L43:
	cmpl	%eax, %ecx
	jle	.L71
	addl	(%rsi,%rax,4), %edx
	incq	%rax
	jmp	.L43
.L71:
	movslq	%edx, %rax
	xorl	%ebx, %ebx
	leaq	.LC42(%rip), %r12
	cmpq	56(%rsp), %rax
	je	.L45
	leaq	.LC41(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L63
.L47:
	movq	hist_h(%rip), %rax
	movl	(%rax,%rbx,4), %ecx
	movq	hist_c(%rip), %rax
	movl	(%rax,%rbx,4), %r8d
	cmpl	%r8d, %ecx
	je	.L46
	movl	%ebx, %edx
	movq	%r12, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L46:
	incq	%rbx
.L45:
	cmpl	%ebx, 24(%rsp)
	jg	.L47
	movq	%rbp, %rsi
	leaq	.LC43(%rip), %rdi
	leaq	.LC44(%rip), %rbp
	xorl	%r12d, %r12d
	call	fopen@PLT
	movq	%rbp, %rdx
	movl	$2, %esi
	movq	%rax, %rdi
	movq	%rax, %rbx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L48:
	cmpl	%r12d, 24(%rsp)
	jle	.L72
	cvtsi2sdl	%r12d, %xmm0
	cvtss2sd	8(%rsp), %xmm1
	addsd	.LC34(%rip), %xmm0
	movq	hist_c(%rip), %rax
	leaq	.LC35(%rip), %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movl	(%rax,%r12,4), %ecx
	movb	$1, %al
	incq	%r12
	mulsd	%xmm1, %xmm0
	cvtss2sd	28(%rsp), %xmm1
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__fprintf_chk@PLT
	jmp	.L48
.L72:
	movq	%rbx, %rdi
	xorl	%ebx, %ebx
	call	fclose@PLT
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L50:
	cmpl	%ebx, 24(%rsp)
	jle	.L73
	cvtsi2sdl	%ebx, %xmm0
	addsd	.LC34(%rip), %xmm0
	cvtss2sd	8(%rsp), %xmm1
	movq	hist_c(%rip), %rax
	leaq	.LC35(%rip), %rsi
	movl	$2, %edi
	movl	(%rax,%rbx,4), %edx
	movb	$1, %al
	incq	%rbx
	mulsd	%xmm1, %xmm0
	cvtss2sd	28(%rsp), %xmm1
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	jmp	.L50
.L73:
	call	cudaDeviceReset@PLT
	movq	data_h(%rip), %rdi
	call	free@PLT
	movq	hist_h(%rip), %rdi
	call	free@PLT
	movq	hist_c(%rip), %rdi
.L61:
	call	free@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L52
	call	__stack_chk_fail@PLT
.L52:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC45:
	.string	"_Z10hist_shmemPflPjiff"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC45(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z10hist_shmemPflPjiff(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2058:
	.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
	.globl	hist_c
	.bss
	.align 8
	.type	hist_c, @object
	.size	hist_c, 8
hist_c:
	.zero	8
	.globl	hist_d
	.align 8
	.type	hist_d, @object
	.size	hist_d, 8
hist_d:
	.zero	8
	.globl	data_d
	.align 8
	.type	data_d, @object
	.size	data_d, 8
data_d:
	.zero	8
	.globl	hist_h
	.align 8
	.type	hist_h, @object
	.size	hist_h, 8
hist_h:
	.zero	8
	.globl	data_h
	.align 8
	.type	data_h, @object
	.size	data_h, 8
data_h:
	.zero	8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1040187392
	.align 8
.LC2:
	.long	0
	.long	1072693248
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC3:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC4:
	.long	1610612736
	.long	1075388923
	.section	.rodata.cst16
	.align 16
.LC5:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC27:
	.long	0
	.long	1093567616
	.align 8
.LC34:
	.long	0
	.long	1071644672
	.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:

// To compute histogram with atomic operations */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <hip/hip_runtime.h>


// Variables
float* data_h;          // host vectors
unsigned int* hist_h;   // GPU solution back to the CPU 
float* data_d;          // device vectors
unsigned int* hist_d;
unsigned int* hist_c;   // CPU solution


// Functions
void RandomUniform(float*, long);
void RandomNormal(float*, long);
void RandomExpDecay(float*, long);

__global__ void hist_shmem(float *data, const long N, unsigned int *hist, 
                           const int bins, const float Rmin, const float binsize) 
{

    // use shared memory and atomic addition

    extern __shared__  unsigned int temp[];     // assume the blocksize is equal to the total # bins
    temp[threadIdx.x] = 0;
    __syncthreads();

    long i = threadIdx.x + blockIdx.x * blockDim.x;
    long stride = blockDim.x * gridDim.x;

//    if( (index > bins-1) || (index < 0)) {
//      printf("data[%d]=%f, index=%d\n",i,data[i],index);
//    }

    while (i < N) {
        int index = (int)((data[i] - Rmin) / binsize);
        atomicAdd(&temp[index], 1);
        i += stride;
    }

    __syncthreads();
    atomicAdd( &(hist[threadIdx.x]), temp[threadIdx.x] );

}


int main(void)
{

    int gid;

    // Error code to check return values for CUDA calls
    hipError_t err = hipSuccess;

    scanf("%d",&gid);
    err = hipSetDevice(gid);
    if (err != hipSuccess) {
        printf("!!! Cannot select GPU with device ID = %d\n", gid);
        exit(1);
    }
    printf("Set GPU with device ID = %d\n", gid);

    hipSetDevice(gid);

    printf("To find the histogram of a data set (with real numbers): \n");
    long N; 
    int bins,index;
    float Rmin, Rmax, binsize;

    printf("Enter the size of the data vector: ");
    scanf("%ld",&N);
    printf("%ld\n",N);
    long size = N * sizeof(float);

    printf("Enter the data range [Rmin, Rmax] for the histogram: ");
    scanf("%f %f",&Rmin, &Rmax);
    printf("%f %f\n",Rmin, Rmax);

    printf("Enter the number of bins of the histogram: ");
    scanf("%d",&bins);
    printf("%d\n",bins);
    if(bins > 1024) {
        printf("The number of bins is set to # of threads per block < 1024 ! \n");
        exit(0);
    }
    int bsize = bins*sizeof(int);
    binsize = (Rmax - Rmin)/(float)bins;
     
    data_h = (float*)malloc(size);
    hist_h = (unsigned int*)malloc(bsize);

    // Check memory allocations
    if(data_h == NULL || hist_h == NULL)
    {
        fprintf(stderr, "Failed to allocate host vectors!\n");
        exit(EXIT_FAILURE);
    }

    for(int i=0; i<bins; i++){
        hist_h[i]=0;
    }

    // initialize the data_h vector
    // srand(time(NULL));  // initialize the seed with the current time
    srand(12345);  

//    RandomUniform(data_h, N);      // uniform deviate in (0,1)
    RandomExpDecay(data_h, N);       

    int threadsPerBlock;
    printf("Enter the number of threads per block: ");
    scanf("%d",&threadsPerBlock);
    printf("%d\n",threadsPerBlock);
    if( threadsPerBlock != bins ) {
        printf("The number of threads per block must be equal to the number of bins ! \n");
        exit(0);
    }
    fflush(stdout);

    int blocksPerGrid;
    printf("Enter the number of blocks per grid: ");
    scanf("%d",&blocksPerGrid);
    printf("%d\n",blocksPerGrid);
    if( blocksPerGrid > 2147483647 ) {
        printf("The number of blocks must be less than 2147483647 ! \n");
        exit(0);
    }
    printf("The number of blocks is %d\n", blocksPerGrid);
    fflush(stdout);

    int CPU;
    printf("To compute the histogram with CPU (1/0) ? ");
    scanf("%d",&CPU);
    printf("%d\n",CPU);
    fflush(stdout);


    // create the timer
    hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);

    // start the timer
    hipEventRecord(start,0);

    // Allocate vectors in device memory

    hipMalloc((void**)&hist_d, bsize);
    hipMalloc((void**)&data_d, size);

    // Copy vectors from host memory to device memory

    hipMemcpy(data_d, data_h, size, hipMemcpyHostToDevice);
    hipMemcpy(hist_d, hist_h, bsize, hipMemcpyHostToDevice);

    // stop the timer
    hipEventRecord(stop,0);
    hipEventSynchronize(stop);

    float Intime;
    hipEventElapsedTime( &Intime, start, stop);
    printf("Input time for GPU: %f (ms) \n",Intime);

   // start the timer
    hipEventRecord(start,0);
    
    int sm = threadsPerBlock * sizeof(int);

    hist_shmem <<< blocksPerGrid, threadsPerBlock, sm >>> (data_d, N, hist_d, bins, Rmin, binsize);

    // stop the timer
    hipEventRecord(stop,0);
    hipEventSynchronize(stop);

    float gputime;
    hipEventElapsedTime( &gputime, start, stop);
    printf("Processing time for GPU: %f (ms) \n",gputime);
    printf("GPU Gflops: %f\n",2*N/(1000000.0*gputime));

    // Copy result from device memory to host memory
    // hist_h contains the result in host memory

    // start the timer
    hipEventRecord(start,0);

    hipMemcpy(hist_h, hist_d, bsize, hipMemcpyDeviceToHost);

    hipFree(data_d);
    hipFree(hist_d);

    // stop the timer
    hipEventRecord(stop,0);
    hipEventSynchronize(stop);

    float Outime;
    hipEventElapsedTime( &Outime, start, stop);
    printf("Output time for GPU: %f (ms) \n", Outime);

    float gputime_tot;
    gputime_tot = Intime + gputime + Outime;
    printf("Total time for GPU: %f (ms) \n", gputime_tot);

    // Save histogram in file
    FILE *out;
    out = fopen("hist_shmem.dat","w");

    fprintf(out, "Histogram (GPU):\n");
    for(int i=0; i<bins; i++) {
        float x = Rmin + (i + 0.5) * binsize;         // the center of each bin
        fprintf(out,"%f %d \n",x,hist_h[i]);
    }
    fclose(out);

    // Print the histogram on screen
    printf("Histogram (GPU):\n");
    for(int i = 0; i < bins; i = i+1) {
      float x = Rmin + (i + 0.5) * binsize;         // the center of each bin
      printf("%f %d\n", x, hist_h[i]);
    }

    if(CPU==0) {
      hipEventDestroy(start);
      hipEventDestroy(stop);
      hipDeviceReset();
      free(data_h);
      free(hist_h);
      return 0;
    }

    // To compute the CPU reference solution 

    hist_c = (unsigned int*)malloc(bsize);
    for(int i = 0; i < bins; i = i+1){
        hist_c[i] = 0;
    }

    // start the timer
    hipEventRecord(start,0);

    for(int i = 0; i < N; i = i+1) {
        index = (int)((data_h[i] - Rmin) / binsize);
        if( (index > bins - 1) || (index < 0)) {
            printf("data[%d]=%f, index=%d\n",i,data_h[i],index);
            exit(0);
        } 
        hist_c[index]++;
    }

    // stop the timer
    hipEventRecord(stop,0);
    hipEventSynchronize(stop);

    float cputime;
    hipEventElapsedTime( &cputime, start, stop);
    printf("Processing time for CPU: %f (ms) \n",cputime);
    printf("CPU Gflops: %f\n",2*N/(1000000.0*cputime));
    printf("Speed up of GPU = %f\n", cputime/(gputime_tot));

    // destroy the timer
    hipEventDestroy(start);
    hipEventDestroy(stop);

    // check histogram sum equal to the total number of data 

    int sum = 0;
    for(int i = 0; i < bins; i = i+1) {
        sum += hist_c[i];
    }
    if(sum != N) {
        printf("Error, sum = %d\n",sum);
        exit(0);
    }

    // compare histograms from CPU and GPU

    for (int i = 0; i < bins; i++) {
        if(hist_h[i] != hist_c[i]) {
            printf("i=%d, hist_h=%d, hist_c=%d \n", i, hist_h[i], hist_c[i]);
        }
    }

    // save histogram in file
    FILE *out1;            
    out1 = fopen("hist_cpu.dat","w");

    fprintf(out1, "Histogram (CPU):\n");
    for(int i=0; i<bins; i++) {
        float x=Rmin+(i+0.5)*binsize;         // the center of each bin
        fprintf(out1,"%f %d \n",x,hist_c[i]);
    }
    fclose(out1);

    printf("Histogram (CPU):\n");
    for(int i=0; i<bins; i++) {
      float x=Rmin+(i+0.5)*binsize;         // the center of each bin
      printf("%f %d \n",x,hist_c[i]);
    }

    hipDeviceReset();

    free(data_h);
    free(hist_h);
    free(hist_c);

    return 0;
}


void RandomUniform(float* data, long n)   // RNG with uniform distribution in (0,1)
{
    for(long i = 0; i < n; i++){
        data[i] = rand()/(float)RAND_MAX;
    }
}

void RandomNormal(float* data, long n)   // RNG with normal distribution, mu=0, sigma=1
{
    const float Pi = acos(-1.0);

    for(long i = 0; i < n; i++) {
        double y = (double) rand() / (float)RAND_MAX;
        double x = -log(1.0-y);
        double z = (double) rand() / (float)RAND_MAX;
        double theta = 2*Pi*z;
        data[i] = (float) (sqrt(2.0*x)*cos(theta));   
    }
}


void RandomExpDecay(float* data, long n)   // RNG with Exponential Decay
{
    for(long i = 0; i < n; i = i+1){
        double y = (double) rand() / (float) RAND_MAX;
        data[i] = (float) -log(1.0 - y);
    }
}

	.text
	.file	"hist_1gpu_shmem.hip"
	.globl	_Z25__device_stub__hist_shmemPflPjiff # -- Begin function _Z25__device_stub__hist_shmemPflPjiff
	.type	_Z25__device_stub__hist_shmemPflPjiff,@function
_Z25__device_stub__hist_shmemPflPjiff:  # @_Z25__device_stub__hist_shmemPflPjiff
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movss	%xmm0, (%rcx)
	leaq	12(%rsp), %r8
	movss	%xmm1, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z10hist_shmemPflPjiff, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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	_Z25__device_stub__hist_shmemPflPjiff, .Lfunc_end0-_Z25__device_stub__hist_shmemPflPjiff
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI1_0:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI1_1:
	.quad	0x3fe0000000000000              # double 0.5
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.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	$96, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	76(%rsp), %rbx
	movl	$.L.str, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	(%rbx), %edi
	callq	hipSetDevice
	movl	(%rbx), %esi
	testl	%eax, %eax
	jne	.LBB1_43
# %bb.1:
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	movl	76(%rsp), %edi
	callq	hipSetDevice
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	40(%rsp), %rbx
	movl	$.L.str.5, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movq	(%rbx), %rsi
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movq	(%rbx), %r14
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	12(%rsp), %rbx
	leaq	72(%rsp), %r15
	movl	$.L.str.8, %edi
	movq	%rbx, %rsi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_scanf
	cvtss2sd	(%rbx), %xmm0
	cvtss2sd	(%r15), %xmm1
	movl	$.L.str.9, %edi
	movb	$2, %al
	callq	printf
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	8(%rsp), %rbx
	movl	$.L.str, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	(%rbx), %esi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movl	(%rbx), %r12d
	cmpl	$1025, %r12d                    # imm = 0x401
	jge	.LBB1_45
# %bb.2:
	shlq	$2, %r14
	leal	(,%r12,4), %ebx
	movss	72(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	subss	12(%rsp), %xmm0
	movss	%xmm0, 28(%rsp)                 # 4-byte Spill
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rax, data_h(%rip)
	movslq	%ebx, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, hist_h(%rip)
	testq	%r15, %r15
	je	.LBB1_46
# %bb.3:
	testq	%rax, %rax
	je	.LBB1_46
# %bb.4:                                # %.preheader102
	testl	%r12d, %r12d
	jle	.LBB1_6
# %bb.5:                                # %.lr.ph.preheader
	movq	%r12, %rdx
	shlq	$2, %rdx
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB1_6:                                # %._crit_edge
	movl	$12345, %edi                    # imm = 0x3039
	callq	srand
	movq	data_h(%rip), %rdi
	movq	40(%rsp), %rsi
	callq	_Z14RandomExpDecayPfl
	movl	$.L.str.14, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	68(%rsp), %r15
	movl	$.L.str, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	(%r15), %esi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movl	(%r15), %eax
	cmpl	8(%rsp), %eax
	jne	.LBB1_47
# %bb.7:
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r12d, %xmm0
	movss	28(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	divss	%xmm0, %xmm1
	movss	%xmm1, 28(%rsp)                 # 4-byte Spill
	movq	stdout(%rip), %rdi
	callq	fflush
	movl	$.L.str.16, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	92(%rsp), %r15
	movl	$.L.str, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	(%r15), %esi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movl	(%r15), %esi
	movl	$.L.str.18, %edi
	xorl	%eax, %eax
	callq	printf
	movq	stdout(%rip), %rdi
	callq	fflush
	movl	$.L.str.19, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	64(%rsp), %r12
	movl	$.L.str, %edi
	movq	%r12, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	(%r12), %esi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movq	stdout(%rip), %rdi
	callq	fflush
	leaq	32(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	$hist_d, %edi
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	$data_d, %edi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	data_d(%rip), %rdi
	movq	data_h(%rip), %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	hist_d(%rip), %rdi
	movq	hist_h(%rip), %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r13), %rdi
	callq	hipEventSynchronize
	movq	(%r12), %rsi
	movq	(%r13), %rdx
	leaq	60(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%r14), %xmm0
	movl	$.L.str.20, %edi
	movb	$1, %al
	callq	printf
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	68(%rsp), %edx
	leal	(,%rdx,4), %eax
	movl	(%r15), %edi
	movslq	%eax, %r8
	btsq	$32, %rdi
	btsq	$32, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.8:
	movq	data_d(%rip), %rdi
	movq	40(%rsp), %rsi
	movq	hist_d(%rip), %rdx
	movl	8(%rsp), %ecx
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	28(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	callq	_Z25__device_stub__hist_shmemPflPjiff
.LBB1_9:
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	88(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14), %xmm0
	movl	$.L.str.21, %edi
	movb	$1, %al
	callq	printf
	movq	40(%rsp), %rax
	addq	%rax, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	(%r14), %xmm1
	mulsd	.LCPI1_0(%rip), %xmm1
	divsd	%xmm1, %xmm0
	movl	$.L.str.22, %edi
	movb	$1, %al
	callq	printf
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	hist_h(%rip), %rdi
	movq	hist_d(%rip), %rsi
	movq	%rbx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	data_d(%rip), %rdi
	callq	hipFree
	movq	hist_d(%rip), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	84(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str.23, %edi
	movb	$1, %al
	callq	printf
	movss	60(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	addss	(%r14), %xmm0
	addss	(%r15), %xmm0
	movss	%xmm0, 56(%rsp)                 # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.24, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.25, %edi
	movl	$.L.str.26, %esi
	callq	fopen
	movq	%rax, %r14
	movl	$.L.str.27, %edi
	movl	$17, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fwrite@PLT
	cmpl	$0, 8(%rsp)
	cvtss2sd	28(%rsp), %xmm2                 # 4-byte Folded Reload
	movsd	%xmm2, 48(%rsp)                 # 8-byte Spill
	jle	.LBB1_12
# %bb.10:                               # %.lr.ph108
	xorl	%r15d, %r15d
.LBB1_11:                               # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	12(%rsp), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r15d, %xmm1
	addsd	.LCPI1_1(%rip), %xmm1
	mulsd	%xmm2, %xmm1
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	hist_h(%rip), %rax
	movl	(%rax,%r15,4), %edx
	movl	$.L.str.28, %esi
	movq	%r14, %rdi
	movb	$1, %al
	callq	fprintf
	movsd	48(%rsp), %xmm2                 # 8-byte Reload
                                        # xmm2 = mem[0],zero
	incq	%r15
	movslq	8(%rsp), %rax
	cmpq	%rax, %r15
	jl	.LBB1_11
.LBB1_12:                               # %._crit_edge109
	movq	%r14, %rdi
	callq	fclose
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	8(%rsp), %r15d
	testl	%r15d, %r15d
	jle	.LBB1_15
# %bb.13:                               # %.lr.ph112
	xorl	%r14d, %r14d
.LBB1_14:                               # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	12(%rsp), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r14d, %xmm1
	addsd	.LCPI1_1(%rip), %xmm1
	mulsd	48(%rsp), %xmm1                 # 8-byte Folded Reload
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	hist_h(%rip), %rax
	movl	(%rax,%r14,4), %esi
	movl	$.L.str.29, %edi
	movb	$1, %al
	callq	printf
	incq	%r14
	movslq	8(%rsp), %r15
	cmpq	%r15, %r14
	jl	.LBB1_14
.LBB1_15:                               # %._crit_edge113
	cmpl	$0, 64(%rsp)
	je	.LBB1_32
# %bb.16:
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, hist_c(%rip)
	testl	%r15d, %r15d
	jle	.LBB1_18
# %bb.17:                               # %.lr.ph116.preheader
	movl	%r15d, %edx
	shlq	$2, %rdx
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB1_18:                               # %._crit_edge117
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rax
	testq	%rax, %rax
	movss	28(%rsp), %xmm3                 # 4-byte Reload
                                        # xmm3 = mem[0],zero,zero,zero
	jle	.LBB1_23
# %bb.19:                               # %.lr.ph120
	movq	data_h(%rip), %rcx
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movq	hist_c(%rip), %rdi
	xorl	%esi, %esi
.LBB1_20:                               # =>This Inner Loop Header: Depth=1
	movss	(%rcx,%rsi,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	movaps	%xmm1, %xmm2
	subss	%xmm0, %xmm2
	divss	%xmm3, %xmm2
	cvttss2si	%xmm2, %edx
	cmpl	%edx, 8(%rsp)
	jle	.LBB1_42
# %bb.21:                               #   in Loop: Header=BB1_20 Depth=1
	testl	%edx, %edx
	js	.LBB1_42
# %bb.22:                               #   in Loop: Header=BB1_20 Depth=1
	movl	%edx, %edx
	incl	(%rdi,%rdx,4)
	incq	%rsi
	cmpq	%rsi, %rax
	jne	.LBB1_20
.LBB1_23:                               # %._crit_edge121
	movq	16(%rsp), %rdi
	xorl	%ebx, %ebx
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	80(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14), %xmm0
	movl	$.L.str.31, %edi
	movb	$1, %al
	callq	printf
	movq	40(%rsp), %rax
	addq	%rax, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	(%r14), %xmm1
	mulsd	.LCPI1_0(%rip), %xmm1
	divsd	%xmm1, %xmm0
	movl	$.L.str.32, %edi
	movb	$1, %al
	callq	printf
	movss	(%r14), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	divss	56(%rsp), %xmm0                 # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.33, %edi
	movb	$1, %al
	callq	printf
	movq	32(%rsp), %rdi
	callq	hipEventDestroy
	movq	16(%rsp), %rdi
	callq	hipEventDestroy
	movl	8(%rsp), %eax
	testl	%eax, %eax
	jle	.LBB1_33
# %bb.24:                               # %.lr.ph125
	xorl	%ecx, %ecx
	movq	hist_c(%rip), %rdx
	xorl	%ebx, %ebx
.LBB1_25:                               # =>This Inner Loop Header: Depth=1
	addl	(%rdx,%rcx,4), %ebx
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB1_25
# %bb.26:                               # %._crit_edge126
	movslq	%ebx, %rcx
	cmpq	%rcx, 40(%rsp)
	jne	.LBB1_50
# %bb.27:                               # %.preheader
	testl	%eax, %eax
	jle	.LBB1_34
# %bb.28:                               # %.lr.ph128.preheader
	movq	hist_h(%rip), %rsi
	movq	hist_c(%rip), %rdi
	xorl	%ebx, %ebx
.LBB1_29:                               # %.lr.ph128
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rsi,%rbx,4), %edx
	movl	(%rdi,%rbx,4), %ecx
	cmpl	%ecx, %edx
	je	.LBB1_31
# %bb.30:                               #   in Loop: Header=BB1_29 Depth=1
	movl	$.L.str.35, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	movq	hist_h(%rip), %rsi
	movq	hist_c(%rip), %rdi
	movl	8(%rsp), %eax
.LBB1_31:                               #   in Loop: Header=BB1_29 Depth=1
	incq	%rbx
	movslq	%eax, %rcx
	cmpq	%rcx, %rbx
	jl	.LBB1_29
	jmp	.LBB1_34
.LBB1_32:
	movq	32(%rsp), %rdi
	callq	hipEventDestroy
	movq	16(%rsp), %rdi
	callq	hipEventDestroy
	callq	hipDeviceReset
	movq	data_h(%rip), %rdi
	callq	free
	movq	hist_h(%rip), %rdi
	jmp	.LBB1_41
.LBB1_33:                               # %._crit_edge126.thread
	cmpq	$0, 40(%rsp)
	jne	.LBB1_50
.LBB1_34:                               # %._crit_edge129
	movl	$.L.str.36, %edi
	movl	$.L.str.26, %esi
	callq	fopen
	movq	%rax, %rbx
	movl	$.L.str.37, %edi
	movl	$17, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fwrite@PLT
	cmpl	$0, 8(%rsp)
	jle	.LBB1_37
# %bb.35:                               # %.lr.ph132
	xorl	%r14d, %r14d
.LBB1_36:                               # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	12(%rsp), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r14d, %xmm1
	addsd	.LCPI1_1(%rip), %xmm1
	mulsd	48(%rsp), %xmm1                 # 8-byte Folded Reload
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	hist_c(%rip), %rax
	movl	(%rax,%r14,4), %edx
	movl	$.L.str.28, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	incq	%r14
	movslq	8(%rsp), %rax
	cmpq	%rax, %r14
	jl	.LBB1_36
.LBB1_37:                               # %._crit_edge133
	movq	%rbx, %rdi
	callq	fclose
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	cmpl	$0, 8(%rsp)
	jle	.LBB1_40
# %bb.38:                               # %.lr.ph136
	xorl	%ebx, %ebx
.LBB1_39:                               # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	12(%rsp), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sd	%ebx, %xmm1
	addsd	.LCPI1_1(%rip), %xmm1
	mulsd	48(%rsp), %xmm1                 # 8-byte Folded Reload
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	hist_c(%rip), %rax
	movl	(%rax,%rbx,4), %esi
	movl	$.L.str.28, %edi
	movb	$1, %al
	callq	printf
	incq	%rbx
	movslq	8(%rsp), %rax
	cmpq	%rax, %rbx
	jl	.LBB1_39
.LBB1_40:                               # %._crit_edge137
	callq	hipDeviceReset
	movq	data_h(%rip), %rdi
	callq	free
	movq	hist_h(%rip), %rdi
	callq	free
	movq	hist_c(%rip), %rdi
.LBB1_41:
	callq	free
	xorl	%eax, %eax
	addq	$96, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB1_42:
	.cfi_def_cfa_offset 144
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.30, %edi
                                        # kill: def $esi killed $esi killed $rsi
	movb	$1, %al
	callq	printf
.LBB1_49:
	xorl	%edi, %edi
	callq	exit
.LBB1_43:
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_44
.LBB1_45:
	movl	$.Lstr.4, %edi
	jmp	.LBB1_48
.LBB1_46:
	movq	stderr(%rip), %rcx
	movl	$.L.str.13, %edi
	movl	$33, %esi
	movl	$1, %edx
	callq	fwrite@PLT
.LBB1_44:
	movl	$1, %edi
	callq	exit
.LBB1_47:
	movl	$.Lstr.3, %edi
.LBB1_48:
	callq	puts@PLT
	jmp	.LBB1_49
.LBB1_50:
	movl	$.L.str.34, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_49
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z14RandomExpDecayPfl
.LCPI2_0:
	.quad	0xbe00000000000000              # double -4.6566128730773926E-10
.LCPI2_1:
	.quad	0x3ff0000000000000              # double 1
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI2_2:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.text
	.globl	_Z14RandomExpDecayPfl
	.type	_Z14RandomExpDecayPfl,@function
_Z14RandomExpDecayPfl:                  # @_Z14RandomExpDecayPfl
	.cfi_startproc
# %bb.0:
	testq	%rsi, %rsi
	jle	.LBB2_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	mulsd	.LCPI2_0(%rip), %xmm0
	addsd	.LCPI2_1(%rip), %xmm0
	callq	log
	cvtsd2ss	%xmm0, %xmm0
	xorps	.LCPI2_2(%rip), %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	%r15, %rbx
	jne	.LBB2_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB2_4:                                # %._crit_edge
	retq
.Lfunc_end2:
	.size	_Z14RandomExpDecayPfl, .Lfunc_end2-_Z14RandomExpDecayPfl
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z13RandomUniformPfl
.LCPI3_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	_Z13RandomUniformPfl
	.type	_Z13RandomUniformPfl,@function
_Z13RandomUniformPfl:                   # @_Z13RandomUniformPfl
	.cfi_startproc
# %bb.0:
	testq	%rsi, %rsi
	jle	.LBB3_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	xorl	%r15d, %r15d
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	%r15, %rbx
	jne	.LBB3_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB3_4:                                # %._crit_edge
	retq
.Lfunc_end3:
	.size	_Z13RandomUniformPfl, .Lfunc_end3-_Z13RandomUniformPfl
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z12RandomNormalPfl
.LCPI4_0:
	.quad	0x3e00000000000000              # double 4.6566128730773926E-10
.LCPI4_1:
	.quad	0x3ff0000000000000              # double 1
.LCPI4_2:
	.quad	0x401921fb60000000              # double 6.2831854820251465
.LCPI4_3:
	.quad	0xc000000000000000              # double -2
.LCPI4_4:
	.quad	0x0000000000000000              # double 0
	.text
	.globl	_Z12RandomNormalPfl
	.type	_Z12RandomNormalPfl,@function
_Z12RandomNormalPfl:                    # @_Z12RandomNormalPfl
	.cfi_startproc
# %bb.0:
	testq	%rsi, %rsi
	jle	.LBB4_7
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	xorl	%r15d, %r15d
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	movsd	.LCPI4_0(%rip), %xmm0           # xmm0 = mem[0],zero
	mulsd	%xmm0, %xmm1
	movsd	.LCPI4_1(%rip), %xmm0           # xmm0 = mem[0],zero
	subsd	%xmm1, %xmm0
	callq	log
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	callq	rand
	movsd	(%rsp), %xmm1                   # 8-byte Reload
                                        # xmm1 = mem[0],zero
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	mulsd	.LCPI4_0(%rip), %xmm0
	mulsd	.LCPI4_2(%rip), %xmm0
	mulsd	.LCPI4_3(%rip), %xmm1
	ucomisd	.LCPI4_4(%rip), %xmm1
	jb	.LBB4_4
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=1
	sqrtsd	%xmm1, %xmm1
	movsd	%xmm1, (%rsp)                   # 8-byte Spill
	jmp	.LBB4_5
.LBB4_4:                                # %call.sqrt
                                        #   in Loop: Header=BB4_2 Depth=1
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movapd	%xmm1, %xmm0
	callq	sqrt
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
.LBB4_5:                                # %.lr.ph.split
                                        #   in Loop: Header=BB4_2 Depth=1
	callq	cos
	mulsd	(%rsp), %xmm0                   # 8-byte Folded Reload
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	%r15, %rbx
	jne	.LBB4_2
# %bb.6:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB4_7:                                # %._crit_edge
	retq
.Lfunc_end4:
	.size	_Z12RandomNormalPfl, .Lfunc_end4-_Z12RandomNormalPfl
	.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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10hist_shmemPflPjiff, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	data_h,@object                  # @data_h
	.bss
	.globl	data_h
	.p2align	3, 0x0
data_h:
	.quad	0
	.size	data_h, 8

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

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

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

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

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

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"!!! Cannot select GPU with device ID = %d\n"
	.size	.L.str.1, 43

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Set GPU with device ID = %d\n"
	.size	.L.str.2, 29

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Enter the size of the data vector: "
	.size	.L.str.4, 36

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%ld"
	.size	.L.str.5, 4

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%ld\n"
	.size	.L.str.6, 5

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Enter the data range [Rmin, Rmax] for the histogram: "
	.size	.L.str.7, 54

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"%f %f"
	.size	.L.str.8, 6

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%f %f\n"
	.size	.L.str.9, 7

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Enter the number of bins of the histogram: "
	.size	.L.str.10, 44

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

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Failed to allocate host vectors!\n"
	.size	.L.str.13, 34

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Enter the number of threads per block: "
	.size	.L.str.14, 40

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Enter the number of blocks per grid: "
	.size	.L.str.16, 38

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"The number of blocks is %d\n"
	.size	.L.str.18, 28

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"To compute the histogram with CPU (1/0) ? "
	.size	.L.str.19, 43

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"Input time for GPU: %f (ms) \n"
	.size	.L.str.20, 30

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"Processing time for GPU: %f (ms) \n"
	.size	.L.str.21, 35

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"GPU Gflops: %f\n"
	.size	.L.str.22, 16

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"Output time for GPU: %f (ms) \n"
	.size	.L.str.23, 31

	.type	.L.str.24,@object               # @.str.24
.L.str.24:
	.asciz	"Total time for GPU: %f (ms) \n"
	.size	.L.str.24, 30

	.type	.L.str.25,@object               # @.str.25
.L.str.25:
	.asciz	"hist_shmem.dat"
	.size	.L.str.25, 15

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

	.type	.L.str.27,@object               # @.str.27
.L.str.27:
	.asciz	"Histogram (GPU):\n"
	.size	.L.str.27, 18

	.type	.L.str.28,@object               # @.str.28
.L.str.28:
	.asciz	"%f %d \n"
	.size	.L.str.28, 8

	.type	.L.str.29,@object               # @.str.29
.L.str.29:
	.asciz	"%f %d\n"
	.size	.L.str.29, 7

	.type	.L.str.30,@object               # @.str.30
.L.str.30:
	.asciz	"data[%d]=%f, index=%d\n"
	.size	.L.str.30, 23

	.type	.L.str.31,@object               # @.str.31
.L.str.31:
	.asciz	"Processing time for CPU: %f (ms) \n"
	.size	.L.str.31, 35

	.type	.L.str.32,@object               # @.str.32
.L.str.32:
	.asciz	"CPU Gflops: %f\n"
	.size	.L.str.32, 16

	.type	.L.str.33,@object               # @.str.33
.L.str.33:
	.asciz	"Speed up of GPU = %f\n"
	.size	.L.str.33, 22

	.type	.L.str.34,@object               # @.str.34
.L.str.34:
	.asciz	"Error, sum = %d\n"
	.size	.L.str.34, 17

	.type	.L.str.35,@object               # @.str.35
.L.str.35:
	.asciz	"i=%d, hist_h=%d, hist_c=%d \n"
	.size	.L.str.35, 29

	.type	.L.str.36,@object               # @.str.36
.L.str.36:
	.asciz	"hist_cpu.dat"
	.size	.L.str.36, 13

	.type	.L.str.37,@object               # @.str.37
.L.str.37:
	.asciz	"Histogram (CPU):\n"
	.size	.L.str.37, 18

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

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

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"To find the histogram of a data set (with real numbers): "
	.size	.Lstr, 58

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Histogram (GPU):"
	.size	.Lstr.1, 17

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Histogram (CPU):"
	.size	.Lstr.2, 17

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"The number of threads per block must be equal to the number of bins ! "
	.size	.Lstr.3, 71

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"The number of bins is set to # of threads per block < 1024 ! "
	.size	.Lstr.4, 62

	.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 _Z25__device_stub__hist_shmemPflPjiff
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym data_d
	.addrsig_sym hist_d
	.addrsig_sym _Z10hist_shmemPflPjiff
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10hist_shmemPflPjiff  ; -- Begin function _Z10hist_shmemPflPjiff
	.globl	_Z10hist_shmemPflPjiff
	.p2align	8
	.type	_Z10hist_shmemPflPjiff,@function
_Z10hist_shmemPflPjiff:                 ; @_Z10hist_shmemPflPjiff
; %bb.0:
	s_clause 0x2
	s_load_b32 s8, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x10
	s_add_u32 s10, s0, 40
	v_mov_b32_e32 v3, 0
	s_addc_u32 s11, s1, 0
	v_lshl_add_u32 v5, v0, 2, 0
	s_mov_b32 s9, 0
	s_mov_b32 s12, exec_lo
	ds_store_b32 v5, v3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_b32 s8, s8, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s8, v[0:1]
	v_mov_b32_e32 v2, v3
	v_cmpx_gt_i64_e64 s[6:7], v[1:2]
	s_cbranch_execz .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b32 s13, s[10:11], 0x0
	s_load_b64 s[10:11], s[0:1], 0x1c
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_mov_b32_e32 v6, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v3, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s8, s13, s8
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[4:5], s[8:9], 2
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b32 v7, v[3:4], off
	v_add_co_u32 v3, s0, v3, s4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v4, s0, s5, v4, s0
	s_waitcnt vmcnt(0)
	v_subrev_f32_e32 v7, s10, v7
	v_div_scale_f32 v8, null, s11, s11, v7
	v_div_scale_f32 v11, vcc_lo, v7, s11, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v9, v8
	s_waitcnt_depctr 0xfff
	v_fma_f32 v10, -v8, v9, 1.0
	v_fmac_f32_e32 v9, v10, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v10, v11, v9
	v_fma_f32 v12, -v8, v10, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v10, v12, v9
	v_fma_f32 v8, -v8, v10, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v8, v8, v9, v10
	v_add_co_u32 v1, vcc_lo, v1, s8
	v_add_co_ci_u32_e32 v2, vcc_lo, 0, v2, vcc_lo
	v_div_fixup_f32 v7, v8, s11, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_le_i64_e32 vcc_lo, s[6:7], v[1:2]
	v_cvt_i32_f32_e32 v7, v7
	s_or_b32 s9, vcc_lo, s9
	s_delay_alu instid0(VALU_DEP_1)
	v_lshl_add_u32 v7, v7, 2, 0
	ds_add_u32 v7, v6
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB0_2
.LBB0_3:                                ; %Flow27
	s_or_b32 exec_lo, exec_lo, s12
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b32 v1, v5
	v_lshlrev_b32_e32 v0, 2, v0
	s_waitcnt lgkmcnt(0)
	global_atomic_add_u32 v0, v1, s[2:3]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10hist_shmemPflPjiff
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 13
		.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	_Z10hist_shmemPflPjiff, .Lfunc_end0-_Z10hist_shmemPflPjiff
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 416
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; 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 temp
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           8
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         160
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10hist_shmemPflPjiff
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10hist_shmemPflPjiff.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
