/*--------------------------------------------------------------------------------------------------*/
/*                                                                                                  */
/*       Alberto Quesada Aranda                                                                     */
/*       Åbo Akademi University                                                                     */
/*       Advanced Computer Graphics and Graphics Hardware                                           */
/*                                                                                                  */
/*       Two-Point angula correlation code                                                          */
/*       Input: two list of galaxies                                                                */
/*       Output: .txt file with the data for generate the histogram                                 */
/*                                                                                                  */
/*       Base code taken from: https://github.com/djbard/ccogs/tree/master/angular_correlation      */
/*                                                                                                  */
/*--------------------------------------------------------------------------------------------------*/


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

using namespace std;

#define SUBMATRIX_SIZE 16384 // parallel threads: 32 blocks * 512 threads/block = 16384 threads
#define DEFAULT_NBINS 256  // num of bins for the histogram

#define	arcm_to_rad 1/3437.7468  // (1/60)*(pi/180), convert from arcm to rad
#define conv_angle 57.2957795; // 180/pi, convert from rad to degrees

// variables for calculate the execution time
static clock_t start_time;
static double elapsed;

/*------------------------------------------------------------------
	Kernel to calculate angular distances
-------------------------------------------------------------------*/

__global__ void distance(volatile float *a0, volatile float *d0, volatile float *a1, volatile float *d1, int xind, int yind, int max_xind, int max_yind, volatile int *dev_hist, float hist_min, float hist_max, int nbins, float bin_width, bool two_different_files=1) {

    int idx = blockIdx.x * blockDim.x + threadIdx.x;  // idx is the thread id, it must range to 32blocks * 512threads/block = 16384 threads
    idx += xind;    // allow the thread to know which submatrix has to calculate

    // printf("%d  %d  %d\n", blockIdx.x, threadIdx.x, blockDim.x);
    // blockIdx.x [0-31]
    // blockDim.x 512
    // threadIdx.x [0-511]

    __shared__ int shared_hist[DEFAULT_NBINS+2];    // shared vector for save the results within a block of threads

    // initialize it only once in each block
    if(threadIdx.x==0)
    {
        for (int i=0;i<nbins+2;i++)
            shared_hist[i] = 0;
    }

    // before starting the calculations we need to be sure that the shared_hist is initialized; if not, we take the risk
    // of loss calculations because we don't know the order in which the threads are executed and is possible that a thread
    // performs the calculations and write the results in shared_hist before the thread 0 has initialized it.
    __syncthreads();

    // if NUM_GALAXIES0 % SUBMATRIX_SIZE != 0 in the last submatrix we will have more threads than needed calculations, therefore
    // we won't perform calculations with those threads.
    if (idx<max_xind) {

        float dist, alpha1, delta1, a_diff;
        float alpha0 = a0[idx];
        float delta0 = d0[idx];

        bool do_calc = 1;
        int bin_index = 0; 

        // each kernel will calculate the angle between one galaxy of the first input data (idx) and all the galaxies within [yind-ymax]
        int ymax = yind + SUBMATRIX_SIZE; // ymax will be the end of the submatrix that we are calculating of the second galaxies input

        // we have to take care and if ymax > NUM_GALAXIES1, we stop the calculations bucle at that point
        if (ymax>max_yind)
            ymax = max_yind;

        // we will perform the same calculation between input0[idx] and every input1[] (range [yind-ymax])
        for(int i=yind; i<ymax; i++) 
        {
            // if the two input files are different (DR case) we have to perform all N*N calculations
            if (two_different_files) {
                do_calc = 1;
            }
            // if the two input files are the same (DD, RR cases) we have to perform N*(N-1)/2 calculations
            else {
                if (xind != yind) {
                    do_calc = 1;
                }
                else {
                    if(idx > i)
                        do_calc=1;
                    else
                        do_calc=0;
                }
            }

            if (do_calc)
            {              
                alpha1 = a1[i];
                delta1 = d1[i];
                a_diff = alpha0 - alpha1;
                dist = acos(sin(delta0)*sin(delta1) + cos(alpha0)*cos(alpha1)*cos(a_diff));
                dist *= conv_angle; // convert from rad to degrees

                // check in which bin we have to include the angle calculated
                if(dist < hist_min) // underflow
                    bin_index = 0; 
                else if(dist >= hist_max) // overflow
                    bin_index = nbins + 1;
                else {
                    bin_index = int((dist-hist_min)/bin_width) + 1;
                }

                // more than one thread could try to write its result in the shared_hist at the same time and in the same memory
                // location. We need an atomic operation for prevent the loss of data
                atomicAdd(&shared_hist[bin_index],1); // increment by one the corresponding histogram bin 

            }
        }
    }

    // before copy the results of each block to the global histogram we have to be sure that all the threads within the block have
    // ended its calculations
    __syncthreads();

    // only one thread (0) will write the results of the block to which it belongs to the global histogram
    // for avoid the need of another atomic operation, our global histogram save the result of each block successively :
    // [block[0], block[1] .... block [31]]
    if(threadIdx.x==0)
    {
        for(int i=0;i<nbins+2;i++)
            dev_hist[i+(blockIdx.x*(nbins+2))]=shared_hist[i]; 
    }

}


/*------------------------------------------------------------------
	Calculations and call to kernel
-------------------------------------------------------------------*/

int calc(FILE *infile0, FILE *infile1, FILE *outfile, int nbins, float hist_lower_range, float hist_upper_range, float hist_bin_width, bool two_different_files){
    
	//d_ means device -> GPU, h_ means host -> CPU
    float *d_alpha0, *d_delta0, *d_alpha1, *d_delta1;
    float *h_alpha0, *h_delta0, *h_alpha1, *h_delta1;
    int NUM_GALAXIES0, NUM_GALAXIES1;

    // reading the data of the input files
    // first we read the number of galaxies of each file
    fscanf(infile0, "%d", &NUM_GALAXIES0);
    fscanf(infile1, "%d", &NUM_GALAXIES1);

    // calculate the size of the array needed for save in memory all the galaxies
    int size_of_galaxy_array0 = NUM_GALAXIES0 * sizeof(float);    
	int size_of_galaxy_array1 = NUM_GALAXIES1 * sizeof(float); 

	printf("SIZE 0 # GALAXIES: %d\n",NUM_GALAXIES0);
  	printf("SIZE 1 # GALAXIES: %d\n",NUM_GALAXIES1);

  	// allocate space for the galaxies data in global memory
    h_alpha0 = (float*)malloc(size_of_galaxy_array0);
    h_delta0 = (float*)malloc(size_of_galaxy_array0);
    h_alpha1 = (float*)malloc(size_of_galaxy_array1);
    h_delta1 = (float*)malloc(size_of_galaxy_array1);

    float temp0, temp1;

    // reading and saving the galaxies data in radians
    for(int i=0; i<NUM_GALAXIES0; i++)
    {
        fscanf(infile0, "%f %f", &temp0, &temp1);
        h_alpha0[i] = temp0 * arcm_to_rad;
        h_delta0[i] = temp1 * arcm_to_rad;
    }

    for(int i=0; i<NUM_GALAXIES1; i++)
    {
        fscanf(infile1, "%f %f", &temp0, &temp1);
        h_alpha1[i] = temp0 * arcm_to_rad;
        h_delta1[i] = temp1 * arcm_to_rad;
    }

    // defining dimensions for the grid and block
    dim3 grid, block;
    grid.x = 8192/(DEFAULT_NBINS); // number of blocks = 32
    block.x = SUBMATRIX_SIZE/grid.x; // number of threads/block = 512

    // allocating the histograms
    /* I will need 3 arrays for the histograms:
        - hist : for each submatrix, save the results of each thread block seccuentially (global memory)
        - dev_hist : the same as hist, but in GPU memory
        - hist_array : save the global result of all the submatrix in global memory
    */

    int *hist, *dev_hist;

    int size_hist = grid.x * (nbins+2); // I use +2, one for underflow and other for overflow
    int size_hist_bytes = size_hist*sizeof(int);

    // allocating and initializing to 0 hist in global mem
    hist = (int*)malloc(size_hist_bytes);
    memset(hist, 0, size_hist_bytes);

    // allocating and initializing to 0 dev_hist in GPU mem
    cudaMalloc((void **) &dev_hist, (size_hist_bytes));
    cudaMemset(dev_hist, 0, size_hist_bytes);

    unsigned long  *hist_array;

    // allocating and initializing to 0 the array for the final histogram (the sum of each submatrix partial result)
    int hist_array_size = (nbins+2) * sizeof(unsigned long);
    hist_array =  (unsigned long*)malloc(hist_array_size);
    memset(hist_array,0,hist_array_size); 

    // allocating memory in GPU for save the galaxies data
    cudaMalloc((void **) &d_alpha0, size_of_galaxy_array0 );
    cudaMalloc((void **) &d_delta0, size_of_galaxy_array0 );
    cudaMalloc((void **) &d_alpha1, size_of_galaxy_array1 );
    cudaMalloc((void **) &d_delta1, size_of_galaxy_array1 );

    // check to see if we allocated enough memory.
    if (0==d_alpha0 || 0==d_delta0 || 0==d_alpha1 || 0==d_delta1 || 0==dev_hist)
    {
        printf("couldn't allocate enough memory in GPU\n");
        return 1;
    }

    // initialize array to all 0's
    /*cudaMemset(d_alpha0,0,size_of_galaxy_array0);
    cudaMemset(d_delta0,0,size_of_galaxy_array0);
    cudaMemset(d_alpha1,0,size_of_galaxy_array1);
    cudaMemset(d_delta1,0,size_of_galaxy_array1);*/

    // copy galaxies data to GPU
    cudaMemcpy(d_alpha0, h_alpha0, size_of_galaxy_array0, cudaMemcpyHostToDevice );
    cudaMemcpy(d_delta0, h_delta0, size_of_galaxy_array0, cudaMemcpyHostToDevice );
    cudaMemcpy(d_alpha1, h_alpha1, size_of_galaxy_array1, cudaMemcpyHostToDevice );
    cudaMemcpy(d_delta1, h_delta1, size_of_galaxy_array1, cudaMemcpyHostToDevice );

    int x, y;
    int num_submatrices_x = NUM_GALAXIES0 / SUBMATRIX_SIZE;
    int num_submatrices_y = NUM_GALAXIES1 / SUBMATRIX_SIZE;

    // if NUM_GALAXIES % SUBMATRIX_SIZE != 0, we will need one submatrix more (not the whole submatrix) for perform all the calculations
    if (NUM_GALAXIES0%SUBMATRIX_SIZE != 0) {
        num_submatrices_x += 1;
    }
    if (NUM_GALAXIES1%SUBMATRIX_SIZE != 0) {
        num_submatrices_y += 1;
    }

    int bin_index = 0;
    // explanation of the iterations in the documentation
    for(int k = 0; k < num_submatrices_y; k++)
    {
        y = k*SUBMATRIX_SIZE;

        int jmax = 0;
        
        // if the two files are the same, then only loop over the upper half of the matrix of operations
        if (two_different_files == 0)
            jmax = k;

        for(int j = jmax; j < num_submatrices_x; j++)
        {
            x = j*SUBMATRIX_SIZE; 

            // set the histogram to all zeros each time.
            cudaMemset(dev_hist,0,size_hist_bytes);

            // call to the kernel
            distance<<<grid,block>>>(d_alpha0, d_delta0,d_alpha1, d_delta1, x, y, NUM_GALAXIES0, NUM_GALAXIES1, dev_hist, hist_lower_range, hist_upper_range, nbins, hist_bin_width, two_different_files);

            // copy the results from GPU memory to global mem
            cudaMemcpy(hist, dev_hist, size_hist_bytes, cudaMemcpyDeviceToHost);

            // add together the results of each block in a single histogram
            for(int m=0; m<size_hist; m++)
            {
                bin_index = m%(nbins+2); // range it to [0-258]
                hist_array[bin_index] += hist[m];
            }    
        }  
    }

    unsigned long total = 0;

    // write in the output file the range of the bin of the histogram and the number of galaxies included in that range
    // start in k = 1 and finish before nbins+1 for avoid the over/underflow
    float lo = hist_lower_range;
    float hi = 0;
    for(int k=1; k<nbins+1; k++)
    {
        hi = lo + hist_bin_width;

        fprintf(outfile, "%.3e %.3e %lu \n",lo,hi,hist_array[k]);
        total += hist_array[k];

        lo = hi;
    }
    printf("total: %lu \n", total);

    // close opened files
    fclose(infile0);
    fclose(infile1);
    fclose(outfile);

    // free global memory
    free(h_alpha0);
    free(h_delta0);
    free(h_alpha1);
    free(h_delta1);
    free(hist);

    // free GPU memory
    cudaFree(d_alpha0);
    cudaFree(d_delta0);  
    cudaFree(d_alpha1);
    cudaFree(d_delta1);  
    cudaFree(dev_hist);

    return 0;
}  

