
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <string.h>

#define NUM_ELEMENTS 7
#define MAX_ELEMENTS_BLOCK 2048

struct Point
{
	unsigned int X;
	unsigned int Y;
	unsigned int leftID; // counter-clockwise neighbor
	unsigned int rightID; // clockwise neighbor
};

extern __shared__ Point hullData[];

cudaError_t convexHull(Point* h_data, int numPoints);

Point* h_data;

Point* d_data;

__device__ void findHull(int &currA, int &currB)
{
	int result;
	//int startIndex;
	int currAorig = currA;
	int currBorig = currB;
	Point c;
	bool isEven = (threadIdx.x % 2) == 0;

	if (isEven)
	{
		c = hullData[hullData[currA].leftID];
	}
	else
	{
		c = hullData[hullData[currA].rightID];
	}

	bool hullFound = false;
	while (!hullFound)
	{
		result = ((hullData[currB].X - hullData[currA].X)*(c.Y - hullData[currA].Y) - (hullData[currB].Y - hullData[currA].Y)*(c.X - hullData[currA].X));

		/*if (i == 1 && (idx == 49 || idx == 48))
			printf("idx: %d      a: %d   b: %d\n", idx, currA, currB);*/

		if (isEven)
		{
			if (result >= 0 && hullData[currA].leftID != currAorig)
			{
				currA = hullData[currA].leftID;
				c = hullData[hullData[currA].leftID];
			}
			else
			{
				c = hullData[hullData[currB].rightID];
				
				//result = ((b.X - a.X)*(c.Y - a.Y) - (b.Y - a.Y)*(c.X - a.X));
				result = ((hullData[currB].X - hullData[currA].X)*(c.Y - hullData[currA].Y) - (hullData[currB].Y - hullData[currA].Y)*(c.X - hullData[currA].X));
				
				if (result >= 0 && hullData[currB].rightID != currBorig)
				{
					currB = hullData[currB].rightID;
					c = hullData[hullData[currA].leftID];
				}
				else
				{
					hullFound = true;
				}
			}
		}
		else
		{
			if (result <= 0 && hullData[currA].rightID != currAorig)
			{
				currA = hullData[currA].rightID;
				c = hullData[hullData[currA].rightID];
			}
			else
			{
				c = hullData[hullData[currB].leftID];
				
				result = ((hullData[currB].X - hullData[currA].X)*(c.Y - hullData[currA].Y) - (hullData[currB].Y - hullData[currA].Y)*(c.X - hullData[currA].X));
				
				if (result <= 0 && hullData[currB].leftID != currBorig)
				{
					currB = hullData[currB].leftID;
					c = hullData[hullData[currA].rightID];
				}
				else
				{
					hullFound = true;
				}
			}
		}
	}
}

__device__ void findHull(int &currA, int &currB, Point* data)
{
	int result;
	//int startIndex;
	int currAorig = currA;
	int currBorig = currB;
	Point c;
	bool isEven = (threadIdx.x % 2) == 0;

	if (isEven)
	{
		c = data[data[currA].leftID];
	}
	else
	{
		c = data[data[currA].rightID];
	}

	//if (threadIdx.x == 0)
	//		printf("thread: %d\n   currA: %d ( %d, %d )     currB: %d ( %d, %d )    c: ( %d, %d )\n", threadIdx.x, currA, data[currA].X, data[currA].Y, currB, data[currB].X, data[currB].Y, c.X, c.Y);

	/*if (threadIdx.x == 0 && blockIdx.x == 0)
	{
		int j = 0;
		int stop = j;
		int count = 0;
		//printf("%d\n", h_data[0].rightID);
		for (int i=0; i<50; i++)
		{
			if (j == stop && i != 0)
				break;

			printf("i: %d  ( %d, %d )\nr: %d   l: %d\n\n", i, data[j].X, data[j].Y, data[j].rightID, data[j].leftID);
			j = data[j].rightID; 
			count++;
		}

		printf("\nCount: %d\n", count);
	}*/

	bool hullFound = false;
	while (!hullFound)
	{
		result = ((data[currB].X - data[currA].X)*(c.Y - data[currA].Y) - (data[currB].Y - data[currA].Y)*(c.X - data[currA].X));

		/*if (i == 1 && (idx == 49 || idx == 48))
			printf("idx: %d      a: %d   b: %d\n", idx, currA, currB);*/

		if (isEven)
		{
			if (result >= 0 && data[currA].leftID != currAorig)
			{
				currA = data[currA].leftID;
				c = data[data[currA].leftID];
			}
			else
			{
				c = data[data[currB].rightID];
				
				//result = ((b.X - a.X)*(c.Y - a.Y) - (b.Y - a.Y)*(c.X - a.X));
				result = ((data[currB].X - data[currA].X)*(c.Y - data[currA].Y) - (data[currB].Y - data[currA].Y)*(c.X - data[currA].X));
				
				if (result >= 0 && data[currB].rightID != currBorig)
				{
					currB = data[currB].rightID;
					c = data[data[currA].leftID];
				}
				else
				{
					hullFound = true;
				}
			}
		}
		else
		{
			if (result <= 0 && data[currA].rightID != currAorig)
			{
				currA = data[currA].rightID;
				c = data[data[currA].rightID];
			}
			else
			{
				c = data[data[currB].leftID];
				
				result = ((data[currB].X - data[currA].X)*(c.Y - data[currA].Y) - (data[currB].Y - data[currA].Y)*(c.X - data[currA].X));
				
				if (result <= 0 && data[currB].leftID != currBorig)
				{
					currB = data[currB].leftID;
					c = data[data[currA].rightID];
				}
				else
				{
					hullFound = true;
				}
			}
		}
	}
}

__global__ void divideAndConquer(Point* data, int numElements)
{
	int idx = threadIdx.x;
	int bidx = blockIdx.x;
	int numElementsPBlock = blockDim.x * 2;
	int numThreads = blockDim.x;
	//int numBlocks = gridDim.x;
	bool isEven = (idx % 2) == 0;
/*
	if (idx == 0)
	{
		printf("%d\n", idx);
		printf("%d\n", bidx);
		printf("%d\n", numElementsPBlock);
		printf("%d\n", numElements);
		printf("%d\n", numThreads);
		printf("%d\n", numBlocks);
	}*/

	hullData[idx] = data[idx + (numElementsPBlock * bidx)];

	if ((idx + (numElementsPBlock * bidx)) + numThreads < numElements)
		hullData[idx + numThreads] = data[(idx + (numElementsPBlock * bidx)) + numThreads];
	/*hullData[idx + (2 * blockDim.x)] = data[idx + (2 * blockDim.x)];
	hullData[idx + (3 * blockDim.x)] = data[idx + (3 * blockDim.x)];*/
	__syncthreads();
	
	if ((idx << 1) + 1 < numElementsPBlock)
	{
		hullData[(idx << 1)].leftID = (idx << 1) + 1;
		hullData[(idx << 1)].rightID = (idx << 1) + 1;
		hullData[(idx << 1) + 1].leftID = (idx << 1);
		hullData[(idx << 1) + 1].rightID = (idx << 1);
	}
	else
	{
		hullData[(idx << 1)].leftID = (idx << 1);
		hullData[(idx << 1)].rightID = (idx << 1);
	}
	
	//printf("thread: %d\n  (%d, %d)\n  neighborRight: %d\n  neighborLeft: %d\n  (%d, %d)\n  neighborRight: %d\n  neighborLeft: %d\n", idx, hullData[(idx << 1)].X, hullData[(idx << 1)].Y, hullData[(idx << 1)].rightID, hullData[(idx << 1)].leftID, hullData[(idx << 1) + 1].X, hullData[(idx << 1) + 1].Y, hullData[(idx << 1) + 1].rightID, hullData[(idx << 1) + 1].leftID);
	
	
	/*int currA = startIndex + 1;
	int currB = startIndex + 2;
	Point c = hullData[hullData[currA].leftID];
	
	if (!isEven)
	{
		c = hullData[hullData[currA].rightID];
	}*/
	//int startIndex;
	int currA;
	int currB;

	__syncthreads();
	for (int i = 1; i < ((numElementsPBlock + 1) / 2); i *= 2)
	{
		int index = 4 * i * (idx / 2);

		/*if (idx == 0)
			printf("-------------------- i = %d --------------------\n", i);
		__syncthreads();
		if (i == 2 && (idx == 49 || idx == 48))
		printf("thread: %d\n  %d: (%d, %d)\n  neighborRight: %d\n  neighborLeft: %d\n  %d: (%d, %d)\n  neighborRight: %d\n  neighborLeft: %d\n", idx, (idx << 1), hullData[(idx << 1)].X, hullData[(idx << 1)].Y, hullData[(idx << 1)].rightID, hullData[(idx << 1)].leftID, ((idx << 1) + 1), hullData[(idx << 1) + 1].X, hullData[(idx << 1) + 1].Y, hullData[(idx << 1) + 1].rightID, hullData[(idx << 1) + 1].leftID);*/
		if (index + (i << 1) < numElementsPBlock)
		{
			currA = index + (i << 1) - 1;
			currB = index + (i << 1);

			findHull(currA, currB);
		}

		__syncthreads();
		if (index + (i << 1) < numElementsPBlock)
		{
			if (isEven)
			{
				hullData[currA].rightID = currB;
				hullData[currB].leftID = currA;
			}
			else
			{
				hullData[currA].leftID = currB;
				hullData[currB].rightID = currA;
			}
		}

		//__syncthreads();
		//	if (isEven)
		//	{
		//		int j = 0;
		//		int count = 0;
		//		//printf("%d\n", h_data[0].rightID);
		//		for (int i=0; i<numElements; i++)
		//		{
		//			if (j != 0 || i == 0)
		//			printf("id: %d    %d, %d\n", idx, hullData[j].X, hullData[j].Y);
		//			else 
		//				break;

		//			j = hullData[j].rightID; 
		//			count++;
		//			//system("PAUSE");
		//			
		//		}
		//		__syncthreads();
		//		printf("\nCount: %d\n", count);
		//	}
	}
	
	__syncthreads();

	hullData[idx].rightID = (hullData[idx].rightID + (numElementsPBlock * blockIdx.x));
	hullData[idx].leftID = (hullData[idx].leftID + (numElementsPBlock * blockIdx.x));

	if (idx + numThreads < numElementsPBlock)
	{
		hullData[idx + numThreads].rightID = (hullData[idx + numThreads].rightID + (numElementsPBlock * blockIdx.x));
		hullData[idx + numThreads].leftID = (hullData[idx + numThreads].leftID + (numElementsPBlock * blockIdx.x));
	}
	__syncthreads();

	data[idx + (numElementsPBlock * bidx)] = hullData[idx];

	if ((idx + (numElementsPBlock * bidx)) + numThreads < numElements)
		data[(idx + (numElementsPBlock * bidx)) + numThreads] = hullData[idx + numThreads];
		
	__syncthreads();
}

