//Elapsed Real Time for input-4.txt: 0.603, 0.606, 0.599
//Elapsed Real Time for input-5.txt: 1.419, 1.391, 1.408

#include <stdio.h>
#include <stdbool.h>
#include <cuda_runtime.h>

// Representation for a 2D point with integer coordinates.
typedef struct {
  // Coordinates of the point.
  int x, y;
} Point;
// Return the squared distance between point i and point j in the ptList.
__device__ double distSquared(Point *devPtList, int i, int j ) {
  double dx = (double)devPtList[ i ].x - (double)devPtList[ j ].x;
  double dy = (double)devPtList[ i ].y - (double)devPtList[ j ].y;
  return dx * dx + dy * dy;
}
/**
* This function finds the largest of 3 numbers.
*@param p0 number 1
*@param p1 number 2
*@param p2 number 3
*@return the largest of the 3 parameters
*/
__device__ double findLargest( double p0, double p1, double p2){
    if ( p0 >= p1 && p0 >= p2 ){
         return p0;
    } else if (p1 >= p2 && p1 >= p0) {
        return p1;
    } else
        return p2;
}
/**
* This function finds the smallest of 3 numbers.
*@param p0 number 1
*@param p1 number 2
*@param p2 number 3
*@return the smallest of the 3 parameters
*/
__device__ double findSmallest( double p0, double p1, double p2){
    if ( p0 <= p1 && p0 <= p2 ){
        return p0;
    }else if( p1 <= p2 && p1 <= p0){
        return p1;
    }else
        return p2;
}
/**
* This function determines whether the 3 points are within an acceptable range of each other
* in order to qualify as points of a "semilateral" triangle. That range being +/- 10%.
*@param d0 distance b/w point 1 and point 2
*@param d1 distance b/w point 2 and point 3
*@param d2 distance b/w point 3 and point 1
*@return true/false: true if the difference is acceptable. false if not.
*/
__device__ bool check( double d0, double d1, double d2 ){
    double largest = findLargest( d0, d1, d2 );
    double smallest = findSmallest( d0, d1, d2 );
    double diff = (smallest * .10);
  //  printf("Largest: %.2f, Smallest: %.2f, pts[%.2f, %.2f, %.2f]\n", largest, smallest, d0, d1, d2);
    if ( ( largest - smallest ) < diff ){
        return true;
    } else
        return false;
}
__global__ void countTriangles( int *devCountList, Point *devPtList, int n ) {
  //for(int k = 0; k < n; k++)
    // printf("%d, %d\n", devPtList[k].x, devPtList[k].y);
  // Unique index for this worker, it's the index of the first point
  // in any triangles we're supposed to find.
  int a = blockDim.x * blockIdx.x + threadIdx.x;
  int total = 0;
  // Make sure I actually have something to work on.
  if ( a < n ) {
       //If the index is above 2, then we can check the points.
       double p0, p1, p2;
       //The loop starts comparing : arr[a], arr[i], arr[j]
       //So it effectively compares a to all following indicies.
       for( int i = a + 1; i < n - 1; i++ ){
         for( int j = i + 1; j < n; j++ ){
           p0 = (double)distSquared(devPtList, a, i);
           p0 = sqrt(p0);
           p1 = (double)distSquared(devPtList, i, j);
           p1 = sqrt(p1);
           p2 = (double)distSquared(devPtList, a, j);
           p2 = sqrt(p2);
           if ( check( p0, p1, p2 ) )
               total++;
         }
       }
       //printf("a:%d, pts[%.2f, %.2f, %.2f]\n", a, p0, p1, p2);

  }
  devCountList[a] = total;
}


// List of all points from the input
Point *ptList;
int *countList;
// Number of points in the input.
int ptCount = 0;
// Read the list of all points
void readPoints() {
  // Use a resizable array, increasing capacity as we read
  int capacity = 10;
  ptList = (Point *) malloc( capacity * sizeof( Point ) );
  // Read points until we can't read any more.
  int x, y;
  while ( scanf( "%d%d", &x, &y ) == 2 ) {
    // Grow the point list if needed.
    if ( ptCount >= capacity ) {
      capacity *= 2;
      ptList = (Point *) realloc( ptList, capacity * sizeof( Point ) );
    }
    // Add this new point to the end of the list.
    ptList[ ptCount ].x = x;
    ptList[ ptCount ].y = y;
    ptCount += 1;
  }
}

// General function to report a failure and exit.
static void fail( char const *message ) {
  fprintf( stderr, "%s\n", message );
  exit( 1 );
}