/*------------------------------------------------------------------
	MAIN
-------------------------------------------------------------------*/

int main(int argc, char **argv) {

    start_time = clock(); // start the timer

    int nbins = DEFAULT_NBINS; // 256 bins --> 0-64º --> 64/0.25 = 256
    float bin_width = 0.25;
    float lower_range = 0.0000001;
    float upper_range = nbins * bin_width; // 256 * 0.25 = 64
    bool different_files = 1;

    if (argc != 3) {
        printf("\nMust pass two input files.\n");
        exit(1);
    }
    
    // opening the input files and creating the output file
    FILE *infile0, *infile1, *outfile;
    infile0 = fopen(argv[optind],"r");
    infile1 = fopen(argv[optind+1],"r");
    outfile = fopen("output.txt", "w");

    // if the input files are the same (DD, RR) the calculations needed are different from the DR case
    if (strcmp(argv[optind],argv[optind+1]) == 0) {
        different_files = 0;
        printf("Input files are the same!\n");
    }

    calc(infile0, infile1, outfile, nbins, lower_range, upper_range, bin_width, different_files);

    // total time 
    elapsed = clock() - start_time;
    elapsed = elapsed / CLOCKS_PER_SEC;
    printf("Execution time: %f \n", elapsed);

    return 0;
}


	.file	"tmpxft_0020659a_00000000-6_project.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2044:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2044:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z49__device_stub__Z8distancePVfS0_S0_S0_iiiiPViffifbPVfS0_S0_S0_iiiiPViffifb
	.type	_Z49__device_stub__Z8distancePVfS0_S0_S0_iiiiPViffifbPVfS0_S0_S0_iiiiPViffifb, @function
