/*
 * Copyright 1993-2006 NVIDIA Corporation.  All rights reserved.
 *
 * NOTICE TO USER:   
 *
 * This source code is subject to NVIDIA ownership rights under U.S. and 
 * international Copyright laws.  
 *
 * This software and the information contained herein is PROPRIETARY and 
 * CONFIDENTIAL to NVIDIA and is being provided under the terms and 
 * conditions of a Non-Disclosure Agreement.  Any reproduction or 
 * disclosure to any third party without the express written consent of 
 * NVIDIA is prohibited.     
 *
 * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE 
 * CODE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR 
 * IMPLIED WARRANTY OF ANY KIND.  NVIDIA DISCLAIMS ALL WARRANTIES WITH 
 * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF 
 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.   
 * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, 
 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE 
 * OR PERFORMANCE OF THIS SOURCE CODE.  
 *
 * U.S. Government End Users.  This source code is a "commercial item" as 
 * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting  of 
 * "commercial computer software" and "commercial computer software 
 * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) 
 * and is provided to the U.S. Government only as a commercial end item.  
 * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 
 * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the 
 * source code with only those rights set forth herein.
 */

#ifdef _WIN32
#  define NOMINMAX 
#endif

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <fstream>
#include <assert.h>

using namespace std;

#define errCheck(stmt) do {\
    cudaError_t err = stmt;\
    if (err != cudaSuccess) {\
        printf("%s in %s at line %d\n",cudaGetErrorString(err), __FILE__, __LINE__);\
        exit(EXIT_FAILURE);\
    }\
} while(0)

// You can use any other block size you wish.
#define BLOCK_SIZE 1024
#define DEFAULT_NUM_ELEMENTS 16777216 //16000000 
#define MAX_RAND 2


// **===-------- Modify the body of this function -----------===**
// You may need to make multiple kernel calls.

__global__ void scan_hs(float *d_odata, float *d_idata, int length) {
    volatile extern __shared__ float temp[];
    int tid = threadIdx.x;
    int tx = threadIdx.x;

    volatile __shared__ float acc;
    acc = 0;

    for(int i=0; i< (length-1)/blockDim.x+1; i++ ){
        tid = i*blockDim.x + threadIdx.x;
        temp[tx] = (tx == 0)?acc:d_idata[tid-1];
        __syncthreads();

        int pout = 0; int pin = 1;
    
        //if(tid < length)  
        {
            for (int offset = 1; offset < blockDim.x; offset <<= 1) {
                pout = 1 - pout;
                pin = 1 - pin;

                if (tx >= offset)
                  temp[pout * blockDim.x + tx] = temp[pin * blockDim.x + tx] + temp[pin * blockDim.x + tx - offset];
                else 
                  temp[pout * blockDim.x + tx] = temp[pin * blockDim.x + tx];
                __syncthreads();
            }
            d_odata[tid] = temp[pout * blockDim.x + tx];
            if (tx == blockDim.x - 1) 
                acc = d_idata[tid] + d_odata[tid];
        }
        __syncthreads();

    }
}


void prescanArray(float *outArray, float *inArray, int numElements)
{
    scan_hs<<<1, BLOCK_SIZE, 2*sizeof(float)*BLOCK_SIZE>>>(outArray, inArray, numElements);
}
// **===-----------------------------------------------------------===**



////////////////////////////////////////////////////////////////////////////////
// declaration, forward
void runTest( int argc, char** argv);

int ReadFile(float*, char* file_name, int size);
void WriteFile(float*, char* file_name, int size);

extern "C" 
unsigned int compare( const float* reference, const float* data, 
                     const unsigned int len);
extern "C" 
void computeGold( float* reference, float* idata, const unsigned int len);

////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int 
main( int argc, char** argv) 
{
    runTest( argc, argv);
    return EXIT_SUCCESS;
}

////////////////////////////////////////////////////////////////////////////////
//! Run a scan test for CUDA
////////////////////////////////////////////////////////////////////////////////
void
runTest( int argc, char** argv) 
{
    cudaEvent_t cpuStart, cpuStop, gpuIncluStart, gpuIncluStop;

    errCheck(cudaEventCreate(&cpuStart));
    errCheck(cudaEventCreate(&gpuIncluStart));
    errCheck(cudaEventCreate(&cpuStop));
    errCheck(cudaEventCreate(&gpuIncluStop));
    float cpuTime, gpuIncluTime;

    int errorM = 0;
    int size = 0;
    int num_elements = 0; // Must support large, non-power-of-2 arrays

    // allocate host memory to store the input data
    unsigned int mem_size = sizeof(float) * num_elements;
    //float* h_data = (float*) malloc( mem_size);
    float * h_data;
    errCheck(cudaMallocHost((void**) &h_data, mem_size));

    // * No arguments: Randomly generate input data and compare against the 
    //   host's result.
    // * One argument: Randomly generate input data and write the result to
    //   file name specified by first argument
    // * Two arguments: Read the first argument which indicates the size of the array,
    //   randomly generate input data and write the input data
    //   to the second argument. (for generating random input data)
    // * Three arguments: Read the first file which indicate the size of the array,
    //   then input data from the file name specified by 2nd argument and write the
    //   SCAN output to file name specified by the 3rd argument.
    switch(argc-1)
    {      
        case 2: 
            // Determine size of array
            size = atoi(argv[1]);
            if(size < 1){
                printf("Error reading parameter file\n");
                exit(1);
            }

            num_elements = size;

            // allocate host memory to store the input data
            mem_size = sizeof( float) * num_elements;
            //h_data = (float*) malloc( mem_size);
            errCheck(cudaMallocHost((void**) &h_data, mem_size));

            for(unsigned int i = 0; i < num_elements; ++i) 
            {
                h_data[i] = (int)(rand() % MAX_RAND);
            }
            WriteFile(h_data, argv[2], num_elements);
        break;
    
        case 3:  // Three Arguments
            size = atoi(argv[1]);
            if(size < 1){
                printf("Error reading parameter file\n");
                exit(1);
            }

            num_elements = size;
            
            // allocate host memory to store the input data
            mem_size = sizeof( float) * num_elements;
            //h_data = (float*) malloc( mem_size);
            errCheck(cudaMallocHost((void**) &h_data, mem_size));

            errorM = ReadFile(h_data, argv[2], size);
            if(errorM != 0)
            {
                printf("Error reading input file!\n");
                exit(1);
            }
        break;
        
        default:  // No Arguments or one argument
            // initialize the input data on the host to be integer values
            // between 0 and 1000
            // Use DEFAULT_NUM_ELEMENTS num_elements
            num_elements = DEFAULT_NUM_ELEMENTS;
            
            // allocate host memory to store the input data
            mem_size = sizeof( float) * num_elements;
            //h_data = (float*) malloc(mem_size);
            errCheck(cudaMallocHost((void**) &h_data, mem_size));

            // initialize the input data on the host
            for( unsigned int i = 0; i < num_elements; ++i) 
            {
//                h_data[i] = 1.0f;
                h_data[i] = (int)(rand() % MAX_RAND);
            }
        break;  
    }    
      
    // compute reference solution
    float* reference = (float*) malloc(mem_size);  

    errCheck(cudaEventRecord(cpuStart, NULL));
    computeGold( reference, h_data, num_elements);
    errCheck(cudaEventRecord(cpuStop, NULL));
    errCheck(cudaEventSynchronize(cpuStop));
    errCheck(cudaEventElapsedTime(&cpuTime, cpuStart, cpuStop));
    printf("\n\n**===-------------------------------------------------===**\n");
    printf("Processing %d elements...\n", num_elements);
    printf("Host CPU Processing time: %f (ms)\n", cpuTime);



    // allocate device memory input and output arrays
    float* d_idata = NULL;
    float* d_odata = NULL;

    errCheck( cudaMalloc( (void**) &d_idata, mem_size));
    errCheck( cudaMalloc( (void**) &d_odata, mem_size));
    
    
    // copy host memory to device input array
    errCheck( cudaMemcpy( d_idata, h_data, mem_size, cudaMemcpyHostToDevice) );
    // initialize all the other device arrays to be safe
    errCheck( cudaMemcpy( d_odata, h_data, mem_size, cudaMemcpyHostToDevice) );

    // **===-------- Allocate data structure here -----------===**
    // preallocBlockSums(num_elements);
    // **===-----------------------------------------------------------===**

    // Run just once to remove startup overhead for more accurate performance 
    // measurement
    prescanArray(d_odata, d_idata, 16);

    errCheck(cudaEventRecord(gpuIncluStart, NULL));
    // copy host memory to device input array
    errCheck( cudaMemcpy( d_idata, h_data, mem_size, cudaMemcpyHostToDevice) );
    // initialize all the other device arrays to be safe
    errCheck( cudaMemcpy( d_odata, h_data, mem_size, cudaMemcpyHostToDevice) );
    
    // **===-------- Modify the body of this function -----------===**
    prescanArray(d_odata, d_idata, num_elements);
    // **===-----------------------------------------------------------===**
    //errCheck( cudaThreadSynchronize() );



    // **===-------- Deallocate data structure here -----------===**
    // deallocBlockSums();
    // **===-----------------------------------------------------------===**


    // copy result from device to host
    errCheck(cudaMemcpy( h_data, d_odata, sizeof(float) * num_elements, 
                               cudaMemcpyDeviceToHost));

    errCheck(cudaEventRecord(gpuIncluStop, NULL));
    errCheck(cudaEventSynchronize(gpuIncluStop));
    errCheck(cudaEventElapsedTime(&gpuIncluTime, gpuIncluStart, gpuIncluStop));
    printf("GPU inclusive time: %f (ms)\n", gpuIncluTime);
    printf("Speedup: %fX\n", cpuTime/gpuIncluTime);


    if ((argc - 1) == 3)  // Three Arguments, write result to file
    {
        WriteFile(h_data, argv[3], num_elements);
    }
    else if ((argc - 1) == 1)  // One Argument, write result to file
    {
        WriteFile(h_data, argv[1], num_elements);
    }

    // Check if the result is equivalent to the expected soluion
    unsigned int result_regtest = compare(reference, h_data, num_elements);
    printf( "Test %s\n", (1 == result_regtest) ? "PASSED" : "FAILED");

    // cleanup memory
    //free(h_data);
    free(reference);
    cudaFree(h_data);
    cudaFree(d_odata);
    cudaFree(d_idata);
}