int main( ) {
  readPoints();
  //for(int k = 0; k < ptCount; k++)
    // printf("%d, %d\n", ptList[k].x, ptList[k].y);
  // ...
  countList = (int *)malloc( ptCount * sizeof(int) );
  //
  //
  Point *devPtList = NULL;
  if ( cudaMalloc((void **)&devPtList, ptCount * sizeof(Point) ) != cudaSuccess )
    fail( "Failed to allocate space for lenght list on device" );
  //copy list to device from host
  if ( cudaMemcpy( devPtList, ptList, ptCount * sizeof(Point),
                    cudaMemcpyHostToDevice) != cudaSuccess )
    fail( "Can't copy list to device from host" );
  int *devCountList = NULL;
  if ( cudaMalloc((void **)&devCountList, ptCount * sizeof(int) ) != cudaSuccess )
    fail( "Failed to allocate space for lenght list on device" );
  // Block and grid dimensions.
  int threadsPerBlock = 250;
  // Round up.
  int blocksPerGrid = ( ptCount + threadsPerBlock - 1 ) / threadsPerBlock;
  // Run our kernel on these block/grid dimensions
  countTriangles<<<blocksPerGrid, threadsPerBlock>>>( devCountList, devPtList, ptCount );
  if ( cudaGetLastError() != cudaSuccess )
    fail( "Failure in CUDA kernel execution." );
    // copy list from device to host
    if ( cudaMemcpy( ptList, devPtList, ptCount * sizeof(Point),
                     cudaMemcpyDeviceToHost) != cudaSuccess )
      fail( "Can't copy list from device to host" );
    // copy list from device to host
    if ( cudaMemcpy( countList, devCountList, ptCount * sizeof(int),
                     cudaMemcpyDeviceToHost) != cudaSuccess )
      fail( "Can't copy list from device to host" );
  // Print out a sample of the resulting values.
  int sum = 0;
  for ( int i = 0; i < ptCount; i++ ){
       sum += countList[ i ];
  }
  printf("Triangles: %d\n", sum);
  //
  cudaFree( devCountList );
  cudaFree( devPtList );
  //
  free( ptList );
  free( countList );

  cudaDeviceReset();
}

	.file	"tmpxft_00361883_00000000-6_semilateral.cudafe1.cpp"
	.text
#APP

	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s\n"
#NO_APP
	.text
	.type	_ZL4failPKc, @function
_ZL4failPKc:
.LFB2032:
	.cfi_startproc
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rdi, %rcx
	movq	stderr(%rip), %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL4failPKc, .-_ZL4failPKc
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2036:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2036:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11distSquaredP5Pointii
	.type	_Z11distSquaredP5Pointii, @function
_Z11distSquaredP5Pointii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z11distSquaredP5Pointii, .-_Z11distSquaredP5Pointii
	.globl	_Z11findLargestddd
	.type	_Z11findLargestddd, @function
_Z11findLargestddd:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z11findLargestddd, .-_Z11findLargestddd
	.globl	_Z12findSmallestddd
	.type	_Z12findSmallestddd, @function
_Z12findSmallestddd:
.LFB2178:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2178:
	.size	_Z12findSmallestddd, .-_Z12findSmallestddd
	.globl	_Z5checkddd
	.type	_Z5checkddd, @function
_Z5checkddd:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z5checkddd, .-_Z5checkddd
	.section	.rodata.str1.1
.LC1:
	.string	"%d%d"
	.text
	.globl	_Z10readPointsv
	.type	_Z10readPointsv, @function
_Z10readPointsv:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	$80, %edi
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	$10, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movq	%rax, ptList(%rip)
.L13:
	xorl	%eax, %eax
	leaq	4(%rsp), %rdx
	movq	%rsp, %rsi
	movq	%rbp, %rdi
	call	__isoc23_scanf@PLT
	cmpl	$2, %eax
	jne	.L19
	cmpl	%ebx, ptCount(%rip)
	jl	.L14
	addl	%ebx, %ebx
	movq	ptList(%rip), %rdi
	movslq	%ebx, %rsi
	salq	$3, %rsi
	call	realloc@PLT
	movq	%rax, ptList(%rip)
.L14:
	movslq	ptCount(%rip), %rcx
	movq	ptList(%rip), %rdx
	movq	%rcx, %rax
	leaq	(%rdx,%rcx,8), %rdx
	movl	(%rsp), %ecx
	incl	%eax
	movl	%ecx, (%rdx)
	movl	4(%rsp), %ecx
	movl	%eax, ptCount(%rip)
	movl	%ecx, 4(%rdx)
	jmp	.L13
.L19:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z10readPointsv, .-_Z10readPointsv
	.globl	_Z42__device_stub__Z14countTrianglesPiP5PointiPiP5Pointi
	.type	_Z42__device_stub__Z14countTrianglesPiP5PointiPiP5Pointi, @function
