// ---------------------------------------------------------------------------- 
// CUDA code to compute minimun distance between n points
//
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits>
#include <float.h>

#define MAX_POINTS 1048576

// ---------------------------------------------------------------------------- 
// Kernel Function to compute distance between all pairs of points
// Input: 
//	X: X[i] = x-coordinate of the ith point
//	Y: Y[i] = y-coordinate of the ith point
//	n: number of points
// Output: 
//	D: D[0] = minimum distance
//

#define block_size 1024


// Working minimum_distance function
__device__ unsigned int finished_blocks = 0; 

__global__ void minimum_distance(float * X, float * Y, volatile float * D, int n) 
{
    unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x;

    int i, z;
    float dx, dy, temp_distance;    
    float minDist = FLT_MAX; 
    
    bool isLastBlockDone;
    
    __shared__ float block_local_minimums[block_size];

    if(idx < n - 1)
    {
        for(z = idx + 1; z<n; z++)
        {   
            dx = X[z] - X[idx];
            dy = Y[z] - Y[idx];

            temp_distance = sqrtf(dx * dx + dy * dy);   

            if(temp_distance < minDist)
            {
                minDist = temp_distance;
            }
        }

        block_local_minimums[threadIdx.x] = minDist;
    
        __syncthreads();

        // Compute the block local minimum
        int largest_index = (n % block_size);

        if(largest_index == 0)
        {
            largest_index = block_size;   
        }
        else
        {
            if(blockIdx.x != n/block_size)
            {
                largest_index = block_size;    
            }
        }

        for(i = 1; i<largest_index; i *= 2) 
        {
            if(threadIdx.x % (2 * i) == 0 && (threadIdx.x + i) < largest_index - 1)
            {
                if(block_local_minimums[threadIdx.x] > block_local_minimums[threadIdx.x + i])
                {
                    block_local_minimums[threadIdx.x] = block_local_minimums[threadIdx.x + i];  
                }

                __syncthreads();
            } 
        }

        if(threadIdx.x == 0)
        {
            D[blockIdx.x] = block_local_minimums[0];

            int value = atomicInc(&finished_blocks, gridDim.x);
            isLastBlockDone = (value == (gridDim.x - 1));
        }

        // Last thread in the list computes the global minimum and puts it in D[0]
        if(isLastBlockDone && threadIdx.x == 0)
        {
            int num_blocks = n / block_size + (n % block_size != 0);

            for(i = 1; i<num_blocks; i++)
            {
                if(D[0] > D[i])
                {
                    D[0] = D[i];                   
                }
            }
        }            
    }    
}


// ---------------------------------------------------------------------------- 
// Host function to compute minimum distance between points
// Input:
//	X: X[i] = x-coordinate of the ith point
//	Y: Y[i] = y-coordinate of the ith point
//	n: number of points
// Output: 
//	D: minimum distance
//
float minimum_distance_host(float * X, float * Y, int n) {
    float dx, dy, Dij, min_distance, min_distance_i;
    int i, j;
    dx = X[1]-X[0];
    dy = Y[1]-Y[0];
    min_distance = sqrtf(dx*dx+dy*dy);
    for (i = 0; i < n-1; i++) {
	for (j = i+1; j < i+2; j++) {
	    dx = X[j]-X[i];
	    dy = Y[j]-Y[i];
	    min_distance_i = sqrtf(dx*dx+dy*dy);
	}
	for (j = i+1; j < n; j++) {
	    dx = X[j]-X[i];
	    dy = Y[j]-Y[i];
	    Dij = sqrtf(dx*dx+dy*dy);
	    if (min_distance_i > Dij) min_distance_i = Dij;
	}
	if (min_distance > min_distance_i) min_distance = min_distance_i;
    }
    return min_distance;
}
// ---------------------------------------------------------------------------- 
// Print device properties
void print_device_properties() {
    int i, deviceCount;
    cudaDeviceProp deviceProp;
    cudaGetDeviceCount(&deviceCount);
    printf("------------------------------------------------------------\n");
    printf("Number of GPU devices found = %d\n", deviceCount);
    for ( i = 0; i < deviceCount; ++i ) {
	cudaGetDeviceProperties(&deviceProp, i);
	printf("[Device: %1d] Compute Capability %d.%d.\n", i, deviceProp.major, deviceProp.minor);
	printf(" ... multiprocessor count  = %d\n", deviceProp.multiProcessorCount); 
	printf(" ... max threads per multiprocessor = %d\n", deviceProp.maxThreadsPerMultiProcessor); 
	printf(" ... max threads per block = %d\n", deviceProp.maxThreadsPerBlock); 
	printf(" ... max block dimension   = %d, %d, %d (along x, y, z)\n",
		deviceProp.maxThreadsDim[0], deviceProp.maxThreadsDim[1], deviceProp.maxThreadsDim[2]); 
	printf(" ... max grid size         = %d, %d, %d (along x, y, z)\n",
		deviceProp.maxGridSize[0], deviceProp.maxGridSize[1], deviceProp.maxGridSize[2]); 
	printf(" ... warp size             = %d\n", deviceProp.warpSize); 
	printf(" ... clock rate            = %d MHz\n", deviceProp.clockRate/1000); 
    }
    printf("------------------------------------------------------------\n");
}
// ---------------------------------------------------------------------------- 
// Main program - initializes points and computes minimum distance 
// between the points
//
int main(int argc, char* argv[]) {

    // Host Data
    float * hVx;		// host x-coordinate array
    float * hVy;		// host y-coordinate array
    float * hmin_dist;		// minimum value on host

    // Device Data
    float * dVx;		// device x-coordinate array
    float * dVy;		// device x-coordinate array
    float * dmin_dist;		// minimum value on device

    // Device parameters
    int MAX_BLOCK_SIZE;		// Maximum number of threads allowed on the device
    int blocks;			// Number of blocks in grid
    int threads_per_block;	// Number of threads per block

    // Timing variables
    cudaEvent_t start, stop;		// GPU timing variables
    struct timespec cpu_start, cpu_stop; // CPU timing variables
    float time_array[10]; 

    // Other variables
    int i, size, num_points; 
    float min_distance, sqrtn;
    int seed = 0;

    // Print device properties
    print_device_properties(); 

    // Get device information and set device to use
    int deviceCount;
    cudaDeviceProp deviceProp;
    cudaGetDeviceCount(&deviceCount);
    if (deviceCount > 0) {
	cudaSetDevice(0); 
	cudaGetDeviceProperties(&deviceProp, 0);
	MAX_BLOCK_SIZE = deviceProp.maxThreadsPerBlock;
    } else {
	printf("Warning: No GPU device found ... results may be incorrect\n");
    }

    // Timing initializations
    cudaEventCreate(&start);
    cudaEventCreate(&stop);

    // Check input
    if (argc != 2) {
	printf("Use: %s <number of points>\n", argv[0]);  
	exit(0);
    }
    if ((num_points = atoi(argv[argc-1])) < 2) {
	printf("Minimum number of points allowed: 2\n");
	exit(0);
    } 
    if ((num_points = atoi(argv[argc-1])) > MAX_POINTS) {
	printf("Maximum number of points allowed: %d\n", MAX_POINTS);
	exit(0);
    } 

    // Allocate host coordinate arrays 
    size = num_points * sizeof(float); 
    hVx = (float *) malloc(size); 
    hVy = (float *) malloc(size);
    hmin_dist = (float *) malloc(size);

    // Initialize points
    srand48(seed);                                // UNCOMMENT THIS UNCOMMENT THIS UNCOMMENT THIS!!!
    sqrtn = (float) sqrt(num_points); 
    for (i = 0; i < num_points; i++) {
	hVx[i] = sqrtn * (float)drand48();
	hVy[i] = sqrtn * (float)drand48();
    }

    // Allocate device coordinate arrays
    cudaMalloc(&dVx, size);
    cudaMalloc(&dVy, size);
    cudaMalloc(&dmin_dist, size);

    // Copy coordinate arrays from host memory to device memory 
    cudaEventRecord( start, 0 ); 

    cudaMemcpy(dVx, hVx, size, cudaMemcpyHostToDevice);
    cudaMemcpy(dVy, hVy, size, cudaMemcpyHostToDevice);

    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&(time_array[0]), start, stop);

    // Invoke kernel
    cudaEventRecord( start, 0 ); 

    // Custom variables to create blocks
    int num_blocks = num_points / (block_size) + ((num_points % (block_size)) != 0);

    //
    // Kernel function invocation
    //
    minimum_distance<<<num_blocks, block_size>>>(dVx, dVy, dmin_dist, num_points);

    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&(time_array[1]), start, stop);

    // Copy result from device memory to host memory 
    cudaEventRecord( start, 0 ); 

    cudaMemcpy(hmin_dist, dmin_dist, sizeof(float), cudaMemcpyDeviceToHost);

    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&(time_array[2]), start, stop);

    // Compute minimum distance on host to check device computation
    clock_gettime(CLOCK_REALTIME, &cpu_start);

    min_distance = minimum_distance_host(hVx, hVy, num_points); 

    clock_gettime(CLOCK_REALTIME, &cpu_stop);
    time_array[3] = 1000*((cpu_stop.tv_sec-cpu_start.tv_sec)                    
	    +0.000000001*(cpu_stop.tv_nsec-cpu_start.tv_nsec));

    // Print results
    printf("Number of Points    = %d\n", num_points); 
    printf("GPU Host-to-device  = %f ms \n", time_array[0]);
    printf("GPU Device-to-host  = %f ms \n", time_array[2]);
    printf("GPU execution time  = %f ms \n", time_array[1]);
    printf("CPU execution time  = %f ms\n", time_array[3]);
    printf("Min. distance (GPU) = %e\n", hmin_dist[0]);
    printf("Min. distance (CPU) = %e\n", min_distance);
    printf("Relative error      = %e\n", fabs(min_distance-hmin_dist[0])/min_distance);


    // Free device memory 
    cudaFree(dVx);
    cudaFree(dVy);
    cudaFree(dmin_dist);

    // Free host memory 
    free(hVx);
    free(hVy);
}  

	.file	"tmpxft_002a2a99_00000000-6_nbody.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z21minimum_distance_hostPfS_i
	.type	_Z21minimum_distance_hostPfS_i, @function