int ReadFile(float* M, char* file_name, int data_read)
{
   unsigned int i = 0;
   std::ifstream ifile(file_name);
   for(; i < data_read; i++){
      ifile>>M[i];
   }
   ifile.close();
   return (i==data_read)? 0:1;
}


void WriteFile(float* M, char* file_name, int data_write)
{
   std::ofstream ofile(file_name);
   for(unsigned int i = 0; i < data_write; i++){
      ofile<<M[i]<<" ";
   }
   ofile.close();
}

unsigned int compare(const float* reference, const float* data, const unsigned int len)
{
   for(unsigned int i = 0; i < len; i++){
        /*
        if(i > 1020 && i <1028){
             cout<<"i = "<<i<<endl;
             cout<<"Host = "<<reference[i]<<endl;
             cout<<"Device = "<<data[i]<<endl;
         //return false;
        }
        */
      float error = fabs(reference[i]-data[i]);
      if(error > 0.0001f){
         return false;
      } 
   }
   return true;
}

unsigned int compare( const float* reference, const float* data, 
                     const unsigned int len);

	.file	"tmpxft_00346548_00000000-6_scan_largearray.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3774:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3774:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	compare
	.type	compare, @function
compare:
.LFB3771:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	movss	.LC0(%rip), %xmm1
.L3:
	cmpl	%edx, %eax
	jnb	.L8
	movss	(%rdi,%rax,4), %xmm0
	subss	(%rsi,%rax,4), %xmm0
	incq	%rax
	andps	%xmm1, %xmm0
	comiss	.LC1(%rip), %xmm0
	jbe	.L3
	xorl	%eax, %eax
	ret
.L8:
	movl	$1, %eax
	ret
	.cfi_endproc
.LFE3771:
	.size	compare, .-compare
	.globl	_Z29__device_stub__Z7scan_hsPfS_iPfS_i
	.type	_Z29__device_stub__Z7scan_hsPfS_iPfS_i, @function
_Z29__device_stub__Z7scan_hsPfS_iPfS_i:
.LFB3796:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L9
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z7scan_hsPfS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L9:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3796:
	.size	_Z29__device_stub__Z7scan_hsPfS_iPfS_i, .-_Z29__device_stub__Z7scan_hsPfS_iPfS_i
	.globl	_Z7scan_hsPfS_i
	.type	_Z7scan_hsPfS_i, @function
_Z7scan_hsPfS_i:
.LFB3797:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z7scan_hsPfS_iPfS_i
	.cfi_endproc
.LFE3797:
	.size	_Z7scan_hsPfS_i, .-_Z7scan_hsPfS_i
	.globl	_Z12prescanArrayPfS_i
	.type	_Z12prescanArrayPfS_i, @function
_Z12prescanArrayPfS_i:
.LFB3766:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%edx, %r12d
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	salq	$10, %rdx
	movq	%rsi, %rbp
	movl	$8192, %r8d
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	$1, %ecx
	movq	%rdi, %rbx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	movl	%r12d, %edx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	_Z29__device_stub__Z7scan_hsPfS_iPfS_i