_Z42__device_stub__Z14countTrianglesPiP5PointiPiP5Pointi:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L20
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z14countTrianglesPiP5Pointi(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L20:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z42__device_stub__Z14countTrianglesPiP5PointiPiP5Pointi, .-_Z42__device_stub__Z14countTrianglesPiP5PointiPiP5Pointi
	.globl	_Z14countTrianglesPiP5Pointi
	.type	_Z14countTrianglesPiP5Pointi, @function
_Z14countTrianglesPiP5Pointi:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z14countTrianglesPiP5PointiPiP5Pointi
	.cfi_endproc
.LFE2059:
	.size	_Z14countTrianglesPiP5Pointi, .-_Z14countTrianglesPiP5Pointi
	.section	.rodata.str1.1
.LC2:
	.string	"Failed to allocate space for lenght list on device"
.LC3:
	.string	"Can't copy list to device from host"
.LC4:
	.string	"Failure in CUDA kernel execution."
.LC5:
	.string	"Can't copy list from device to host"
.LC6:
	.string	"Triangles: %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$48, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	_Z10readPointsv
	movslq	ptCount(%rip), %rbx
	leaq	0(,%rbx,4), %rdi
	call	malloc@PLT
	xorl	%edx, %edx
	leaq	0(,%rbx,8), %rsi
	movq	%rsp, %rdi
	movq	%rax, countList(%rip)
	movq	%rdx, (%rsp)
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L26
.L30:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	leaq	.LC2(%rip), %rdi
	je	.L42
	jmp	.L43
.L26:
	movslq	ptCount(%rip), %rdx
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movq	ptList(%rip), %rsi
	salq	$3, %rdx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L28
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	leaq	.LC3(%rip), %rdi
	je	.L42
	jmp	.L43
.L28:
	movslq	ptCount(%rip), %rsi
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	movq	%rax, 8(%rsp)
	salq	$2, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	jne	.L30
	movl	ptCount(%rip), %eax
	movl	$250, %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, 36(%rsp)
	addl	$249, %eax
	cltd
	idivl	%ecx
	movl	$2147483773, %edx
	movl	$1, %ecx
	addq	%rdx, %rdx
	movq	%rdx, 28(%rsp)
	movl	%eax, 16(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 20(%rsp)
	movq	16(%rsp), %rdi
	movl	24(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movl	ptCount(%rip), %edx
	movq	(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	_Z42__device_stub__Z14countTrianglesPiP5PointiPiP5Pointi
.L31:
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L32
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	leaq	.LC4(%rip), %rdi
	jne	.L43
.L42:
	call	_ZL4failPKc
.L32:
	movslq	ptCount(%rip), %rdx
	movq	(%rsp), %rsi
	movl	$2, %ecx
	movq	ptList(%rip), %rdi
	salq	$3, %rdx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L34
.L36:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	leaq	.LC5(%rip), %rdi
	je	.L42
	jmp	.L43
.L34:
	movslq	ptCount(%rip), %rdx
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	countList(%rip), %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L36
	movl	ptCount(%rip), %ecx
	movq	countList(%rip), %rsi
	xorl	%eax, %eax
	xorl	%edx, %edx
.L37:
	cmpl	%eax, %ecx
	jle	.L44
	addl	(%rsi,%rax,4), %edx
	incq	%rax
	jmp	.L37
.L44:
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	ptList(%rip), %rdi
	call	free@PLT
	movq	countList(%rip), %rdi
	call	free@PLT
	call	cudaDeviceReset@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
.L43:
	call	__stack_chk_fail@PLT
.L39:
	addq	$48, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	main, .-main
	.section	.rodata.str1.1
.LC7:
	.string	"_Z14countTrianglesPiP5Pointi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.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	.LC7(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14countTrianglesPiP5Pointi(%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
.LFE2061:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	ptCount
	.bss
	.align 4
	.type	ptCount, @object
	.size	ptCount, 4
ptCount:
	.zero	4
	.globl	countList
	.align 8
	.type	countList, @object
	.size	countList, 8
countList:
	.zero	8
	.globl	ptList
	.align 8
	.type	ptList, @object
	.size	ptList, 8
ptList:
	.zero	8
	.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:

//Elapsed Real Time for input-4.txt: 0.603, 0.606, 0.599
//Elapsed Real Time for input-5.txt: 1.419, 1.391, 1.408

#include <stdio.h>
#include <stdbool.h>
#include <hip/hip_runtime.h>

// Representation for a 2D point with integer coordinates.
typedef struct {
  // Coordinates of the point.
  int x, y;
} Point;
// Return the squared distance between point i and point j in the ptList.
__device__ double distSquared(Point *devPtList, int i, int j ) {
  double dx = (double)devPtList[ i ].x - (double)devPtList[ j ].x;
  double dy = (double)devPtList[ i ].y - (double)devPtList[ j ].y;
  return dx * dx + dy * dy;
}
/**
* This function finds the largest of 3 numbers.
*@param p0 number 1
*@param p1 number 2
*@param p2 number 3
*@return the largest of the 3 parameters
*/
__device__ double findLargest( double p0, double p1, double p2){
    if ( p0 >= p1 && p0 >= p2 ){
         return p0;
    } else if (p1 >= p2 && p1 >= p0) {
        return p1;
    } else
        return p2;
}
/**
* This function finds the smallest of 3 numbers.
*@param p0 number 1
*@param p1 number 2
*@param p2 number 3
*@return the smallest of the 3 parameters
*/
__device__ double findSmallest( double p0, double p1, double p2){
    if ( p0 <= p1 && p0 <= p2 ){
        return p0;
    }else if( p1 <= p2 && p1 <= p0){
        return p1;
    }else
        return p2;
}
/**
* This function determines whether the 3 points are within an acceptable range of each other
* in order to qualify as points of a "semilateral" triangle. That range being +/- 10%.
*@param d0 distance b/w point 1 and point 2
*@param d1 distance b/w point 2 and point 3
*@param d2 distance b/w point 3 and point 1
*@return true/false: true if the difference is acceptable. false if not.
*/
__device__ bool check( double d0, double d1, double d2 ){
    double largest = findLargest( d0, d1, d2 );
    double smallest = findSmallest( d0, d1, d2 );
    double diff = (smallest * .10);
  //  printf("Largest: %.2f, Smallest: %.2f, pts[%.2f, %.2f, %.2f]\n", largest, smallest, d0, d1, d2);
    if ( ( largest - smallest ) < diff ){
        return true;
    } else
        return false;
}
__global__ void countTriangles( int *devCountList, Point *devPtList, int n ) {
  //for(int k = 0; k < n; k++)
    // printf("%d, %d\n", devPtList[k].x, devPtList[k].y);
  // Unique index for this worker, it's the index of the first point
  // in any triangles we're supposed to find.
  int a = blockDim.x * blockIdx.x + threadIdx.x;
  int total = 0;
  // Make sure I actually have something to work on.
  if ( a < n ) {
       //If the index is above 2, then we can check the points.
       double p0, p1, p2;
       //The loop starts comparing : arr[a], arr[i], arr[j]
       //So it effectively compares a to all following indicies.
       for( int i = a + 1; i < n - 1; i++ ){
         for( int j = i + 1; j < n; j++ ){
           p0 = (double)distSquared(devPtList, a, i);
           p0 = sqrt(p0);
           p1 = (double)distSquared(devPtList, i, j);
           p1 = sqrt(p1);
           p2 = (double)distSquared(devPtList, a, j);
           p2 = sqrt(p2);
           if ( check( p0, p1, p2 ) )
               total++;
         }
       }
       //printf("a:%d, pts[%.2f, %.2f, %.2f]\n", a, p0, p1, p2);

  }
  devCountList[a] = total;
}


// List of all points from the input
Point *ptList;
int *countList;
// Number of points in the input.
int ptCount = 0;
// Read the list of all points
void readPoints() {
  // Use a resizable array, increasing capacity as we read
  int capacity = 10;
  ptList = (Point *) malloc( capacity * sizeof( Point ) );
  // Read points until we can't read any more.
  int x, y;
  while ( scanf( "%d%d", &x, &y ) == 2 ) {
    // Grow the point list if needed.
    if ( ptCount >= capacity ) {
      capacity *= 2;
      ptList = (Point *) realloc( ptList, capacity * sizeof( Point ) );
    }
    // Add this new point to the end of the list.
    ptList[ ptCount ].x = x;
    ptList[ ptCount ].y = y;
    ptCount += 1;
  }
}

// General function to report a failure and exit.
static void fail( char const *message ) {
  fprintf( stderr, "%s\n", message );
  exit( 1 );
}

int main( ) {
  readPoints();
  //for(int k = 0; k < ptCount; k++)
    // printf("%d, %d\n", ptList[k].x, ptList[k].y);
  // ...
  countList = (int *)malloc( ptCount * sizeof(int) );
  //
  //
  Point *devPtList = NULL;
  if ( hipMalloc((void **)&devPtList, ptCount * sizeof(Point) ) != hipSuccess )
    fail( "Failed to allocate space for lenght list on device" );
  //copy list to device from host
  if ( hipMemcpy( devPtList, ptList, ptCount * sizeof(Point),
                    hipMemcpyHostToDevice) != hipSuccess )
    fail( "Can't copy list to device from host" );
  int *devCountList = NULL;
  if ( hipMalloc((void **)&devCountList, ptCount * sizeof(int) ) != hipSuccess )
    fail( "Failed to allocate space for lenght list on device" );
  // Block and grid dimensions.
  int threadsPerBlock = 250;
  // Round up.
  int blocksPerGrid = ( ptCount + threadsPerBlock - 1 ) / threadsPerBlock;
  // Run our kernel on these block/grid dimensions
  countTriangles<<<blocksPerGrid, threadsPerBlock>>>( devCountList, devPtList, ptCount );
  if ( hipGetLastError() != hipSuccess )
    fail( "Failure in CUDA kernel execution." );
    // copy list from device to host
    if ( hipMemcpy( ptList, devPtList, ptCount * sizeof(Point),
                     hipMemcpyDeviceToHost) != hipSuccess )
      fail( "Can't copy list from device to host" );
    // copy list from device to host
    if ( hipMemcpy( countList, devCountList, ptCount * sizeof(int),
                     hipMemcpyDeviceToHost) != hipSuccess )
      fail( "Can't copy list from device to host" );
  // Print out a sample of the resulting values.
  int sum = 0;
  for ( int i = 0; i < ptCount; i++ ){
       sum += countList[ i ];
  }
  printf("Triangles: %d\n", sum);
  //
  hipFree( devCountList );
  hipFree( devPtList );
  //
  free( ptList );
  free( countList );

  hipDeviceReset();
}

	.text
	.file	"semilateral.hip"
	.globl	_Z29__device_stub__countTrianglesPiP5Pointi # -- Begin function _Z29__device_stub__countTrianglesPiP5Pointi
	.type	_Z29__device_stub__countTrianglesPiP5Pointi,@function
_Z29__device_stub__countTrianglesPiP5Pointi: # @_Z29__device_stub__countTrianglesPiP5Pointi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z14countTrianglesPiP5Pointi, %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	_Z29__device_stub__countTrianglesPiP5Pointi, .Lfunc_end0-_Z29__device_stub__countTrianglesPiP5Pointi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10readPointsv                 # -- Begin function _Z10readPointsv
	.type	_Z10readPointsv,@function
_Z10readPointsv:                        # @_Z10readPointsv
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	$80, %edi
	callq	malloc
	movq	%rax, ptList(%rip)
	leaq	12(%rsp), %rsi
	leaq	8(%rsp), %rdx
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	cmpl	$2, %eax
	jne	.LBB1_5
# %bb.1:                                # %.lr.ph.preheader
	movl	$10, %ebp
	leaq	12(%rsp), %rbx
	leaq	8(%rsp), %r14
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	ptCount(%rip), %ecx
	movq	ptList(%rip), %rax
	cmpl	%ebp, %ecx
	jl	.LBB1_4
# %bb.3:                                #   in Loop: Header=BB1_2 Depth=1
	addl	%ebp, %ebp
	movslq	%ebp, %rsi
	shlq	$3, %rsi
	movq	%rax, %rdi
	callq	realloc
	movq	%rax, ptList(%rip)
	movl	ptCount(%rip), %ecx
.LBB1_4:                                #   in Loop: Header=BB1_2 Depth=1
	movl	12(%rsp), %edx
	movslq	%ecx, %rcx
	movl	%edx, (%rax,%rcx,8)
	movl	8(%rsp), %ecx
	movslq	ptCount(%rip), %rdx
	movl	%ecx, 4(%rax,%rdx,8)
	incl	ptCount(%rip)
	movl	$.L.str, %edi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_scanf
	cmpl	$2, %eax
	je	.LBB1_2
.LBB1_5:                                # %._crit_edge
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z10readPointsv, .Lfunc_end1-_Z10readPointsv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	callq	_Z10readPointsv
	movslq	ptCount(%rip), %rbx
	leaq	(,%rbx,4), %rdi
	callq	malloc
	movq	%rax, countList(%rip)
	movq	%rsp, %rdi
	movq	$0, (%rdi)
	shlq	$3, %rbx
	movq	%rbx, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB2_1
# %bb.3:
	movq	(%rsp), %rdi
	movq	ptList(%rip), %rsi
	movslq	ptCount(%rip), %rdx
	shlq	$3, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_4
# %bb.5:
	leaq	8(%rsp), %rdi
	movq	$0, (%rdi)
	movslq	ptCount(%rip), %rsi
	shlq	$2, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB2_1
# %bb.6:
	movl	$249, %eax
	addl	ptCount(%rip), %eax
	cltq
	imulq	$274877907, %rax, %rdi          # imm = 0x10624DD3
	movq	%rdi, %rax
	shrq	$63, %rax
	sarq	$36, %rdi
	addl	%eax, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$250, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_8
# %bb.7:
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movl	ptCount(%rip), %edx
	callq	_Z29__device_stub__countTrianglesPiP5Pointi
.LBB2_8:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_9
# %bb.10:
	movq	ptList(%rip), %rdi
	movq	(%rsp), %rsi
	movslq	ptCount(%rip), %rdx
	shlq	$3, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_11
# %bb.12:
	movq	countList(%rip), %rdi
	movq	8(%rsp), %rsi
	movslq	ptCount(%rip), %rdx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_11
# %bb.13:                               # %.preheader
	movl	ptCount(%rip), %eax
	testl	%eax, %eax
	jle	.LBB2_14
# %bb.16:                               # %.lr.ph
	xorl	%ecx, %ecx
	movq	countList(%rip), %rdx
	xorl	%esi, %esi
.LBB2_17:                               # =>This Inner Loop Header: Depth=1
	addl	(%rdx,%rcx,4), %esi
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB2_17
	jmp	.LBB2_15
.LBB2_14:
	xorl	%esi, %esi
.LBB2_15:                               # %._crit_edge
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	ptList(%rip), %rdi
	callq	free
	movq	countList(%rip), %rdi
	callq	free
	callq	hipDeviceReset
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB2_1:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rdi
	movl	$.L.str.6, %esi
	movl	$.L.str.1, %edx
	jmp	.LBB2_2
.LBB2_11:
	movq	stderr(%rip), %rdi
	movl	$.L.str.6, %esi
	movl	$.L.str.4, %edx
	jmp	.LBB2_2
.LBB2_4:
	movq	stderr(%rip), %rdi
	movl	$.L.str.6, %esi
	movl	$.L.str.2, %edx
	jmp	.LBB2_2
.LBB2_9:
	movq	stderr(%rip), %rdi
	movl	$.L.str.6, %esi
	movl	$.L.str.3, %edx
.LBB2_2:
	xorl	%eax, %eax
	callq	fprintf
	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	$_Z14countTrianglesPiP5Pointi, %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	_Z14countTrianglesPiP5Pointi,@object # @_Z14countTrianglesPiP5Pointi
	.section	.rodata,"a",@progbits
	.globl	_Z14countTrianglesPiP5Pointi
	.p2align	3, 0x0
_Z14countTrianglesPiP5Pointi:
	.quad	_Z29__device_stub__countTrianglesPiP5Pointi
	.size	_Z14countTrianglesPiP5Pointi, 8

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

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

	.type	ptCount,@object                 # @ptCount
	.globl	ptCount
	.p2align	2, 0x0
ptCount:
	.long	0                               # 0x0
	.size	ptCount, 4

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Failed to allocate space for lenght list on device"
	.size	.L.str.1, 51

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Can't copy list to device from host"
	.size	.L.str.2, 36

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Failure in CUDA kernel execution."
	.size	.L.str.3, 34

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Can't copy list from device to host"
	.size	.L.str.4, 36

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Triangles: %d\n"
	.size	.L.str.5, 15

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

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

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

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z29__device_stub__countTrianglesPiP5Pointi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14countTrianglesPiP5Pointi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14countTrianglesPiP5Pointi ; -- Begin function _Z14countTrianglesPiP5Pointi
	.globl	_Z14countTrianglesPiP5Pointi
	.p2align	8
	.type	_Z14countTrianglesPiP5Pointi,@function
_Z14countTrianglesPiP5Pointi:           ; @_Z14countTrianglesPiP5Pointi
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s12, s[0:1], 0x10
	s_load_b128 s[8:11], s[0:1], 0x0
	s_mov_b32 s5, exec_lo
	s_waitcnt lgkmcnt(0)
	s_and_b32 s0, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[1:2], null, s15, s0, v[0:1]
	v_mov_b32_e32 v0, 0
	v_cmpx_gt_i32_e64 s12, v1
	s_cbranch_execz .LBB0_10
; %bb.1:
	v_add_nc_u32_e32 v6, 1, v1
	v_mov_b32_e32 v0, 0
	s_add_i32 s14, s12, -1
	s_mov_b32 s13, exec_lo
	s_delay_alu instid0(VALU_DEP_2)
	v_cmpx_gt_i32_e64 s14, v6
	s_cbranch_execz .LBB0_9
; %bb.2:                                ; %.lr.ph39
	v_add_nc_u32_e32 v3, 2, v1
	v_ashrrev_i32_e32 v2, 31, v1
	s_mov_b32 s6, 0x9999999a
	s_mov_b32 s7, 0x3fb99999
	s_mov_b32 s15, 0
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[7:8], 3, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 3, v[3:4]
	v_add_co_u32 v0, vcc_lo, v3, s10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_ci_u32_e32 v5, vcc_lo, s11, v4, vcc_lo
	v_add_co_u32 v2, vcc_lo, s10, v7
	v_add_co_ci_u32_e32 v3, vcc_lo, s11, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_u32 v4, vcc_lo, v0, 4
	v_mov_b32_e32 v0, 0
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
.LBB0_3:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_5 Depth 2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v18, 1, v6
	s_mov_b32 s16, exec_lo
	v_cmpx_gt_i32_e64 s12, v18
	s_cbranch_execz .LBB0_7
; %bb.4:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_3 Depth=1
	v_ashrrev_i32_e32 v7, 31, v6
	s_mov_b32 s17, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[6:7], 3, v[6:7]
	v_add_co_u32 v6, vcc_lo, s10, v6
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v7, vcc_lo, s11, v7, vcc_lo
	s_clause 0x1
	global_load_b64 v[10:11], v[2:3], off
	global_load_b64 v[12:13], v[6:7], off
	s_waitcnt vmcnt(1)
	v_cvt_f64_i32_e32 v[6:7], v11
	s_waitcnt vmcnt(0)
	v_cvt_f64_i32_e32 v[8:9], v13
	v_cvt_f64_i32_e32 v[10:11], v10
	v_cvt_f64_i32_e32 v[12:13], v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_f64 v[14:15], v[6:7], -v[8:9]
	v_add_f64 v[16:17], v[10:11], -v[12:13]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[14:15], v[14:15], v[14:15]
	v_fma_f64 v[14:15], v[16:17], v[16:17], v[14:15]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_gt_f64_e32 vcc_lo, 0x10000000, v[14:15]
	v_cndmask_b32_e64 v16, 0, 1, vcc_lo
	v_lshlrev_b32_e32 v16, 8, v16
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ldexp_f64 v[16:17], v[14:15], v16
	v_rsq_f64_e32 v[14:15], v[16:17]
	s_waitcnt_depctr 0xfff
	v_mul_f64 v[19:20], v[16:17], v[14:15]
	v_mul_f64 v[14:15], v[14:15], 0.5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[21:22], -v[14:15], v[19:20], 0.5
	v_fma_f64 v[19:20], v[19:20], v[21:22], v[19:20]
	v_fma_f64 v[14:15], v[14:15], v[21:22], v[14:15]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[21:22], -v[19:20], v[19:20], v[16:17]
	v_fma_f64 v[19:20], v[21:22], v[14:15], v[19:20]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[21:22], -v[19:20], v[19:20], v[16:17]
	v_fma_f64 v[14:15], v[21:22], v[14:15], v[19:20]
	v_cndmask_b32_e64 v19, 0, 0xffffff80, vcc_lo
	v_cmp_class_f64_e64 vcc_lo, v[16:17], 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ldexp_f64 v[19:20], v[14:15], v19
	v_dual_mov_b32 v15, v5 :: v_dual_mov_b32 v14, v4
	v_dual_cndmask_b32 v17, v20, v17 :: v_dual_cndmask_b32 v16, v19, v16
	v_mov_b32_e32 v19, v18
.LBB0_5:                                ;   Parent Loop BB0_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_b64 v[20:21], v[14:15], off offset:-4
	v_add_nc_u32_e32 v19, 1, v19
	s_waitcnt vmcnt(0)
	v_cvt_f64_i32_e32 v[21:22], v21
	v_cvt_f64_i32_e32 v[23:24], v20
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_add_f64 v[25:26], v[8:9], -v[21:22]
	v_add_f64 v[20:21], v[6:7], -v[21:22]
	v_add_f64 v[27:28], v[12:13], -v[23:24]
	v_add_f64 v[22:23], v[10:11], -v[23:24]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_mul_f64 v[24:25], v[25:26], v[25:26]
	v_mul_f64 v[20:21], v[20:21], v[20:21]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[24:25], v[27:28], v[27:28], v[24:25]
	v_fma_f64 v[20:21], v[22:23], v[22:23], v[20:21]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_f64_e32 vcc_lo, 0x10000000, v[24:25]
	v_cmp_gt_f64_e64 s0, 0x10000000, v[20:21]
	v_cndmask_b32_e64 v22, 0, 1, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v23, 0, 1, s0
	v_lshlrev_b32_e32 v22, 8, v22
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b32_e32 v26, 8, v23
	v_ldexp_f64 v[22:23], v[24:25], v22
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ldexp_f64 v[20:21], v[20:21], v26
	v_rsq_f64_e32 v[24:25], v[22:23]
	s_delay_alu instid0(VALU_DEP_1)
	v_rsq_f64_e32 v[26:27], v[20:21]
	s_waitcnt_depctr 0xfff
	v_mul_f64 v[28:29], v[22:23], v[24:25]
	v_mul_f64 v[24:25], v[24:25], 0.5
	v_mul_f64 v[30:31], v[20:21], v[26:27]
	v_mul_f64 v[26:27], v[26:27], 0.5
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[32:33], -v[24:25], v[28:29], 0.5
	v_fma_f64 v[34:35], -v[26:27], v[30:31], 0.5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fma_f64 v[28:29], v[28:29], v[32:33], v[28:29]
	v_fma_f64 v[24:25], v[24:25], v[32:33], v[24:25]
	v_fma_f64 v[30:31], v[30:31], v[34:35], v[30:31]
	v_fma_f64 v[26:27], v[26:27], v[34:35], v[26:27]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fma_f64 v[32:33], -v[28:29], v[28:29], v[22:23]
	v_fma_f64 v[34:35], -v[30:31], v[30:31], v[20:21]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[28:29], v[32:33], v[24:25], v[28:29]
	v_fma_f64 v[30:31], v[34:35], v[26:27], v[30:31]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[32:33], -v[28:29], v[28:29], v[22:23]
	v_fma_f64 v[34:35], -v[30:31], v[30:31], v[20:21]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fma_f64 v[24:25], v[32:33], v[24:25], v[28:29]
	v_cndmask_b32_e64 v28, 0, 0xffffff80, vcc_lo
	v_fma_f64 v[26:27], v[34:35], v[26:27], v[30:31]
	v_cndmask_b32_e64 v29, 0, 0xffffff80, s0
	v_cmp_class_f64_e64 vcc_lo, v[22:23], 0x260
	v_cmp_class_f64_e64 s0, v[20:21], 0x260
	v_ldexp_f64 v[24:25], v[24:25], v28
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ldexp_f64 v[26:27], v[26:27], v29
	v_dual_cndmask_b32 v23, v25, v23 :: v_dual_cndmask_b32 v22, v24, v22
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v21, v27, v21, s0
	v_cndmask_b32_e64 v20, v26, v20, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cmp_nge_f64_e64 s0, v[22:23], v[16:17]
	v_cmp_nge_f64_e64 s1, v[16:17], v[22:23]
	v_cmp_nge_f64_e32 vcc_lo, v[22:23], v[20:21]
	v_cmp_nle_f64_e64 s2, v[22:23], v[20:21]
	v_cmp_nle_f64_e64 s3, v[16:17], v[20:21]
	v_cmp_nge_f64_e64 s4, v[16:17], v[20:21]
	s_or_b32 vcc_lo, s0, vcc_lo
	s_delay_alu instid0(VALU_DEP_3)
	s_or_b32 s2, s1, s2
	v_cndmask_b32_e32 v24, v22, v20, vcc_lo
	v_cndmask_b32_e64 v20, v22, v20, s2
	v_cndmask_b32_e32 v22, v23, v21, vcc_lo
	v_cndmask_b32_e64 v23, v23, v21, s2
	s_or_b32 vcc_lo, s0, s3
	s_or_b32 s0, s1, s4
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	v_cndmask_b32_e64 v21, v17, v22, s0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_dual_cndmask_b32 v23, v17, v23 :: v_dual_cndmask_b32 v22, v16, v20
	v_cndmask_b32_e64 v20, v16, v24, s0
	v_add_co_u32 v14, vcc_lo, v14, 8
	v_add_co_ci_u32_e32 v15, vcc_lo, 0, v15, vcc_lo
	v_mul_f64 v[24:25], v[22:23], s[6:7]
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_add_f64 v[20:21], v[20:21], -v[22:23]
	v_cmp_le_i32_e32 vcc_lo, s12, v19
	s_or_b32 s17, vcc_lo, s17
	v_cmp_lt_f64_e64 s0, v[20:21], v[24:25]
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v0, s0, 0, v0, s0
	s_and_not1_b32 exec_lo, exec_lo, s17
	s_cbranch_execnz .LBB0_5
; %bb.6:                                ; %Flow
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s17
.LBB0_7:                                ; %Flow52
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s16
	v_cmp_le_i32_e32 vcc_lo, s14, v18
	v_add_co_u32 v4, s0, v4, 8
	v_add_co_ci_u32_e64 v5, s0, 0, v5, s0
	v_mov_b32_e32 v6, v18
	s_or_b32 s15, vcc_lo, s15
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s15
	s_cbranch_execnz .LBB0_3
; %bb.8:                                ; %Flow53
	s_or_b32 exec_lo, exec_lo, s15
.LBB0_9:                                ; %Flow54
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 exec_lo, exec_lo, s13
.LBB0_10:                               ; %.loopexit34
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s5
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s8, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s9, v2, vcc_lo
	global_store_b32 v[1:2], v0, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14countTrianglesPiP5Pointi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 36
		.amdhsa_next_free_sgpr 18
		.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	_Z14countTrianglesPiP5Pointi, .Lfunc_end0-_Z14countTrianglesPiP5Pointi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1300
; NumSgprs: 20
; NumVgprs: 36
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 4
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 36
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14countTrianglesPiP5Pointi
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z14countTrianglesPiP5Pointi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     36
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