__global__ void divideAndConquerBlocks(Point* data, int numElements, int iteration)
{
	int idx = threadIdx.x;
	//int bidx = blockIdx.x;
	bool isEven = (idx % 2) == 0;
	
	int currA;
	int currB;

	//currA = ((((MAX_ELEMENTS_BLOCK * 2) * ((idx / 2) + 1)) + (MAX_ELEMENTS_BLOCK * (MAX_ELEMENTS_BLOCK / 4) * bidx)) * iteration) - 1;
	//currB = ((((MAX_ELEMENTS_BLOCK * 2) * ((idx / 2) + 1)) + (MAX_ELEMENTS_BLOCK * (MAX_ELEMENTS_BLOCK / 4) * bidx)) * iteration);
	
	currA = (((MAX_ELEMENTS_BLOCK * 2 * (idx / 2)) + MAX_ELEMENTS_BLOCK) * iteration) - 1;
	currB = (((MAX_ELEMENTS_BLOCK * 2 * (idx / 2)) + MAX_ELEMENTS_BLOCK) * iteration);
	
	  //printf("Id: %d  Before FindHull--- currA: %d   currB: %d\n", idx, currA, currB);

	findHull(currA, currB, data);

	   //printf("Id: %d  After FindHull--- currA: %d   currB: %d\n", idx, currA, currB);

	__syncthreads();
	
	if (isEven)
	{
		data[currA].rightID = currB;
		data[currB].leftID = currA;
	}
	else
	{
		data[currA].leftID = currB;
		data[currB].rightID = currA;
	}
	
	__syncthreads();
}

int main(int argc, char** argv)
{
	FILE* input;
	if (argc > 1)
	{
		input = fopen(argv[1], "r");
	}
	else
	{
		input = fopen("sorted_8192.txt", "r");
	}

	//get number of points
	int numPoints;
	fscanf(input, "%d", &numPoints);
	fscanf(input, "%d", &numPoints);
	//printf("%d\n", numPoints);
	//system("PAUSE");

	h_data = (Point*)malloc(sizeof(Point) * numPoints);

	//initialize input
	for (int i = 0; i < numPoints; i++){
		fscanf(input, "%d %d", &h_data[i].X, &h_data[i].Y);
	}
	cudaError_t cudaStatus = convexHull(h_data, numPoints);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "addWithCuda failed!");
		//system("PAUSE");
        return 1;
    }

    // cudaDeviceReset must be called before exiting in order for profiling and
    // tracing tools such as Nsight and Visual Profiler to show complete traces.
    cudaStatus = cudaDeviceReset();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceReset failed!");
		//system("PAUSE");
        return 1;
    }

	free(h_data);
	//system("PAUSE");
    return 0;
}

// Helper function for using CUDA to add vectors in parallel.
cudaError_t convexHull(Point* h_data, int numPoints)
{
    cudaError_t cudaStatus;

    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaStatus = cudaSetDevice(0);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?");
    }

	cudaStatus = cudaMalloc((void**)&d_data, numPoints * sizeof(Point));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
    }

    // Copy input vectors from host memory to GPU buffers.
	
	cudaStatus = cudaMemcpy(d_data, h_data, numPoints * sizeof(Point), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
    }

	//printf("\n\nNum Threads to be launched: %d\n\n", numThreads);

	int numBlocks = 1;
	if ((numPoints % MAX_ELEMENTS_BLOCK) == 0)
		numBlocks = (numPoints / MAX_ELEMENTS_BLOCK);
	else
		numBlocks = ((numPoints / MAX_ELEMENTS_BLOCK) + 1);

	int numThreads = 1;
	if (numBlocks > 1)
		numThreads = (MAX_ELEMENTS_BLOCK / 2);
	else
		numThreads = ((numPoints + 1) / 2);

	printf("\n----------Starting first DnC---------\nnumBlocks: %d    numThreads: %d\n\n", numBlocks, numThreads);
	divideAndConquer<<<numBlocks, numThreads, sizeof(Point) * (numThreads * 2)>>>(d_data, numPoints);

	cudaStatus = cudaGetLastError();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "divideAndConquer launch failed: %s\n", cudaGetErrorString(cudaStatus));
    }

    // cudaDeviceSynchronize waits for the kernel to finish, and returns
    // any errors encountered during the launch.
    cudaStatus = cudaDeviceSynchronize();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
    }

	int j = 1;
	for (int i = 1; i < numBlocks; i *= 2)
	{
		int newNumBlocks = (numBlocks / i) / (MAX_ELEMENTS_BLOCK / 4);

		if (newNumBlocks == 0)
			newNumBlocks++;

		int newNumThreads = 1;
		int num = 1024;
		if (newNumBlocks > 1)
			newNumThreads = (MAX_ELEMENTS_BLOCK / 2);
		else
		{
			if (numBlocks > 1024)
			{
				newNumThreads = (num / j);
			}
			else
			{
				newNumThreads = (numBlocks / j);
			}

			j *= 2;
		}

		printf("\n----------Starting second DnC---------\nnewNumBlocks: %d    newNumThreads: %d\n\n", newNumBlocks, newNumThreads);
		divideAndConquerBlocks<<<newNumBlocks, newNumThreads>>>(d_data, numPoints, i);
		cudaStatus = cudaGetLastError();
		if (cudaStatus != cudaSuccess) {
			fprintf(stderr, "divideAndConquer launch failed: %s\n", cudaGetErrorString(cudaStatus));
		}

		// cudaDeviceSynchronize waits for the kernel to finish, and returns
		// any errors encountered during the launch.
		cudaStatus = cudaDeviceSynchronize();
		if (cudaStatus != cudaSuccess) {
			fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
		}
	}
	
	cudaStatus = cudaMemcpy(h_data, d_data, numPoints * sizeof(Point), cudaMemcpyDeviceToHost);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
    }

	cudaFree(d_data);
	
	j = 0;
	int count = 0;
	//printf("%d\n", h_data[0].rightID);
	for (int i=0; i<numPoints; i++)
	{
		if (j == 0 && i != 0)
			break;

		printf("j: %d  ( %d, %d )\nr: %d   l: %d\n\n", j, h_data[j].X, h_data[j].Y, h_data[j].rightID, h_data[j].leftID);
		j = h_data[j].rightID; 
		count++;
		//system("PAUSE");
	}

	printf("\nCount: %d\n", count);

	/*for (int i = 0; i < numPoints; i++)
	{
		printf("%d, %d\n", h_data[i].X, h_data[i].Y);
		system("PAUSE");
	}*/

    return cudaStatus;
}

	.file	"tmpxft_002bf799_00000000-6_ConvexHull.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z8findHullRiS_
	.type	_Z8findHullRiS_, @function
_Z8findHullRiS_:
.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	_Z8findHullRiS_, .-_Z8findHullRiS_
	.globl	_Z8findHullRiS_P5Point
	.type	_Z8findHullRiS_P5Point, @function
_Z8findHullRiS_P5Point:
.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	_Z8findHullRiS_P5Point, .-_Z8findHullRiS_P5Point
	.globl	_Z42__device_stub__Z16divideAndConquerP5PointiP5Pointi
	.type	_Z42__device_stub__Z16divideAndConquerP5PointiP5Pointi, @function