_Z21minimum_distance_hostPfS_i:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	leal	-1(%r12), %r13d
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	$1, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movss	4(%rdi), %xmm0
	movss	4(%rsi), %xmm1
	subss	(%rdi), %xmm0
	subss	(%rsi), %xmm1
	mulss	%xmm0, %xmm0
	mulss	%xmm1, %xmm1
	addss	%xmm1, %xmm0
	call	sqrtf@PLT
	movss	%xmm0, (%rsp)
.L3:
	leal	-1(%rbx), %eax
	cmpl	%r13d, %eax
	jge	.L11
	movss	-4(%rbp,%rbx,4), %xmm3
	movss	-4(%r14,%rbx,4), %xmm5
	movq	%rbx, %r15
	movss	0(%rbp,%rbx,4), %xmm0
	movss	(%r14,%rbx,4), %xmm1
	movss	%xmm3, 4(%rsp)
	subss	%xmm3, %xmm0
	subss	%xmm5, %xmm1
	movss	%xmm5, 8(%rsp)
	mulss	%xmm1, %xmm1
	mulss	%xmm0, %xmm0
	addss	%xmm1, %xmm0
	call	sqrtf@PLT
	movaps	%xmm0, %xmm2
.L4:
	cmpl	%r15d, %r12d
	jle	.L12
	movss	0(%rbp,%r15,4), %xmm0
	movss	(%r14,%r15,4), %xmm1
	incq	%r15
	movss	%xmm2, 12(%rsp)
	subss	4(%rsp), %xmm0
	subss	8(%rsp), %xmm1
	mulss	%xmm0, %xmm0
	mulss	%xmm1, %xmm1
	addss	%xmm1, %xmm0
	call	sqrtf@PLT
	movss	12(%rsp), %xmm2
	minss	%xmm2, %xmm0
	movaps	%xmm0, %xmm2
	jmp	.L4
.L12:
	minss	(%rsp), %xmm2
	incq	%rbx
	movss	%xmm2, (%rsp)
	jmp	.L3
.L11:
	movss	(%rsp), %xmm0
	addq	$24, %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
.LFE2027:
	.size	_Z21minimum_distance_hostPfS_i, .-_Z21minimum_distance_hostPfS_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"------------------------------------------------------------\n"
.LC1:
	.string	"Number of GPU devices found = %d\n"
.LC2:
	.string	"[Device: %1d] Compute Capability %d.%d.\n"
.LC3:
	.string	" ... multiprocessor count  = %d\n"
.LC4:
	.string	" ... max threads per multiprocessor = %d\n"
.LC5:
	.string	" ... max threads per block = %d\n"
.LC6:
	.string	" ... max block dimension   = %d, %d, %d (along x, y, z)\n"
.LC7:
	.string	" ... max grid size         = %d, %d, %d (along x, y, z)\n"
.LC8:
	.string	" ... warp size             = %d\n"
.LC9:
	.string	" ... clock rate            = %d MHz\n"
	.text
	.globl	_Z23print_device_propertiesv
	.type	_Z23print_device_propertiesv, @function