.L14:
	.cfi_restore_state
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3766:
	.size	_Z12prescanArrayPfS_i, .-_Z12prescanArrayPfS_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"_Z7scan_hsPfS_i"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3799:
	.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	.LC2(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z7scan_hsPfS_i(%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
.LFE3799:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.text
	.globl	_Z8ReadFilePfPci
	.type	_Z8ReadFilePfPci, @function
_Z8ReadFilePfPci:
.LFB3769:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3769
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%edx, %r13d
	movl	$8, %edx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	subq	$536, %rsp
	.cfi_def_cfa_offset 576
	movq	%fs:40, %rax
	movq	%rax, 520(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbp
	movq	%rbp, %rdi
.LEHB0:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT
.LEHE0:
.L20:
	cmpl	%r13d, %r12d
	jnb	.L28
	movq	%rbx, %rsi
	movq	%rbp, %rdi
.LEHB1:
	call	_ZNSi10_M_extractIfEERSiRT_@PLT
	incl	%r12d
	addq	$4, %rbx
	jmp	.L20
.L28:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv@PLT
.LEHE1:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	xorl	%eax, %eax
	cmpl	%r12d, %r13d
	setne	%al
	movq	520(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L24
	jmp	.L26
.L25:
	endbr64
	movq	%rax, %rbx
.L22:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L26
	movq	%rbx, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L26:
	call	__stack_chk_fail@PLT
.L24:
	addq	$536, %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
.LFE3769:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3769:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3769-.LLSDACSB3769
.LLSDACSB3769:
	.uleb128 .LEHB0-.LFB3769
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3769
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L25-.LFB3769
	.uleb128 0
	.uleb128 .LEHB2-.LFB3769
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE3769:
	.text
	.size	_Z8ReadFilePfPci, .-_Z8ReadFilePfPci
	.section	.rodata.str1.1
.LC3:
	.string	" "
	.text
	.globl	_Z9WriteFilePfPci
	.type	_Z9WriteFilePfPci, @function
_Z9WriteFilePfPci:
.LFB3770:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3770
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC3(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	movl	$16, %edx
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$528, %rsp
	.cfi_def_cfa_offset 576
	movq	%fs:40, %rax
	movq	%rax, 520(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
.LEHB3:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT
.LEHE3:
.L30:
	cmpl	%r12d, %ebp
	jnb	.L38
	movq	%rbx, %rdi
	cvtss2sd	0(%r13,%rbp,4), %xmm0
.LEHB4:
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	movl	$1, %edx
	movq	%r14, %rsi
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	incq	%rbp
	jmp	.L30
.L38:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv@PLT
.LEHE4:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
	jmp	.L36
.L35:
	endbr64
	movq	%rax, %rbp
.L32:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L36
	movq	%rbp, %rdi
.LEHB5:
	call	_Unwind_Resume@PLT
.LEHE5:
.L36:
	call	__stack_chk_fail@PLT
.L34:
	addq	$528, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3770:
	.section	.gcc_except_table
.LLSDA3770:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3770-.LLSDACSB3770
.LLSDACSB3770:
	.uleb128 .LEHB3-.LFB3770
	.uleb128 .LEHE3-.LEHB3
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB4-.LFB3770
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L35-.LFB3770
	.uleb128 0
	.uleb128 .LEHB5-.LFB3770
	.uleb128 .LEHE5-.LEHB5
	.uleb128 0
	.uleb128 0
.LLSDACSE3770:
	.text
	.size	_Z9WriteFilePfPci, .-_Z9WriteFilePfPci
	.section	.rodata.str1.1
.LC4:
	.string	"PASSED"
.LC5:
	.string	"FAILED"
.LC6:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/szywind/HPC-759/master/HW08/scan_largearray.cu"
.LC7:
	.string	"%s in %s at line %d\n"
.LC8:
	.string	"Error reading parameter file\n"
.LC9:
	.string	"Error reading input file!\n"
.LC10:
	.string	"\n\n**===-------------------------------------------------===**\n"
.LC11:
	.string	"Processing %d elements...\n"
.LC12:
	.string	"Host CPU Processing time: %f (ms)\n"
.LC13:
	.string	"GPU inclusive time: %f (ms)\n"
.LC14:
	.string	"Speedup: %fX\n"
.LC15:
	.string	"Test %s\n"
	.text
	.globl	_Z7runTestiPPc
	.type	_Z7runTestiPPc, @function
_Z7runTestiPPc:
.LFB3768:
	.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
	movl	%edi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	testl	%eax, %eax
	je	.L40
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$143, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L40:
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L41
	call	cudaGetErrorString@PLT
	movl	$144, %r8d
	movq	%rax, %rdx
.L86:
	leaq	.LC6(%rip), %rcx
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L87:
	movl	$1, %edi
	call	exit@PLT
.L41:
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L42
	call	cudaGetErrorString@PLT
	movl	$145, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L42:
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L43
	call	cudaGetErrorString@PLT
	movl	$146, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L43:
	leaq	48(%rsp), %r14
	xorl	%esi, %esi
	movq	%r14, %rdi
	call	cudaMallocHost@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L44
	call	cudaGetErrorString@PLT
	movl	$157, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L44:
	leal	-1(%r13), %eax
	cmpl	$3, %r13d
	je	.L45
	cmpl	$3, %eax
	je	.L46
	jmp	.L89
.L45:
	movq	8(%r12), %rdi
	call	atoi@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jg	.L48
.L51:
	leaq	.LC8(%rip), %rsi
	jmp	.L88
.L48:
	movq	%r14, %rdi
	leal	0(,%rax,4), %esi
	xorl	%r14d, %r14d
	movl	$2, %r15d
	movq	%rsi, %rbp
	call	cudaMallocHost@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L49
	call	cudaGetErrorString@PLT
	movl	$184, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L49:
	call	rand@PLT
	movq	48(%rsp), %rdi
	cltd
	idivl	%r15d
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, (%rdi,%r14,4)
	incq	%r14
	cmpl	%ebx, %r14d
	jb	.L49
	movq	16(%r12), %rsi
	movl	%ebx, %edx
	call	_Z9WriteFilePfPci
	jmp	.L50
.L46:
	movq	8(%r12), %rdi
	call	atoi@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jle	.L51
	leal	0(,%rax,4), %esi
	movq	%r14, %rdi
	movq	%rsi, %rbp
	call	cudaMallocHost@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L52
	call	cudaGetErrorString@PLT
	movl	$205, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L52:
	movq	16(%r12), %rsi
	movq	48(%rsp), %rdi
	movl	%ebx, %edx
	call	_Z8ReadFilePfPci
	testl	%eax, %eax
	je	.L50
	leaq	.LC9(%rip), %rsi
.L88:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L87
.L89:
	movq	%r14, %rdi
	movl	$67108864, %esi
	xorl	%ebx, %ebx
	movl	$2, %ebp
	call	cudaMallocHost@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L53
	call	cudaGetErrorString@PLT
	movl	$224, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L53:
	call	rand@PLT
	cltd
	idivl	%ebp
	movq	48(%rsp), %rax
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, (%rax,%rbx)
	addq	$4, %rbx
	cmpq	$67108864, %rbx
	jne	.L53
	movl	$67108864, %ebp
	movl	$16777216, %ebx
.L50:
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rax, %r14
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L54
	call	cudaGetErrorString@PLT
	movl	$238, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L54:
	movq	48(%rsp), %rsi
	movl	%ebx, %edx
	movq	%r14, %rdi
	call	computeGold@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L55
	call	cudaGetErrorString@PLT
	movl	$240, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L55:
	movq	24(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L56
	call	cudaGetErrorString@PLT
	movl	$241, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L56:
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	leaq	8(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L57
	call	cudaGetErrorString@PLT
	movl	$242, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L57:
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %edx
	leaq	.LC11(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	8(%rsp), %xmm0
	call	__printf_chk@PLT
	xorl	%eax, %eax
	leaq	56(%rsp), %rdi
	movq	%rbp, %rsi
	movq	%rax, 56(%rsp)
	movq	%rax, 64(%rsp)
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L58
	call	cudaGetErrorString@PLT
	movl	$253, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L58:
	leaq	64(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L59
	call	cudaGetErrorString@PLT
	movl	$254, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L59:
	movq	56(%rsp), %rdi
	movq	48(%rsp), %rsi
	movl	$1, %ecx
	movq	%rbp, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L60
	call	cudaGetErrorString@PLT
	movl	$258, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L60:
	movq	64(%rsp), %rdi
	movq	48(%rsp), %rsi
	movl	$1, %ecx
	movq	%rbp, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L61
	call	cudaGetErrorString@PLT
	movl	$260, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L61:
	movq	56(%rsp), %rsi
	movq	64(%rsp), %rdi
	movl	$16, %edx
	call	_Z12prescanArrayPfS_i
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L62
	call	cudaGetErrorString@PLT
	movl	$270, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L62:
	movq	56(%rsp), %rdi
	movq	48(%rsp), %rsi
	movl	$1, %ecx
	movq	%rbp, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L63
	call	cudaGetErrorString@PLT
	movl	$272, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L63:
	movq	64(%rsp), %rdi
	movq	48(%rsp), %rsi
	movl	$1, %ecx
	movq	%rbp, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L64
	call	cudaGetErrorString@PLT
	movl	$274, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L64:
	movq	56(%rsp), %rsi
	movq	64(%rsp), %rdi
	movl	%ebx, %edx
	call	_Z12prescanArrayPfS_i
	movq	48(%rsp), %rdi
	movq	64(%rsp), %rsi
	movslq	%ebx, %rdx
	salq	$2, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L65
	call	cudaGetErrorString@PLT
	movl	$289, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L65:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L66
	call	cudaGetErrorString@PLT
	movl	$292, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L66:
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L67
	call	cudaGetErrorString@PLT
	movl	$293, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L67:
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	12(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L68
	call	cudaGetErrorString@PLT
	movl	$294, %r8d
	movq	%rax, %rdx
	jmp	.L86
.L68:
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC14(%rip), %rsi
	movss	8(%rsp), %xmm0
	divss	12(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	cmpl	$4, %r13d
	movq	48(%rsp), %rdi
	jne	.L69
	movq	24(%r12), %rsi
	jmp	.L85
.L69:
	cmpl	$2, %r13d
	jne	.L70
	movq	8(%r12), %rsi
.L85:
	movl	%ebx, %edx
	call	_Z9WriteFilePfPci
.L70:
	movq	48(%rsp), %rsi
	movl	%ebx, %edx
	movq	%r14, %rdi
	call	compare
	leaq	.LC5(%rip), %rdx
	movl	$2, %edi
	leaq	.LC15(%rip), %rsi
	decl	%eax
	leaq	.LC4(%rip), %rax
	cmove	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L72
	call	__stack_chk_fail@PLT
.L72:
	addq	$88, %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
.LFE3768:
	.size	_Z7runTestiPPc, .-_Z7runTestiPPc
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3767:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	_Z7runTestiPPc
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3767:
	.size	main, .-main
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	953267991
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

/*
 * Copyright 1993-2006 NVIDIA Corporation.  All rights reserved.
 *
 * NOTICE TO USER:   
 *
 * This source code is subject to NVIDIA ownership rights under U.S. and 
 * international Copyright laws.  
 *
 * This software and the information contained herein is PROPRIETARY and 
 * CONFIDENTIAL to NVIDIA and is being provided under the terms and 
 * conditions of a Non-Disclosure Agreement.  Any reproduction or 
 * disclosure to any third party without the express written consent of 
 * NVIDIA is prohibited.     
 *
 * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE 
 * CODE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR 
 * IMPLIED WARRANTY OF ANY KIND.  NVIDIA DISCLAIMS ALL WARRANTIES WITH 
 * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF 
 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.   
 * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, 
 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE 
 * OR PERFORMANCE OF THIS SOURCE CODE.  
 *
 * U.S. Government End Users.  This source code is a "commercial item" as 
 * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting  of 
 * "commercial computer software" and "commercial computer software 
 * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) 
 * and is provided to the U.S. Government only as a commercial end item.  
 * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 
 * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the 
 * source code with only those rights set forth herein.
 */

#ifdef _WIN32
#  define NOMINMAX 
#endif


#include <hip/hip_runtime.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <fstream>
#include <assert.h>

using namespace std;

#define errCheck(stmt) do {\
    hipError_t err = stmt;\
    if (err != hipSuccess) {\
        printf("%s in %s at line %d\n",hipGetErrorString(err), __FILE__, __LINE__);\
        exit(EXIT_FAILURE);\
    }\
} while(0)

// You can use any other block size you wish.
#define BLOCK_SIZE 1024
#define DEFAULT_NUM_ELEMENTS 16777216 //16000000 
#define MAX_RAND 2


// **===-------- Modify the body of this function -----------===**
// You may need to make multiple kernel calls.

__global__ void scan_hs(float *d_odata, float *d_idata, int length) {
    volatile extern __shared__ float temp[];
    int tid = threadIdx.x;
    int tx = threadIdx.x;

    volatile __shared__ float acc;
    acc = 0;

    for(int i=0; i< (length-1)/blockDim.x+1; i++ ){
        tid = i*blockDim.x + threadIdx.x;
        temp[tx] = (tx == 0)?acc:d_idata[tid-1];
        __syncthreads();

        int pout = 0; int pin = 1;
    
        //if(tid < length)  
        {
            for (int offset = 1; offset < blockDim.x; offset <<= 1) {
                pout = 1 - pout;
                pin = 1 - pin;

                if (tx >= offset)
                  temp[pout * blockDim.x + tx] = temp[pin * blockDim.x + tx] + temp[pin * blockDim.x + tx - offset];
                else 
                  temp[pout * blockDim.x + tx] = temp[pin * blockDim.x + tx];
                __syncthreads();
            }
            d_odata[tid] = temp[pout * blockDim.x + tx];
            if (tx == blockDim.x - 1) 
                acc = d_idata[tid] + d_odata[tid];
        }
        __syncthreads();

    }
}


void prescanArray(float *outArray, float *inArray, int numElements)
{
    scan_hs<<<1, BLOCK_SIZE, 2*sizeof(float)*BLOCK_SIZE>>>(outArray, inArray, numElements);
}
// **===-----------------------------------------------------------===**



////////////////////////////////////////////////////////////////////////////////
// declaration, forward
void runTest( int argc, char** argv);

int ReadFile(float*, char* file_name, int size);
void WriteFile(float*, char* file_name, int size);

extern "C" 
unsigned int compare( const float* reference, const float* data, 
                     const unsigned int len);
extern "C" 
void computeGold( float* reference, float* idata, const unsigned int len);

////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int 
main( int argc, char** argv) 
{
    runTest( argc, argv);
    return EXIT_SUCCESS;
}

////////////////////////////////////////////////////////////////////////////////
//! Run a scan test for CUDA
////////////////////////////////////////////////////////////////////////////////
void
runTest( int argc, char** argv) 
{
    hipEvent_t cpuStart, cpuStop, gpuIncluStart, gpuIncluStop;

    errCheck(hipEventCreate(&cpuStart));
    errCheck(hipEventCreate(&gpuIncluStart));
    errCheck(hipEventCreate(&cpuStop));
    errCheck(hipEventCreate(&gpuIncluStop));
    float cpuTime, gpuIncluTime;

    int errorM = 0;
    int size = 0;
    int num_elements = 0; // Must support large, non-power-of-2 arrays

    // allocate host memory to store the input data
    unsigned int mem_size = sizeof(float) * num_elements;
    //float* h_data = (float*) malloc( mem_size);
    float * h_data;
    errCheck(hipHostMalloc((void**) &h_data, mem_size, hipHostMallocDefault));

    // * No arguments: Randomly generate input data and compare against the 
    //   host's result.
    // * One argument: Randomly generate input data and write the result to
    //   file name specified by first argument
    // * Two arguments: Read the first argument which indicates the size of the array,
    //   randomly generate input data and write the input data
    //   to the second argument. (for generating random input data)
    // * Three arguments: Read the first file which indicate the size of the array,
    //   then input data from the file name specified by 2nd argument and write the
    //   SCAN output to file name specified by the 3rd argument.
    switch(argc-1)
    {      
        case 2: 
            // Determine size of array
            size = atoi(argv[1]);
            if(size < 1){
                printf("Error reading parameter file\n");
                exit(1);
            }

            num_elements = size;

            // allocate host memory to store the input data
            mem_size = sizeof( float) * num_elements;
            //h_data = (float*) malloc( mem_size);
            errCheck(hipHostMalloc((void**) &h_data, mem_size, hipHostMallocDefault));

            for(unsigned int i = 0; i < num_elements; ++i) 
            {
                h_data[i] = (int)(rand() % MAX_RAND);
            }
            WriteFile(h_data, argv[2], num_elements);
        break;
    
        case 3:  // Three Arguments
            size = atoi(argv[1]);
            if(size < 1){
                printf("Error reading parameter file\n");
                exit(1);
            }

            num_elements = size;
            
            // allocate host memory to store the input data
            mem_size = sizeof( float) * num_elements;
            //h_data = (float*) malloc( mem_size);
            errCheck(hipHostMalloc((void**) &h_data, mem_size, hipHostMallocDefault));

            errorM = ReadFile(h_data, argv[2], size);
            if(errorM != 0)
            {
                printf("Error reading input file!\n");
                exit(1);
            }
        break;
        
        default:  // No Arguments or one argument
            // initialize the input data on the host to be integer values
            // between 0 and 1000
            // Use DEFAULT_NUM_ELEMENTS num_elements
            num_elements = DEFAULT_NUM_ELEMENTS;
            
            // allocate host memory to store the input data
            mem_size = sizeof( float) * num_elements;
            //h_data = (float*) malloc(mem_size);
            errCheck(hipHostMalloc((void**) &h_data, mem_size, hipHostMallocDefault));

            // initialize the input data on the host
            for( unsigned int i = 0; i < num_elements; ++i) 
            {
//                h_data[i] = 1.0f;
                h_data[i] = (int)(rand() % MAX_RAND);
            }
        break;  
    }    
      
    // compute reference solution
    float* reference = (float*) malloc(mem_size);  

    errCheck(hipEventRecord(cpuStart, NULL));
    computeGold( reference, h_data, num_elements);
    errCheck(hipEventRecord(cpuStop, NULL));
    errCheck(hipEventSynchronize(cpuStop));
    errCheck(hipEventElapsedTime(&cpuTime, cpuStart, cpuStop));
    printf("\n\n**===-------------------------------------------------===**\n");
    printf("Processing %d elements...\n", num_elements);
    printf("Host CPU Processing time: %f (ms)\n", cpuTime);



    // allocate device memory input and output arrays
    float* d_idata = NULL;
    float* d_odata = NULL;

    errCheck( hipMalloc( (void**) &d_idata, mem_size));
    errCheck( hipMalloc( (void**) &d_odata, mem_size));
    
    
    // copy host memory to device input array
    errCheck( hipMemcpy( d_idata, h_data, mem_size, hipMemcpyHostToDevice) );
    // initialize all the other device arrays to be safe
    errCheck( hipMemcpy( d_odata, h_data, mem_size, hipMemcpyHostToDevice) );

    // **===-------- Allocate data structure here -----------===**
    // preallocBlockSums(num_elements);
    // **===-----------------------------------------------------------===**

    // Run just once to remove startup overhead for more accurate performance 
    // measurement
    prescanArray(d_odata, d_idata, 16);

    errCheck(hipEventRecord(gpuIncluStart, NULL));
    // copy host memory to device input array
    errCheck( hipMemcpy( d_idata, h_data, mem_size, hipMemcpyHostToDevice) );
    // initialize all the other device arrays to be safe
    errCheck( hipMemcpy( d_odata, h_data, mem_size, hipMemcpyHostToDevice) );
    
    // **===-------- Modify the body of this function -----------===**
    prescanArray(d_odata, d_idata, num_elements);
    // **===-----------------------------------------------------------===**
    //errCheck( cudaThreadSynchronize() );



    // **===-------- Deallocate data structure here -----------===**
    // deallocBlockSums();
    // **===-----------------------------------------------------------===**


    // copy result from device to host
    errCheck(hipMemcpy( h_data, d_odata, sizeof(float) * num_elements, 
                               hipMemcpyDeviceToHost));

    errCheck(hipEventRecord(gpuIncluStop, NULL));
    errCheck(hipEventSynchronize(gpuIncluStop));
    errCheck(hipEventElapsedTime(&gpuIncluTime, gpuIncluStart, gpuIncluStop));
    printf("GPU inclusive time: %f (ms)\n", gpuIncluTime);
    printf("Speedup: %fX\n", cpuTime/gpuIncluTime);


    if ((argc - 1) == 3)  // Three Arguments, write result to file
    {
        WriteFile(h_data, argv[3], num_elements);
    }
    else if ((argc - 1) == 1)  // One Argument, write result to file
    {
        WriteFile(h_data, argv[1], num_elements);
    }

    // Check if the result is equivalent to the expected soluion
    unsigned int result_regtest = compare(reference, h_data, num_elements);
    printf( "Test %s\n", (1 == result_regtest) ? "PASSED" : "FAILED");

    // cleanup memory
    //free(h_data);
    free(reference);
    hipFree(h_data);
    hipFree(d_odata);
    hipFree(d_idata);
}


int ReadFile(float* M, char* file_name, int data_read)
{
   unsigned int i = 0;
   std::ifstream ifile(file_name);
   for(; i < data_read; i++){
      ifile>>M[i];
   }
   ifile.close();
   return (i==data_read)? 0:1;
}


void WriteFile(float* M, char* file_name, int data_write)
{
   std::ofstream ofile(file_name);
   for(unsigned int i = 0; i < data_write; i++){
      ofile<<M[i]<<" ";
   }
   ofile.close();
}

unsigned int compare(const float* reference, const float* data, const unsigned int len)
{
   for(unsigned int i = 0; i < len; i++){
        /*
        if(i > 1020 && i <1028){
             cout<<"i = "<<i<<endl;
             cout<<"Host = "<<reference[i]<<endl;
             cout<<"Device = "<<data[i]<<endl;
         //return false;
        }
        */
      float error = fabs(reference[i]-data[i]);
      if(error > 0.0001f){
         return false;
      } 
   }
   return true;
}

unsigned int compare( const float* reference, const float* data, 
                     const unsigned int len);

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

                                        # End of file scope inline assembly
	.globl	_Z22__device_stub__scan_hsPfS_i # -- Begin function _Z22__device_stub__scan_hsPfS_i
	.type	_Z22__device_stub__scan_hsPfS_i,@function
_Z22__device_stub__scan_hsPfS_i:        # @_Z22__device_stub__scan_hsPfS_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z7scan_hsPfS_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z22__device_stub__scan_hsPfS_i, .Lfunc_end0-_Z22__device_stub__scan_hsPfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z12prescanArrayPfS_i           # -- Begin function _Z12prescanArrayPfS_i
	.type	_Z12prescanArrayPfS_i,@function
_Z12prescanArrayPfS_i:                  # @_Z12prescanArrayPfS_i
	.cfi_startproc
# %bb.0:
	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
	movl	%edx, %ebx
	movq	%rsi, %r14
	movq	%rdi, %r15
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	leaq	1023(%rdi), %rdx
	movl	$8192, %r8d                     # imm = 0x2000
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	je	.LBB1_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB1_2:
	.cfi_def_cfa_offset 32
	movq	%r15, %rdi
	movq	%r14, %rsi
	movl	%ebx, %edx
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	_Z22__device_stub__scan_hsPfS_i # TAILCALL
.Lfunc_end1:
	.size	_Z12prescanArrayPfS_i, .Lfunc_end1-_Z12prescanArrayPfS_i
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	_Z7runTestiPPc
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z7runTestiPPc
.LCPI3_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI3_1:
	.long	0x38d1b717                      # float 9.99999974E-5
	.text
	.globl	_Z7runTestiPPc
	.type	_Z7runTestiPPc,@function
_Z7runTestiPPc:                         # @_Z7runTestiPPc
	.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	%rsi, %rbx
	movl	%edi, %ebp
	leaq	64(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_46
# %bb.1:
	leaq	56(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_47
# %bb.2:
	leaq	48(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_48
# %bb.3:
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_49
# %bb.4:
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	hipHostMalloc
	testl	%eax, %eax
	jne	.LBB3_50
# %bb.5:
	cmpl	$4, %ebp
	je	.LBB3_12
# %bb.6:
	cmpl	$3, %ebp
	jne	.LBB3_16
# %bb.7:
	movq	8(%rbx), %rdi
	callq	atoi
	testl	%eax, %eax
	jle	.LBB3_66
# %bb.8:
	movl	%eax, %r14d
	leal	(,%r14,4), %r15d
	leaq	8(%rsp), %rdi
	movq	%r15, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	testl	%eax, %eax
	jne	.LBB3_70
# %bb.9:                                # %.preheader150.preheader
	movl	%r14d, %r12d
	xorl	%r13d, %r13d
.LBB3_10:                               # %.preheader150
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movl	%eax, %ecx
	shrl	$31, %ecx
	addl	%eax, %ecx
	andl	$-2, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movq	8(%rsp), %rdi
	movss	%xmm0, (%rdi,%r13,4)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB3_10
# %bb.11:
	movq	16(%rbx), %rsi
	movl	%r14d, %edx
	callq	_Z9WriteFilePfPci
	jmp	.LBB3_20
.LBB3_12:
	movq	8(%rbx), %rdi
	callq	atoi
	testl	%eax, %eax
	jle	.LBB3_66
# %bb.13:
	movl	%eax, %r14d
	leal	(,%r14,4), %r15d
	leaq	8(%rsp), %rdi
	movq	%r15, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	testl	%eax, %eax
	jne	.LBB3_71
# %bb.14:
	movq	8(%rsp), %rdi
	movq	16(%rbx), %rsi
	movl	%r14d, %edx
	callq	_Z8ReadFilePfPci
	testl	%eax, %eax
	je	.LBB3_20
# %bb.15:
	movl	$.Lstr, %edi
	jmp	.LBB3_67
.LBB3_16:
	leaq	8(%rsp), %rdi
	movl	$67108864, %esi                 # imm = 0x4000000
	xorl	%edx, %edx
	callq	hipHostMalloc
	testl	%eax, %eax
	jne	.LBB3_69
# %bb.17:                               # %.preheader.preheader
	xorl	%r14d, %r14d
.LBB3_18:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movl	%eax, %ecx
	shrl	$31, %ecx
	addl	%eax, %ecx
	andl	$-2, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movq	8(%rsp), %rax
	movss	%xmm0, (%rax,%r14,4)
	incq	%r14
	cmpq	$16777216, %r14                 # imm = 0x1000000
	jne	.LBB3_18
# %bb.19:
	movl	$16777216, %r14d                # imm = 0x1000000
	movl	$67108864, %r15d                # imm = 0x4000000
.LBB3_20:                               # %.loopexit
	movl	%r15d, %r12d
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_51
# %bb.21:
	movq	8(%rsp), %rsi
	movq	%r15, %rdi
	movl	%r14d, %edx
	callq	computeGold
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_52
# %bb.22:
	movq	48(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB3_53
# %bb.23:
	movq	64(%rsp), %rsi
	movq	48(%rsp), %rdx
	leaq	36(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB3_54
# %bb.24:
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	xorl	%r13d, %r13d
	movl	$.L.str.5, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	36(%rsp), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	leaq	24(%rsp), %rdi
	movq	%r13, (%rdi)
	movq	%r13, 16(%rsp)
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_55
# %bb.25:
	leaq	16(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_56
# %bb.26:
	movq	24(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_57
# %bb.27:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_58
# %bb.28:
	movq	16(%rsp), %rdi
	movq	24(%rsp), %rsi
	movl	$16, %edx
	callq	_Z12prescanArrayPfS_i
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_59
# %bb.29:
	movq	24(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_60
# %bb.30:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_61
# %bb.31:
	movq	16(%rsp), %rdi
	movq	24(%rsp), %rsi
	movl	%r14d, %edx
	callq	_Z12prescanArrayPfS_i
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	%r14d, %r12d
	leaq	(,%r12,4), %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_62
# %bb.32:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_63
# %bb.33:
	movq	40(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB3_64
# %bb.34:
	movq	56(%rsp), %rsi
	movq	40(%rsp), %rdx
	leaq	32(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB3_65
# %bb.35:
	cvtss2sd	32(%rsp), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movss	36(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	divss	32(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	cmpl	$4, %ebp
	je	.LBB3_38
# %bb.36:
	cmpl	$2, %ebp
	jne	.LBB3_40
# %bb.37:
	movl	$1, %eax
	jmp	.LBB3_39
.LBB3_38:
	movl	$3, %eax
.LBB3_39:                               # %.lr.ph.preheader.i.sink.split
	movq	8(%rsp), %rdi
	movq	(%rbx,%rax,8), %rsi
	movl	%r14d, %edx
	callq	_Z9WriteFilePfPci
.LBB3_40:                               # %.lr.ph.preheader.i
	movq	8(%rsp), %rax
	movss	(%r15), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	subss	(%rax), %xmm0
	andps	.LCPI3_0(%rip), %xmm0
	movl	$.L.str.11, %esi
	ucomiss	.LCPI3_1(%rip), %xmm0
	ja	.LBB3_45
# %bb.41:                               # %.lr.ph.preheader
	movl	$1, %edx
	movaps	.LCPI3_0(%rip), %xmm0           # xmm0 = [NaN,NaN,NaN,NaN]
	movss	.LCPI3_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
.LBB3_42:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%rdx, %rcx
	cmpq	%rdx, %r12
	je	.LBB3_44
# %bb.43:                               # %.lr.ph.i
                                        #   in Loop: Header=BB3_42 Depth=1
	movss	(%r15,%rcx,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	(%rax,%rcx,4), %xmm2
	andps	%xmm0, %xmm2
	leaq	1(%rcx), %rdx
	ucomiss	%xmm1, %xmm2
	jbe	.LBB3_42
.LBB3_44:                               # %compare.exit.loopexit
	cmpq	%r12, %rcx
	movl	$.L.str.11, %eax
	movl	$.L.str.10, %esi
	cmovbq	%rax, %rsi
.LBB3_45:                               # %compare.exit
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movq	%r15, %rdi
	callq	free
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	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_46:
	.cfi_def_cfa_offset 128
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$145, %ecx
	jmp	.LBB3_72
.LBB3_47:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$146, %ecx
	jmp	.LBB3_72
.LBB3_48:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$147, %ecx
	jmp	.LBB3_72
.LBB3_49:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$148, %ecx
	jmp	.LBB3_72
.LBB3_50:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$159, %ecx
	jmp	.LBB3_72
.LBB3_51:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$240, %ecx
	jmp	.LBB3_72
.LBB3_52:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$242, %ecx
	jmp	.LBB3_72
.LBB3_53:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$243, %ecx
	jmp	.LBB3_72
.LBB3_54:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$244, %ecx
	jmp	.LBB3_72
.LBB3_55:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$255, %ecx
	jmp	.LBB3_72
.LBB3_56:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$256, %ecx                      # imm = 0x100
	jmp	.LBB3_72
.LBB3_57:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$260, %ecx                      # imm = 0x104
	jmp	.LBB3_72
.LBB3_58:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$262, %ecx                      # imm = 0x106
	jmp	.LBB3_72
.LBB3_59:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$272, %ecx                      # imm = 0x110
	jmp	.LBB3_72
.LBB3_60:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$274, %ecx                      # imm = 0x112
	jmp	.LBB3_72
.LBB3_61:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$276, %ecx                      # imm = 0x114
	jmp	.LBB3_72
.LBB3_62:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$292, %ecx                      # imm = 0x124
	jmp	.LBB3_72
.LBB3_63:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$294, %ecx                      # imm = 0x126
	jmp	.LBB3_72
.LBB3_64:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$295, %ecx                      # imm = 0x127
	jmp	.LBB3_72
.LBB3_65:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$296, %ecx                      # imm = 0x128
	jmp	.LBB3_72
.LBB3_66:
	movl	$.Lstr.2, %edi
.LBB3_67:
	callq	puts@PLT
	jmp	.LBB3_68
.LBB3_69:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$226, %ecx
	jmp	.LBB3_72
.LBB3_70:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$186, %ecx
	jmp	.LBB3_72
.LBB3_71:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	$207, %ecx
.LBB3_72:
	xorl	%eax, %eax
	callq	printf
.LBB3_68:
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z7runTestiPPc, .Lfunc_end3-_Z7runTestiPPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z9WriteFilePfPci               # -- Begin function _Z9WriteFilePfPci
	.type	_Z9WriteFilePfPci,@function
_Z9WriteFilePfPci:                      # @_Z9WriteFilePfPci
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$512, %rsp                      # imm = 0x200
	.cfi_def_cfa_offset 560
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
	movq	%rdi, %rbx
	movq	%rsp, %rdi
	movl	$16, %edx
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode
	testl	%ebp, %ebp
	je	.LBB4_5
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
	movq	%rsp, %r14
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r12,4), %xmm0
.Ltmp0:
	movq	%r14, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp1:
# %bb.3:                                # %_ZNSolsEf.exit
                                        #   in Loop: Header=BB4_2 Depth=1
.Ltmp2:
	movl	$.L.str.12, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp3:
# %bb.4:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB4_2
.LBB4_5:                                # %._crit_edge
.Ltmp5:
	movq	%rsp, %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv
.Ltmp6:
# %bb.6:
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE(%rip), %rax
	leaq	8(%rsp), %rdi
	movq	%rax, -8(%rdi)
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE+24(%rip), %rcx
	movq	-24(%rax), %rax
	movq	%rcx, (%rsp,%rax)
	callq	_ZNSt13basic_filebufIcSt11char_traitsIcEED2Ev
	leaq	248(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	addq	$512, %rsp                      # imm = 0x200
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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
.LBB4_7:
	.cfi_def_cfa_offset 560
.Ltmp7:
	jmp	.LBB4_8
.LBB4_9:
.Ltmp4:
.LBB4_8:
	movq	%rax, %rbx
	movq	%rsp, %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end4:
	.size	_Z9WriteFilePfPci, .Lfunc_end4-_Z9WriteFilePfPci
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table4:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp3-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp3
	.uleb128 .Ltmp4-.Lfunc_begin0           #     jumps to .Ltmp4
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp5-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp6-.Ltmp5                  #   Call between .Ltmp5 and .Ltmp6
	.uleb128 .Ltmp7-.Lfunc_begin0           #     jumps to .Ltmp7
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Lfunc_end4-.Ltmp6             #   Call between .Ltmp6 and .Lfunc_end4
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.globl	_Z8ReadFilePfPci                # -- Begin function _Z8ReadFilePfPci
	.type	_Z8ReadFilePfPci,@function
_Z8ReadFilePfPci:                       # @_Z8ReadFilePfPci
.Lfunc_begin1:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception1
# %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	$520, %rsp                      # imm = 0x208
	.cfi_def_cfa_offset 560
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
	movq	%rdi, %rbx
	movq	%rsp, %rdi
	movl	$8, %edx
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode
	testl	%ebp, %ebp
	je	.LBB5_4
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r15d
	movq	%rsp, %r14
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
.Ltmp8:
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	_ZNSi10_M_extractIfEERSiRT_
.Ltmp9:
# %bb.3:                                # %_ZNSirsERf.exit
                                        #   in Loop: Header=BB5_2 Depth=1
	addq	$4, %rbx
	decq	%r15
	jne	.LBB5_2
.LBB5_4:                                # %._crit_edge
.Ltmp11:
	movq	%rsp, %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv
.Ltmp12:
# %bb.5:
	movq	%rsp, %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	xorl	%eax, %eax
	addq	$520, %rsp                      # imm = 0x208
	.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
.LBB5_7:                                # %.loopexit.split-lp
	.cfi_def_cfa_offset 560
.Ltmp13:
	jmp	.LBB5_8
.LBB5_6:                                # %.loopexit
.Ltmp10:
.LBB5_8:
	movq	%rax, %rbx
	movq	%rsp, %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end5:
	.size	_Z8ReadFilePfPci, .Lfunc_end5-_Z8ReadFilePfPci
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table5:
.Lexception1:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end1-.Lcst_begin1
.Lcst_begin1:
	.uleb128 .Lfunc_begin1-.Lfunc_begin1    # >> Call Site 1 <<
	.uleb128 .Ltmp8-.Lfunc_begin1           #   Call between .Lfunc_begin1 and .Ltmp8
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp8-.Lfunc_begin1           # >> Call Site 2 <<
	.uleb128 .Ltmp9-.Ltmp8                  #   Call between .Ltmp8 and .Ltmp9
	.uleb128 .Ltmp10-.Lfunc_begin1          #     jumps to .Ltmp10
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp11-.Lfunc_begin1          # >> Call Site 3 <<
	.uleb128 .Ltmp12-.Ltmp11                #   Call between .Ltmp11 and .Ltmp12
	.uleb128 .Ltmp13-.Lfunc_begin1          #     jumps to .Ltmp13
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp12-.Lfunc_begin1          # >> Call Site 4 <<
	.uleb128 .Lfunc_end5-.Ltmp12            #   Call between .Ltmp12 and .Lfunc_end5
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end1:
	.p2align	2, 0x0
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function compare
.LCPI6_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI6_1:
	.long	0x38d1b717                      # float 9.99999974E-5
	.text
	.globl	compare
	.type	compare,@function
compare:                                # @compare
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	je	.LBB6_1
# %bb.3:                                # %.lr.ph.preheader
	movss	(%rdi), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	subss	(%rsi), %xmm0
	andps	.LCPI6_0(%rip), %xmm0
	xorl	%eax, %eax
	ucomiss	.LCPI6_1(%rip), %xmm0
	ja	.LBB6_2
# %bb.4:                                # %.lr.ph19.preheader
	movl	%edx, %ecx
	movl	$1, %eax
	movaps	.LCPI6_0(%rip), %xmm0           # xmm0 = [NaN,NaN,NaN,NaN]
	movss	.LCPI6_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
.LBB6_5:                                # %.lr.ph19
                                        # =>This Inner Loop Header: Depth=1
	movq	%rax, %rdx
	cmpq	%rax, %rcx
	je	.LBB6_7
# %bb.6:                                # %.lr.ph
                                        #   in Loop: Header=BB6_5 Depth=1
	movss	(%rdi,%rdx,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	(%rsi,%rdx,4), %xmm2
	andps	%xmm0, %xmm2
	leaq	1(%rdx), %rax
	ucomiss	%xmm1, %xmm2
	jbe	.LBB6_5
.LBB6_7:                                # %._crit_edge.loopexit.loopexit
	xorl	%eax, %eax
	cmpq	%rcx, %rdx
	setae	%al
	retq
.LBB6_1:
	movl	$1, %eax
.LBB6_2:                                # %._crit_edge
	retq
.Lfunc_end6:
	.size	compare, .Lfunc_end6-compare
	.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	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7scan_hsPfS_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z7scan_hsPfS_i,@object         # @_Z7scan_hsPfS_i
	.section	.rodata,"a",@progbits
	.globl	_Z7scan_hsPfS_i
	.p2align	3, 0x0
_Z7scan_hsPfS_i:
	.quad	_Z22__device_stub__scan_hsPfS_i
	.size	_Z7scan_hsPfS_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%s in %s at line %d\n"
	.size	.L.str, 21

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/szywind/HPC-759/master/HW08/scan_largearray.hip"
	.size	.L.str.1, 110

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Processing %d elements...\n"
	.size	.L.str.5, 27

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"GPU inclusive time: %f (ms)\n"
	.size	.L.str.7, 29

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Speedup: %fX\n"
	.size	.L.str.8, 14

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

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"PASSED"
	.size	.L.str.10, 7

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"FAILED"
	.size	.L.str.11, 7

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7scan_hsPfS_i"
	.size	.L__unnamed_1, 16

	.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	"Error reading input file!"
	.size	.Lstr, 26

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Error reading parameter file"
	.size	.Lstr.2, 29

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"\n\n**===-------------------------------------------------===**"
	.size	.Lstr.3, 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 _Z22__device_stub__scan_hsPfS_i
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z7scan_hsPfS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7scan_hsPfS_i         ; -- Begin function _Z7scan_hsPfS_i
	.globl	_Z7scan_hsPfS_i
	.p2align	8
	.type	_Z7scan_hsPfS_i,@function
_Z7scan_hsPfS_i:                        ; @_Z7scan_hsPfS_i
; %bb.0:
	s_mov_b64 s[2:3], src_shared_base
	s_delay_alu instid0(SALU_CYCLE_1)
	v_dual_mov_b32 v1, 0 :: v_dual_mov_b32 v2, s3
	s_mov_b32 s8, 0
	s_load_b32 s4, s[0:1], 0x10
	flat_store_b32 v[1:2], v1 dlc
	s_waitcnt_vscnt null, 0x0
	s_load_b32 s2, s[0:1], 0x24
	s_waitcnt lgkmcnt(0)
	s_add_i32 s4, s4, -1
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f32_u32_e32 v2, s2
	s_sub_i32 s6, 0, s2
	v_rcp_iflag_f32_e32 v2, v2
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v2, 0x4f7ffffe, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v2, v2
	v_readfirstlane_b32 s5, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s6, s6, s5
	s_mul_hi_u32 s6, s5, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s5, s5, s6
	s_mul_hi_u32 s5, s4, s5
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s6, s5, s2
	s_sub_i32 s4, s4, s6
	s_add_i32 s6, s5, 1
	s_sub_i32 s7, s4, s2
	s_cmp_ge_u32 s4, s2
	s_cselect_b32 s5, s6, s5
	s_cselect_b32 s4, s7, s4
	s_add_i32 s6, s5, 1
	s_cmp_ge_u32 s4, s2
	s_cselect_b32 s4, s6, s5
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v9, s4, s4, 1
	s_and_b32 vcc_lo, exec_lo, s4
	s_cbranch_vccnz .LBB0_10
; %bb.1:                                ; %.lr.ph44
	s_load_b128 s[4:7], s[0:1], 0x0
	v_lshl_add_u32 v10, v0, 2, 4
	s_cmp_gt_u32 s2, 1
	v_cmp_eq_u32_e64 s0, 0, v0
	s_cselect_b32 s9, -1, 0
	s_add_i32 s1, s2, -1
	v_cmp_ne_u32_e32 vcc_lo, -1, v10
	v_cmp_eq_u32_e64 s1, s1, v0
	v_dual_mov_b32 v2, s3 :: v_dual_cndmask_b32 v3, 0, v10
	v_cndmask_b32_e64 v4, 0, s3, vcc_lo
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	v_mad_u64_u32 v[5:6], null, s8, s2, v[0:1]
	s_mov_b32 s10, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v6, 31, v5
	v_lshlrev_b64 v[7:8], 2, v[5:6]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s6, v7
	v_add_co_ci_u32_e32 v6, vcc_lo, s7, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v11, vcc_lo, v5, -4
	v_add_co_ci_u32_e32 v12, vcc_lo, -1, v6, vcc_lo
	s_and_not1_b32 vcc_lo, exec_lo, s9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v11, v11, 0, s0
	v_cndmask_b32_e64 v12, v12, s3, s0
	flat_load_b32 v11, v[11:12] glc dlc
	s_waitcnt vmcnt(0) lgkmcnt(0)
	flat_store_b32 v[3:4], v11 dlc
	s_waitcnt_vscnt null, 0x0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_vccnz .LBB0_7
; %bb.3:                                ; %.lr.ph.preheader
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_mov_b32 s11, 1
	s_mov_b32 s12, 1
.LBB0_4:                                ; %.lr.ph
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_sub_i32 s12, 1, s12
	s_mov_b32 s13, exec_lo
	s_mul_i32 s14, s12, s2
	v_lshl_add_u32 v11, s14, 2, v10
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v11
	v_cndmask_b32_e32 v11, 0, v11, vcc_lo
	v_cndmask_b32_e64 v12, 0, s3, vcc_lo
	flat_load_b32 v11, v[11:12] glc dlc
	s_waitcnt vmcnt(0)
	v_cmpx_le_u32_e64 s11, v0
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=2
	v_add_nc_u32_e32 v12, s14, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_subrev_nc_u32_e32 v12, s11, v12
	v_lshl_add_u32 v12, v12, 2, 4
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v12
	v_cndmask_b32_e32 v12, 0, v12, vcc_lo
	v_cndmask_b32_e64 v13, 0, s3, vcc_lo
	flat_load_b32 v12, v[12:13] glc dlc
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_add_f32_e32 v11, v11, v12
.LBB0_6:                                ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s13
	s_sub_i32 s10, 1, s10
	s_lshl_b32 s11, s11, 1
	s_mul_i32 s13, s10, s2
	s_cmp_ge_u32 s11, s2
	v_lshl_add_u32 v12, s13, 2, v10
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v12
	v_cndmask_b32_e32 v12, 0, v12, vcc_lo
	v_cndmask_b32_e64 v13, 0, s3, vcc_lo
	s_waitcnt lgkmcnt(0)
	flat_store_b32 v[12:13], v11 dlc
	s_waitcnt_vscnt null, 0x0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_4
.LBB0_7:                                ; %Flow58
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_mul_i32 s10, s10, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshl_add_u32 v11, s10, 2, v10
	v_cmp_ne_u32_e32 vcc_lo, -1, v11
	v_cndmask_b32_e32 v11, 0, v11, vcc_lo
	v_cndmask_b32_e64 v12, 0, s3, vcc_lo
	v_add_co_u32 v7, vcc_lo, s4, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s5, v8, vcc_lo
	flat_load_b32 v11, v[11:12] glc dlc
	s_waitcnt vmcnt(0) lgkmcnt(0)
	global_store_b32 v[7:8], v11, off
	s_and_saveexec_b32 s10, s1
	s_cbranch_execz .LBB0_9
; %bb.8:                                ;   in Loop: Header=BB0_2 Depth=1
	global_load_b32 v5, v[5:6], off
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v5, v11, v5
	flat_store_b32 v[1:2], v5 dlc
	s_waitcnt_vscnt null, 0x0
.LBB0_9:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	s_add_i32 s8, s8, 1
	s_waitcnt lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
	v_cmp_ge_u32_e32 vcc_lo, s8, v9
	s_barrier
	buffer_gl0_inv
	s_cbranch_vccz .LBB0_2
.LBB0_10:                               ; %._crit_edge45
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7scan_hsPfS_i
		.amdhsa_group_segment_fixed_size 4
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 14
		.amdhsa_next_free_sgpr 15
		.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	_Z7scan_hsPfS_i, .Lfunc_end0-_Z7scan_hsPfS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 744
; NumSgprs: 17
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 17
; NumVGPRsForWavesPerEU: 14
; 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 4
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7scan_hsPfS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     17
    .sgpr_spill_count: 0
    .symbol:         _Z7scan_hsPfS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     14
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