_Z42__device_stub__Z16divideAndConquerP5PointiP5Pointi:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L6
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z16divideAndConquerP5Pointi(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L6:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z42__device_stub__Z16divideAndConquerP5PointiP5Pointi, .-_Z42__device_stub__Z16divideAndConquerP5PointiP5Pointi
	.globl	_Z16divideAndConquerP5Pointi
	.type	_Z16divideAndConquerP5Pointi, @function
_Z16divideAndConquerP5Pointi:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z16divideAndConquerP5PointiP5Pointi
	.cfi_endproc
.LFE2056:
	.size	_Z16divideAndConquerP5Pointi, .-_Z16divideAndConquerP5Pointi
	.globl	_Z49__device_stub__Z22divideAndConquerBlocksP5PointiiP5Pointii
	.type	_Z49__device_stub__Z22divideAndConquerBlocksP5PointiiP5Pointii, @function
_Z49__device_stub__Z22divideAndConquerBlocksP5PointiiP5Pointii:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	32(%rsp), %rdi
	movl	%esi, 4(%rsp)
	leaq	44(%rsp), %rsi
	movl	%edx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z22divideAndConquerBlocksP5Pointii(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L12:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z49__device_stub__Z22divideAndConquerBlocksP5PointiiP5Pointii, .-_Z49__device_stub__Z22divideAndConquerBlocksP5PointiiP5Pointii
	.globl	_Z22divideAndConquerBlocksP5Pointii
	.type	_Z22divideAndConquerBlocksP5Pointii, @function
_Z22divideAndConquerBlocksP5Pointii:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z49__device_stub__Z22divideAndConquerBlocksP5PointiiP5Pointii
	.cfi_endproc
.LFE2058:
	.size	_Z22divideAndConquerBlocksP5Pointii, .-_Z22divideAndConquerBlocksP5Pointii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?"
.LC1:
	.string	"cudaMalloc failed!"
.LC2:
	.string	"cudaMemcpy failed!"
.LC3:
	.string	"\n----------Starting first DnC---------\nnumBlocks: %d    numThreads: %d\n\n"
.LC4:
	.string	"divideAndConquer launch failed: %s\n"
.LC5:
	.string	"cudaDeviceSynchronize returned error code %d after launching addKernel!\n"
.LC6:
	.string	"\n----------Starting second DnC---------\nnewNumBlocks: %d    newNumThreads: %d\n\n"
.LC7:
	.string	"j: %d  ( %d, %d )\nr: %d   l: %d\n\n"
.LC8:
	.string	"\nCount: %d\n"
	.text
	.globl	_Z10convexHullP5Pointi
	.type	_Z10convexHullP5Pointi, @function
_Z10convexHullP5Pointi:
.LFB2030:
	.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	%rdi, %r14
	xorl	%edi, %edi
	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	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	call	cudaSetDevice@PLT
	testl	%eax, %eax
	je	.L18
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L18:
	movslq	%ebp, %rax
	leaq	d_data(%rip), %rdi
	salq	$4, %rax
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L19
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L19:
	movq	(%rsp), %rdx
	movq	d_data(%rip), %rdi
	movl	$1, %ecx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L20
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L20:
	movl	%ebp, %eax
	movl	$2048, %ecx
	movl	$1024, %r12d
	cltd
	idivl	%ecx
	movl	%ebp, %edx
	andl	$2047, %edx
	cmpl	$1, %edx
	sbbl	$-1, %eax
	movl	%eax, %ebx
	cmpl	$1, %eax
	jg	.L22
	leal	1(%rbp), %eax
	movl	$2, %ecx
	cltd
	idivl	%ecx
	movl	%eax, %r12d
.L22:
	movl	%r12d, %ecx
	movl	%ebx, %edx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leal	(%r12,%r12), %r8d
	movl	%ebx, 24(%rsp)
	xorl	%r9d, %r9d
	movabsq	$4294967297, %rax
	movl	%r12d, 36(%rsp)
	movslq	%r8d, %r8
	movq	%rax, 40(%rsp)
	movl	44(%rsp), %ecx
	salq	$4, %r8
	movq	%rax, 28(%rsp)
	movq	36(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	32(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	movq	d_data(%rip), %rdi
	movl	%ebp, %esi
	call	_Z42__device_stub__Z16divideAndConquerP5PointiP5Pointi
.L23:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L24
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC4(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L24:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %ecx
	testl	%eax, %eax
	je	.L25
	movq	stderr(%rip), %rdi
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L25:
	movl	$1, %r12d
	movl	$1, %r13d
.L26:
	cmpl	%r12d, %ebx
	jle	.L75
	movl	%ebx, %eax
	movl	$512, %ecx
	cltd
	idivl	%r12d
	cltd
	movl	%eax, %esi
	idivl	%ecx
	movl	%eax, %r15d
	testl	%eax, %eax
	je	.L41
	movl	$1024, %ecx
	cmpl	$1023, %esi
	jg	.L28
	jmp	.L27
.L41:
	movl	$1, %r15d
.L27:
	movl	$1024, %eax
	cmpl	$1024, %ebx
	jg	.L74
	movl	%ebx, %eax
.L74:
	cltd
	idivl	%r13d
	addl	%r13d, %r13d
	movl	%eax, %ecx
.L28:
	movl	%r15d, %edx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	%ecx, 12(%rsp)
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	12(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%r15d, 24(%rsp)
	movl	%ecx, 36(%rsp)
	movq	%rax, 40(%rsp)
	movl	44(%rsp), %ecx
	movq	%rax, 28(%rsp)
	movq	36(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	32(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movq	d_data(%rip), %rdi
	movl	%r12d, %edx
	movl	%ebp, %esi
	call	_Z49__device_stub__Z22divideAndConquerBlocksP5PointiiP5Pointii
.L31:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L32
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC4(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L32:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %ecx
	testl	%eax, %eax
	je	.L33
	movq	stderr(%rip), %rdi
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L33:
	addl	%r12d, %r12d
	jmp	.L26
.L75:
	movq	(%rsp), %rdx
	movq	d_data(%rip), %rsi
	movl	$2, %ecx
	movq	%r14, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L35
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L35:
	movq	d_data(%rip), %rdi
	xorl	%r15d, %r15d
	leaq	.LC7(%rip), %r13
	call	cudaFree@PLT
	xorl	%edx, %edx
.L36:
	cmpl	%ebp, %r15d
	jge	.L37
	testl	%edx, %edx
	jne	.L43
	testl	%r15d, %r15d
	jne	.L37
.L43:
	movslq	%edx, %rbx
	pushq	%rax
	.cfi_def_cfa_offset 120
	movq	%r13, %rsi
	movl	$2, %edi
	salq	$4, %rbx
	incl	%r15d
	addq	%r14, %rbx
	movl	8(%rbx), %eax
	pushq	%rax
	.cfi_def_cfa_offset 128
	movl	(%rbx), %ecx
	xorl	%eax, %eax
	movl	12(%rbx), %r9d
	movl	4(%rbx), %r8d
	call	__printf_chk@PLT
	popq	%rcx
	.cfi_def_cfa_offset 120
	movl	12(%rbx), %edx
	popq	%rsi
	.cfi_def_cfa_offset 112
	jmp	.L36
.L37:
	movl	%r15d, %edx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	movl	%r12d, %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
.LFE2030:
	.size	_Z10convexHullP5Pointi, .-_Z10convexHullP5Pointi
	.section	.rodata.str1.1
.LC9:
	.string	"r"
.LC10:
	.string	"sorted_8192.txt"
.LC11:
	.string	"%d"
.LC12:
	.string	"%d %d"
.LC13:
	.string	"addWithCuda failed!"
.LC14:
	.string	"cudaDeviceReset failed!"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	decl	%edi
	leaq	.LC9(%rip), %rax
	jle	.L77
	movq	8(%rsi), %rdi
	movq	%rax, %rsi
	jmp	.L87
.L77:
	movq	%rax, %rsi
	leaq	.LC10(%rip), %rdi
.L87:
	call	fopen@PLT
	leaq	4(%rsp), %r12
	leaq	.LC11(%rip), %rbp
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movq	%rax, %rdi
	movq	%rax, %rbx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	leaq	.LC12(%rip), %r12
	call	__isoc23_fscanf@PLT
	movslq	4(%rsp), %rdi
	salq	$4, %rdi
	call	malloc@PLT
	movq	%rax, h_data(%rip)
.L79:
	movl	4(%rsp), %esi
	movq	h_data(%rip), %rdi
	cmpl	%ebp, %esi
	jle	.L89
	movq	%rbp, %rax
	movq	%r12, %rsi
	incq	%rbp
	salq	$4, %rax
	leaq	(%rdi,%rax), %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	4(%rdx), %rcx
	call	__isoc23_fscanf@PLT
	jmp	.L79
.L89:
	call	_Z10convexHullP5Pointi
	leaq	.LC13(%rip), %rdx
	testl	%eax, %eax
	jne	.L88
	call	cudaDeviceReset@PLT
	testl	%eax, %eax
	je	.L83
	leaq	.LC14(%rip), %rdx
.L88:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L76
.L83:
	movq	h_data(%rip), %rdi
	call	free@PLT
	xorl	%eax, %eax
.L76:
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L85
	call	__stack_chk_fail@PLT
.L85:
	addq	$16, %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
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC15:
	.string	"_Z22divideAndConquerBlocksP5Pointii"
.LC16:
	.string	"_Z16divideAndConquerP5Pointi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z22divideAndConquerBlocksP5Pointii(%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	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC16(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z16divideAndConquerP5Pointi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2060:
	.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	d_data
	.bss
	.align 8
	.type	d_data, @object
	.size	d_data, 8
d_data:
	.zero	8
	.globl	h_data
	.align 8
	.type	h_data, @object
	.size	h_data, 8
h_data:
	.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:


#include "hip/hip_runtime.h"


#include <stdio.h>
#include <string.h>

#define NUM_ELEMENTS 7
#define MAX_ELEMENTS_BLOCK 2048

struct Point
{
	unsigned int X;
	unsigned int Y;
	unsigned int leftID; // counter-clockwise neighbor
	unsigned int rightID; // clockwise neighbor
};

extern __shared__ Point hullData[];

hipError_t convexHull(Point* h_data, int numPoints);

Point* h_data;

Point* d_data;

__device__ void findHull(int &currA, int &currB)
{
	int result;
	//int startIndex;
	int currAorig = currA;
	int currBorig = currB;
	Point c;
	bool isEven = (threadIdx.x % 2) == 0;

	if (isEven)
	{
		c = hullData[hullData[currA].leftID];
	}
	else
	{
		c = hullData[hullData[currA].rightID];
	}

	bool hullFound = false;
	while (!hullFound)
	{
		result = ((hullData[currB].X - hullData[currA].X)*(c.Y - hullData[currA].Y) - (hullData[currB].Y - hullData[currA].Y)*(c.X - hullData[currA].X));

		/*if (i == 1 && (idx == 49 || idx == 48))
			printf("idx: %d      a: %d   b: %d\n", idx, currA, currB);*/

		if (isEven)
		{
			if (result >= 0 && hullData[currA].leftID != currAorig)
			{
				currA = hullData[currA].leftID;
				c = hullData[hullData[currA].leftID];
			}
			else
			{
				c = hullData[hullData[currB].rightID];
				
				//result = ((b.X - a.X)*(c.Y - a.Y) - (b.Y - a.Y)*(c.X - a.X));
				result = ((hullData[currB].X - hullData[currA].X)*(c.Y - hullData[currA].Y) - (hullData[currB].Y - hullData[currA].Y)*(c.X - hullData[currA].X));
				
				if (result >= 0 && hullData[currB].rightID != currBorig)
				{
					currB = hullData[currB].rightID;
					c = hullData[hullData[currA].leftID];
				}
				else
				{
					hullFound = true;
				}
			}
		}
		else
		{
			if (result <= 0 && hullData[currA].rightID != currAorig)
			{
				currA = hullData[currA].rightID;
				c = hullData[hullData[currA].rightID];
			}
			else
			{
				c = hullData[hullData[currB].leftID];
				
				result = ((hullData[currB].X - hullData[currA].X)*(c.Y - hullData[currA].Y) - (hullData[currB].Y - hullData[currA].Y)*(c.X - hullData[currA].X));
				
				if (result <= 0 && hullData[currB].leftID != currBorig)
				{
					currB = hullData[currB].leftID;
					c = hullData[hullData[currA].rightID];
				}
				else
				{
					hullFound = true;
				}
			}
		}
	}
}

__device__ void findHull(int &currA, int &currB, Point* data)
{
	int result;
	//int startIndex;
	int currAorig = currA;
	int currBorig = currB;
	Point c;
	bool isEven = (threadIdx.x % 2) == 0;

	if (isEven)
	{
		c = data[data[currA].leftID];
	}
	else
	{
		c = data[data[currA].rightID];
	}

	//if (threadIdx.x == 0)
	//		printf("thread: %d\n   currA: %d ( %d, %d )     currB: %d ( %d, %d )    c: ( %d, %d )\n", threadIdx.x, currA, data[currA].X, data[currA].Y, currB, data[currB].X, data[currB].Y, c.X, c.Y);

	/*if (threadIdx.x == 0 && blockIdx.x == 0)
	{
		int j = 0;
		int stop = j;
		int count = 0;
		//printf("%d\n", h_data[0].rightID);
		for (int i=0; i<50; i++)
		{
			if (j == stop && i != 0)
				break;

			printf("i: %d  ( %d, %d )\nr: %d   l: %d\n\n", i, data[j].X, data[j].Y, data[j].rightID, data[j].leftID);
			j = data[j].rightID; 
			count++;
		}

		printf("\nCount: %d\n", count);
	}*/

	bool hullFound = false;
	while (!hullFound)
	{
		result = ((data[currB].X - data[currA].X)*(c.Y - data[currA].Y) - (data[currB].Y - data[currA].Y)*(c.X - data[currA].X));

		/*if (i == 1 && (idx == 49 || idx == 48))
			printf("idx: %d      a: %d   b: %d\n", idx, currA, currB);*/

		if (isEven)
		{
			if (result >= 0 && data[currA].leftID != currAorig)
			{
				currA = data[currA].leftID;
				c = data[data[currA].leftID];
			}
			else
			{
				c = data[data[currB].rightID];
				
				//result = ((b.X - a.X)*(c.Y - a.Y) - (b.Y - a.Y)*(c.X - a.X));
				result = ((data[currB].X - data[currA].X)*(c.Y - data[currA].Y) - (data[currB].Y - data[currA].Y)*(c.X - data[currA].X));
				
				if (result >= 0 && data[currB].rightID != currBorig)
				{
					currB = data[currB].rightID;
					c = data[data[currA].leftID];
				}
				else
				{
					hullFound = true;
				}
			}
		}
		else
		{
			if (result <= 0 && data[currA].rightID != currAorig)
			{
				currA = data[currA].rightID;
				c = data[data[currA].rightID];
			}
			else
			{
				c = data[data[currB].leftID];
				
				result = ((data[currB].X - data[currA].X)*(c.Y - data[currA].Y) - (data[currB].Y - data[currA].Y)*(c.X - data[currA].X));
				
				if (result <= 0 && data[currB].leftID != currBorig)
				{
					currB = data[currB].leftID;
					c = data[data[currA].rightID];
				}
				else
				{
					hullFound = true;
				}
			}
		}
	}
}

__global__ void divideAndConquer(Point* data, int numElements)
{
	int idx = threadIdx.x;
	int bidx = blockIdx.x;
	int numElementsPBlock = blockDim.x * 2;
	int numThreads = blockDim.x;
	//int numBlocks = gridDim.x;
	bool isEven = (idx % 2) == 0;
/*
	if (idx == 0)
	{
		printf("%d\n", idx);
		printf("%d\n", bidx);
		printf("%d\n", numElementsPBlock);
		printf("%d\n", numElements);
		printf("%d\n", numThreads);
		printf("%d\n", numBlocks);
	}*/

	hullData[idx] = data[idx + (numElementsPBlock * bidx)];

	if ((idx + (numElementsPBlock * bidx)) + numThreads < numElements)
		hullData[idx + numThreads] = data[(idx + (numElementsPBlock * bidx)) + numThreads];
	/*hullData[idx + (2 * blockDim.x)] = data[idx + (2 * blockDim.x)];
	hullData[idx + (3 * blockDim.x)] = data[idx + (3 * blockDim.x)];*/
	__syncthreads();
	
	if ((idx << 1) + 1 < numElementsPBlock)
	{
		hullData[(idx << 1)].leftID = (idx << 1) + 1;
		hullData[(idx << 1)].rightID = (idx << 1) + 1;
		hullData[(idx << 1) + 1].leftID = (idx << 1);
		hullData[(idx << 1) + 1].rightID = (idx << 1);
	}
	else
	{
		hullData[(idx << 1)].leftID = (idx << 1);
		hullData[(idx << 1)].rightID = (idx << 1);
	}
	
	//printf("thread: %d\n  (%d, %d)\n  neighborRight: %d\n  neighborLeft: %d\n  (%d, %d)\n  neighborRight: %d\n  neighborLeft: %d\n", idx, hullData[(idx << 1)].X, hullData[(idx << 1)].Y, hullData[(idx << 1)].rightID, hullData[(idx << 1)].leftID, hullData[(idx << 1) + 1].X, hullData[(idx << 1) + 1].Y, hullData[(idx << 1) + 1].rightID, hullData[(idx << 1) + 1].leftID);
	
	
	/*int currA = startIndex + 1;
	int currB = startIndex + 2;
	Point c = hullData[hullData[currA].leftID];
	
	if (!isEven)
	{
		c = hullData[hullData[currA].rightID];
	}*/
	//int startIndex;
	int currA;
	int currB;

	__syncthreads();
	for (int i = 1; i < ((numElementsPBlock + 1) / 2); i *= 2)
	{
		int index = 4 * i * (idx / 2);

		/*if (idx == 0)
			printf("-------------------- i = %d --------------------\n", i);
		__syncthreads();
		if (i == 2 && (idx == 49 || idx == 48))
		printf("thread: %d\n  %d: (%d, %d)\n  neighborRight: %d\n  neighborLeft: %d\n  %d: (%d, %d)\n  neighborRight: %d\n  neighborLeft: %d\n", idx, (idx << 1), hullData[(idx << 1)].X, hullData[(idx << 1)].Y, hullData[(idx << 1)].rightID, hullData[(idx << 1)].leftID, ((idx << 1) + 1), hullData[(idx << 1) + 1].X, hullData[(idx << 1) + 1].Y, hullData[(idx << 1) + 1].rightID, hullData[(idx << 1) + 1].leftID);*/
		if (index + (i << 1) < numElementsPBlock)
		{
			currA = index + (i << 1) - 1;
			currB = index + (i << 1);

			findHull(currA, currB);
		}

		__syncthreads();
		if (index + (i << 1) < numElementsPBlock)
		{
			if (isEven)
			{
				hullData[currA].rightID = currB;
				hullData[currB].leftID = currA;
			}
			else
			{
				hullData[currA].leftID = currB;
				hullData[currB].rightID = currA;
			}
		}

		//__syncthreads();
		//	if (isEven)
		//	{
		//		int j = 0;
		//		int count = 0;
		//		//printf("%d\n", h_data[0].rightID);
		//		for (int i=0; i<numElements; i++)
		//		{
		//			if (j != 0 || i == 0)
		//			printf("id: %d    %d, %d\n", idx, hullData[j].X, hullData[j].Y);
		//			else 
		//				break;

		//			j = hullData[j].rightID; 
		//			count++;
		//			//system("PAUSE");
		//			
		//		}
		//		__syncthreads();
		//		printf("\nCount: %d\n", count);
		//	}
	}
	
	__syncthreads();

	hullData[idx].rightID = (hullData[idx].rightID + (numElementsPBlock * blockIdx.x));
	hullData[idx].leftID = (hullData[idx].leftID + (numElementsPBlock * blockIdx.x));

	if (idx + numThreads < numElementsPBlock)
	{
		hullData[idx + numThreads].rightID = (hullData[idx + numThreads].rightID + (numElementsPBlock * blockIdx.x));
		hullData[idx + numThreads].leftID = (hullData[idx + numThreads].leftID + (numElementsPBlock * blockIdx.x));
	}
	__syncthreads();

	data[idx + (numElementsPBlock * bidx)] = hullData[idx];

	if ((idx + (numElementsPBlock * bidx)) + numThreads < numElements)
		data[(idx + (numElementsPBlock * bidx)) + numThreads] = hullData[idx + numThreads];
		
	__syncthreads();
}

__global__ void divideAndConquerBlocks(Point* data, int numElements, int iteration)
{
	int idx = threadIdx.x;
	//int bidx = blockIdx.x;
	bool isEven = (idx % 2) == 0;
	
	int currA;
	int currB;

	//currA = ((((MAX_ELEMENTS_BLOCK * 2) * ((idx / 2) + 1)) + (MAX_ELEMENTS_BLOCK * (MAX_ELEMENTS_BLOCK / 4) * bidx)) * iteration) - 1;
	//currB = ((((MAX_ELEMENTS_BLOCK * 2) * ((idx / 2) + 1)) + (MAX_ELEMENTS_BLOCK * (MAX_ELEMENTS_BLOCK / 4) * bidx)) * iteration);
	
	currA = (((MAX_ELEMENTS_BLOCK * 2 * (idx / 2)) + MAX_ELEMENTS_BLOCK) * iteration) - 1;
	currB = (((MAX_ELEMENTS_BLOCK * 2 * (idx / 2)) + MAX_ELEMENTS_BLOCK) * iteration);
	
	  //printf("Id: %d  Before FindHull--- currA: %d   currB: %d\n", idx, currA, currB);

	findHull(currA, currB, data);

	   //printf("Id: %d  After FindHull--- currA: %d   currB: %d\n", idx, currA, currB);

	__syncthreads();
	
	if (isEven)
	{
		data[currA].rightID = currB;
		data[currB].leftID = currA;
	}
	else
	{
		data[currA].leftID = currB;
		data[currB].rightID = currA;
	}
	
	__syncthreads();
}

int main(int argc, char** argv)
{
	FILE* input;
	if (argc > 1)
	{
		input = fopen(argv[1], "r");
	}
	else
	{
		input = fopen("sorted_8192.txt", "r");
	}

	//get number of points
	int numPoints;
	fscanf(input, "%d", &numPoints);
	fscanf(input, "%d", &numPoints);
	//printf("%d\n", numPoints);
	//system("PAUSE");

	h_data = (Point*)malloc(sizeof(Point) * numPoints);

	//initialize input
	for (int i = 0; i < numPoints; i++){
		fscanf(input, "%d %d", &h_data[i].X, &h_data[i].Y);
	}
	hipError_t cudaStatus = convexHull(h_data, numPoints);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "addWithCuda failed!");
		//system("PAUSE");
        return 1;
    }

    // cudaDeviceReset must be called before exiting in order for profiling and
    // tracing tools such as Nsight and Visual Profiler to show complete traces.
    cudaStatus = hipDeviceReset();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipDeviceReset failed!");
		//system("PAUSE");
        return 1;
    }

	free(h_data);
	//system("PAUSE");
    return 0;
}

// Helper function for using CUDA to add vectors in parallel.
hipError_t convexHull(Point* h_data, int numPoints)
{
    hipError_t cudaStatus;

    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaStatus = hipSetDevice(0);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipSetDevice failed!  Do you have a CUDA-capable GPU installed?");
    }

	cudaStatus = hipMalloc((void**)&d_data, numPoints * sizeof(Point));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
    }

    // Copy input vectors from host memory to GPU buffers.
	
	cudaStatus = hipMemcpy(d_data, h_data, numPoints * sizeof(Point), hipMemcpyHostToDevice);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
    }

	//printf("\n\nNum Threads to be launched: %d\n\n", numThreads);

	int numBlocks = 1;
	if ((numPoints % MAX_ELEMENTS_BLOCK) == 0)
		numBlocks = (numPoints / MAX_ELEMENTS_BLOCK);
	else
		numBlocks = ((numPoints / MAX_ELEMENTS_BLOCK) + 1);

	int numThreads = 1;
	if (numBlocks > 1)
		numThreads = (MAX_ELEMENTS_BLOCK / 2);
	else
		numThreads = ((numPoints + 1) / 2);

	printf("\n----------Starting first DnC---------\nnumBlocks: %d    numThreads: %d\n\n", numBlocks, numThreads);
	divideAndConquer<<<numBlocks, numThreads, sizeof(Point) * (numThreads * 2)>>>(d_data, numPoints);

	cudaStatus = hipGetLastError();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "divideAndConquer launch failed: %s\n", hipGetErrorString(cudaStatus));
    }

    // cudaDeviceSynchronize waits for the kernel to finish, and returns
    // any errors encountered during the launch.
    cudaStatus = hipDeviceSynchronize();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
    }

	int j = 1;
	for (int i = 1; i < numBlocks; i *= 2)
	{
		int newNumBlocks = (numBlocks / i) / (MAX_ELEMENTS_BLOCK / 4);

		if (newNumBlocks == 0)
			newNumBlocks++;

		int newNumThreads = 1;
		int num = 1024;
		if (newNumBlocks > 1)
			newNumThreads = (MAX_ELEMENTS_BLOCK / 2);
		else
		{
			if (numBlocks > 1024)
			{
				newNumThreads = (num / j);
			}
			else
			{
				newNumThreads = (numBlocks / j);
			}

			j *= 2;
		}

		printf("\n----------Starting second DnC---------\nnewNumBlocks: %d    newNumThreads: %d\n\n", newNumBlocks, newNumThreads);
		divideAndConquerBlocks<<<newNumBlocks, newNumThreads>>>(d_data, numPoints, i);
		cudaStatus = hipGetLastError();
		if (cudaStatus != hipSuccess) {
			fprintf(stderr, "divideAndConquer launch failed: %s\n", hipGetErrorString(cudaStatus));
		}

		// cudaDeviceSynchronize waits for the kernel to finish, and returns
		// any errors encountered during the launch.
		cudaStatus = hipDeviceSynchronize();
		if (cudaStatus != hipSuccess) {
			fprintf(stderr, "hipDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
		}
	}
	
	cudaStatus = hipMemcpy(h_data, d_data, numPoints * sizeof(Point), hipMemcpyDeviceToHost);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
    }

	hipFree(d_data);
	
	j = 0;
	int count = 0;
	//printf("%d\n", h_data[0].rightID);
	for (int i=0; i<numPoints; i++)
	{
		if (j == 0 && i != 0)
			break;

		printf("j: %d  ( %d, %d )\nr: %d   l: %d\n\n", j, h_data[j].X, h_data[j].Y, h_data[j].rightID, h_data[j].leftID);
		j = h_data[j].rightID; 
		count++;
		//system("PAUSE");
	}

	printf("\nCount: %d\n", count);

	/*for (int i = 0; i < numPoints; i++)
	{
		printf("%d, %d\n", h_data[i].X, h_data[i].Y);
		system("PAUSE");
	}*/

    return cudaStatus;
}

	.text
	.file	"ConvexHull.hip"
	.globl	_Z31__device_stub__divideAndConquerP5Pointi # -- Begin function _Z31__device_stub__divideAndConquerP5Pointi
	.type	_Z31__device_stub__divideAndConquerP5Pointi,@function