_Z23print_device_propertiesv:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC2(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
	subq	$1056, %rsp
	.cfi_def_cfa_offset 1088
	movq	%fs:40, %rax
	movq	%rax, 1048(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	12(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
.L14:
	cmpl	%ebx, 12(%rsp)
	jle	.L18
	movl	%ebx, %esi
	leaq	16(%rsp), %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	376(%rsp), %ecx
	movl	%ebx, %edx
	xorl	%eax, %eax
	movl	380(%rsp), %r8d
	movq	%r12, %rsi
	movl	$2, %edi
	incl	%ebx
	call	__printf_chk@PLT
	movl	404(%rsp), %edx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	640(%rsp), %edx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	336(%rsp), %edx
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	348(%rsp), %r8d
	xorl	%eax, %eax
	movl	344(%rsp), %ecx
	movl	340(%rsp), %edx
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	360(%rsp), %r8d
	xorl	%eax, %eax
	movl	356(%rsp), %ecx
	movl	352(%rsp), %edx
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	324(%rsp), %edx
	leaq	.LC8(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$1000, %ecx
	movl	$2, %edi
	movl	364(%rsp), %eax
	leaq	.LC9(%rip), %rsi
	cltd
	idivl	%ecx
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L14
.L18:
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	1048(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$1056, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z23print_device_propertiesv, .-_Z23print_device_propertiesv
	.globl	_Z42__device_stub__Z16minimum_distancePfS_PVfiPfS_PVfi
	.type	_Z42__device_stub__Z16minimum_distancePfS_PVfiPfS_PVfi, @function
_Z42__device_stub__Z16minimum_distancePfS_PVfiPfS_PVfi:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z16minimum_distancePfS_PVfi(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L19:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z42__device_stub__Z16minimum_distancePfS_PVfiPfS_PVfi, .-_Z42__device_stub__Z16minimum_distancePfS_PVfiPfS_PVfi
	.globl	_Z16minimum_distancePfS_PVfi
	.type	_Z16minimum_distancePfS_PVfi, @function
_Z16minimum_distancePfS_PVfi:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z16minimum_distancePfS_PVfiPfS_PVfi
	.cfi_endproc
.LFE2055:
	.size	_Z16minimum_distancePfS_PVfi, .-_Z16minimum_distancePfS_PVfi
	.section	.rodata.str1.1
.LC10:
	.string	"Warning: No GPU device found ... results may be incorrect\n"
.LC11:
	.string	"Use: %s <number of points>\n"
.LC12:
	.string	"Minimum number of points allowed: 2\n"
.LC13:
	.string	"Maximum number of points allowed: %d\n"
.LC16:
	.string	"Number of Points    = %d\n"
.LC17:
	.string	"GPU Host-to-device  = %f ms \n"
.LC18:
	.string	"GPU Device-to-host  = %f ms \n"
.LC19:
	.string	"GPU execution time  = %f ms \n"
.LC20:
	.string	"CPU execution time  = %f ms\n"
.LC21:
	.string	"Min. distance (GPU) = %e\n"
.LC22:
	.string	"Min. distance (CPU) = %e\n"
.LC24:
	.string	"Relative error      = %e\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$1192, %rsp
	.cfi_def_cfa_offset 1248
	movq	%fs:40, %rax
	movq	%rax, 1176(%rsp)
	xorl	%eax, %eax
	call	_Z23print_device_propertiesv
	leaq	28(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	cmpl	$0, 28(%rsp)
	jle	.L25
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	leaq	144(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaGetDeviceProperties_v2@PLT
	jmp	.L26
.L25:
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L26:
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	cmpl	$2, %ebp
	je	.L27
	movq	(%rbx), %rdx
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L35
.L27:
	movq	8(%rbx), %rdi
	call	atoi@PLT
	movl	%eax, %ebx
	cmpl	$1, %eax
	jg	.L28
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L35:
	xorl	%edi, %edi
	call	exit@PLT
.L28:
	cmpl	$1048576, %eax
	jle	.L29
	movl	$1048576, %edx
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L35
.L29:
	leal	0(,%rbx,4), %r14d
	xorl	%r15d, %r15d
	movq	%r14, %rdi
	call	malloc@PLT
	movq	%r14, %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	%r14, %rdi
	movq	%rax, %rbp
	call	malloc@PLT
	xorl	%edi, %edi
	movq	%rax, %r13
	call	srand48@PLT
	cvtsi2sdl	%ebx, %xmm0
	call	sqrt@PLT
	cvtsd2ss	%xmm0, %xmm2
	movss	%xmm2, 12(%rsp)
.L30:
	call	drand48@PLT
	cvtsd2ss	%xmm0, %xmm0
	mulss	12(%rsp), %xmm0
	movss	%xmm0, (%r12,%r15,4)
	call	drand48@PLT
	cvtsd2ss	%xmm0, %xmm0
	mulss	12(%rsp), %xmm0
	movss	%xmm0, 0(%rbp,%r15,4)
	incq	%r15
	cmpl	%r15d, %ebx
	jg	.L30
	leaq	32(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	leaq	48(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	movq	%r14, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	movq	%r14, %rdx
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	leaq	104(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$4194305, %edx
	xorl	%eax, %eax
	movl	%ebx, %ecx
	salq	$10, %rdx
	testl	$1023, %ebx
	movl	$1, 96(%rsp)
	setne	%al
	sarl	$10, %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	addl	%ecx, %eax
	movl	$1, %ecx
	movq	%rdx, 88(%rsp)
	movl	%eax, 72(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 76(%rsp)
	movq	72(%rsp), %rdi
	movl	80(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	movl	%ebx, %ecx
	movq	32(%rsp), %rdi
	call	_Z42__device_stub__Z16minimum_distancePfS_PVfiPfS_PVfi
.L31:
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	leaq	108(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rsi
	movl	$2, %ecx
	movq	%r13, %rdi
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	leaq	112(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	xorl	%edi, %edi
	leaq	72(%rsp), %rsi
	call	clock_gettime@PLT
	movl	%ebx, %edx
	movq	%rbp, %rsi
	movq	%r12, %rdi
	call	_Z21minimum_distance_hostPfS_i
	xorl	%edi, %edi
	leaq	88(%rsp), %rsi
	movss	%xmm0, 12(%rsp)
	call	clock_gettime@PLT
	movq	96(%rsp), %rax
	subq	80(%rsp), %rax
	movl	%ebx, %edx
	cvtsi2sdq	%rax, %xmm0
	movq	88(%rsp), %rax
	subq	72(%rsp), %rax
	leaq	.LC16(%rip), %rsi
	mulsd	.LC14(%rip), %xmm0
	cvtsi2sdq	%rax, %xmm1
	movl	$2, %edi
	xorl	%eax, %eax
	addsd	%xmm1, %xmm0
	mulsd	.LC15(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 116(%rsp)
	call	__printf_chk@PLT
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	104(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC18(%rip), %rsi
	cvtss2sd	112(%rsp), %xmm0
	call	__printf_chk@PLT
	leaq	.LC19(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	108(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC20(%rip), %rsi
	cvtss2sd	116(%rsp), %xmm0
	call	__printf_chk@PLT
	leaq	.LC21(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	0(%r13), %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC22(%rip), %rsi
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	leaq	.LC24(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movss	12(%rsp), %xmm0
	subss	0(%r13), %xmm0
	andps	.LC23(%rip), %xmm0
	divss	12(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	1176(%rsp), %rax
	subq	%fs:40, %rax
	je	.L32
	call	__stack_chk_fail@PLT
.L32:
	addq	$1192, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC25:
	.string	"_Z16minimum_distancePfS_PVfi"
.LC26:
	.string	"finished_blocks"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC25(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z16minimum_distancePfS_PVfi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC26(%rip), %rdx
	movl	$4, %r9d
	leaq	_ZL15finished_blocks(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2057:
	.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	_ZL15finished_blocks
	.comm	_ZL15finished_blocks,4,4
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC14:
	.long	-400107883
	.long	1041313291
	.align 8
.LC15:
	.long	0
	.long	1083129856
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC23:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.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:

// ---------------------------------------------------------------------------- 
// CUDA code to compute minimun distance between n points
//

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

#define MAX_POINTS 1048576

// ---------------------------------------------------------------------------- 
// Kernel Function to compute distance between all pairs of points
// Input: 
//	X: X[i] = x-coordinate of the ith point
//	Y: Y[i] = y-coordinate of the ith point
//	n: number of points
// Output: 
//	D: D[0] = minimum distance
//

#define block_size 1024


// Working minimum_distance function
__device__ unsigned int finished_blocks = 0; 

__global__ void minimum_distance(float * X, float * Y, volatile float * D, int n) 
{
    unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x;

    int i, z;
    float dx, dy, temp_distance;    
    float minDist = FLT_MAX; 
    
    bool isLastBlockDone;
    
    __shared__ float block_local_minimums[block_size];

    if(idx < n - 1)
    {
        for(z = idx + 1; z<n; z++)
        {   
            dx = X[z] - X[idx];
            dy = Y[z] - Y[idx];

            temp_distance = sqrtf(dx * dx + dy * dy);   

            if(temp_distance < minDist)
            {
                minDist = temp_distance;
            }
        }

        block_local_minimums[threadIdx.x] = minDist;
    
        __syncthreads();

        // Compute the block local minimum
        int largest_index = (n % block_size);

        if(largest_index == 0)
        {
            largest_index = block_size;   
        }
        else
        {
            if(blockIdx.x != n/block_size)
            {
                largest_index = block_size;    
            }
        }

        for(i = 1; i<largest_index; i *= 2) 
        {
            if(threadIdx.x % (2 * i) == 0 && (threadIdx.x + i) < largest_index - 1)
            {
                if(block_local_minimums[threadIdx.x] > block_local_minimums[threadIdx.x + i])
                {
                    block_local_minimums[threadIdx.x] = block_local_minimums[threadIdx.x + i];  
                }

                __syncthreads();
            } 
        }

        if(threadIdx.x == 0)
        {
            D[blockIdx.x] = block_local_minimums[0];

            int value = atomicInc(&finished_blocks, gridDim.x);
            isLastBlockDone = (value == (gridDim.x - 1));
        }

        // Last thread in the list computes the global minimum and puts it in D[0]
        if(isLastBlockDone && threadIdx.x == 0)
        {
            int num_blocks = n / block_size + (n % block_size != 0);

            for(i = 1; i<num_blocks; i++)
            {
                if(D[0] > D[i])
                {
                    D[0] = D[i];                   
                }
            }
        }            
    }    
}


// ---------------------------------------------------------------------------- 
// Host function to compute minimum distance between points
// Input:
//	X: X[i] = x-coordinate of the ith point
//	Y: Y[i] = y-coordinate of the ith point
//	n: number of points
// Output: 
//	D: minimum distance
//
float minimum_distance_host(float * X, float * Y, int n) {
    float dx, dy, Dij, min_distance, min_distance_i;
    int i, j;
    dx = X[1]-X[0];
    dy = Y[1]-Y[0];
    min_distance = sqrtf(dx*dx+dy*dy);
    for (i = 0; i < n-1; i++) {
	for (j = i+1; j < i+2; j++) {
	    dx = X[j]-X[i];
	    dy = Y[j]-Y[i];
	    min_distance_i = sqrtf(dx*dx+dy*dy);
	}
	for (j = i+1; j < n; j++) {
	    dx = X[j]-X[i];
	    dy = Y[j]-Y[i];
	    Dij = sqrtf(dx*dx+dy*dy);
	    if (min_distance_i > Dij) min_distance_i = Dij;
	}
	if (min_distance > min_distance_i) min_distance = min_distance_i;
    }
    return min_distance;
}
// ---------------------------------------------------------------------------- 
// Print device properties
void print_device_properties() {
    int i, deviceCount;
    hipDeviceProp_t deviceProp;
    hipGetDeviceCount(&deviceCount);
    printf("------------------------------------------------------------\n");
    printf("Number of GPU devices found = %d\n", deviceCount);
    for ( i = 0; i < deviceCount; ++i ) {
	hipGetDeviceProperties(&deviceProp, i);
	printf("[Device: %1d] Compute Capability %d.%d.\n", i, deviceProp.major, deviceProp.minor);
	printf(" ... multiprocessor count  = %d\n", deviceProp.multiProcessorCount); 
	printf(" ... max threads per multiprocessor = %d\n", deviceProp.maxThreadsPerMultiProcessor); 
	printf(" ... max threads per block = %d\n", deviceProp.maxThreadsPerBlock); 
	printf(" ... max block dimension   = %d, %d, %d (along x, y, z)\n",
		deviceProp.maxThreadsDim[0], deviceProp.maxThreadsDim[1], deviceProp.maxThreadsDim[2]); 
	printf(" ... max grid size         = %d, %d, %d (along x, y, z)\n",
		deviceProp.maxGridSize[0], deviceProp.maxGridSize[1], deviceProp.maxGridSize[2]); 
	printf(" ... warp size             = %d\n", deviceProp.warpSize); 
	printf(" ... clock rate            = %d MHz\n", deviceProp.clockRate/1000); 
    }
    printf("------------------------------------------------------------\n");
}
// ---------------------------------------------------------------------------- 
// Main program - initializes points and computes minimum distance 
// between the points
//
int main(int argc, char* argv[]) {

    // Host Data
    float * hVx;		// host x-coordinate array
    float * hVy;		// host y-coordinate array
    float * hmin_dist;		// minimum value on host

    // Device Data
    float * dVx;		// device x-coordinate array
    float * dVy;		// device x-coordinate array
    float * dmin_dist;		// minimum value on device

    // Device parameters
    int MAX_BLOCK_SIZE;		// Maximum number of threads allowed on the device
    int blocks;			// Number of blocks in grid
    int threads_per_block;	// Number of threads per block

    // Timing variables
    hipEvent_t start, stop;		// GPU timing variables
    struct timespec cpu_start, cpu_stop; // CPU timing variables
    float time_array[10]; 

    // Other variables
    int i, size, num_points; 
    float min_distance, sqrtn;
    int seed = 0;

    // Print device properties
    print_device_properties(); 

    // Get device information and set device to use
    int deviceCount;
    hipDeviceProp_t deviceProp;
    hipGetDeviceCount(&deviceCount);
    if (deviceCount > 0) {
	hipSetDevice(0); 
	hipGetDeviceProperties(&deviceProp, 0);
	MAX_BLOCK_SIZE = deviceProp.maxThreadsPerBlock;
    } else {
	printf("Warning: No GPU device found ... results may be incorrect\n");
    }

    // Timing initializations
    hipEventCreate(&start);
    hipEventCreate(&stop);

    // Check input
    if (argc != 2) {
	printf("Use: %s <number of points>\n", argv[0]);  
	exit(0);
    }
    if ((num_points = atoi(argv[argc-1])) < 2) {
	printf("Minimum number of points allowed: 2\n");
	exit(0);
    } 
    if ((num_points = atoi(argv[argc-1])) > MAX_POINTS) {
	printf("Maximum number of points allowed: %d\n", MAX_POINTS);
	exit(0);
    } 

    // Allocate host coordinate arrays 
    size = num_points * sizeof(float); 
    hVx = (float *) malloc(size); 
    hVy = (float *) malloc(size);
    hmin_dist = (float *) malloc(size);

    // Initialize points
    srand48(seed);                                // UNCOMMENT THIS UNCOMMENT THIS UNCOMMENT THIS!!!
    sqrtn = (float) sqrt(num_points); 
    for (i = 0; i < num_points; i++) {
	hVx[i] = sqrtn * (float)drand48();
	hVy[i] = sqrtn * (float)drand48();
    }

    // Allocate device coordinate arrays
    hipMalloc(&dVx, size);
    hipMalloc(&dVy, size);
    hipMalloc(&dmin_dist, size);

    // Copy coordinate arrays from host memory to device memory 
    hipEventRecord( start, 0 ); 

    hipMemcpy(dVx, hVx, size, hipMemcpyHostToDevice);
    hipMemcpy(dVy, hVy, size, hipMemcpyHostToDevice);

    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&(time_array[0]), start, stop);

    // Invoke kernel
    hipEventRecord( start, 0 ); 

    // Custom variables to create blocks
    int num_blocks = num_points / (block_size) + ((num_points % (block_size)) != 0);

    //
    // Kernel function invocation
    //
    minimum_distance<<<num_blocks, block_size>>>(dVx, dVy, dmin_dist, num_points);

    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&(time_array[1]), start, stop);

    // Copy result from device memory to host memory 
    hipEventRecord( start, 0 ); 

    hipMemcpy(hmin_dist, dmin_dist, sizeof(float), hipMemcpyDeviceToHost);

    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&(time_array[2]), start, stop);

    // Compute minimum distance on host to check device computation
    clock_gettime(CLOCK_REALTIME, &cpu_start);

    min_distance = minimum_distance_host(hVx, hVy, num_points); 

    clock_gettime(CLOCK_REALTIME, &cpu_stop);
    time_array[3] = 1000*((cpu_stop.tv_sec-cpu_start.tv_sec)                    
	    +0.000000001*(cpu_stop.tv_nsec-cpu_start.tv_nsec));

    // Print results
    printf("Number of Points    = %d\n", num_points); 
    printf("GPU Host-to-device  = %f ms \n", time_array[0]);
    printf("GPU Device-to-host  = %f ms \n", time_array[2]);
    printf("GPU execution time  = %f ms \n", time_array[1]);
    printf("CPU execution time  = %f ms\n", time_array[3]);
    printf("Min. distance (GPU) = %e\n", hmin_dist[0]);
    printf("Min. distance (CPU) = %e\n", min_distance);
    printf("Relative error      = %e\n", fabs(min_distance-hmin_dist[0])/min_distance);


    // Free device memory 
    hipFree(dVx);
    hipFree(dVy);
    hipFree(dmin_dist);

    // Free host memory 
    free(hVx);
    free(hVy);
}  

	.text
	.file	"nbody.hip"
	.globl	_Z31__device_stub__minimum_distancePfS_PVfi # -- Begin function _Z31__device_stub__minimum_distancePfS_PVfi
	.type	_Z31__device_stub__minimum_distancePfS_PVfi,@function
_Z31__device_stub__minimum_distancePfS_PVfi: # @_Z31__device_stub__minimum_distancePfS_PVfi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z16minimum_distancePfS_PVfi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z31__device_stub__minimum_distancePfS_PVfi, .Lfunc_end0-_Z31__device_stub__minimum_distancePfS_PVfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z21minimum_distance_hostPfS_i  # -- Begin function _Z21minimum_distance_hostPfS_i
	.type	_Z21minimum_distance_hostPfS_i,@function
_Z21minimum_distance_hostPfS_i:         # @_Z21minimum_distance_hostPfS_i
	.cfi_startproc
# %bb.0:
                                        # kill: def $edx killed $edx def $rdx
	movss	4(%rdi), %xmm0                  # xmm0 = mem[0],zero,zero,zero
	subss	(%rdi), %xmm0
	movss	4(%rsi), %xmm1                  # xmm1 = mem[0],zero,zero,zero
	subss	(%rsi), %xmm1
	mulss	%xmm0, %xmm0
	mulss	%xmm1, %xmm1
	addss	%xmm0, %xmm1
	sqrtss	%xmm1, %xmm1
	cmpl	$2, %edx
	jl	.LBB1_1
# %bb.3:                                # %.lr.ph72.preheader
	leal	-1(%rdx), %eax
	movl	%edx, %ecx
	movl	$1, %edx
	xorl	%r8d, %r8d
	movq	%rdi, %r9
	movq	%rsi, %r10
.LBB1_4:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_5 Depth 2
	movss	(%rdi,%r8,4), %xmm2             # xmm2 = mem[0],zero,zero,zero
	movss	(%rsi,%r8,4), %xmm3             # xmm3 = mem[0],zero,zero,zero
	incq	%r8
	movss	(%rdi,%rdx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	subss	%xmm2, %xmm0
	mulss	%xmm0, %xmm0
	movss	(%rsi,%rdx,4), %xmm4            # xmm4 = mem[0],zero,zero,zero
	subss	%xmm3, %xmm4
	mulss	%xmm4, %xmm4
	addss	%xmm0, %xmm4
	xorps	%xmm0, %xmm0
	sqrtss	%xmm4, %xmm0
	movl	$1, %r11d
.LBB1_5:                                #   Parent Loop BB1_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movaps	%xmm0, %xmm4
	movss	(%r9,%r11,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	subss	%xmm2, %xmm0
	movss	(%r10,%r11,4), %xmm5            # xmm5 = mem[0],zero,zero,zero
	subss	%xmm3, %xmm5
	mulss	%xmm0, %xmm0
	mulss	%xmm5, %xmm5
	addss	%xmm0, %xmm5
	xorps	%xmm0, %xmm0
	sqrtss	%xmm5, %xmm0
	minss	%xmm4, %xmm0
	incq	%r11
	cmpq	%r11, %rcx
	jne	.LBB1_5
# %bb.6:                                # %._crit_edge
                                        #   in Loop: Header=BB1_4 Depth=1
	minss	%xmm1, %xmm0
	incq	%rdx
	addq	$4, %r10
	addq	$4, %r9
	decq	%rcx
	movaps	%xmm0, %xmm1
	cmpq	%rax, %r8
	jne	.LBB1_4
# %bb.2:                                # %._crit_edge73
	retq
.LBB1_1:
	movaps	%xmm1, %xmm0
	retq
.Lfunc_end1:
	.size	_Z21minimum_distance_hostPfS_i, .Lfunc_end1-_Z21minimum_distance_hostPfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z23print_device_propertiesv    # -- Begin function _Z23print_device_propertiesv
	.type	_Z23print_device_propertiesv,@function
_Z23print_device_propertiesv:           # @_Z23print_device_propertiesv
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 1504
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	leaq	4(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	(%rbx), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, (%rbx)
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph
	leaq	8(%rsp), %rbx
	xorl	%ebp, %ebp
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	movl	368(%rsp), %edx
	movl	372(%rsp), %ecx
	movl	$.L.str.2, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	movl	396(%rsp), %esi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movl	632(%rsp), %esi
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movl	328(%rsp), %esi
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movl	332(%rsp), %esi
	movl	336(%rsp), %edx
	movl	340(%rsp), %ecx
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	344(%rsp), %esi
	movl	348(%rsp), %edx
	movl	352(%rsp), %ecx
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	316(%rsp), %esi
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movslq	356(%rsp), %rax
	imulq	$274877907, %rax, %rsi          # imm = 0x10624DD3
	movq	%rsi, %rax
	shrq	$63, %rax
	sarq	$38, %rsi
	addl	%eax, %esi
	movl	$.L.str.9, %edi
                                        # kill: def $esi killed $esi killed $rsi
	xorl	%eax, %eax
	callq	printf
	incl	%ebp
	cmpl	4(%rsp), %ebp
	jl	.LBB2_2
.LBB2_3:                                # %._crit_edge
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	addq	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z23print_device_propertiesv, .Lfunc_end2-_Z23print_device_propertiesv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI3_0:
	.quad	0x3e112e0be826d695              # double 1.0000000000000001E-9
.LCPI3_1:
	.quad	0x408f400000000000              # double 1000
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI3_2:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.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
	subq	$1608, %rsp                     # imm = 0x648
	.cfi_def_cfa_offset 1664
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	callq	_Z23print_device_propertiesv
	leaq	60(%rsp), %r14
	movq	%r14, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%r14)
	jle	.LBB3_2
# %bb.1:
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	136(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	jmp	.LBB3_3
.LBB3_2:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
.LBB3_3:
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	cmpl	$2, %ebp
	jne	.LBB3_14
# %bb.4:
	movq	8(%rbx), %rdi
	callq	atoi
	cmpl	$1, %eax
	jle	.LBB3_15
# %bb.5:
	movl	%eax, %r12d
	cmpl	$1048577, %eax                  # imm = 0x100001
	jae	.LBB3_17
# %bb.6:                                # %.lr.ph.preheader
	leal	(,%r12,4), %r13d
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	xorl	%edi, %edi
	callq	srand48
	cvtsi2sd	%r12d, %xmm0
	xorpd	%xmm1, %xmm1
	ucomisd	%xmm1, %xmm0
	jb	.LBB3_8
# %bb.7:
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB3_9
.LBB3_8:                                # %call.sqrt
	callq	sqrt
.LBB3_9:                                # %.lr.ph.preheader.split
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	movl	%r12d, %r15d
	xorl	%ebp, %ebp
.LBB3_10:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	drand48
	cvtsd2ss	%xmm0, %xmm0
	mulss	4(%rsp), %xmm0                  # 4-byte Folded Reload
	movss	%xmm0, (%rbx,%rbp,4)
	callq	drand48
	cvtsd2ss	%xmm0, %xmm0
	mulss	4(%rsp), %xmm0                  # 4-byte Folded Reload
	movss	%xmm0, (%r14,%rbp,4)
	incq	%rbp
	cmpq	%rbp, %r15
	jne	.LBB3_10
# %bb.11:                               # %._crit_edge
	leaq	48(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	40(%rsp), %r15
	movq	%r15, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbp), %rdi
	movq	%rbx, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	movq	%r14, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	64(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	%r12d, %edi
	shrl	$10, %edi
	movl	%r12d, %eax
	andl	$1023, %eax                     # imm = 0x3FF
	cmpl	$1, %eax
	sbbl	$-1, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$1024, %rdx                     # imm = 0x400
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_13
# %bb.12:
	movq	48(%rsp), %rdi
	movq	40(%rsp), %rsi
	movq	24(%rsp), %rdx
	movl	%r12d, %ecx
	callq	_Z31__device_stub__minimum_distancePfS_PVfi
.LBB3_13:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	68(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	callq	hipEventElapsedTime
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	24(%rsp), %rsi
	movl	$4, %edx
	movq	32(%rsp), %rdi                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	72(%rsp), %r13
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movq	%r13, %rdi
	callq	hipEventElapsedTime
	leaq	120(%rsp), %r15
	xorl	%edi, %edi
	movq	%r15, %rsi
	callq	clock_gettime
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movl	%r12d, %edx
	callq	_Z21minimum_distance_hostPfS_i
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	leaq	104(%rsp), %rbp
	xorl	%edi, %edi
	movq	%rbp, %rsi
	callq	clock_gettime
	movq	(%rbp), %rax
	movq	8(%rbp), %rcx
	subq	(%r15), %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	subq	8(%r15), %rcx
	cvtsi2sd	%rcx, %xmm1
	mulsd	.LCPI3_0(%rip), %xmm1
	addsd	%xmm0, %xmm1
	mulsd	.LCPI3_1(%rip), %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, 4(%r13)
	movl	$.L.str.14, %edi
	movl	%r12d, %esi
	xorl	%eax, %eax
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	-8(%r13), %xmm0
	movl	$.L.str.15, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r13), %xmm0
	movl	$.L.str.16, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	-4(%r13), %xmm0
	movl	$.L.str.17, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	4(%r13), %xmm0
	movl	$.L.str.18, %edi
	movb	$1, %al
	callq	printf
	movq	32(%rsp), %r15                  # 8-byte Reload
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str.19, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	4(%rsp), %xmm0                  # 4-byte Folded Reload
	movl	$.L.str.20, %edi
	movb	$1, %al
	callq	printf
	movss	4(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movaps	%xmm1, %xmm0
	subss	(%r15), %xmm0
	andps	.LCPI3_2(%rip), %xmm0
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.21, %edi
	movb	$1, %al
	callq	printf
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$1608, %rsp                     # imm = 0x648
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_14:
	.cfi_def_cfa_offset 1664
	movq	(%rbx), %rsi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB3_16
.LBB3_15:
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	jmp	.LBB3_16
.LBB3_17:
	movl	$.L.str.13, %edi
	movl	$1048576, %esi                  # imm = 0x100000
	xorl	%eax, %eax
	callq	printf
.LBB3_16:
	xorl	%edi, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16minimum_distancePfS_PVfi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$0, (%rsp)
	movl	$finished_blocks, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	finished_blocks,@object         # @finished_blocks
	.local	finished_blocks
	.comm	finished_blocks,4,4
	.type	_Z16minimum_distancePfS_PVfi,@object # @_Z16minimum_distancePfS_PVfi
	.section	.rodata,"a",@progbits
	.globl	_Z16minimum_distancePfS_PVfi
	.p2align	3, 0x0
_Z16minimum_distancePfS_PVfi:
	.quad	_Z31__device_stub__minimum_distancePfS_PVfi
	.size	_Z16minimum_distancePfS_PVfi, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"Number of GPU devices found = %d\n"
	.size	.L.str.1, 34

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"[Device: %1d] Compute Capability %d.%d.\n"
	.size	.L.str.2, 41

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	" ... multiprocessor count  = %d\n"
	.size	.L.str.3, 33

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	" ... max threads per multiprocessor = %d\n"
	.size	.L.str.4, 42

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	" ... max threads per block = %d\n"
	.size	.L.str.5, 33

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	" ... max block dimension   = %d, %d, %d (along x, y, z)\n"
	.size	.L.str.6, 57

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	" ... max grid size         = %d, %d, %d (along x, y, z)\n"
	.size	.L.str.7, 57

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	" ... warp size             = %d\n"
	.size	.L.str.8, 33

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	" ... clock rate            = %d MHz\n"
	.size	.L.str.9, 37

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Use: %s <number of points>\n"
	.size	.L.str.11, 28

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Maximum number of points allowed: %d\n"
	.size	.L.str.13, 38

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Number of Points    = %d\n"
	.size	.L.str.14, 26

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"GPU Host-to-device  = %f ms \n"
	.size	.L.str.15, 30

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"GPU Device-to-host  = %f ms \n"
	.size	.L.str.16, 30

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"GPU execution time  = %f ms \n"
	.size	.L.str.17, 30

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"CPU execution time  = %f ms\n"
	.size	.L.str.18, 29

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"Min. distance (GPU) = %e\n"
	.size	.L.str.19, 26

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"Min. distance (CPU) = %e\n"
	.size	.L.str.20, 26

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"Relative error      = %e\n"
	.size	.L.str.21, 26

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16minimum_distancePfS_PVfi"
	.size	.L__unnamed_1, 29

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"finished_blocks"
	.size	.L__unnamed_2, 16

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

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

	.type	.Lstr.1,@object                 # @str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr.1:
	.asciz	"------------------------------------------------------------"
	.size	.Lstr.1, 61

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Warning: No GPU device found ... results may be incorrect"
	.size	.Lstr.2, 58

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Minimum number of points allowed: 2"
	.size	.Lstr.3, 36

	.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 _Z31__device_stub__minimum_distancePfS_PVfi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym finished_blocks
	.addrsig_sym _Z16minimum_distancePfS_PVfi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16minimum_distancePfS_PVfi ; -- Begin function _Z16minimum_distancePfS_PVfi
	.globl	_Z16minimum_distancePfS_PVfi
	.p2align	8
	.type	_Z16minimum_distancePfS_PVfi,@function
_Z16minimum_distancePfS_PVfi:           ; @_Z16minimum_distancePfS_PVfi
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s9, s[0:1], 0x18
	s_add_u32 s10, s0, 32
	s_mov_b32 s8, s15
	s_addc_u32 s11, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mad_u64_u32 v[2:3], null, s8, s2, v[0:1]
	s_add_i32 s2, s9, -1
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_cmp_gt_u32_e32 vcc_lo, s2, v2
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_24
; %bb.1:                                ; %.preheader
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x10
	s_load_b32 s1, s[10:11], 0x0
	v_dual_mov_b32 v6, 0x7f7fffff :: v_dual_add_nc_u32 v1, 1, v2
	s_mov_b32 s10, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s9, v1
	s_cbranch_execz .LBB0_5
; %bb.2:                                ; %.lr.ph
	v_dual_mov_b32 v3, 0 :: v_dual_mov_b32 v6, 0x7f7fffff
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v4, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v3, vcc_lo
	v_add_co_u32 v2, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	global_load_b32 v7, v[4:5], off
	global_load_b32 v8, v[2:3], off
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[4:5], 2, v[1:2]
	v_add_co_u32 v2, vcc_lo, s4, v4
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v5, vcc_lo
	v_add_co_u32 v4, vcc_lo, s6, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v5, vcc_lo
	s_mov_b32 s4, 0
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	global_load_b32 v9, v[4:5], off
	global_load_b32 v10, v[2:3], off
	v_add_nc_u32_e32 v1, 1, v1
	s_waitcnt vmcnt(0)
	v_dual_sub_f32 v9, v9, v8 :: v_dual_sub_f32 v10, v10, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v9, v9, v9
	v_fmac_f32_e32 v9, v10, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v10, 0x4f800000, v9
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v9
	v_cndmask_b32_e32 v9, v9, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_sqrt_f32_e32 v10, v9
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v11, -1, v10
	v_add_nc_u32_e32 v12, 1, v10
	v_fma_f32 v13, -v11, v10, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v14, -v12, v10, v9
	v_cmp_ge_f32_e64 s0, 0, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v10, v10, v11, s0
	v_cmp_lt_f32_e64 s0, 0, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v10, v10, v12, s0
	v_add_co_u32 v2, s0, v2, 4
	v_add_co_ci_u32_e64 v3, s0, 0, v3, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v11, 0x37800000, v10
	v_cndmask_b32_e32 v10, v10, v11, vcc_lo
	v_cmp_class_f32_e64 s0, v9, 0x260
	v_add_co_u32 v4, vcc_lo, v4, 4
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v9, v10, v9, s0
	v_cmp_le_i32_e64 s0, s9, v1
	v_cmp_lt_f32_e32 vcc_lo, v9, v6
	s_delay_alu instid0(VALU_DEP_2)
	s_or_b32 s4, s0, s4
	v_cndmask_b32_e32 v6, v6, v9, vcc_lo
	s_and_not1_b32 exec_lo, exec_lo, s4
	s_cbranch_execnz .LBB0_3
; %bb.4:                                ; %Flow95
	s_or_b32 exec_lo, exec_lo, s4
.LBB0_5:                                ; %Flow96
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(SALU_CYCLE_1)
	s_or_b32 exec_lo, exec_lo, s10
	s_ashr_i32 s0, s9, 31
	v_lshlrev_b32_e32 v1, 2, v0
	s_lshr_b32 s0, s0, 22
	s_add_i32 s0, s9, s0
	ds_store_b32 v1, v6
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s0, 0xfffffc00
	s_delay_alu instid0(SALU_CYCLE_1)
	s_sub_i32 s5, s9, s4
	s_ashr_i32 s4, s0, 10
	s_cmp_eq_u32 s5, 0
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_7
; %bb.6:
	s_cmp_eq_u32 s8, s4
	s_cselect_b32 s0, s5, 0x400
	s_branch .LBB0_8
.LBB0_7:
	s_movk_i32 s0, 0x400
.LBB0_8:
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lt_i32 s0, 2
	s_cbranch_scc1 .LBB0_16
; %bb.9:                                ; %.lr.ph64
	s_add_i32 s6, s0, -1
	s_mov_b32 s7, 1
.LBB0_10:                               ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	s_mov_b32 s10, s7
	s_lshl_b32 s7, s7, 1
	s_add_i32 s9, s7, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_and_b32_e32 v2, s9, v0
	s_mov_b32 s9, exec_lo
	v_cmpx_eq_u32_e32 0, v2
	s_cbranch_execz .LBB0_15
; %bb.11:                               ;   in Loop: Header=BB0_10 Depth=1
	v_add_nc_u32_e32 v2, s10, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_gt_u32_e32 vcc_lo, s6, v2
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_15
; %bb.12:                               ;   in Loop: Header=BB0_10 Depth=1
	v_lshl_add_u32 v2, s10, 2, v1
	ds_load_b32 v3, v1
	ds_load_b32 v2, v2
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_f32_e32 vcc_lo, v3, v2
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_14
; %bb.13:                               ;   in Loop: Header=BB0_10 Depth=1
	ds_store_b32 v1, v2
.LBB0_14:                               ;   in Loop: Header=BB0_10 Depth=1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_15:                               ;   in Loop: Header=BB0_10 Depth=1
	s_or_b32 exec_lo, exec_lo, s9
	s_cmp_lt_i32 s7, s0
	s_cbranch_scc1 .LBB0_10
.LBB0_16:                               ; %._crit_edge65
	v_cmp_ne_u32_e32 vcc_lo, 0, v0
	s_mov_b32 s9, 0
	s_mov_b32 s6, exec_lo
                                        ; implicit-def: $sgpr7
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_18
; %bb.17:
	s_lshl_b64 s[8:9], s[8:9], 2
	s_add_i32 s0, s1, -1
	s_add_u32 s8, s2, s8
	s_addc_u32 s9, s3, s9
	v_mov_b32_e32 v2, 0
	v_dual_mov_b32 v0, s8 :: v_dual_mov_b32 v1, s9
	v_mov_b32_e32 v4, s1
	s_getpc_b64 s[8:9]
	s_add_u32 s8, s8, finished_blocks@rel32@lo+4
	s_addc_u32 s9, s9, finished_blocks@rel32@hi+12
	ds_load_b32 v3, v2
	s_waitcnt lgkmcnt(0)
	flat_store_b32 v[0:1], v3 dlc
	s_waitcnt_vscnt null, 0x0
	global_atomic_inc_u32 v0, v2, v4, s[8:9] glc
	s_waitcnt vmcnt(0)
	v_cmp_ne_u32_e64 s0, s0, v0
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 s7, s0, exec_lo
.LBB0_18:
	s_or_b32 exec_lo, exec_lo, s6
	s_or_b32 s0, vcc_lo, s7
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_xor_b32 s0, s0, -1
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB0_24
; %bb.19:
	s_cmp_lg_u32 s5, 0
	s_cselect_b32 s0, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	s_cmp_lg_u32 s0, 0
	s_addc_u32 s0, s4, 0
	s_cmp_lt_i32 s0, 2
	s_cbranch_scc1 .LBB0_24
; %bb.20:                               ; %.lr.ph68.preheader
	v_dual_mov_b32 v0, s2 :: v_dual_mov_b32 v1, s3
	s_add_i32 s4, s0, -1
	s_add_u32 s0, s2, 4
	s_addc_u32 s1, s3, 0
.LBB0_21:                               ; %.lr.ph68
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	v_dual_mov_b32 v3, s1 :: v_dual_mov_b32 v2, s0
	s_mov_b32 s2, exec_lo
	flat_load_b32 v4, v[0:1] glc dlc
	s_waitcnt vmcnt(0)
	flat_load_b32 v2, v[2:3] glc dlc
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_cmpx_gt_f32_e32 v4, v2
	s_cbranch_execz .LBB0_23
; %bb.22:                               ;   in Loop: Header=BB0_21 Depth=1
	v_dual_mov_b32 v3, s1 :: v_dual_mov_b32 v2, s0
	flat_load_b32 v2, v[2:3] glc dlc
	s_waitcnt vmcnt(0) lgkmcnt(0)
	flat_store_b32 v[0:1], v2 dlc
	s_waitcnt_vscnt null, 0x0
.LBB0_23:                               ;   in Loop: Header=BB0_21 Depth=1
	s_or_b32 exec_lo, exec_lo, s2
	s_add_i32 s4, s4, -1
	s_add_u32 s0, s0, 4
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s4, 0
	s_cbranch_scc1 .LBB0_21
.LBB0_24:                               ; %.loopexit
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16minimum_distancePfS_PVfi
		.amdhsa_group_segment_fixed_size 4096
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 15
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z16minimum_distancePfS_PVfi, .Lfunc_end0-_Z16minimum_distancePfS_PVfi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1060
; NumSgprs: 18
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4096 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 15
; 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
	.protected	finished_blocks         ; @finished_blocks
	.type	finished_blocks,@object
	.section	.bss,"aw",@nobits
	.globl	finished_blocks
	.p2align	2, 0x0
finished_blocks:
	.long	0                               ; 0x0
	.size	finished_blocks, 4

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.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 finished_blocks
	.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
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 4096
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16minimum_distancePfS_PVfi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16minimum_distancePfS_PVfi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