_Z49__device_stub__Z8distancePVfS0_S0_S0_iiiiPViffifbPVfS0_S0_S0_iiiiPViffifb:
.LFB2066:
	.cfi_startproc
	endbr64
	subq	$264, %rsp
	.cfi_def_cfa_offset 272
	movq	288(%rsp), %rax
	movq	%rdi, 56(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rax, 16(%rsp)
	movl	304(%rsp), %eax
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movq	%rcx, 32(%rsp)
	leaq	80(%rsp), %rcx
	movl	%r8d, 28(%rsp)
	movl	%r9d, 24(%rsp)
	movb	%al, (%rsp)
	movss	%xmm0, 12(%rsp)
	movss	%xmm1, 8(%rsp)
	movss	%xmm2, 4(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 248(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	272(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	280(%rsp), %rax
	movq	%rax, 192(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 200(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 208(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 216(%rsp)
	leaq	296(%rsp), %rax
	movq	%rax, 224(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 232(%rsp)
	movq	%rsp, %rax
	movq	%rax, 240(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 88(%rsp)
	movl	$1, 96(%rsp)
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	80(%rsp)
	.cfi_def_cfa_offset 280
	leaq	_Z8distancePVfS0_S0_S0_iiiiPViffifb(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 288
	movq	116(%rsp), %rcx
	movl	124(%rsp), %r8d
	movq	104(%rsp), %rsi
	movl	112(%rsp), %edx
	leaq	152(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 280
	popq	%rdx
	.cfi_def_cfa_offset 272
.L2:
	movq	248(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$264, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2066:
	.size	_Z49__device_stub__Z8distancePVfS0_S0_S0_iiiiPViffifbPVfS0_S0_S0_iiiiPViffifb, .-_Z49__device_stub__Z8distancePVfS0_S0_S0_iiiiPViffifbPVfS0_S0_S0_iiiiPViffifb
	.globl	_Z8distancePVfS0_S0_S0_iiiiPViffifb
	.type	_Z8distancePVfS0_S0_S0_iiiiPViffifb, @function
_Z8distancePVfS0_S0_S0_iiiiPViffifb:
.LFB2067:
	.cfi_startproc
	endbr64
	movzbl	40(%rsp), %eax
	movl	%eax, 40(%rsp)
	jmp	_Z49__device_stub__Z8distancePVfS0_S0_S0_iiiiPViffifbPVfS0_S0_S0_iiiiPViffifb
	.cfi_endproc
.LFE2067:
	.size	_Z8distancePVfS0_S0_S0_iiiiPViffifb, .-_Z8distancePVfS0_S0_S0_iiiiPViffifb
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"SIZE 0 # GALAXIES: %d\n"
.LC2:
	.string	"SIZE 1 # GALAXIES: %d\n"
.LC3:
	.string	"%f %f"
.LC5:
	.string	"couldn't allocate enough memory in GPU\n"
.LC6:
	.string	"%.3e %.3e %lu \n"
.LC7:
	.string	"total: %lu \n"
	.text
	.globl	_Z4calcP8_IO_FILES0_S0_ifffb
	.type	_Z4calcP8_IO_FILES0_S0_ifffb, @function
_Z4calcP8_IO_FILES0_S0_ifffb:
.LFB2040:
	.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
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%ecx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC0(%rip), %rbx
	subq	$216, %rsp
	.cfi_def_cfa_offset 272
	movb	%r8b, 91(%rsp)
	movq	%rdi, 56(%rsp)
	movq	%rsi, 64(%rsp)
	movq	%rbx, %rsi
	movq	%rdx, 72(%rsp)
	leaq	120(%rsp), %rdx
	movss	%xmm0, 80(%rsp)
	movss	%xmm1, 108(%rsp)
	movss	%xmm2, 84(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	64(%rsp), %rdi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	leaq	124(%rsp), %rdx
	leaq	.LC3(%rip), %rbx
	call	__isoc23_fscanf@PLT
	movl	120(%rsp), %ebp
	movl	124(%rsp), %eax
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movl	%ebp, %edx
	leal	0(,%rax,4), %r13d
	xorl	%eax, %eax
	sall	$2, %ebp
	call	__printf_chk@PLT
	movl	124(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	movslq	%ebp, %rbp
	movslq	%r13d, %r13
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	movq	%r13, %rdi
	movq	%rax, 32(%rsp)
	call	malloc@PLT
	movq	%r13, %rdi
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	movq	%rax, 48(%rsp)
.L9:
	cmpl	%r14d, 120(%rsp)
	jle	.L38
	movq	56(%rsp), %rdi
	leaq	132(%rsp), %rcx
	movq	%rbx, %rsi
	xorl	%eax, %eax
	leaq	128(%rsp), %rdx
	call	__isoc23_fscanf@PLT
	movsd	.LC4(%rip), %xmm1
	movq	24(%rsp), %rax
	cvtss2sd	128(%rsp), %xmm0
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rax,%r14,4)
	movq	32(%rsp), %rax
	cvtss2sd	132(%rsp), %xmm0
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rax,%r14,4)
	incq	%r14
	jmp	.L9
.L38:
	xorl	%r14d, %r14d
	leaq	.LC3(%rip), %rbx
.L11:
	cmpl	%r14d, 124(%rsp)
	jle	.L39
	movq	64(%rsp), %rdi
	leaq	132(%rsp), %rcx
	movq	%rbx, %rsi
	xorl	%eax, %eax
	leaq	128(%rsp), %rdx
	call	__isoc23_fscanf@PLT
	movsd	.LC4(%rip), %xmm1
	movq	40(%rsp), %rax
	cvtss2sd	128(%rsp), %xmm0
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rax,%r14,4)
	movq	48(%rsp), %rax
	cvtss2sd	132(%rsp), %xmm0
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rax,%r14,4)
	incq	%r14
	jmp	.L11
.L39:
	movabsq	$4294967297, %rax
	leal	2(%r12), %r14d
	movl	$1, 196(%rsp)
	movq	%rax, 180(%rsp)
	addq	$511, %rax
	leal	0(,%r14,8), %r15d
	movq	%rax, 188(%rsp)
	movl	%r14d, %eax
	movslq	%r15d, %r15
	sall	$7, %eax
	cltq
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rcx
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	movq	%rcx, %rdx
	call	__memset_chk@PLT
	movq	8(%rsp), %rsi
	leaq	168(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdx
	movq	168(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movq	%r15, %rdi
	call	malloc@PLT
	movq	%r15, %rcx
	movq	%r15, %rdx
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	__memset_chk@PLT
	leaq	136(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	leaq	144(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	leaq	152(%rsp), %rdi
	movq	%r13, %rsi
	call	cudaMalloc@PLT
	leaq	160(%rsp), %rdi
	movq	%r13, %rsi
	call	cudaMalloc@PLT
	movq	136(%rsp), %rdi
	testq	%rdi, %rdi
	je	.L13
	cmpq	$0, 144(%rsp)
	je	.L13
	cmpq	$0, 152(%rsp)
	je	.L13
	cmpq	$0, 160(%rsp)
	je	.L13
	cmpq	$0, 168(%rsp)
	jne	.L14
.L13:
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L8
.L14:
	movq	24(%rsp), %rsi
	movl	$1, %ecx
	movq	%rbp, %rdx
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rsi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	144(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rsi
	movq	%r13, %rdx
	movq	152(%rsp), %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	48(%rsp), %rsi
	movq	%r13, %rdx
	movq	160(%rsp), %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	120(%rsp), %eax
	movl	$16384, %ecx
	movzbl	91(%rsp), %r15d
	cltd
	idivl	%ecx
	movl	%eax, %esi
	movl	124(%rsp), %eax
	cltd
	idivl	%ecx
	movl	120(%rsp), %edx
	andl	$16383, %edx
	cmpl	$1, %edx
	movl	124(%rsp), %edx
	sbbl	$-1, %esi
	andl	$16383, %edx
	movl	%esi, 92(%rsp)
	cmpl	$1, %edx
	sbbl	$-1, %eax
	xorl	%r13d, %r13d
	movl	%eax, 96(%rsp)
	movl	%r14d, %eax
	sall	$5, %eax
	movl	%eax, 100(%rsp)
.L18:
	cmpl	%r13d, 96(%rsp)
	jle	.L40
	movl	%r13d, %eax
	xorl	%ebp, %ebp
	sall	$14, %eax
	cmpb	$0, 91(%rsp)
	movl	%eax, 104(%rsp)
	cmove	%r13d, %ebp
.L20:
	cmpl	%ebp, 92(%rsp)
	jle	.L41
	movq	8(%rsp), %rdx
	movq	168(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	196(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	188(%rsp), %rdx
	movl	184(%rsp), %esi
	movl	$32, 176(%rsp)
	movq	176(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	pushq	%rax
	.cfi_def_cfa_offset 280
	movl	%ebp, %r8d
	pushq	%r15
	.cfi_def_cfa_offset 288
	sall	$14, %r8d
	pushq	%r12
	.cfi_def_cfa_offset 296
	pushq	192(%rsp)
	.cfi_def_cfa_offset 304
	movl	156(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 312
	movl	160(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 320
	movl	152(%rsp), %r9d
	movq	208(%rsp), %rcx
	movq	200(%rsp), %rdx
	movq	192(%rsp), %rsi
	movq	184(%rsp), %rdi
	movss	132(%rsp), %xmm2
	movss	156(%rsp), %xmm1
	movss	128(%rsp), %xmm0
	call	_Z49__device_stub__Z8distancePVfS0_S0_S0_iiiiPViffifbPVfS0_S0_S0_iiiiPViffifb
	addq	$48, %rsp
	.cfi_def_cfa_offset 272
.L21:
	movq	8(%rsp), %rdx
	movq	16(%rsp), %rdi
	movl	$2, %ecx
	movq	168(%rsp), %rsi
	call	cudaMemcpy@PLT
	xorl	%ecx, %ecx
.L22:
	movl	%ecx, %eax
	cmpl	%ecx, 100(%rsp)
	jle	.L42
	cltd
	idivl	%r14d
	movq	16(%rsp), %rax
	movslq	(%rax,%rcx,4), %rax
	incq	%rcx
	movslq	%edx, %rdx
	addq	%rax, (%rbx,%rdx,8)
	jmp	.L22
.L42:
	incl	%ebp
	jmp	.L20
.L41:
	incl	%r13d
	jmp	.L18
.L40:
	xorl	%r14d, %r14d
	xorl	%r15d, %r15d
	leaq	.LC6(%rip), %r13
.L26:
	incq	%r14
	cmpl	%r14d, %r12d
	jl	.L43
	movq	(%rbx,%r14,8), %rbp
	movss	80(%rsp), %xmm2
	movq	%r13, %rdx
	movb	$2, %al
	addss	84(%rsp), %xmm2
	movq	72(%rsp), %rdi
	movl	$2, %esi
	cvtss2sd	80(%rsp), %xmm0
	movq	%rbp, %rcx
	addq	%rbp, %r15
	movss	%xmm2, 8(%rsp)
	cvtss2sd	%xmm2, %xmm1
	call	__fprintf_chk@PLT
	movss	8(%rsp), %xmm2
	movss	%xmm2, 80(%rsp)
	jmp	.L26
.L43:
	movq	%r15, %rdx
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	56(%rsp), %rdi
	call	fclose@PLT
	movq	64(%rsp), %rdi
	call	fclose@PLT
	movq	72(%rsp), %rdi
	call	fclose@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	free@PLT
	movq	48(%rsp), %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	136(%rsp), %rdi
	call	cudaFree@PLT
	movq	144(%rsp), %rdi
	call	cudaFree@PLT
	movq	152(%rsp), %rdi
	call	cudaFree@PLT
	movq	160(%rsp), %rdi
	call	cudaFree@PLT
	movq	168(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%eax, %eax
.L8:
	movq	200(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$216, %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
.LFE2040:
	.size	_Z4calcP8_IO_FILES0_S0_ifffb, .-_Z4calcP8_IO_FILES0_S0_ifffb
	.section	.rodata.str1.1
.LC8:
	.string	"\nMust pass two input files.\n"
.LC9:
	.string	"r"
.LC10:
	.string	"w"
.LC11:
	.string	"output.txt"
.LC12:
	.string	"Input files are the same!\n"
.LC17:
	.string	"Execution time: %f \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2041:
	.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
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rsi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	call	clock@PLT
	movq	%rax, _ZL10start_time(%rip)
	cmpl	$3, %ebp
	je	.L45
	movl	$2, %edi
	leaq	.LC8(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L45:
	movslq	optind(%rip), %rax
	leaq	.LC9(%rip), %r12
	movq	%r12, %rsi
	movq	(%rbx,%rax,8), %rdi
	call	fopen@PLT
	movq	%r12, %rsi
	movq	%rax, %rbp
	movslq	optind(%rip), %rax
	movq	8(%rbx,%rax,8), %rdi
	call	fopen@PLT
	leaq	.LC10(%rip), %rsi
	leaq	.LC11(%rip), %rdi
	movq	%rax, %r12
	call	fopen@PLT
	movq	%rax, %r13
	movslq	optind(%rip), %rax
	incq	%rax
	movq	(%rbx,%rax,8), %rsi
	movq	-8(%rbx,%rax,8), %rdi
	call	strcmp@PLT
	movb	$1, %r8b
	testl	%eax, %eax
	jne	.L46
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	xorl	%r8d, %r8d
.L46:
	movq	%r13, %rdx
	movq	%r12, %rsi
	movq	%rbp, %rdi
	andl	$1, %r8d
	movss	.LC13(%rip), %xmm2
	movss	.LC14(%rip), %xmm1
	movl	$256, %ecx
	movss	.LC15(%rip), %xmm0
	call	_Z4calcP8_IO_FILES0_S0_ifffb
	call	clock@PLT
	subq	_ZL10start_time(%rip), %rax
	movl	$2, %edi
	leaq	.LC17(%rip), %rsi
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC16(%rip), %xmm0
	call	__printf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.LFE2041:
	.size	main, .-main
	.section	.rodata.str1.1
.LC18:
	.string	"_Z8distancePVfS0_S0_S0_iiiiPViffifb"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2069:
	.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	.LC18(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z8distancePVfS0_S0_S0_iiiiPViffifb(%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
.LFE2069:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZL10start_time
	.comm	_ZL10start_time,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	1553060174
	.long	1084939134
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC13:
	.long	1048576000
	.align 4
.LC14:
	.long	1115684864
	.align 4
.LC15:
	.long	869711765
	.section	.rodata.cst8
	.align 8
.LC16:
	.long	0
	.long	1093567616
	.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:

/*--------------------------------------------------------------------------------------------------*/
/*                                                                                                  */
/*       Alberto Quesada Aranda                                                                     */
/*       Åbo Akademi University                                                                     */
/*       Advanced Computer Graphics and Graphics Hardware                                           */
/*                                                                                                  */
/*       Two-Point angula correlation code                                                          */
/*       Input: two list of galaxies                                                                */
/*       Output: .txt file with the data for generate the histogram                                 */
/*                                                                                                  */
/*       Base code taken from: https://github.com/djbard/ccogs/tree/master/angular_correlation      */
/*                                                                                                  */
/*--------------------------------------------------------------------------------------------------*/


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

using namespace std;

#define SUBMATRIX_SIZE 16384 // parallel threads: 32 blocks * 512 threads/block = 16384 threads
#define DEFAULT_NBINS 256  // num of bins for the histogram

#define	arcm_to_rad 1/3437.7468  // (1/60)*(pi/180), convert from arcm to rad
#define conv_angle 57.2957795; // 180/pi, convert from rad to degrees

// variables for calculate the execution time
static clock_t start_time;
static double elapsed;

/*------------------------------------------------------------------
	Kernel to calculate angular distances
-------------------------------------------------------------------*/

__global__ void distance(volatile float *a0, volatile float *d0, volatile float *a1, volatile float *d1, int xind, int yind, int max_xind, int max_yind, volatile int *dev_hist, float hist_min, float hist_max, int nbins, float bin_width, bool two_different_files=1) {

    int idx = blockIdx.x * blockDim.x + threadIdx.x;  // idx is the thread id, it must range to 32blocks * 512threads/block = 16384 threads
    idx += xind;    // allow the thread to know which submatrix has to calculate

    // printf("%d  %d  %d\n", blockIdx.x, threadIdx.x, blockDim.x);
    // blockIdx.x [0-31]
    // blockDim.x 512
    // threadIdx.x [0-511]

    __shared__ int shared_hist[DEFAULT_NBINS+2];    // shared vector for save the results within a block of threads

    // initialize it only once in each block
    if(threadIdx.x==0)
    {
        for (int i=0;i<nbins+2;i++)
            shared_hist[i] = 0;
    }

    // before starting the calculations we need to be sure that the shared_hist is initialized; if not, we take the risk
    // of loss calculations because we don't know the order in which the threads are executed and is possible that a thread
    // performs the calculations and write the results in shared_hist before the thread 0 has initialized it.
    __syncthreads();

    // if NUM_GALAXIES0 % SUBMATRIX_SIZE != 0 in the last submatrix we will have more threads than needed calculations, therefore
    // we won't perform calculations with those threads.
    if (idx<max_xind) {

        float dist, alpha1, delta1, a_diff;
        float alpha0 = a0[idx];
        float delta0 = d0[idx];

        bool do_calc = 1;
        int bin_index = 0; 

        // each kernel will calculate the angle between one galaxy of the first input data (idx) and all the galaxies within [yind-ymax]
        int ymax = yind + SUBMATRIX_SIZE; // ymax will be the end of the submatrix that we are calculating of the second galaxies input

        // we have to take care and if ymax > NUM_GALAXIES1, we stop the calculations bucle at that point
        if (ymax>max_yind)
            ymax = max_yind;

        // we will perform the same calculation between input0[idx] and every input1[] (range [yind-ymax])
        for(int i=yind; i<ymax; i++) 
        {
            // if the two input files are different (DR case) we have to perform all N*N calculations
            if (two_different_files) {
                do_calc = 1;
            }
            // if the two input files are the same (DD, RR cases) we have to perform N*(N-1)/2 calculations
            else {
                if (xind != yind) {
                    do_calc = 1;
                }
                else {
                    if(idx > i)
                        do_calc=1;
                    else
                        do_calc=0;
                }
            }

            if (do_calc)
            {              
                alpha1 = a1[i];
                delta1 = d1[i];
                a_diff = alpha0 - alpha1;
                dist = acos(sin(delta0)*sin(delta1) + cos(alpha0)*cos(alpha1)*cos(a_diff));
                dist *= conv_angle; // convert from rad to degrees

                // check in which bin we have to include the angle calculated
                if(dist < hist_min) // underflow
                    bin_index = 0; 
                else if(dist >= hist_max) // overflow
                    bin_index = nbins + 1;
                else {
                    bin_index = int((dist-hist_min)/bin_width) + 1;
                }

                // more than one thread could try to write its result in the shared_hist at the same time and in the same memory
                // location. We need an atomic operation for prevent the loss of data
                atomicAdd(&shared_hist[bin_index],1); // increment by one the corresponding histogram bin 

            }
        }
    }

    // before copy the results of each block to the global histogram we have to be sure that all the threads within the block have
    // ended its calculations
    __syncthreads();

    // only one thread (0) will write the results of the block to which it belongs to the global histogram
    // for avoid the need of another atomic operation, our global histogram save the result of each block successively :
    // [block[0], block[1] .... block [31]]
    if(threadIdx.x==0)
    {
        for(int i=0;i<nbins+2;i++)
            dev_hist[i+(blockIdx.x*(nbins+2))]=shared_hist[i]; 
    }

}


/*------------------------------------------------------------------
	Calculations and call to kernel
-------------------------------------------------------------------*/

int calc(FILE *infile0, FILE *infile1, FILE *outfile, int nbins, float hist_lower_range, float hist_upper_range, float hist_bin_width, bool two_different_files){
    
	//d_ means device -> GPU, h_ means host -> CPU
    float *d_alpha0, *d_delta0, *d_alpha1, *d_delta1;
    float *h_alpha0, *h_delta0, *h_alpha1, *h_delta1;
    int NUM_GALAXIES0, NUM_GALAXIES1;

    // reading the data of the input files
    // first we read the number of galaxies of each file
    fscanf(infile0, "%d", &NUM_GALAXIES0);
    fscanf(infile1, "%d", &NUM_GALAXIES1);

    // calculate the size of the array needed for save in memory all the galaxies
    int size_of_galaxy_array0 = NUM_GALAXIES0 * sizeof(float);    
	int size_of_galaxy_array1 = NUM_GALAXIES1 * sizeof(float); 

	printf("SIZE 0 # GALAXIES: %d\n",NUM_GALAXIES0);
  	printf("SIZE 1 # GALAXIES: %d\n",NUM_GALAXIES1);

  	// allocate space for the galaxies data in global memory
    h_alpha0 = (float*)malloc(size_of_galaxy_array0);
    h_delta0 = (float*)malloc(size_of_galaxy_array0);
    h_alpha1 = (float*)malloc(size_of_galaxy_array1);
    h_delta1 = (float*)malloc(size_of_galaxy_array1);

    float temp0, temp1;

    // reading and saving the galaxies data in radians
    for(int i=0; i<NUM_GALAXIES0; i++)
    {
        fscanf(infile0, "%f %f", &temp0, &temp1);
        h_alpha0[i] = temp0 * arcm_to_rad;
        h_delta0[i] = temp1 * arcm_to_rad;
    }

    for(int i=0; i<NUM_GALAXIES1; i++)
    {
        fscanf(infile1, "%f %f", &temp0, &temp1);
        h_alpha1[i] = temp0 * arcm_to_rad;
        h_delta1[i] = temp1 * arcm_to_rad;
    }

    // defining dimensions for the grid and block
    dim3 grid, block;
    grid.x = 8192/(DEFAULT_NBINS); // number of blocks = 32
    block.x = SUBMATRIX_SIZE/grid.x; // number of threads/block = 512

    // allocating the histograms
    /* I will need 3 arrays for the histograms:
        - hist : for each submatrix, save the results of each thread block seccuentially (global memory)
        - dev_hist : the same as hist, but in GPU memory
        - hist_array : save the global result of all the submatrix in global memory
    */

    int *hist, *dev_hist;

    int size_hist = grid.x * (nbins+2); // I use +2, one for underflow and other for overflow
    int size_hist_bytes = size_hist*sizeof(int);

    // allocating and initializing to 0 hist in global mem
    hist = (int*)malloc(size_hist_bytes);
    memset(hist, 0, size_hist_bytes);

    // allocating and initializing to 0 dev_hist in GPU mem
    hipMalloc((void **) &dev_hist, (size_hist_bytes));
    hipMemset(dev_hist, 0, size_hist_bytes);

    unsigned long  *hist_array;

    // allocating and initializing to 0 the array for the final histogram (the sum of each submatrix partial result)
    int hist_array_size = (nbins+2) * sizeof(unsigned long);
    hist_array =  (unsigned long*)malloc(hist_array_size);
    memset(hist_array,0,hist_array_size); 

    // allocating memory in GPU for save the galaxies data
    hipMalloc((void **) &d_alpha0, size_of_galaxy_array0 );
    hipMalloc((void **) &d_delta0, size_of_galaxy_array0 );
    hipMalloc((void **) &d_alpha1, size_of_galaxy_array1 );
    hipMalloc((void **) &d_delta1, size_of_galaxy_array1 );

    // check to see if we allocated enough memory.
    if (0==d_alpha0 || 0==d_delta0 || 0==d_alpha1 || 0==d_delta1 || 0==dev_hist)
    {
        printf("couldn't allocate enough memory in GPU\n");
        return 1;
    }

    // initialize array to all 0's
    /*cudaMemset(d_alpha0,0,size_of_galaxy_array0);
    cudaMemset(d_delta0,0,size_of_galaxy_array0);
    cudaMemset(d_alpha1,0,size_of_galaxy_array1);
    cudaMemset(d_delta1,0,size_of_galaxy_array1);*/

    // copy galaxies data to GPU
    hipMemcpy(d_alpha0, h_alpha0, size_of_galaxy_array0, hipMemcpyHostToDevice );
    hipMemcpy(d_delta0, h_delta0, size_of_galaxy_array0, hipMemcpyHostToDevice );
    hipMemcpy(d_alpha1, h_alpha1, size_of_galaxy_array1, hipMemcpyHostToDevice );
    hipMemcpy(d_delta1, h_delta1, size_of_galaxy_array1, hipMemcpyHostToDevice );

    int x, y;
    int num_submatrices_x = NUM_GALAXIES0 / SUBMATRIX_SIZE;
    int num_submatrices_y = NUM_GALAXIES1 / SUBMATRIX_SIZE;

    // if NUM_GALAXIES % SUBMATRIX_SIZE != 0, we will need one submatrix more (not the whole submatrix) for perform all the calculations
    if (NUM_GALAXIES0%SUBMATRIX_SIZE != 0) {
        num_submatrices_x += 1;
    }
    if (NUM_GALAXIES1%SUBMATRIX_SIZE != 0) {
        num_submatrices_y += 1;
    }

    int bin_index = 0;
    // explanation of the iterations in the documentation
    for(int k = 0; k < num_submatrices_y; k++)
    {
        y = k*SUBMATRIX_SIZE;

        int jmax = 0;
        
        // if the two files are the same, then only loop over the upper half of the matrix of operations
        if (two_different_files == 0)
            jmax = k;

        for(int j = jmax; j < num_submatrices_x; j++)
        {
            x = j*SUBMATRIX_SIZE; 

            // set the histogram to all zeros each time.
            hipMemset(dev_hist,0,size_hist_bytes);

            // call to the kernel
            distance<<<grid,block>>>(d_alpha0, d_delta0,d_alpha1, d_delta1, x, y, NUM_GALAXIES0, NUM_GALAXIES1, dev_hist, hist_lower_range, hist_upper_range, nbins, hist_bin_width, two_different_files);

            // copy the results from GPU memory to global mem
            hipMemcpy(hist, dev_hist, size_hist_bytes, hipMemcpyDeviceToHost);

            // add together the results of each block in a single histogram
            for(int m=0; m<size_hist; m++)
            {
                bin_index = m%(nbins+2); // range it to [0-258]
                hist_array[bin_index] += hist[m];
            }    
        }  
    }

    unsigned long total = 0;

    // write in the output file the range of the bin of the histogram and the number of galaxies included in that range
    // start in k = 1 and finish before nbins+1 for avoid the over/underflow
    float lo = hist_lower_range;
    float hi = 0;
    for(int k=1; k<nbins+1; k++)
    {
        hi = lo + hist_bin_width;

        fprintf(outfile, "%.3e %.3e %lu \n",lo,hi,hist_array[k]);
        total += hist_array[k];

        lo = hi;
    }
    printf("total: %lu \n", total);

    // close opened files
    fclose(infile0);
    fclose(infile1);
    fclose(outfile);

    // free global memory
    free(h_alpha0);
    free(h_delta0);
    free(h_alpha1);
    free(h_delta1);
    free(hist);

    // free GPU memory
    hipFree(d_alpha0);
    hipFree(d_delta0);  
    hipFree(d_alpha1);
    hipFree(d_delta1);  
    hipFree(dev_hist);

    return 0;
}  

/*------------------------------------------------------------------
	MAIN
-------------------------------------------------------------------*/

int main(int argc, char **argv) {

    start_time = clock(); // start the timer

    int nbins = DEFAULT_NBINS; // 256 bins --> 0-64º --> 64/0.25 = 256
    float bin_width = 0.25;
    float lower_range = 0.0000001;
    float upper_range = nbins * bin_width; // 256 * 0.25 = 64
    bool different_files = 1;

    if (argc != 3) {
        printf("\nMust pass two input files.\n");
        exit(1);
    }
    
    // opening the input files and creating the output file
    FILE *infile0, *infile1, *outfile;
    infile0 = fopen(argv[optind],"r");
    infile1 = fopen(argv[optind+1],"r");
    outfile = fopen("output.txt", "w");

    // if the input files are the same (DD, RR) the calculations needed are different from the DR case
    if (strcmp(argv[optind],argv[optind+1]) == 0) {
        different_files = 0;
        printf("Input files are the same!\n");
    }

    calc(infile0, infile1, outfile, nbins, lower_range, upper_range, bin_width, different_files);

    // total time 
    elapsed = clock() - start_time;
    elapsed = elapsed / CLOCKS_PER_SEC;
    printf("Execution time: %f \n", elapsed);

    return 0;
}


	.text
	.file	"project.hip"
	.globl	_Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb # -- Begin function _Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb
	.type	_Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb,@function
_Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb: # @_Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb
	.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	$224, %rsp
	.cfi_def_cfa_offset 272
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movb	304(%rsp), %al
	leaq	72(%rsp), %r10
	movq	%rdi, (%r10)
	leaq	64(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	56(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	48(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	28(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	24(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	20(%rsp), %r9
	movss	%xmm0, (%r9)
	leaq	16(%rsp), %r11
	movss	%xmm1, (%r11)
	leaq	12(%rsp), %r14
	movss	%xmm2, (%r14)
	leaq	11(%rsp), %r15
	movb	%al, (%r15)
	leaq	112(%rsp), %rbx
	movq	%r10, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	272(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	280(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	288(%rsp), %rax
	movq	%rax, 64(%rbx)
	movq	%r9, 72(%rbx)
	movq	%r11, 80(%rbx)
	leaq	296(%rsp), %rax
	movq	%rax, 88(%rbx)
	movq	%r14, 96(%rbx)
	movq	%r15, 104(%rbx)
	leaq	96(%rsp), %r14
	leaq	80(%rsp), %r15
	leaq	40(%rsp), %r12
	leaq	32(%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	$_Z8distancePVfS0_S0_S0_iiiiPViffifb, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$240, %rsp
	.cfi_adjust_cfa_offset -240
	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	_Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb, .Lfunc_end0-_Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z4calcP8_IO_FILES0_S0_ifffb
.LCPI1_0:
	.quad	0x40aadb7e5c91d14e              # double 3437.7467999999999
	.text
	.globl	_Z4calcP8_IO_FILES0_S0_ifffb
	.type	_Z4calcP8_IO_FILES0_S0_ifffb,@function
_Z4calcP8_IO_FILES0_S0_ifffb:           # @_Z4calcP8_IO_FILES0_S0_ifffb
	.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	$200, %rsp
	.cfi_def_cfa_offset 256
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%r8d, 52(%rsp)                  # 4-byte Spill
	movss	%xmm2, 60(%rsp)                 # 4-byte Spill
	movss	%xmm1, 128(%rsp)                # 4-byte Spill
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
                                        # kill: def $ecx killed $ecx def $rcx
	movq	%rcx, 104(%rsp)                 # 8-byte Spill
	movq	%rdx, 160(%rsp)                 # 8-byte Spill
	movq	%rsi, %r15
	movq	%rdi, %r12
	leaq	28(%rsp), %rbx
	movl	$.L.str, %esi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	leaq	16(%rsp), %r14
	movl	$.L.str, %esi
	movq	%r15, 152(%rsp)                 # 8-byte Spill
	movq	%r15, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	(%rbx), %esi
	leal	(,%rsi,4), %r15d
	movl	(%r14), %ebp
	shll	$2, %ebp
	movl	$.L.str.1, %edi
                                        # kill: def $esi killed $esi killed $rsi
	xorl	%eax, %eax
	callq	printf
	movl	(%r14), %esi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	movslq	%r15d, %r15
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%r15, 32(%rsp)                  # 8-byte Spill
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %r13
	movslq	%ebp, %r15
	movq	%r14, %rbp
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	movq	%r15, 112(%rsp)                 # 8-byte Spill
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, 88(%rsp)                  # 8-byte Spill
	cmpl	$0, (%rbx)
	jle	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	leaq	24(%rsp), %rbx
	leaq	20(%rsp), %r14
	xorl	%r15d, %r15d
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.3, %esi
	movq	%r12, %rdi
	movq	%rbx, %rdx
	movq	%r14, %rcx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	xorps	%xmm0, %xmm0
	cvtss2sd	24(%rsp), %xmm0
	movsd	.LCPI1_0(%rip), %xmm2           # xmm2 = mem[0],zero
	divsd	%xmm2, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	20(%rsp), %xmm1
	movss	%xmm0, (%rbp,%r15,4)
	divsd	%xmm2, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, (%r13,%r15,4)
	incq	%r15
	movslq	28(%rsp), %rax
	cmpq	%rax, %r15
	jl	.LBB1_2
.LBB1_3:                                # %.preheader136
	movq	%r13, 136(%rsp)                 # 8-byte Spill
	movq	%rbp, 144(%rsp)                 # 8-byte Spill
	movq	%r12, 176(%rsp)                 # 8-byte Spill
	cmpl	$0, 16(%rsp)
	movq	96(%rsp), %r12                  # 8-byte Reload
	movq	88(%rsp), %r13                  # 8-byte Reload
	movq	152(%rsp), %rbp                 # 8-byte Reload
	jle	.LBB1_6
# %bb.4:                                # %.lr.ph139.preheader
	leaq	24(%rsp), %rbx
	leaq	20(%rsp), %r14
	xorl	%r15d, %r15d
.LBB1_5:                                # %.lr.ph139
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.3, %esi
	movq	%rbp, %rdi
	movq	%rbx, %rdx
	movq	%r14, %rcx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	xorps	%xmm0, %xmm0
	cvtss2sd	24(%rsp), %xmm0
	movsd	.LCPI1_0(%rip), %xmm2           # xmm2 = mem[0],zero
	divsd	%xmm2, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	20(%rsp), %xmm1
	movss	%xmm0, (%r12,%r15,4)
	divsd	%xmm2, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, (%r13,%r15,4)
	incq	%r15
	movslq	16(%rsp), %rax
	cmpq	%rax, %r15
	jl	.LBB1_5
.LBB1_6:                                # %._crit_edge
	movq	104(%rsp), %r12                 # 8-byte Reload
	leal	2(%r12), %ebx
	movl	%ebx, %eax
	shll	$7, %eax
	movslq	%eax, %rbp
	movl	$1, %edi
	movq	%rbp, %rsi
	callq	calloc@PLT
	movq	%rax, %r15
	leaq	40(%rsp), %r14
	movq	%r14, %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	xorl	%esi, %esi
	movq	%rbp, %rdx
	callq	hipMemset
	leal	16(,%r12,8), %eax
	movslq	%eax, %rsi
	movl	$1, %edi
	callq	calloc@PLT
	movq	%rax, %r13
	leaq	168(%rsp), %r14
	movq	%r14, %rdi
	movq	32(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	80(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	72(%rsp), %rdi
	movq	112(%rsp), %r12                 # 8-byte Reload
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	64(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	testq	%rdi, %rdi
	je	.LBB1_11
# %bb.7:                                # %._crit_edge
	cmpq	$0, 80(%rsp)
	je	.LBB1_11
# %bb.8:                                # %._crit_edge
	cmpq	$0, 72(%rsp)
	je	.LBB1_11
# %bb.9:                                # %._crit_edge
	cmpq	$0, 64(%rsp)
	je	.LBB1_11
# %bb.10:                               # %._crit_edge
	cmpq	$0, 40(%rsp)
	je	.LBB1_11
# %bb.12:
	movq	144(%rsp), %rsi                 # 8-byte Reload
	movq	32(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	80(%rsp), %rdi
	movq	136(%rsp), %rsi                 # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	72(%rsp), %rdi
	movq	96(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	64(%rsp), %rdi
	movq	88(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	28(%rsp), %eax
	movl	$16383, %ecx                    # imm = 0x3FFF
	leal	(%rax,%rcx), %edi
	testl	%eax, %eax
	cmovnsl	%eax, %edi
	sarl	$14, %edi
	movl	16(%rsp), %edx
	leal	(%rdx,%rcx), %esi
	testl	%edx, %edx
	cmovnsl	%edx, %esi
	sarl	$14, %esi
	andl	%ecx, %eax
	cmpl	$1, %eax
	sbbl	$-1, %edi
	movl	%edi, 32(%rsp)                  # 4-byte Spill
	xorl	%eax, %eax
	testl	$16383, %edx                    # imm = 0x3FFF
	setne	%al
	addl	%esi, %eax
	movl	%eax, 124(%rsp)                 # 4-byte Spill
	jle	.LBB1_23
# %bb.13:                               # %.lr.ph150
	movl	%ebx, %eax
	shll	$5, %eax
	movabsq	$4294967328, %rcx               # imm = 0x100000020
	movl	%eax, 112(%rsp)                 # 4-byte Spill
	movl	%eax, %r12d
	leaq	480(%rcx), %rax
	movq	%rax, 192(%rsp)                 # 8-byte Spill
	movzbl	52(%rsp), %eax                  # 1-byte Folded Reload
	movq	%rax, 184(%rsp)                 # 8-byte Spill
	xorl	%r14d, %r14d
.LBB1_14:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_16 Depth 2
                                        #       Child Loop BB1_20 Depth 3
	cmpb	$0, 52(%rsp)                    # 1-byte Folded Reload
	movl	%r14d, 56(%rsp)                 # 4-byte Spill
	movl	$0, %eax
	cmovnel	%eax, %r14d
	cmpl	32(%rsp), %r14d                 # 4-byte Folded Reload
	jge	.LBB1_22
# %bb.15:                               #   in Loop: Header=BB1_14 Depth=1
	movl	56(%rsp), %eax                  # 4-byte Reload
	shll	$14, %eax
	movl	%eax, 132(%rsp)                 # 4-byte Spill
.LBB1_16:                               # %.lr.ph146
                                        #   Parent Loop BB1_14 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_20 Depth 3
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rbp, %rdx
	callq	hipMemset
	movabsq	$4294967328, %rdi               # imm = 0x100000020
	movl	$1, %esi
	movq	192(%rsp), %rdx                 # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_18
# %bb.17:                               #   in Loop: Header=BB1_16 Depth=2
	movl	%r14d, %r8d
	shll	$14, %r8d
	movq	168(%rsp), %rdi
	movq	80(%rsp), %rsi
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rcx
	movl	28(%rsp), %eax
	movl	16(%rsp), %r10d
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	140(%rsp), %r9d                 # 4-byte Reload
	movss	20(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movss	136(%rsp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movss	68(%rsp), %xmm2                 # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	pushq	192(%rsp)                       # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	pushq	120(%rsp)                       # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	pushq	64(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	callq	_Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb
	addq	$48, %rsp
	.cfi_adjust_cfa_offset -48
.LBB1_18:                               #   in Loop: Header=BB1_16 Depth=2
	movq	40(%rsp), %rsi
	movq	%r15, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	cmpl	$0, 112(%rsp)                   # 4-byte Folded Reload
	jle	.LBB1_21
# %bb.19:                               # %.lr.ph142.preheader
                                        #   in Loop: Header=BB1_16 Depth=2
	xorl	%ecx, %ecx
.LBB1_20:                               # %.lr.ph142
                                        #   Parent Loop BB1_14 Depth=1
                                        #     Parent Loop BB1_16 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	%ecx, %eax
	cltd
	idivl	%ebx
                                        # kill: def $edx killed $edx def $rdx
	movslq	(%r15,%rcx,4), %rax
	addq	%rax, (%r13,%rdx,8)
	incq	%rcx
	cmpq	%rcx, %r12
	jne	.LBB1_20
.LBB1_21:                               # %._crit_edge143
                                        #   in Loop: Header=BB1_16 Depth=2
	incl	%r14d
	cmpl	32(%rsp), %r14d                 # 4-byte Folded Reload
	jne	.LBB1_16
.LBB1_22:                               # %._crit_edge147
                                        #   in Loop: Header=BB1_14 Depth=1
	movl	56(%rsp), %r14d                 # 4-byte Reload
	incl	%r14d
	cmpl	124(%rsp), %r14d                # 4-byte Folded Reload
	jne	.LBB1_14
.LBB1_23:                               # %.preheader
	movq	104(%rsp), %rbx                 # 8-byte Reload
	testl	%ebx, %ebx
	jle	.LBB1_24
# %bb.25:                               # %.lr.ph155.preheader
	incl	%ebx
	movl	$1, %ebp
	xorl	%r14d, %r14d
	movss	12(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
.LBB1_26:                               # %.lr.ph155
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	addss	60(%rsp), %xmm1                 # 4-byte Folded Reload
	movss	%xmm1, 12(%rsp)                 # 4-byte Spill
	xorps	%xmm1, %xmm1
	cvtss2sd	12(%rsp), %xmm1                 # 4-byte Folded Reload
	movq	(%r13,%rbp,8), %r12
	movl	$.L.str.5, %esi
	movq	160(%rsp), %rdi                 # 8-byte Reload
	movq	%r12, %rdx
	movb	$2, %al
	callq	fprintf
	movss	12(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	addq	%r12, %r14
	incq	%rbp
	cmpq	%rbp, %rbx
	jne	.LBB1_26
	jmp	.LBB1_27
.LBB1_11:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$1, %eax
	jmp	.LBB1_28
.LBB1_24:
	xorl	%r14d, %r14d
.LBB1_27:                               # %._crit_edge156
	movl	$.L.str.6, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	176(%rsp), %rdi                 # 8-byte Reload
	callq	fclose
	movq	152(%rsp), %rdi                 # 8-byte Reload
	callq	fclose
	movq	160(%rsp), %rdi                 # 8-byte Reload
	callq	fclose
	movq	144(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	136(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	96(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	88(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	168(%rsp), %rdi
	callq	hipFree
	movq	80(%rsp), %rdi
	callq	hipFree
	movq	72(%rsp), %rdi
	callq	hipFree
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
.LBB1_28:
                                        # kill: def $eax killed $eax killed $rax
	addq	$200, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z4calcP8_IO_FILES0_S0_ifffb, .Lfunc_end1-_Z4calcP8_IO_FILES0_S0_ifffb
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x33d6bf95                      # float 1.00000001E-7
.LCPI2_1:
	.long	0x42800000                      # float 64
.LCPI2_2:
	.long	0x3e800000                      # float 0.25
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI2_3:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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, %r15
	movl	%edi, %ebp
	callq	clock
	cmpl	$3, %ebp
	jne	.LBB2_4
# %bb.1:
	movq	%rax, %rbx
	movslq	optind(%rip), %rax
	movq	(%r15,%rax,8), %rdi
	movl	$.L.str.8, %esi
	callq	fopen
	movq	%rax, %r14
	movslq	optind(%rip), %rax
	movq	8(%r15,%rax,8), %rdi
	movl	$.L.str.8, %esi
	callq	fopen
	movq	%rax, %r12
	movl	$.L.str.9, %edi
	movl	$.L.str.10, %esi
	callq	fopen
	movq	%rax, %r13
	movslq	optind(%rip), %rax
	movq	(%r15,%rax,8), %rdi
	movq	8(%r15,%rax,8), %rsi
	callq	strcmp
	movl	%eax, %ebp
	testl	%eax, %eax
	jne	.LBB2_3
# %bb.2:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
.LBB2_3:
	xorl	%r8d, %r8d
	testl	%ebp, %ebp
	setne	%r8b
	movss	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movss	.LCPI2_2(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	movq	%r14, %rdi
	movq	%r12, %rsi
	movq	%r13, %rdx
	movl	$256, %ecx                      # imm = 0x100
	callq	_Z4calcP8_IO_FILES0_S0_ifffb
	callq	clock
	subq	%rbx, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI2_3(%rip), %xmm0
	movl	$.L.str.12, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$8, %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
.LBB2_4:
	.cfi_def_cfa_offset 64
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8distancePVfS0_S0_S0_iiiiPViffifb, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z8distancePVfS0_S0_S0_iiiiPViffifb,@object # @_Z8distancePVfS0_S0_S0_iiiiPViffifb
	.section	.rodata,"a",@progbits
	.globl	_Z8distancePVfS0_S0_S0_iiiiPViffifb
	.p2align	3, 0x0
_Z8distancePVfS0_S0_S0_iiiiPViffifb:
	.quad	_Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb
	.size	_Z8distancePVfS0_S0_S0_iiiiPViffifb, 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	"SIZE 0 # GALAXIES: %d\n"
	.size	.L.str.1, 23

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"SIZE 1 # GALAXIES: %d\n"
	.size	.L.str.2, 23

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%.3e %.3e %lu \n"
	.size	.L.str.5, 16

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"total: %lu \n"
	.size	.L.str.6, 13

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"output.txt"
	.size	.L.str.9, 11

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

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Execution time: %f \n"
	.size	.L.str.12, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z8distancePVfS0_S0_S0_iiiiPViffifb"
	.size	.L__unnamed_1, 36

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

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"couldn't allocate enough memory in GPU"
	.size	.Lstr, 39

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Input files are the same!"
	.size	.Lstr.1, 26

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"\nMust pass two input files."
	.size	.Lstr.2, 28

	.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 _Z23__device_stub__distancePVfS0_S0_S0_iiiiPViffifb
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z8distancePVfS0_S0_S0_iiiiPViffifb
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8distancePVfS0_S0_S0_iiiiPViffifb ; -- Begin function _Z8distancePVfS0_S0_S0_iiiiPViffifb
	.globl	_Z8distancePVfS0_S0_S0_iiiiPViffifb
	.p2align	8
	.type	_Z8distancePVfS0_S0_S0_iiiiPViffifb,@function
_Z8distancePVfS0_S0_S0_iiiiPViffifb:    ; @_Z8distancePVfS0_S0_S0_iiiiPViffifb
; %bb.0:
	s_clause 0x1
	s_load_b128 s[16:19], s[0:1], 0x38
	s_load_b32 s29, s[0:1], 0x48
	v_cmp_eq_u32_e32 vcc_lo, 0, v0
	s_mov_b32 s2, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_gt_i32 s18, -2
	s_cselect_b32 s3, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s14, vcc_lo, s3
	s_and_saveexec_b32 s3, s14
	s_cbranch_execz .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	v_mov_b32_e32 v1, 0
	s_add_i32 s4, s18, 2
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_mov_b32_e32 v2, s2
	s_add_i32 s4, s4, -1
	s_add_i32 s2, s2, 4
	s_cmp_lg_u32 s4, 0
	ds_store_b32 v2, v1
	s_cbranch_scc1 .LBB0_2
.LBB0_3:                                ; %Flow184
	s_or_b32 exec_lo, exec_lo, s3
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x5c
	s_load_b128 s[20:23], s[0:1], 0x20
	s_mov_b32 s24, exec_lo
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_b32 s2, 0xffff, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s2, s15, s2
	v_add3_u32 v0, s2, s20, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s22, v0
	s_cbranch_execz .LBB0_25
; %bb.4:
	s_load_b256 s[4:11], s[0:1], 0x0
	v_ashrrev_i32_e32 v1, 31, v0
	s_cmp_le_i32 s23, s21
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s4, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v2, vcc_lo
	v_add_co_u32 v1, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v2, vcc_lo
	flat_load_b32 v3, v[3:4] glc dlc
	s_waitcnt vmcnt(0)
	flat_load_b32 v4, v[1:2] glc dlc
	s_waitcnt vmcnt(0)
	s_cbranch_scc1 .LBB0_25
; %bb.5:                                ; %.lr.ph111
	s_waitcnt lgkmcnt(0)
	v_dual_mov_b32 v2, 0 :: v_dual_and_b32 v5, 0x7fffffff, v4
	s_mov_b32 s25, 0x7fffff
	v_mul_f32_e64 v23, 0x3f22f983, |v4|
	v_mul_f32_e64 v24, 0x3f22f983, |v3|
	s_delay_alu instid0(VALU_DEP_3)
	v_and_or_b32 v17, v5, s25, 0x800000
	s_mov_b32 s26, 0xb94c1982
	s_mov_b32 s27, 0x37d75334
	s_add_i32 s7, s21, 0x4000
	s_mov_b32 s22, s21
	v_mad_u64_u32 v[6:7], null, 0xfe5163ab, v17, 0
	s_min_i32 s28, s7, s23
	s_bitcmp1_b32 s29, 0
	s_mov_b32 s12, 0x1a47a9e3
	s_mov_b32 s13, 0x404ca5dc
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mov_b32_e32 v1, v7
	v_mad_u64_u32 v[7:8], null, 0x3c439041, v17, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mov_b32_e32 v1, v8
	v_mad_u64_u32 v[8:9], null, 0xdb629599, v17, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mov_b32_e32 v1, v9
	v_mad_u64_u32 v[9:10], null, 0xf534ddc0, v17, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mov_b32_e32 v1, v10
	v_mad_u64_u32 v[10:11], null, 0xfc2757d1, v17, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mov_b32_e32 v1, v11
	v_mad_u64_u32 v[11:12], null, 0x4e441529, v17, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v1, v12
	v_lshrrev_b32_e32 v12, 23, v5
	v_mad_u64_u32 v[15:16], null, 0xa2f9836e, v17, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v12, 0xffffff88, v12
	v_cmp_lt_u32_e32 vcc_lo, 63, v12
	v_dual_cndmask_b32 v6, v8, v6 :: v_dual_and_b32 v19, 0x7fffffff, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_and_or_b32 v22, v19, s25, 0x800000
	v_cndmask_b32_e64 v20, 0, 0xffffffc0, vcc_lo
	v_dual_cndmask_b32 v7, v9, v7 :: v_dual_cndmask_b32 v26, v15, v10
	v_cndmask_b32_e32 v8, v10, v8, vcc_lo
	v_mad_u64_u32 v[13:14], null, 0xfe5163ab, v22, 0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v12, v20, v12
	v_cmp_lt_u32_e64 s3, 31, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mov_b32_e32 v1, v14
	v_lshrrev_b32_e32 v14, 23, v19
	v_add_nc_u32_e32 v14, 0xffffff88, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_u32_e64 s2, 63, v14
	v_cndmask_b32_e64 v21, 0, 0xffffffc0, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v14, v21, v14
	v_cndmask_b32_e64 v21, 0, 0xffffffe0, s3
	v_cmp_lt_u32_e64 s4, 31, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v12, v21, v12
	v_cndmask_b32_e64 v25, 0, 0xffffffe0, s4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_lt_u32_e64 s5, 31, v12
	v_add_nc_u32_e32 v14, v25, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v25, 0, 0xffffffe0, s5
	v_cmp_lt_u32_e64 s6, 31, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v12, v25, v12
	v_mad_u64_u32 v[17:18], null, 0x3c439041, v22, v[1:2]
	v_mov_b32_e32 v1, v18
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[18:19], null, 0xdb629599, v22, v[1:2]
	v_mov_b32_e32 v1, v19
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v13, v18, v13, s2
	v_mad_u64_u32 v[19:20], null, 0xf534ddc0, v22, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v1, v20
	v_cndmask_b32_e64 v17, v19, v17, s2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mad_u64_u32 v[20:21], null, 0xfc2757d1, v22, v[1:2]
	v_cndmask_b32_e64 v1, 0, 0xffffffe0, s6
	v_cndmask_b32_e64 v13, v17, v13, s4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_nc_u32_e32 v25, v1, v14
	v_mov_b32_e32 v1, v21
	v_cndmask_b32_e32 v21, v11, v9, vcc_lo
	v_sub_nc_u32_e32 v9, 32, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_4) | instid1(VALU_DEP_4)
	v_mad_u64_u32 v[14:15], null, 0x4e441529, v22, v[1:2]
	v_cndmask_b32_e32 v1, v16, v11, vcc_lo
	v_cndmask_b32_e64 v16, v7, v6, s3
	v_cndmask_b32_e64 v10, v26, v21, s3
	v_cmp_eq_u32_e32 vcc_lo, 0, v12
	v_cndmask_b32_e64 v11, v1, v26, s3
	v_mov_b32_e32 v1, v15
	v_cndmask_b32_e64 v15, v21, v8, s3
	v_cndmask_b32_e64 v8, v8, v7, s3
	v_cndmask_b32_e64 v21, v14, v19, s2
	v_cndmask_b32_e64 v11, v11, v10, s5
	v_mad_u64_u32 v[6:7], null, 0xa2f9836e, v22, v[1:2]
	v_cndmask_b32_e64 v1, v10, v15, s5
	v_cndmask_b32_e64 v16, v8, v16, s5
	v_cndmask_b32_e64 v8, v15, v8, s5
	v_sub_nc_u32_e32 v10, 32, v25
	s_cselect_b32 s3, -1, 0
	v_alignbit_b32 v15, v11, v1, v9
	v_cndmask_b32_e64 v6, v6, v20, s2
	v_cndmask_b32_e64 v7, v7, v14, s2
	v_cndmask_b32_e64 v14, v20, v18, s2
	v_alignbit_b32 v20, v1, v8, v9
	v_cndmask_b32_e32 v11, v15, v11, vcc_lo
	v_cndmask_b32_e64 v19, v6, v21, s4
	v_cndmask_b32_e64 v6, v7, v6, s4
	v_cndmask_b32_e64 v7, v21, v14, s4
	v_cndmask_b32_e64 v12, v14, v17, s4
	v_cndmask_b32_e32 v1, v20, v1, vcc_lo
	v_bfe_u32 v15, v11, 29, 1
	v_cndmask_b32_e64 v6, v6, v19, s6
	v_cndmask_b32_e64 v14, v19, v7, s6
	v_cndmask_b32_e64 v7, v7, v12, s6
	v_cmp_eq_u32_e64 s2, 0, v25
	v_alignbit_b32 v19, v11, v1, 30
	v_sub_nc_u32_e32 v20, 0, v15
	v_alignbit_b32 v18, v6, v14, v10
	v_alignbit_b32 v21, v14, v7, v10
	v_alignbit_b32 v9, v8, v16, v9
	v_cndmask_b32_e64 v12, v12, v13, s6
	s_cmp_lg_u32 s20, s21
	v_cndmask_b32_e64 v6, v18, v6, s2
	v_xor_b32_e32 v18, v19, v20
	v_cndmask_b32_e64 v14, v21, v14, s2
	v_cndmask_b32_e32 v8, v9, v8, vcc_lo
	v_alignbit_b32 v10, v7, v12, v10
	v_bfe_u32 v17, v6, 29, 1
	v_clz_i32_u32_e32 v9, v18
	v_alignbit_b32 v13, v6, v14, 30
	v_alignbit_b32 v1, v1, v8, 30
	v_alignbit_b32 v8, v8, v16, 30
	v_sub_nc_u32_e32 v19, 0, v17
	v_min_u32_e32 v9, 32, v9
	v_cndmask_b32_e64 v7, v10, v7, s2
	v_xor_b32_e32 v1, v1, v20
	v_xor_b32_e32 v8, v8, v20
	v_xor_b32_e32 v13, v13, v19
	v_sub_nc_u32_e32 v16, 31, v9
	v_lshrrev_b32_e32 v22, 29, v6
	v_lshrrev_b32_e32 v6, 30, v6
	v_cmp_gt_f32_e64 vcc_lo, 0x48000000, |v4|
	v_clz_i32_u32_e32 v10, v13
	v_alignbit_b32 v18, v18, v1, v16
	v_alignbit_b32 v1, v1, v8, v16
	v_alignbit_b32 v8, v14, v7, 30
	v_alignbit_b32 v7, v7, v12, 30
	v_min_u32_e32 v10, 32, v10
	v_lshrrev_b32_e32 v12, 29, v11
	v_alignbit_b32 v14, v18, v1, 9
	v_xor_b32_e32 v8, v8, v19
	v_xor_b32_e32 v7, v7, v19
	v_sub_nc_u32_e32 v16, 31, v10
	v_lshlrev_b32_e32 v12, 31, v12
	v_clz_i32_u32_e32 v20, v14
	v_rndne_f32_e32 v19, v23
	v_lshlrev_b32_e32 v22, 31, v22
	v_alignbit_b32 v13, v13, v8, v16
	v_alignbit_b32 v7, v8, v7, v16
	v_min_u32_e32 v20, 32, v20
	v_rndne_f32_e32 v8, v24
	v_or_b32_e32 v16, 0.5, v12
	v_lshlrev_b32_e32 v23, 23, v9
	v_alignbit_b32 v21, v13, v7, 9
	v_sub_nc_u32_e32 v24, 31, v20
	v_lshrrev_b32_e32 v18, 9, v18
	v_add_lshl_u32 v9, v20, v9, 23
	v_sub_nc_u32_e32 v16, v16, v23
	v_clz_i32_u32_e32 v25, v21
	v_alignbit_b32 v1, v14, v1, v24
	v_or_b32_e32 v23, 0.5, v22
	v_lshlrev_b32_e32 v24, 23, v10
	v_or_b32_e32 v16, v18, v16
	v_min_u32_e32 v14, 32, v25
	v_lshrrev_b32_e32 v1, 9, v1
	v_lshrrev_b32_e32 v13, 9, v13
	v_sub_nc_u32_e32 v20, v23, v24
	v_add_nc_u32_e32 v6, v17, v6
	v_sub_nc_u32_e32 v18, 31, v14
	v_sub_nc_u32_e32 v1, v1, v9
	v_add_lshl_u32 v10, v14, v10, 23
	v_or_b32_e32 v9, v13, v20
	v_fma_f32 v13, 0xbfc90fda, v19, |v4|
	v_alignbit_b32 v7, v21, v7, v18
	v_mul_f32_e32 v18, 0x3fc90fda, v16
	v_add_nc_u32_e32 v1, 0x33000000, v1
	v_mul_f32_e32 v20, 0x3fc90fda, v9
	v_fmac_f32_e32 v13, 0xb3a22168, v19
	v_lshrrev_b32_e32 v7, 9, v7
	v_fma_f32 v14, 0x3fc90fda, v16, -v18
	v_or_b32_e32 v1, v1, v12
	v_fma_f32 v12, 0x3fc90fda, v9, -v20
	s_cselect_b32 s2, -1, 0
	v_sub_nc_u32_e32 v7, v7, v10
	v_fmac_f32_e32 v14, 0x33a22168, v16
	v_fma_f32 v16, 0xbfc90fda, v8, |v3|
	v_cvt_i32_f32_e32 v10, v19
	s_ashr_i32 s23, s21, 31
	v_add_nc_u32_e32 v7, 0x33000000, v7
	v_fmac_f32_e32 v14, 0x3fc90fda, v1
	v_fmac_f32_e32 v16, 0xb3a22168, v8
	v_fmac_f32_e32 v12, 0x33a22168, v9
	s_or_b32 s29, s2, s3
	v_or_b32_e32 v1, v7, v22
	v_add_f32_e32 v9, v18, v14
	v_lshrrev_b32_e32 v7, 30, v11
	v_fmac_f32_e32 v16, 0xa7c234c4, v8
	v_cvt_i32_f32_e32 v8, v8
	v_fmac_f32_e32 v13, 0xa7c234c4, v19
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_dual_fmac_f32 v12, 0x3fc90fda, v1 :: v_dual_add_nc_u32 v1, v15, v7
	s_lshl_b64 s[2:3], s[22:23], 2
	s_add_i32 s20, s18, 1
	v_cndmask_b32_e32 v7, v9, v13, vcc_lo
	s_add_u32 s4, s8, s2
	v_cndmask_b32_e32 v1, v1, v10, vcc_lo
	v_cmp_gt_f32_e64 vcc_lo, 0x48000000, |v3|
	s_addc_u32 s5, s9, s3
	v_dual_mul_f32 v10, v7, v7 :: v_dual_add_f32 v9, v20, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_dual_cndmask_b32 v6, v6, v8 :: v_dual_lshlrev_b32 v11, 30, v1
	s_add_u32 s6, s10, s2
	v_fmaak_f32 v14, s27, v10, 0xbab64f3b
	v_fmaak_f32 v12, s26, v10, 0x3c0881c4
	v_cndmask_b32_e32 v9, v9, v16, vcc_lo
	v_and_b32_e32 v11, 0x80000000, v11
	s_addc_u32 s7, s11, s3
	v_fmaak_f32 v14, v10, v14, 0x3d2aabf7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_dual_fmaak_f32 v12, v10, v12, 0xbe2aaa9d :: v_dual_mul_f32 v13, v9, v9
	v_xor_b32_e32 v11, v11, v4
	s_mov_b32 s8, 0x3d1c21a7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmaak_f32 v14, v10, v14, 0xbf000004
	v_dual_mul_f32 v12, v10, v12 :: v_dual_fmaak_f32 v15, s26, v13, 0x3c0881c4
	v_fmaak_f32 v16, s27, v13, 0xbab64f3b
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fma_f32 v10, v10, v14, 1.0
	v_fmac_f32_e32 v7, v7, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_dual_fmaak_f32 v16, v13, v16, 0x3d2aabf7 :: v_dual_and_b32 v1, 1, v1
	v_dual_fmaak_f32 v15, v13, v15, 0xbe2aaa9d :: v_dual_and_b32 v14, 1, v6
	v_lshlrev_b32_e32 v6, 30, v6
	v_cmp_eq_u32_e32 vcc_lo, 0, v1
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_fmaak_f32 v12, v13, v16, 0xbf000004
	v_mul_f32_e32 v8, v13, v15
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_dual_cndmask_b32 v1, v10, v7 :: v_dual_and_b32 v6, 0x80000000, v6
	v_cmp_eq_u32_e32 vcc_lo, 0, v14
	v_fmac_f32_e32 v9, v9, v8
	v_fma_f32 v8, v13, v12, 1.0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_xor3_b32 v1, v11, v1, v5
	v_cndmask_b32_e64 v7, -v9, v8, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v4, 0x1f8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v5, v6, v7
	v_cndmask_b32_e32 v4, 0x7fc00000, v1, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v3, 0x1f8
	s_delay_alu instid0(VALU_DEP_3)
	v_dual_mov_b32 v6, 1 :: v_dual_cndmask_b32 v5, 0x7fc00000, v5
.LBB0_6:                                ; =>This Inner Loop Header: Depth=1
	v_cmp_lt_i32_e32 vcc_lo, s21, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s2, s29, vcc_lo
	s_and_saveexec_b32 s9, s2
	s_cbranch_execz .LBB0_24
; %bb.7:                                ; %.critedge
                                        ;   in Loop: Header=BB0_6 Depth=1
	v_dual_mov_b32 v8, s5 :: v_dual_mov_b32 v7, s4
	v_dual_mov_b32 v11, s7 :: v_dual_mov_b32 v10, s6
	s_mov_b32 s3, exec_lo
	flat_load_b32 v9, v[7:8] glc dlc
	s_waitcnt vmcnt(0)
	flat_load_b32 v7, v[10:11] glc dlc
	s_waitcnt vmcnt(0)
                                        ; implicit-def: $vgpr11
                                        ; implicit-def: $vgpr10
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_and_b32_e32 v8, 0x7fffffff, v7
	v_cmpx_ngt_f32_e64 0x48000000, |v7|
	s_xor_b32 s10, exec_lo, s3
	s_cbranch_execz .LBB0_9
; %bb.8:                                ;   in Loop: Header=BB0_6 Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_and_or_b32 v18, v8, s25, 0x800000
	v_lshrrev_b32_e32 v15, 23, v8
	v_mad_u64_u32 v[10:11], null, 0xfe5163ab, v18, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v16, 0xffffff88, v15
	v_cmp_lt_u32_e32 vcc_lo, 63, v16
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v1, v11
	v_cndmask_b32_e64 v17, 0, 0xffffffc0, vcc_lo
	v_mad_u64_u32 v[11:12], null, 0x3c439041, v18, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v17, v17, v16
	v_mov_b32_e32 v1, v12
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_lt_u32_e64 s2, 31, v17
	v_mad_u64_u32 v[12:13], null, 0xdb629599, v18, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v19, 0, 0xffffffe0, s2
	v_add_nc_u32_e32 v19, v19, v17
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_mov_b32 v1, v13 :: v_dual_cndmask_b32 v10, v12, v10
	v_cmp_lt_u32_e64 s3, 31, v19
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[13:14], null, 0xf534ddc0, v18, v[1:2]
	v_mov_b32_e32 v1, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v11, v13, v11, vcc_lo
	v_mad_u64_u32 v[14:15], null, 0xfc2757d1, v18, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v10, v11, v10, s2
	v_mov_b32_e32 v1, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[15:16], null, 0x4e441529, v18, v[1:2]
	v_mov_b32_e32 v1, v16
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[16:17], null, 0xa2f9836e, v18, v[1:2]
	v_cndmask_b32_e64 v1, 0, 0xffffffe0, s3
	v_dual_cndmask_b32 v18, v15, v13 :: v_dual_add_nc_u32 v1, v1, v19
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_dual_cndmask_b32 v16, v16, v14 :: v_dual_cndmask_b32 v15, v17, v15
	v_cndmask_b32_e32 v14, v14, v12, vcc_lo
	v_sub_nc_u32_e32 v17, 32, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v13, v16, v18, s2
	v_cndmask_b32_e64 v15, v15, v16, s2
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_2) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v16, v18, v14, s2
	v_cndmask_b32_e64 v14, v14, v11, s2
	v_cmp_eq_u32_e32 vcc_lo, 0, v1
	v_cndmask_b32_e64 v15, v15, v13, s3
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v13, v13, v16, s3
	v_cndmask_b32_e64 v16, v16, v14, s3
	v_cndmask_b32_e64 v10, v14, v10, s3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_alignbit_b32 v18, v15, v13, v17
	v_alignbit_b32 v12, v13, v16, v17
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v1, v18, v15, vcc_lo
	v_cndmask_b32_e32 v11, v12, v13, vcc_lo
	v_alignbit_b32 v15, v16, v10, v17
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_bfe_u32 v12, v1, 29, 1
	v_alignbit_b32 v13, v1, v11, 30
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v15, v15, v16, vcc_lo
	v_sub_nc_u32_e32 v14, 0, v12
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_alignbit_b32 v11, v11, v15, 30
	v_alignbit_b32 v10, v15, v10, 30
	v_xor_b32_e32 v13, v13, v14
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v11, v11, v14
	v_xor_b32_e32 v10, v10, v14
	v_lshrrev_b32_e32 v14, 29, v1
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_clz_i32_u32_e32 v16, v13
	v_lshrrev_b32_e32 v1, 30, v1
	v_lshlrev_b32_e32 v14, 31, v14
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_min_u32_e32 v16, 32, v16
	v_or_b32_e32 v17, 0.5, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b32_e32 v18, 23, v16
	v_sub_nc_u32_e32 v15, 31, v16
	v_sub_nc_u32_e32 v17, v17, v18
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_alignbit_b32 v13, v13, v11, v15
	v_alignbit_b32 v10, v11, v10, v15
	v_alignbit_b32 v11, v13, v10, 9
	v_lshrrev_b32_e32 v13, 9, v13
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_clz_i32_u32_e32 v15, v11
	v_min_u32_e32 v15, 32, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v19, 31, v15
	v_alignbit_b32 v10, v11, v10, v19
	v_or_b32_e32 v11, v13, v17
	v_add_lshl_u32 v13, v15, v16, 23
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshrrev_b32_e32 v10, 9, v10
	v_mul_f32_e32 v15, 0x3fc90fda, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v10, v10, v13
	v_fma_f32 v13, 0x3fc90fda, v11, -v15
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v10, 0x33000000, v10
	v_fmac_f32_e32 v13, 0x33a22168, v11
	v_add_nc_u32_e32 v11, v12, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_or_b32_e32 v10, v10, v14
	v_fmac_f32_e32 v13, 0x3fc90fda, v10
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v10, v15, v13
.LBB0_9:                                ; %Flow179
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_and_not1_saveexec_b32 s2, s10
; %bb.10:                               ;   in Loop: Header=BB0_6 Depth=1
	v_mul_f32_e64 v1, 0x3f22f983, |v7|
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rndne_f32_e32 v1, v1
	v_fma_f32 v10, 0xbfc90fda, v1, |v7|
	v_cvt_i32_f32_e32 v11, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v10, 0xb3a22168, v1
	v_fmac_f32_e32 v10, 0xa7c234c4, v1
; %bb.11:                               ; %_ZL3sinf.exit78
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s2
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr12
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 s3, exec_lo
	v_cmpx_ngt_f32_e64 0x48000000, |v9|
	s_xor_b32 s10, exec_lo, s3
	s_cbranch_execz .LBB0_13
; %bb.12:                               ;   in Loop: Header=BB0_6 Depth=1
	v_and_b32_e32 v17, 0x7fffffff, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_and_or_b32 v20, v17, s25, 0x800000
	v_lshrrev_b32_e32 v17, 23, v17
	v_mad_u64_u32 v[12:13], null, 0xfe5163ab, v20, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v18, 0xffffff88, v17
	v_cmp_lt_u32_e32 vcc_lo, 63, v18
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v1, v13
	v_cndmask_b32_e64 v19, 0, 0xffffffc0, vcc_lo
	v_mad_u64_u32 v[13:14], null, 0x3c439041, v20, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v19, v19, v18
	v_mov_b32_e32 v1, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_lt_u32_e64 s2, 31, v19
	v_mad_u64_u32 v[14:15], null, 0xdb629599, v20, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v21, 0, 0xffffffe0, s2
	v_add_nc_u32_e32 v21, v21, v19
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_mov_b32 v1, v15 :: v_dual_cndmask_b32 v12, v14, v12
	v_cmp_lt_u32_e64 s3, 31, v21
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[15:16], null, 0xf534ddc0, v20, v[1:2]
	v_mov_b32_e32 v1, v16
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v13, v15, v13, vcc_lo
	v_mad_u64_u32 v[16:17], null, 0xfc2757d1, v20, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v12, v13, v12, s2
	v_mov_b32_e32 v1, v17
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[17:18], null, 0x4e441529, v20, v[1:2]
	v_mov_b32_e32 v1, v18
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_mad_u64_u32 v[18:19], null, 0xa2f9836e, v20, v[1:2]
	v_cndmask_b32_e64 v1, 0, 0xffffffe0, s3
	v_cndmask_b32_e32 v20, v17, v15, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_dual_cndmask_b32 v18, v18, v16 :: v_dual_add_nc_u32 v1, v1, v21
	v_dual_cndmask_b32 v17, v19, v17 :: v_dual_cndmask_b32 v16, v16, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v19, 32, v1
	v_cndmask_b32_e64 v15, v18, v20, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v17, v17, v18, s2
	v_cndmask_b32_e64 v18, v20, v16, s2
	v_cndmask_b32_e64 v16, v16, v13, s2
	v_cmp_eq_u32_e32 vcc_lo, 0, v1
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v17, v17, v15, s3
	v_cndmask_b32_e64 v15, v15, v18, s3
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v18, v18, v16, s3
	v_cndmask_b32_e64 v12, v16, v12, s3
	v_alignbit_b32 v20, v17, v15, v19
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_alignbit_b32 v14, v15, v18, v19
	v_cndmask_b32_e32 v1, v20, v17, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v13, v14, v15, vcc_lo
	v_alignbit_b32 v17, v18, v12, v19
	v_bfe_u32 v14, v1, 29, 1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_alignbit_b32 v15, v1, v13, 30
	v_cndmask_b32_e32 v17, v17, v18, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v16, 0, v14
	v_alignbit_b32 v13, v13, v17, 30
	v_alignbit_b32 v12, v17, v12, 30
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v15, v15, v16
	v_xor_b32_e32 v13, v13, v16
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v12, v12, v16
	v_lshrrev_b32_e32 v16, 29, v1
	v_clz_i32_u32_e32 v18, v15
	v_lshrrev_b32_e32 v1, 30, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b32_e32 v16, 31, v16
	v_min_u32_e32 v18, 32, v18
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v14, v14, v1
	v_or_b32_e32 v19, 0.5, v16
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v17, 31, v18
	v_lshlrev_b32_e32 v20, 23, v18
	v_alignbit_b32 v15, v15, v13, v17
	v_alignbit_b32 v12, v13, v12, v17
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v19, v19, v20
	v_alignbit_b32 v13, v15, v12, 9
	v_lshrrev_b32_e32 v15, 9, v15
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_clz_i32_u32_e32 v17, v13
	v_min_u32_e32 v17, 32, v17
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v21, 31, v17
	v_alignbit_b32 v12, v13, v12, v21
	v_or_b32_e32 v13, v15, v19
	v_add_lshl_u32 v15, v17, v18, 23
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshrrev_b32_e32 v12, 9, v12
	v_mul_f32_e32 v17, 0x3fc90fda, v13
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v12, v12, v15
	v_fma_f32 v15, 0x3fc90fda, v13, -v17
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v12, 0x33000000, v12
	v_fmac_f32_e32 v15, 0x33a22168, v13
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_or_b32_e32 v12, v12, v16
	v_fmac_f32_e32 v15, 0x3fc90fda, v12
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v12, v17, v15
.LBB0_13:                               ; %Flow178
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_and_not1_saveexec_b32 s2, s10
; %bb.14:                               ;   in Loop: Header=BB0_6 Depth=1
	v_mul_f32_e64 v1, 0x3f22f983, |v9|
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rndne_f32_e32 v1, v1
	v_fma_f32 v12, 0xbfc90fda, v1, |v9|
	v_cvt_i32_f32_e32 v14, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v12, 0xb3a22168, v1
	v_fmac_f32_e32 v12, 0xa7c234c4, v1
; %bb.15:                               ; %_ZL3cosf.exit89
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s2
	v_sub_f32_e32 v13, v3, v9
                                        ; implicit-def: $vgpr15
                                        ; implicit-def: $vgpr1
	s_mov_b32 s3, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ngt_f32_e64 0x48000000, |v13|
	s_xor_b32 s10, exec_lo, s3
	s_cbranch_execz .LBB0_17
; %bb.16:                               ;   in Loop: Header=BB0_6 Depth=1
	v_and_b32_e32 v20, 0x7fffffff, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_or_b32 v23, v20, s25, 0x800000
	v_mad_u64_u32 v[15:16], null, 0xfe5163ab, v23, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v1, v16
	v_lshrrev_b32_e32 v20, 23, v20
	v_mad_u64_u32 v[16:17], null, 0x3c439041, v23, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v21, 0xffffff88, v20
	v_cmp_lt_u32_e32 vcc_lo, 63, v21
	v_cndmask_b32_e64 v22, 0, 0xffffffc0, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v1, v17 :: v_dual_add_nc_u32 v22, v22, v21
	v_mad_u64_u32 v[17:18], null, 0xdb629599, v23, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_lt_u32_e64 s2, 31, v22
	v_cndmask_b32_e32 v15, v17, v15, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v24, 0, 0xffffffe0, s2
	v_dual_mov_b32 v1, v18 :: v_dual_add_nc_u32 v24, v24, v22
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[18:19], null, 0xf534ddc0, v23, v[1:2]
	v_cmp_lt_u32_e64 s3, 31, v24
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v1, v19 :: v_dual_cndmask_b32 v16, v18, v16
	v_mad_u64_u32 v[19:20], null, 0xfc2757d1, v23, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v15, v16, v15, s2
	v_mov_b32_e32 v1, v20
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[20:21], null, 0x4e441529, v23, v[1:2]
	v_mov_b32_e32 v1, v21
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_mad_u64_u32 v[21:22], null, 0xa2f9836e, v23, v[1:2]
	v_cndmask_b32_e64 v1, 0, 0xffffffe0, s3
	v_cndmask_b32_e32 v23, v20, v18, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_nc_u32_e32 v1, v1, v24
	v_dual_cndmask_b32 v21, v21, v19 :: v_dual_cndmask_b32 v20, v22, v20
	v_cndmask_b32_e32 v19, v19, v17, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v22, 32, v1
	v_cndmask_b32_e64 v18, v21, v23, s2
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v20, v20, v21, s2
	v_cndmask_b32_e64 v21, v23, v19, s2
	v_cndmask_b32_e64 v19, v19, v16, s2
	v_cmp_eq_u32_e32 vcc_lo, 0, v1
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v20, v20, v18, s3
	v_cndmask_b32_e64 v18, v18, v21, s3
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v21, v21, v19, s3
	v_cndmask_b32_e64 v15, v19, v15, s3
	v_alignbit_b32 v23, v20, v18, v22
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_alignbit_b32 v17, v18, v21, v22
	v_dual_cndmask_b32 v1, v23, v20 :: v_dual_cndmask_b32 v16, v17, v18
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_alignbit_b32 v20, v21, v15, v22
	v_bfe_u32 v17, v1, 29, 1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_alignbit_b32 v18, v1, v16, 30
	v_cndmask_b32_e32 v20, v20, v21, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v19, 0, v17
	v_alignbit_b32 v16, v16, v20, 30
	v_alignbit_b32 v15, v20, v15, 30
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v18, v18, v19
	v_xor_b32_e32 v16, v16, v19
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v15, v15, v19
	v_lshrrev_b32_e32 v19, 29, v1
	v_clz_i32_u32_e32 v21, v18
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b32_e32 v19, 31, v19
	v_min_u32_e32 v21, 32, v21
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_or_b32_e32 v22, 0.5, v19
	v_sub_nc_u32_e32 v20, 31, v21
	v_lshlrev_b32_e32 v23, 23, v21
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_alignbit_b32 v18, v18, v16, v20
	v_alignbit_b32 v15, v16, v15, v20
	v_sub_nc_u32_e32 v22, v22, v23
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_alignbit_b32 v16, v18, v15, 9
	v_lshrrev_b32_e32 v18, 9, v18
	v_clz_i32_u32_e32 v20, v16
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_min_u32_e32 v20, 32, v20
	v_sub_nc_u32_e32 v24, 31, v20
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_alignbit_b32 v15, v16, v15, v24
	v_or_b32_e32 v16, v18, v22
	v_add_lshl_u32 v18, v20, v21, 23
	v_lshrrev_b32_e32 v15, 9, v15
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v20, 0x3fc90fda, v16
	v_sub_nc_u32_e32 v15, v15, v18
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v18, 0x3fc90fda, v16, -v20
	v_add_nc_u32_e32 v15, 0x33000000, v15
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v18, 0x33a22168, v16
	v_or_b32_e32 v15, v15, v19
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v18, 0x3fc90fda, v15
	v_lshrrev_b32_e32 v15, 30, v1
	v_add_f32_e32 v1, v20, v18
	s_delay_alu instid0(VALU_DEP_2)
	v_add_nc_u32_e32 v15, v17, v15
.LBB0_17:                               ; %Flow177
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_and_not1_saveexec_b32 s2, s10
; %bb.18:                               ;   in Loop: Header=BB0_6 Depth=1
	v_mul_f32_e64 v1, 0x3f22f983, |v13|
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rndne_f32_e32 v15, v1
	v_fma_f32 v1, 0xbfc90fda, v15, |v13|
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v1, 0xb3a22168, v15
	v_fmac_f32_e32 v1, 0xa7c234c4, v15
	v_cvt_i32_f32_e32 v15, v15
; %bb.19:                               ; %_ZL3cosf.exit95
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_mul_f32 v18, v10, v10 :: v_dual_mul_f32 v21, v1, v1
	v_and_b32_e32 v22, 1, v15
	v_dual_mul_f32 v16, v12, v12 :: v_dual_and_b32 v17, 1, v14
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_4)
	v_fmaak_f32 v23, s26, v18, 0x3c0881c4
	v_lshlrev_b32_e32 v14, 30, v14
	v_fmaak_f32 v26, s27, v21, 0xbab64f3b
	v_fmaak_f32 v19, s26, v16, 0x3c0881c4
	v_cmp_eq_u32_e32 vcc_lo, 0, v17
	v_fmaak_f32 v23, v18, v23, 0xbe2aaa9d
	v_and_b32_e32 v14, 0x80000000, v14
	v_xor_b32_e32 v8, v8, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v23, v18, v23
	v_fmac_f32_e32 v10, v10, v23
	v_fmaak_f32 v19, v16, v19, 0xbe2aaa9d
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_fmaak_f32 v20, s27, v16, 0xbab64f3b :: v_dual_mul_f32 v19, v16, v19
	v_dual_fmaak_f32 v25, s26, v21, 0x3c0881c4 :: v_dual_fmac_f32 v12, v12, v19
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmaak_f32 v19, v21, v25, 0xbe2aaa9d
	v_dual_fmaak_f32 v20, v16, v20, 0x3d2aabf7 :: v_dual_mul_f32 v17, v21, v19
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmaak_f32 v20, v16, v20, 0xbf000004
	v_dual_fmaak_f32 v24, s27, v18, 0xbab64f3b :: v_dual_fmac_f32 v1, v1, v17
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v16, v16, v20, 1.0
	v_cndmask_b32_e64 v12, -v12, v16, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v9, 0x1f8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v12, v14, v12
	v_cndmask_b32_e32 v9, 0x7fc00000, v12, vcc_lo
	v_fmaak_f32 v24, v18, v24, 0x3d2aabf7
	v_lshlrev_b32_e32 v12, 30, v15
	v_and_b32_e32 v15, 1, v11
	v_lshlrev_b32_e32 v11, 30, v11
	v_mul_f32_e32 v9, v5, v9
	v_fmaak_f32 v20, v21, v26, 0x3d2aabf7
	v_fmaak_f32 v16, v18, v24, 0xbf000004
	v_cmp_eq_u32_e32 vcc_lo, 0, v22
	v_and_b32_e32 v12, 0x80000000, v12
	v_and_b32_e32 v11, 0x80000000, v11
	v_fmaak_f32 v19, v21, v20, 0xbf000004
	v_fma_f32 v14, v18, v16, 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v16, v21, v19, 1.0
	v_cndmask_b32_e64 v1, -v1, v16, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, 0, v15
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_xor_b32_e32 v1, v12, v1
	v_cndmask_b32_e32 v10, v14, v10, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v13, 0x1f8
	v_xor3_b32 v8, v8, v11, v10
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v1, 0x7fc00000, v1, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v7, 0x1f8
	v_mul_f32_e32 v1, v9, v1
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v7, 0x7fc00000, v8, vcc_lo
	v_fmac_f32_e32 v1, v4, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_fma_f32 v7, |v1|, -0.5, 0.5
	v_mul_f32_e32 v8, v1, v1
	v_cmp_gt_f32_e64 vcc_lo, |v1|, 0.5
	v_cmp_gt_f32_e64 s2, 0, v1
	v_cndmask_b32_e32 v7, v8, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmaak_f32 v8, s8, v7, 0x3c5fc5da
	v_sqrt_f32_e32 v9, v7
	v_fmaak_f32 v8, v7, v8, 0x3d034c3c
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmaak_f32 v8, v7, v8, 0x3d3641b1
	v_fmaak_f32 v8, v7, v8, 0x3d999bc8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmaak_f32 v8, v7, v8, 0x3e2aaaac
	v_mul_f32_e32 v7, v7, v8
	s_waitcnt_depctr 0xfff
	v_fmac_f32_e32 v9, v9, v7
	v_fmac_f32_e32 v1, v1, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_f32_e32 v8, v9, v9
	v_sub_f32_e32 v1, 0x3fc90fdb, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_f32_e32 v9, 0x40490fdb, v8
	v_cndmask_b32_e64 v7, v8, v9, s2
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v1, v1, v7, vcc_lo
	v_cvt_f64_f32_e32 v[7:8], v1
	v_mov_b32_e32 v1, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[7:8], v[7:8], s[12:13]
	v_cvt_f32_f64_e32 v7, v[7:8]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ngt_f32_e32 s16, v7
	s_cbranch_execz .LBB0_23
; %bb.20:                               ;   in Loop: Header=BB0_6 Depth=1
	v_mov_b32_e32 v1, s20
	s_mov_b32 s3, exec_lo
	v_cmpx_nle_f32_e32 s17, v7
	s_cbranch_execz .LBB0_22
; %bb.21:                               ;   in Loop: Header=BB0_6 Depth=1
	v_subrev_f32_e32 v1, s16, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f32 v7, null, s19, s19, v1
	v_rcp_f32_e32 v8, v7
	s_waitcnt_depctr 0xfff
	v_fma_f32 v9, -v7, v8, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v8, v9, v8
	v_div_scale_f32 v9, vcc_lo, v1, s19, v1
	v_mul_f32_e32 v10, v9, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v11, -v7, v10, v9
	v_fmac_f32_e32 v10, v11, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v7, -v7, v10, v9
	v_div_fmas_f32 v7, v7, v8, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f32 v1, v7, s19, v1
	v_cvt_i32_f32_e32 v1, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v1, 1, v1
.LBB0_22:                               ; %Flow176
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
.LBB0_23:                               ;   in Loop: Header=BB0_6 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s2
	v_lshlrev_b32_e32 v1, 2, v1
	ds_add_u32 v1, v6
.LBB0_24:                               ; %Flow180
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s9
	s_add_i32 s21, s21, 1
	s_add_u32 s4, s4, 4
	s_addc_u32 s5, s5, 0
	s_add_u32 s6, s6, 4
	s_addc_u32 s7, s7, 0
	s_cmp_lt_i32 s21, s28
	s_cbranch_scc1 .LBB0_6
.LBB0_25:                               ; %.loopexit106
	s_or_b32 exec_lo, exec_lo, s24
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s2, s14
	s_cbranch_execz .LBB0_28
; %bb.26:                               ; %.lr.ph113
	s_load_b64 s[0:1], s[0:1], 0x30
	s_add_i32 s3, s18, 2
	s_mov_b32 s5, 0
	s_mul_i32 s2, s3, s15
	s_max_i32 s4, s3, 1
	s_mov_b32 s3, 0
.LBB0_27:                               ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[6:7], s[2:3], 2
	s_waitcnt lgkmcnt(0)
	s_add_u32 s6, s0, s6
	s_addc_u32 s7, s1, s7
	v_mov_b32_e32 v0, s5
	s_add_i32 s4, s4, -1
	s_add_i32 s2, s2, 1
	s_add_i32 s5, s5, 4
	s_cmp_lg_u32 s4, 0
	ds_load_b32 v2, v0
	v_dual_mov_b32 v0, s6 :: v_dual_mov_b32 v1, s7
	s_waitcnt lgkmcnt(0)
	flat_store_b32 v[0:1], v2 dlc
	s_waitcnt_vscnt null, 0x0
	s_cbranch_scc1 .LBB0_27
.LBB0_28:                               ; %.loopexit
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8distancePVfS0_S0_S0_iiiiPViffifb
		.amdhsa_group_segment_fixed_size 1032
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 336
		.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 27
		.amdhsa_next_free_sgpr 30
		.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	_Z8distancePVfS0_S0_S0_iiiiPViffifb, .Lfunc_end0-_Z8distancePVfS0_S0_S0_iiiiPViffifb
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 5364
; NumSgprs: 32
; NumVgprs: 27
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 1032 bytes/workgroup (compile time only)
; SGPRBlocks: 3
; VGPRBlocks: 3
; NumSGPRsForWavesPerEU: 32
; NumVGPRsForWavesPerEU: 27
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     by_value
      - .offset:         44
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         48
        .size:           8
        .value_kind:     global_buffer
      - .offset:         56
        .size:           4
        .value_kind:     by_value
      - .offset:         60
        .size:           4
        .value_kind:     by_value
      - .offset:         64
        .size:           4
        .value_kind:     by_value
      - .offset:         68
        .size:           4
        .value_kind:     by_value
      - .offset:         72
        .size:           1
        .value_kind:     by_value
      - .offset:         80
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         84
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         88
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         92
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         94
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         96
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         98
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         100
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         102
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         120
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         128
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         136
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         144
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 1032
    .kernarg_segment_align: 8
    .kernarg_segment_size: 336
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8distancePVfS0_S0_S0_iiiiPViffifb
    .private_segment_fixed_size: 0
    .sgpr_count:     32
    .sgpr_spill_count: 0
    .symbol:         _Z8distancePVfS0_S0_S0_iiiiPViffifb.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     27
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