_Z31__device_stub__divideAndConquerP5Pointi: # @_Z31__device_stub__divideAndConquerP5Pointi
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z16divideAndConquerP5Pointi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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__divideAndConquerP5Pointi, .Lfunc_end0-_Z31__device_stub__divideAndConquerP5Pointi
	.cfi_endproc
                                        # -- End function
	.globl	_Z37__device_stub__divideAndConquerBlocksP5Pointii # -- Begin function _Z37__device_stub__divideAndConquerBlocksP5Pointii
	.type	_Z37__device_stub__divideAndConquerBlocksP5Pointii,@function
_Z37__device_stub__divideAndConquerBlocksP5Pointii: # @_Z37__device_stub__divideAndConquerBlocksP5Pointii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$96, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	movq	%rsp, %rsi
	movl	%edx, (%rsi)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z22divideAndConquerBlocksP5Pointii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$112, %rsp
	.cfi_adjust_cfa_offset -112
	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_end1:
	.size	_Z37__device_stub__divideAndConquerBlocksP5Pointii, .Lfunc_end1-_Z37__device_stub__divideAndConquerBlocksP5Pointii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	cmpl	$2, %edi
	jl	.LBB2_2
# %bb.1:
	movq	8(%rsi), %rdi
	jmp	.LBB2_3
.LBB2_2:
	movl	$.L.str.1, %edi
.LBB2_3:
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %rbx
	leaq	4(%rsp), %r14
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.2, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	(%r14), %r14
	movq	%r14, %rdi
	shlq	$4, %rdi
	callq	malloc
	movq	%rax, h_data(%rip)
	testq	%r14, %r14
	jle	.LBB2_7
# %bb.4:                                # %.lr.ph.preheader
	xorl	%r15d, %r15d
	xorl	%r12d, %r12d
.LBB2_5:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	h_data(%rip), %rdx
	leaq	(%rdx,%r15), %rcx
	addq	$4, %rcx
	addq	%r15, %rdx
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	incq	%r12
	movslq	4(%rsp), %r14
	addq	$16, %r15
	cmpq	%r14, %r12
	jl	.LBB2_5
# %bb.6:                                # %._crit_edge.loopexit
	movq	h_data(%rip), %rax
.LBB2_7:                                # %._crit_edge
	movq	%rax, %rdi
	movl	%r14d, %esi
	callq	_Z10convexHullP5Pointi
	testl	%eax, %eax
	jne	.LBB2_8
# %bb.10:
	callq	hipDeviceReset
	testl	%eax, %eax
	jne	.LBB2_11
# %bb.12:
	movq	h_data(%rip), %rdi
	callq	free
	xorl	%eax, %eax
.LBB2_13:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB2_8:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rcx
	movl	$.L.str.4, %edi
	movl	$19, %esi
	jmp	.LBB2_9
.LBB2_11:
	movq	stderr(%rip), %rcx
	movl	$.L.str.5, %edi
	movl	$22, %esi
.LBB2_9:
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %eax
	jmp	.LBB2_13
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z10convexHullP5Pointi          # -- Begin function _Z10convexHullP5Pointi
	.type	_Z10convexHullP5Pointi,@function
_Z10convexHullP5Pointi:                 # @_Z10convexHullP5Pointi
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %r12d
	movq	%rdi, %r14
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB3_1
.LBB3_2:
	movslq	%r12d, %rbx
	shlq	$4, %rbx
	movl	$d_data, %edi
	movq	%rbx, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_3
.LBB3_4:
	movq	d_data(%rip), %rdi
	movq	%r14, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_5
.LBB3_6:
	testl	$2047, %r12d                    # imm = 0x7FF
	je	.LBB3_7
# %bb.8:
	leal	2047(%r12), %ebp
	testl	%r12d, %r12d
	cmovnsl	%r12d, %ebp
	sarl	$11, %ebp
	incl	%ebp
	jmp	.LBB3_9
.LBB3_7:
	movl	%r12d, %ebp
	sarl	$11, %ebp
.LBB3_9:
	movl	$1024, %r15d                    # imm = 0x400
	cmpl	$1, %ebp
	jg	.LBB3_11
# %bb.10:
	leal	1(%r12), %eax
	shrl	$31, %eax
	leal	(%r12,%rax), %r15d
	incl	%r15d
	sarl	%r15d
.LBB3_11:
	movl	$.L.str.9, %edi
	movl	%ebp, %esi
	movl	%r15d, %edx
	xorl	%eax, %eax
	callq	printf
	leal	(%r15,%r15), %eax
	movslq	%eax, %r8
	shlq	$4, %r8
	movl	%ebp, %edi
	btsq	$32, %rdi
	movl	%r15d, %edx
	btsq	$32, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_13
# %bb.12:
	movq	d_data(%rip), %rdi
	movl	%r12d, %esi
	callq	_Z31__device_stub__divideAndConquerP5Pointi
.LBB3_13:
	movq	%rbx, 16(%rsp)                  # 8-byte Spill
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB3_14
.LBB3_15:
	movq	%r12, 8(%rsp)                   # 8-byte Spill
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_16
.LBB3_17:
	cmpl	$2, %ebp
	jl	.LBB3_29
# %bb.18:                               # %.lr.ph
	movl	$1024, %eax                     # imm = 0x400
	cmpl	%eax, %ebp
	cmovll	%ebp, %eax
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	movl	$1, %r12d
	movl	$1, %r13d
.LBB3_19:                               # =>This Inner Loop Header: Depth=1
	movl	%ebp, %eax
	xorl	%edx, %edx
	divl	%r13d
	movl	%eax, %r15d
	shrl	$9, %r15d
	cmpl	$512, %eax                      # imm = 0x200
	movl	$1, %eax
	cmovbl	%eax, %r15d
	cmpl	$1, %r15d
	jbe	.LBB3_21
# %bb.20:                               #   in Loop: Header=BB3_19 Depth=1
	movl	$1024, %ebx                     # imm = 0x400
	jmp	.LBB3_22
.LBB3_21:                               #   in Loop: Header=BB3_19 Depth=1
	movl	4(%rsp), %eax                   # 4-byte Reload
	cltd
	idivl	%r12d
	movl	%eax, %ebx
	addl	%r12d, %r12d
.LBB3_22:                               #   in Loop: Header=BB3_19 Depth=1
	movl	$.L.str.12, %edi
	movl	%r15d, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	printf
	movl	%r15d, %edi
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdi
	movl	%ebx, %edx
	orq	%rax, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_24
# %bb.23:                               #   in Loop: Header=BB3_19 Depth=1
	movq	d_data(%rip), %rdi
	movq	8(%rsp), %rsi                   # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	movl	%r13d, %edx
	callq	_Z37__device_stub__divideAndConquerBlocksP5Pointii
.LBB3_24:                               #   in Loop: Header=BB3_19 Depth=1
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB3_25
.LBB3_26:                               #   in Loop: Header=BB3_19 Depth=1
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_27
.LBB3_28:                               #   in Loop: Header=BB3_19 Depth=1
	addl	%r13d, %r13d
	cmpl	%ebp, %r13d
	jl	.LBB3_19
	jmp	.LBB3_29
.LBB3_25:                               #   in Loop: Header=BB3_19 Depth=1
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_26
.LBB3_27:                               #   in Loop: Header=BB3_19 Depth=1
	movq	stderr(%rip), %rdi
	movl	$.L.str.11, %esi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_28
.LBB3_29:                               # %._crit_edge
	movq	d_data(%rip), %rsi
	movq	%r14, %rdi
	movq	16(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %ebp
	testl	%eax, %eax
	jne	.LBB3_30
.LBB3_31:
	movq	d_data(%rip), %rdi
	callq	hipFree
	movq	8(%rsp), %r12                   # 8-byte Reload
	xorl	%r15d, %r15d
	testl	%r12d, %r12d
	jle	.LBB3_37
# %bb.32:                               # %.lr.ph111.preheader
	xorl	%esi, %esi
.LBB3_33:                               # %.lr.ph111
                                        # =>This Inner Loop Header: Depth=1
	testl	%esi, %esi
	jne	.LBB3_35
# %bb.34:                               # %.lr.ph111
                                        #   in Loop: Header=BB3_33 Depth=1
	testl	%r15d, %r15d
	jne	.LBB3_37
.LBB3_35:                               #   in Loop: Header=BB3_33 Depth=1
	movslq	%esi, %rbx
	shlq	$4, %rbx
	movl	(%r14,%rbx), %edx
	movl	4(%r14,%rbx), %ecx
	movl	12(%r14,%rbx), %r8d
	movl	8(%r14,%rbx), %r9d
	movl	$.L.str.13, %edi
	xorl	%eax, %eax
	callq	printf
	movl	12(%r14,%rbx), %esi
	incl	%r15d
	cmpl	%r15d, %r12d
	jne	.LBB3_33
# %bb.36:
	movl	%r12d, %r15d
.LBB3_37:                               # %._crit_edge112
	movl	$.L.str.14, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	%ebp, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_1:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rcx
	movl	$.L.str.6, %edi
	movl	$63, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB3_2
.LBB3_3:
	movq	stderr(%rip), %rcx
	movl	$.L.str.7, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB3_4
.LBB3_5:
	movq	stderr(%rip), %rcx
	movl	$.L.str.8, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB3_6
.LBB3_14:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_15
.LBB3_16:
	movq	stderr(%rip), %rdi
	movl	$.L.str.11, %esi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_17
.LBB3_30:
	movq	stderr(%rip), %rcx
	movl	$.L.str.8, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB3_31
.Lfunc_end3:
	.size	_Z10convexHullP5Pointi, .Lfunc_end3-_Z10convexHullP5Pointi
	.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	$_Z16divideAndConquerP5Pointi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z22divideAndConquerBlocksP5Pointii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	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	h_data,@object                  # @h_data
	.bss
	.globl	h_data
	.p2align	3, 0x0
h_data:
	.quad	0
	.size	h_data, 8

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

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

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"r"
	.size	.L.str, 2

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"sorted_8192.txt"
	.size	.L.str.1, 16

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%d"
	.size	.L.str.2, 3

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"addWithCuda failed!"
	.size	.L.str.4, 20

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"hipDeviceReset failed!"
	.size	.L.str.5, 23

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"hipSetDevice failed!  Do you have a CUDA-capable GPU installed?"
	.size	.L.str.6, 64

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"hipMalloc failed!"
	.size	.L.str.7, 18

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"hipMemcpy failed!"
	.size	.L.str.8, 18

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"\n----------Starting first DnC---------\nnumBlocks: %d    numThreads: %d\n\n"
	.size	.L.str.9, 73

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"divideAndConquer launch failed: %s\n"
	.size	.L.str.10, 36

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"hipDeviceSynchronize returned error code %d after launching addKernel!\n"
	.size	.L.str.11, 72

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"\n----------Starting second DnC---------\nnewNumBlocks: %d    newNumThreads: %d\n\n"
	.size	.L.str.12, 80

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"j: %d  ( %d, %d )\nr: %d   l: %d\n\n"
	.size	.L.str.13, 34

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"\nCount: %d\n"
	.size	.L.str.14, 12

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

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z22divideAndConquerBlocksP5Pointii"
	.size	.L__unnamed_2, 36

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

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

	.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__divideAndConquerP5Pointi
	.addrsig_sym _Z37__device_stub__divideAndConquerBlocksP5Pointii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym d_data
	.addrsig_sym _Z16divideAndConquerP5Pointi
	.addrsig_sym _Z22divideAndConquerBlocksP5Pointii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16divideAndConquerP5Pointi ; -- Begin function _Z16divideAndConquerP5Pointi
	.globl	_Z16divideAndConquerP5Pointi
	.p2align	8
	.type	_Z16divideAndConquerP5Pointi,@function
_Z16divideAndConquerP5Pointi:           ; @_Z16divideAndConquerP5Pointi
; %bb.0:
	s_load_b32 s2, s[0:1], 0x1c
	v_lshl_add_u32 v9, v0, 4, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s2, 0xffff
	s_load_b64 s[2:3], s[0:1], 0x0
	s_lshl_b32 s6, s4, 1
	s_load_b32 s0, s[0:1], 0x8
	s_mul_i32 s5, s6, s15
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v7, s5, v0
	v_ashrrev_i32_e32 v8, 31, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[1:2], 4, v[7:8]
	v_add_nc_u32_e32 v7, s4, v7
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s2, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v2, vcc_lo, s3, v2, vcc_lo
	v_cmp_gt_i32_e32 vcc_lo, s0, v7
	global_load_b128 v[3:6], v[1:2], off
	s_waitcnt vmcnt(0)
	ds_store_2addr_b32 v9, v5, v6 offset0:2 offset1:3
	ds_store_2addr_b32 v9, v3, v4 offset1:1
	s_and_saveexec_b32 s1, vcc_lo
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_lshl_b32 s2, s4, 4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v3, s0, v1, s2
	v_add_co_ci_u32_e64 v4, s0, 0, v2, s0
	v_add_nc_u32_e32 v7, s2, v9
	global_load_b128 v[3:6], v[3:4], off
	s_waitcnt vmcnt(0)
	ds_store_2addr_b32 v7, v5, v6 offset0:2 offset1:3
	ds_store_2addr_b32 v7, v3, v4 offset1:1
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s1
	v_lshlrev_b32_e32 v3, 1, v0
	s_mov_b32 s1, exec_lo
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_or_b32_e32 v5, 1, v3
	v_lshl_add_u32 v4, v3, 4, 0
	v_mov_b32_e32 v6, v3
	s_delay_alu instid0(VALU_DEP_3)
	v_cmpx_gt_u32_e64 s6, v5
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_mov_b32_e32 v6, v5
	ds_store_2addr_b32 v4, v3, v3 offset0:6 offset1:7
.LBB0_4:
	s_or_b32 exec_lo, exec_lo, s1
	s_cmp_lt_u32 s4, 2
	ds_store_2addr_b32 v4, v6, v6 offset0:2 offset1:3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_39
; %bb.5:                                ; %.lr.ph
	v_and_b32_e32 v4, 1, v0
	v_or_b32_e32 v10, 2, v3
	s_mov_b32 s7, 1
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr12
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cmp_eq_u32_e64 s1, 0, v4
	v_cmp_eq_u32_e64 s0, 1, v4
	v_cndmask_b32_e64 v11, 12, 8, s1
.LBB0_6:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_8 Depth 2
	v_mul_lo_u32 v13, v10, s7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s1, s6, v13
	s_and_saveexec_b32 s8, s1
	s_cbranch_execz .LBB0_32
; %bb.7:                                ;   in Loop: Header=BB0_6 Depth=1
	v_dual_mov_b32 v14, v13 :: v_dual_add_nc_u32 v15, -1, v13
	s_mov_b32 s9, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_dual_mov_b32 v12, v15 :: v_dual_lshlrev_b32 v3, 4, v15
	v_mov_b32_e32 v16, v15
	v_add3_u32 v3, 0, v3, v11
	ds_load_b32 v3, v3
	s_waitcnt lgkmcnt(0)
	v_lshl_add_u32 v3, v3, 4, 0
	ds_load_2addr_b32 v[3:4], v3 offset1:1
.LBB0_8:                                ;   Parent Loop BB0_6 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_lshl_add_u32 v22, v14, 4, 0
	v_lshl_add_u32 v24, v16, 4, 0
	s_mov_b32 s11, 0
                                        ; implicit-def: $vgpr17
                                        ; implicit-def: $vgpr21
                                        ; implicit-def: $vgpr18
                                        ; implicit-def: $sgpr10
                                        ; implicit-def: $vgpr23
	ds_load_2addr_b32 v[7:8], v22 offset1:1
	ds_load_2addr_b32 v[5:6], v24 offset1:1
	s_waitcnt lgkmcnt(0)
	v_sub_nc_u32_e32 v19, v7, v5
	v_sub_nc_u32_e32 v4, v4, v6
	v_sub_nc_u32_e32 v20, v8, v6
	v_sub_nc_u32_e32 v3, v5, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v4, v4, v19
	v_mad_u64_u32 v[7:8], null, v20, v3, v[4:5]
                                        ; implicit-def: $vgpr3
	s_and_saveexec_b32 s2, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s12, exec_lo, s2
	s_cbranch_execz .LBB0_18
; %bb.9:                                ;   in Loop: Header=BB0_8 Depth=2
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_i32_e64 s3, 0, v7
	s_mov_b32 s10, exec_lo
                                        ; implicit-def: $vgpr17
                                        ; implicit-def: $vgpr21
                                        ; implicit-def: $vgpr18
	v_cmpx_gt_i32_e32 1, v7
	s_cbranch_execz .LBB0_13
; %bb.10:                               ;   in Loop: Header=BB0_8 Depth=2
	ds_load_b32 v18, v24 offset:12
	s_mov_b32 s13, -1
	s_mov_b32 s14, exec_lo
                                        ; implicit-def: $vgpr17
	s_waitcnt lgkmcnt(0)
	v_cmpx_ne_u32_e64 v18, v15
; %bb.11:                               ;   in Loop: Header=BB0_8 Depth=2
	v_lshlrev_b32_e32 v3, 4, v18
	s_mov_b32 s11, exec_lo
	s_xor_b32 s13, exec_lo, -1
	s_delay_alu instid0(VALU_DEP_1)
	v_add3_u32 v17, 0, v3, 12
; %bb.12:                               ; %Flow123
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s14
	v_mov_b32_e32 v21, v14
	s_and_not1_b32 s2, s3, exec_lo
	s_and_b32 s3, s13, exec_lo
	s_and_b32 s11, s11, exec_lo
	s_or_b32 s3, s2, s3
.LBB0_13:                               ; %Flow122
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s10
                                        ; implicit-def: $sgpr10
                                        ; implicit-def: $vgpr3
	s_and_saveexec_b32 s13, s3
	s_cbranch_execz .LBB0_17
; %bb.14:                               ;   in Loop: Header=BB0_8 Depth=2
	ds_load_b32 v21, v22 offset:8
                                        ; implicit-def: $vgpr17
	s_waitcnt lgkmcnt(0)
	v_lshl_add_u32 v3, v21, 4, 0
	v_cmp_ne_u32_e64 s2, v21, v13
	ds_load_2addr_b32 v[3:4], v3 offset1:1
	s_waitcnt lgkmcnt(0)
	v_sub_nc_u32_e32 v5, v5, v3
	v_sub_nc_u32_e32 v8, v4, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v5, v5, v20
	v_mad_u64_u32 v[6:7], null, v8, v19, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s3, 1, v6
	s_and_b32 s3, s2, s3
	s_mov_b32 s2, s11
	s_and_saveexec_b32 s10, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s3, exec_lo, s10
; %bb.15:                               ;   in Loop: Header=BB0_8 Depth=2
	v_lshlrev_b32_e32 v3, 4, v12
	s_or_b32 s2, s11, exec_lo
                                        ; implicit-def: $vgpr16
                                        ; implicit-def: $vgpr14
	s_delay_alu instid0(VALU_DEP_1)
	v_add3_u32 v17, 0, v3, 12
                                        ; implicit-def: $vgpr3
; %bb.16:                               ; %Flow125
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s3
	v_mov_b32_e32 v18, v12
	s_and_not1_b32 s3, s11, exec_lo
	s_and_b32 s2, s2, exec_lo
	s_mov_b32 s10, -1
	s_or_b32 s11, s3, s2
.LBB0_17:                               ; %Flow124
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s13
	v_mov_b32_e32 v23, v14
	s_and_b32 s11, s11, exec_lo
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr19
                                        ; implicit-def: $vgpr20
                                        ; implicit-def: $vgpr22
                                        ; implicit-def: $vgpr24
                                        ; implicit-def: $vgpr5_vgpr6
                                        ; implicit-def: $vgpr7_vgpr8
.LBB0_18:                               ; %Flow121
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_and_not1_saveexec_b32 s12, s12
	s_cbranch_execz .LBB0_28
; %bb.19:                               ;   in Loop: Header=BB0_8 Depth=2
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_gt_i32_e64 s3, 0, v7
	s_mov_b32 s13, s11
	s_mov_b32 s14, exec_lo
                                        ; implicit-def: $vgpr17
                                        ; implicit-def: $vgpr18
	v_cmpx_lt_i32_e32 -1, v7
	s_cbranch_execz .LBB0_23
; %bb.20:                               ;   in Loop: Header=BB0_8 Depth=2
	ds_load_b32 v18, v24 offset:8
	s_mov_b32 s13, -1
	s_mov_b32 s15, s11
	s_mov_b32 s16, exec_lo
                                        ; implicit-def: $vgpr17
	s_waitcnt lgkmcnt(0)
	v_cmpx_ne_u32_e64 v18, v15
; %bb.21:                               ;   in Loop: Header=BB0_8 Depth=2
	v_lshlrev_b32_e32 v3, 4, v18
	s_or_b32 s15, s11, exec_lo
	s_xor_b32 s13, exec_lo, -1
	s_delay_alu instid0(VALU_DEP_1)
	v_add3_u32 v17, 0, v3, 8
; %bb.22:                               ; %Flow128
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s16
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 s2, s11, exec_lo
	s_and_b32 s15, s15, exec_lo
	s_and_not1_b32 s3, s3, exec_lo
	s_and_b32 s16, s13, exec_lo
	s_or_b32 s13, s2, s15
	s_or_b32 s3, s3, s16
.LBB0_23:                               ; %Flow127
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s14
                                        ; implicit-def: $sgpr2
                                        ; implicit-def: $vgpr3
                                        ; implicit-def: $vgpr23
	s_and_saveexec_b32 s14, s3
	s_cbranch_execz .LBB0_27
; %bb.24:                               ;   in Loop: Header=BB0_8 Depth=2
	ds_load_b32 v7, v22 offset:12
	s_waitcnt lgkmcnt(0)
	v_lshl_add_u32 v3, v7, 4, 0
	v_cmp_ne_u32_e64 s2, v7, v13
	ds_load_2addr_b32 v[3:4], v3 offset1:1
	s_waitcnt lgkmcnt(0)
	v_sub_nc_u32_e32 v5, v5, v3
	v_sub_nc_u32_e32 v6, v4, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v5, v5, v20
	v_mad_u64_u32 v[17:18], null, v6, v19, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_i32_e64 s3, -1, v17
                                        ; implicit-def: $vgpr17
	s_and_b32 s15, s2, s3
	s_mov_b32 s2, s13
	s_and_saveexec_b32 s3, s15
; %bb.25:                               ;   in Loop: Header=BB0_8 Depth=2
	v_lshlrev_b32_e32 v3, 4, v12
	s_or_b32 s2, s13, exec_lo
                                        ; implicit-def: $vgpr16
                                        ; implicit-def: $vgpr14
	s_delay_alu instid0(VALU_DEP_1)
	v_add3_u32 v17, 0, v3, 8
                                        ; implicit-def: $vgpr3
; %bb.26:                               ; %Flow130
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s3
	v_dual_mov_b32 v23, v14 :: v_dual_mov_b32 v14, v7
	v_mov_b32_e32 v18, v12
	s_and_not1_b32 s3, s13, exec_lo
	s_and_b32 s13, s2, exec_lo
	s_mov_b32 s2, -1
	s_or_b32 s13, s3, s13
.LBB0_27:                               ; %Flow129
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s14
	v_mov_b32_e32 v21, v14
	s_and_not1_b32 s3, s10, exec_lo
	s_and_b32 s2, s2, exec_lo
	s_and_not1_b32 s11, s11, exec_lo
	s_and_b32 s13, s13, exec_lo
	s_or_b32 s10, s3, s2
	s_or_b32 s11, s11, s13
.LBB0_28:                               ; %Flow126
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s12
	v_mov_b32_e32 v14, v23
	s_and_saveexec_b32 s2, s11
	s_cbranch_execz .LBB0_30
; %bb.29:                               ; %.sink.split.i
                                        ;   in Loop: Header=BB0_8 Depth=2
	ds_load_b32 v3, v17
	v_mov_b32_e32 v12, v18
	v_mov_b32_e32 v14, v21
	v_mov_b32_e32 v16, v18
	s_and_not1_b32 s10, s10, exec_lo
	s_waitcnt lgkmcnt(0)
	v_lshl_add_u32 v3, v3, 4, 0
	ds_load_2addr_b32 v[3:4], v3 offset1:1
.LBB0_30:                               ;   in Loop: Header=BB0_8 Depth=2
	s_or_b32 exec_lo, exec_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, exec_lo, s10
	s_or_b32 s9, s2, s9
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB0_8
; %bb.31:                               ; %Flow131
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s9
.LBB0_32:                               ; %Flow132
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 exec_lo, exec_lo, s8
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s2, s1
	s_cbranch_execz .LBB0_38
; %bb.33:                               ;   in Loop: Header=BB0_6 Depth=1
	v_lshl_add_u32 v4, v12, 4, 0
	v_lshlrev_b32_e32 v5, 4, v14
                                        ; implicit-def: $vgpr3
	s_and_saveexec_b32 s1, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s1, exec_lo, s1
	s_cbranch_execz .LBB0_35
; %bb.34:                               ;   in Loop: Header=BB0_6 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_add3_u32 v3, 0, v5, 12
	ds_store_b32 v4, v14 offset:8
                                        ; implicit-def: $vgpr4
                                        ; implicit-def: $vgpr5
.LBB0_35:                               ; %Flow
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_and_not1_saveexec_b32 s1, s1
	s_cbranch_execz .LBB0_37
; %bb.36:                               ;   in Loop: Header=BB0_6 Depth=1
	v_add3_u32 v3, 0, v5, 8
	ds_store_b32 v4, v14 offset:12
.LBB0_37:                               ; %.sink.split
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	ds_store_b32 v3, v12
.LBB0_38:                               ; %Flow118
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s2
	s_lshl_b32 s7, s7, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_ge_u32 s7, s4
	s_cbranch_scc0 .LBB0_6
.LBB0_39:                               ; %._crit_edge
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_2addr_b32 v[3:4], v9 offset0:2 offset1:3
	v_add_nc_u32_e32 v0, s4, v0
	s_mov_b32 s1, exec_lo
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v4, s5, v4
	v_add_nc_u32_e32 v3, s5, v3
	ds_store_2addr_b32 v9, v3, v4 offset0:2 offset1:3
	v_cmpx_gt_u32_e64 s6, v0
	s_cbranch_execz .LBB0_41
; %bb.40:
	v_add_nc_u32_e32 v0, 8, v9
	s_delay_alu instid0(VALU_DEP_1)
	v_lshl_add_u32 v0, s4, 4, v0
	ds_load_2addr_b32 v[3:4], v0 offset1:1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v4, s5, v4
	v_add_nc_u32_e32 v3, s5, v3
	ds_store_2addr_b32 v0, v3, v4 offset1:1
.LBB0_41:
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_2addr_b32 v[5:6], v9 offset0:2 offset1:3
	ds_load_2addr_b32 v[3:4], v9 offset1:1
	s_waitcnt lgkmcnt(0)
	global_store_b128 v[1:2], v[3:6], off
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB0_43
; %bb.42:
	s_lshl_b32 s1, s4, 4
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_nc_u32_e32 v0, s1, v9
	ds_load_2addr_b32 v[5:6], v0 offset0:2 offset1:3
	ds_load_2addr_b32 v[3:4], v0 offset1:1
	v_add_co_u32 v0, vcc_lo, v1, s1
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v2, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b128 v[0:1], v[3:6], off
.LBB0_43:
	s_or_b32 exec_lo, exec_lo, s0
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16divideAndConquerP5Pointi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 25
		.amdhsa_next_free_sgpr 17
		.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	_Z16divideAndConquerP5Pointi, .Lfunc_end0-_Z16divideAndConquerP5Pointi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1576
; NumSgprs: 19
; NumVgprs: 25
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 3
; NumSGPRsForWavesPerEU: 19
; NumVGPRsForWavesPerEU: 25
; 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
	.protected	_Z22divideAndConquerBlocksP5Pointii ; -- Begin function _Z22divideAndConquerBlocksP5Pointii
	.globl	_Z22divideAndConquerBlocksP5Pointii
	.p2align	8
	.type	_Z22divideAndConquerBlocksP5Pointii,@function
_Z22divideAndConquerBlocksP5Pointii:    ; @_Z22divideAndConquerBlocksP5Pointii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0xc
	s_load_b64 s[2:3], s[0:1], 0x0
	v_lshl_or_b32 v1, v0, 11, 0x800
	v_and_b32_e32 v5, 1, v0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v2, v1, s4
	s_mov_b32 s4, 0
	v_ashrrev_i32_e32 v3, 31, v2
	v_add_nc_u32_e32 v22, -1, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[3:4], 4, v[2:3]
	v_mov_b32_e32 v7, v22
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v1, vcc_lo, s2, v3
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, v1, 8
	v_add_co_ci_u32_e32 v4, vcc_lo, 0, v3, vcc_lo
	v_add_co_u32 v6, vcc_lo, v1, 12
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v3, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, 0, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e32 v1, v1, v4, vcc_lo
	v_cndmask_b32_e32 v0, v6, v0, vcc_lo
	v_mov_b32_e32 v4, 0
	global_load_b32 v3, v[0:1], off offset:-16
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[0:1], 4, v[3:4]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, 1, v5
	v_mov_b32_e32 v5, v2
	global_load_b64 v[10:11], v[0:1], off
	v_mov_b32_e32 v0, v22
.LBB1_1:                                ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v6, 31, v5
	v_ashrrev_i32_e32 v8, 31, v7
	s_mov_b32 s6, 0
                                        ; implicit-def: $sgpr5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[12:13], 4, v[5:6]
	v_lshlrev_b64 v[8:9], 4, v[7:8]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v16, s0, s2, v12
	v_add_co_ci_u32_e64 v17, s0, s3, v13, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v18, s0, s2, v8
	v_add_co_ci_u32_e64 v19, s0, s3, v9, s0
                                        ; implicit-def: $vgpr12
                                        ; implicit-def: $vgpr13
	s_clause 0x1
	global_load_b64 v[8:9], v[16:17], off
	global_load_b64 v[14:15], v[18:19], off
	s_waitcnt vmcnt(0)
	v_sub_nc_u32_e32 v1, v8, v14
	v_sub_nc_u32_e32 v3, v11, v15
	v_sub_nc_u32_e32 v6, v9, v15
	v_sub_nc_u32_e32 v8, v14, v10
                                        ; implicit-def: $vgpr10
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, v3, v1
	v_mad_u64_u32 v[20:21], null, v6, v8, v[3:4]
                                        ; implicit-def: $vgpr8_vgpr9
	s_and_saveexec_b32 s0, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s7, exec_lo, s0
	s_cbranch_execz .LBB1_11
; %bb.2:                                ;   in Loop: Header=BB1_1 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_i32_e64 s1, 0, v20
	s_mov_b32 s5, exec_lo
                                        ; implicit-def: $vgpr8_vgpr9
                                        ; implicit-def: $vgpr12
	v_cmpx_gt_i32_e32 1, v20
	s_cbranch_execz .LBB1_6
; %bb.3:                                ;   in Loop: Header=BB1_1 Depth=1
	global_load_b32 v12, v[18:19], off offset:12
	s_mov_b32 s8, -1
	s_mov_b32 s9, exec_lo
                                        ; implicit-def: $vgpr8_vgpr9
	s_waitcnt vmcnt(0)
	v_cmpx_ne_u32_e64 v12, v22
; %bb.4:                                ;   in Loop: Header=BB1_1 Depth=1
	v_ashrrev_i32_e32 v13, 31, v12
	s_mov_b32 s6, exec_lo
	s_xor_b32 s8, exec_lo, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[8:9], 4, v[12:13]
	v_add_co_u32 v3, s0, s2, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e64 v9, s0, s3, v9, s0
	v_add_co_u32 v8, s0, v3, 12
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v9, s0, 0, v9, s0
; %bb.5:                                ; %Flow38
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s9
	v_mov_b32_e32 v3, v5
	s_and_not1_b32 s0, s1, exec_lo
	s_and_b32 s1, s8, exec_lo
	s_and_b32 s6, s6, exec_lo
	s_or_b32 s1, s0, s1
.LBB1_6:                                ; %Flow37
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
                                        ; implicit-def: $sgpr5
                                        ; implicit-def: $vgpr10
	s_and_saveexec_b32 s8, s1
	s_cbranch_execz .LBB1_10
; %bb.7:                                ;   in Loop: Header=BB1_1 Depth=1
	global_load_b32 v3, v[16:17], off offset:8
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[8:9], 4, v[3:4]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v8, s0, s2, v8
	v_add_co_ci_u32_e64 v9, s0, s3, v9, s0
	v_cmp_ne_u32_e64 s0, v3, v2
	global_load_b64 v[10:11], v[8:9], off
	s_waitcnt vmcnt(0)
	v_sub_nc_u32_e32 v8, v14, v10
	v_sub_nc_u32_e32 v12, v11, v15
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v6, v8, v6
	v_mad_u64_u32 v[8:9], null, v12, v1, v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s1, 1, v8
                                        ; implicit-def: $vgpr8_vgpr9
	s_and_b32 s1, s0, s1
	s_mov_b32 s0, s6
	s_and_saveexec_b32 s5, s1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s1, exec_lo, s5
; %bb.8:                                ;   in Loop: Header=BB1_1 Depth=1
	v_ashrrev_i32_e32 v1, 31, v0
                                        ; implicit-def: $vgpr10
                                        ; implicit-def: $vgpr7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 4, v[0:1]
	v_add_co_u32 v1, s0, s2, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e64 v5, s0, s3, v6, s0
	v_add_co_u32 v8, s0, v1, 12
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v9, s0, 0, v5, s0
	s_or_b32 s0, s6, exec_lo
                                        ; implicit-def: $vgpr5
; %bb.9:                                ; %Flow40
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	v_mov_b32_e32 v12, v0
	s_and_not1_b32 s1, s6, exec_lo
	s_and_b32 s0, s0, exec_lo
	s_mov_b32 s5, -1
	s_or_b32 s6, s1, s0
.LBB1_10:                               ; %Flow39
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
	v_mov_b32_e32 v13, v5
	s_and_b32 s6, s6, exec_lo
                                        ; implicit-def: $vgpr5
                                        ; implicit-def: $vgpr1
                                        ; implicit-def: $vgpr6
                                        ; implicit-def: $vgpr14_vgpr15
                                        ; implicit-def: $vgpr20_vgpr21
                                        ; implicit-def: $vgpr16
                                        ; implicit-def: $vgpr18
.LBB1_11:                               ; %Flow36
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_and_not1_saveexec_b32 s7, s7
	s_cbranch_execz .LBB1_21
; %bb.12:                               ;   in Loop: Header=BB1_1 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_gt_i32_e64 s1, 0, v20
	s_mov_b32 s8, s6
	s_mov_b32 s9, exec_lo
                                        ; implicit-def: $vgpr8_vgpr9
                                        ; implicit-def: $vgpr12
	v_cmpx_lt_i32_e32 -1, v20
	s_cbranch_execz .LBB1_16
; %bb.13:                               ;   in Loop: Header=BB1_1 Depth=1
	global_load_b32 v12, v[18:19], off offset:8
	s_mov_b32 s8, -1
	s_mov_b32 s11, s6
	s_mov_b32 s10, exec_lo
                                        ; implicit-def: $vgpr8_vgpr9
	s_waitcnt vmcnt(0)
	v_cmpx_ne_u32_e64 v12, v22
; %bb.14:                               ;   in Loop: Header=BB1_1 Depth=1
	v_ashrrev_i32_e32 v13, 31, v12
	s_or_b32 s11, s6, exec_lo
	s_xor_b32 s8, exec_lo, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[8:9], 4, v[12:13]
	v_add_co_u32 v3, s0, s2, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e64 v9, s0, s3, v9, s0
	v_add_co_u32 v8, s0, v3, 8
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v9, s0, 0, v9, s0
; %bb.15:                               ; %Flow43
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 s0, s6, exec_lo
	s_and_b32 s10, s11, exec_lo
	s_and_not1_b32 s1, s1, exec_lo
	s_and_b32 s11, s8, exec_lo
	s_or_b32 s8, s0, s10
	s_or_b32 s1, s1, s11
.LBB1_16:                               ; %Flow42
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s9
                                        ; implicit-def: $sgpr0
                                        ; implicit-def: $vgpr10
                                        ; implicit-def: $vgpr13
	s_and_saveexec_b32 s9, s1
	s_cbranch_execz .LBB1_20
; %bb.17:                               ;   in Loop: Header=BB1_1 Depth=1
	global_load_b32 v3, v[16:17], off offset:12
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[8:9], 4, v[3:4]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v8, s0, s2, v8
	v_add_co_ci_u32_e64 v9, s0, s3, v9, s0
	v_cmp_ne_u32_e64 s0, v3, v2
	global_load_b64 v[10:11], v[8:9], off
	s_waitcnt vmcnt(0)
	v_sub_nc_u32_e32 v8, v14, v10
	v_sub_nc_u32_e32 v12, v11, v15
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v6, v8, v6
	v_mad_u64_u32 v[8:9], null, v12, v1, v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_i32_e64 s1, -1, v8
                                        ; implicit-def: $vgpr8_vgpr9
	s_and_b32 s10, s0, s1
	s_mov_b32 s0, s8
	s_and_saveexec_b32 s1, s10
; %bb.18:                               ;   in Loop: Header=BB1_1 Depth=1
	v_ashrrev_i32_e32 v1, 31, v0
                                        ; implicit-def: $vgpr10
                                        ; implicit-def: $vgpr7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 4, v[0:1]
	v_add_co_u32 v1, s0, s2, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e64 v5, s0, s3, v6, s0
	v_add_co_u32 v8, s0, v1, 8
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v9, s0, 0, v5, s0
	s_or_b32 s0, s8, exec_lo
                                        ; implicit-def: $vgpr5
; %bb.19:                               ; %Flow45
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	v_dual_mov_b32 v13, v5 :: v_dual_mov_b32 v12, v0
	v_mov_b32_e32 v5, v3
	s_and_not1_b32 s1, s8, exec_lo
	s_and_b32 s8, s0, exec_lo
	s_mov_b32 s0, -1
	s_or_b32 s8, s1, s8
.LBB1_20:                               ; %Flow44
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s9
	v_mov_b32_e32 v3, v5
	s_and_not1_b32 s1, s5, exec_lo
	s_and_b32 s0, s0, exec_lo
	s_and_not1_b32 s6, s6, exec_lo
	s_and_b32 s8, s8, exec_lo
	s_or_b32 s5, s1, s0
	s_or_b32 s6, s6, s8
.LBB1_21:                               ; %Flow41
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s7
	v_mov_b32_e32 v5, v13
	s_and_saveexec_b32 s1, s6
	s_cbranch_execz .LBB1_23
; %bb.22:                               ; %.sink.split.i
                                        ;   in Loop: Header=BB1_1 Depth=1
	global_load_b32 v0, v[8:9], off
	v_mov_b32_e32 v1, v4
	v_mov_b32_e32 v7, v12
	s_and_not1_b32 s5, s5, exec_lo
	v_mov_b32_e32 v5, v3
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[0:1], 4, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v0, s0, s2, v0
	v_add_co_ci_u32_e64 v1, s0, s3, v1, s0
	global_load_b64 v[10:11], v[0:1], off
	v_mov_b32_e32 v0, v12
.LBB1_23:                               ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, exec_lo, s5
	s_or_b32 s4, s0, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s4
	s_cbranch_execnz .LBB1_1
; %bb.24:                               ; %_Z8findHullRiS_P5Point.exit
	s_or_b32 exec_lo, exec_lo, s4
	v_ashrrev_i32_e32 v1, 31, v0
	v_ashrrev_i32_e32 v6, 31, v5
	s_waitcnt vmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_lshlrev_b64 v[1:2], 4, v[0:1]
	v_lshlrev_b64 v[3:4], 4, v[5:6]
                                        ; implicit-def: $vgpr6_vgpr7
	s_and_saveexec_b32 s0, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s0, exec_lo, s0
	s_cbranch_execz .LBB1_26
; %bb.25:
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s2, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s3, v4, vcc_lo
	v_add_co_u32 v1, vcc_lo, s2, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s3, v2, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v6, vcc_lo, v3, 12
	v_add_co_ci_u32_e32 v7, vcc_lo, 0, v4, vcc_lo
	global_store_b32 v[1:2], v5, off offset:8
                                        ; implicit-def: $vgpr1_vgpr2
                                        ; implicit-def: $vgpr3_vgpr4
.LBB1_26:                               ; %Flow
	s_and_not1_saveexec_b32 s0, s0
	s_cbranch_execz .LBB1_28
; %bb.27:
	v_add_co_u32 v3, vcc_lo, s2, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s3, v4, vcc_lo
	v_add_co_u32 v1, vcc_lo, s2, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s3, v2, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v6, vcc_lo, v3, 8
	v_add_co_ci_u32_e32 v7, vcc_lo, 0, v4, vcc_lo
	global_store_b32 v[1:2], v5, off offset:12
.LBB1_28:
	s_or_b32 exec_lo, exec_lo, s0
	global_store_b32 v[6:7], v0, off
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z22divideAndConquerBlocksP5Pointii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 16
		.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 23
		.amdhsa_next_free_sgpr 12
		.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_end1:
	.size	_Z22divideAndConquerBlocksP5Pointii, .Lfunc_end1-_Z22divideAndConquerBlocksP5Pointii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1440
; NumSgprs: 14
; NumVgprs: 23
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 14
; NumVGPRsForWavesPerEU: 23
; Occupancy: 16
; WaveLimiterHint : 1
; 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
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         136
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16divideAndConquerP5Pointi
    .private_segment_fixed_size: 0
    .sgpr_count:     19
    .sgpr_spill_count: 0
    .symbol:         _Z16divideAndConquerP5Pointi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     25
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 16
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z22divideAndConquerBlocksP5Pointii
    .private_segment_fixed_size: 0
    .sgpr_count:     14
    .sgpr_spill_count: 0
    .symbol:         _Z22divideAndConquerBlocksP5Pointii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     23
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
