#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// method to read the first, second and fourth input files
int read_input_one_two_four(int** input, char* filepath) {
    FILE* fp = fopen(filepath, "r");
    if (!fp) return fprintf(stderr, "Couldn't open file for reading\n");

    int file_length;
    fscanf(fp, "%d", &file_length);
    *input = (int*) malloc(file_length * sizeof(int));

    int next_int;

    for (int i = 0; i < file_length; i++) {
        fscanf(fp, "%d", &next_int);
        (*input)[i] = next_int;
    }

    fclose(fp);
    return file_length;
}

// method to read the third input file
int read_input_three(int** input1, int** input2, int** input3, int** input4, char* filepath) {
    FILE* fp = fopen(filepath, "r");
    if (!fp) return fprintf(stderr, "Couldn't open file for reading\n");

    int file_length;
    fscanf(fp, "%d", &file_length);

    *input1 = (int*) malloc(file_length * sizeof(int));
    *input2 = (int*) malloc(file_length * sizeof(int));
    *input3 = (int*) malloc(file_length * sizeof(int));
    *input4 = (int*) malloc(file_length * sizeof(int));

    int next_int1;
    int next_int2;
    int next_int3;
    int next_int4;

    for (int i = 0; i < file_length; i++) {
        fscanf(fp, "%d, %d, %d, %d", &next_int1, &next_int2, &next_int3, &next_int4);
        (*input1)[i] = next_int1;
        (*input2)[i] = next_int2;
        (*input3)[i] = next_int3;
        (*input4)[i] = next_int4;
    }

    fclose(fp);
    return file_length;

}

__device__ int globalQueue[7000000];
__device__ int numNextLevelNodes = 0;

__global__ void global_queuing_kernel(int totalThreads, int numNodes, int* nodePtrs, int* currLevelNodes, int* nodeNeighbors, int* nodeVisited, int* nodeGate, int* nodeInput, int* nodeOutput) {
    
    int nodesPerThread = numNodes / totalThreads;
    int threadIndex = threadIdx.x + (blockDim.x * blockIdx.x);
    int beginIndex = threadIndex * nodesPerThread;

    //Loop over all nodes in the current level
    for (int index = beginIndex; index < numNodes && index < beginIndex + nodesPerThread; index++) {
        
        int nodeIndex = currLevelNodes[index];

        //Loop over all neighbors of the node
        for (int secondIndex = nodePtrs[nodeIndex]; secondIndex < nodePtrs[nodeIndex+1]; secondIndex++) {   
            
            int neighborIndex = nodeNeighbors[secondIndex];
            const int alreadyVisited = atomicExch(&(nodeVisited[neighborIndex]),1);
            
            //If the neighbor hasn’t been visited yet
            if (!alreadyVisited) {
                
                int result = 0;
                int nInputV = nodeInput[neighborIndex];
                int nOutputV = nodeOutput[nodeIndex];
                int nGateV = nodeGate[neighborIndex];
                
                switch (nGateV) {
                case 0:
                  if (nInputV == 1 && nOutputV == 1) {
                      result = 1;
                  }
                  else {
                      result = 0;
                  }
                  break;
                case 1:
                  if (nInputV == 0 && nOutputV == 0) {
                      result = 0;
                  }
                  else {
                      result = 1;
                  }
                  break;
                case 2:
                  if (nInputV == 1 && nOutputV == 1) {
                      result = 0;
                  } else {
                      result = 1;
                  }
                  break;
                case 3:
                  if (nInputV == 0 && nOutputV == 0) {
                      result = 1; 
                  } else {
                      result = 0;
                  }
                  break;
                case 4:
                  if (nInputV == nOutputV) {
                      result = 0;
                  } else {
                      result = 1;
                  }
                  break;
                case 5:
                  if (nInputV == nOutputV) {
                      result = 1;
                  } else {
                      result = 0;
                  }
                  break;         
                }  

                //Update node output
                nodeOutput[neighborIndex] = result;
                int globalQueueIndex = atomicAdd(&numNextLevelNodes,1); 
               
                //Add it to the global queue
                globalQueue[globalQueueIndex] = neighborIndex; 
            }    
        }
         __syncthreads();
    }
}

inline cudaError_t checkCudaErr(cudaError_t err, const char* msg) {
  if (err != cudaSuccess) {
    fprintf(stderr, "Error at runtime %s: %s\n", msg, cudaGetErrorString(err));
  }
  return err;
}

int main(int argc, char *argv[]){
    
    if (argc < 7) {
        return fprintf(stderr, "Missing input argument(s)!\n");
    }
    
    // Variables
    int numNodePtrs;
    int numNodes;
    int *nodePtrs_h;
    int *nodeNeighbors_h;
    int *nodeVisited_h;
    int numTotalNeighbors_h;
    int *currLevelNodes_h;
    int numCurrLevelNodes;
    int numNextLevelNodes_h;
    int *nodeGate_h;
    int *nodeInput_h;
    int *nodeOutput_h;
    
    numNodePtrs = read_input_one_two_four(&nodePtrs_h, argv[1]);
    numTotalNeighbors_h = read_input_one_two_four(&nodeNeighbors_h, argv[2]);
    numNodes = read_input_three(&nodeVisited_h, &nodeGate_h, &nodeInput_h, &nodeOutput_h,argv[3]);
    numCurrLevelNodes = read_input_one_two_four(&currLevelNodes_h, argv[4]);
    
    char* nodeOutput_fileName = argv[5];
    char* nextLevelNodes_fileName = argv[6];
    
    // output
    int *nextLevelNodes_h = (int *)malloc(numNodes*sizeof(int));
    
    checkCudaErr(cudaMemcpyToSymbol(globalQueue,nextLevelNodes_h, numNodes * sizeof(int)), "Copying");
    
    int numNodesSize = numNodes * sizeof(int);
    int numBlocks = 35;
    int blockSize = 128;
    
    // Cuda variables
    int* nodePtrs_cuda = (int*)malloc( numNodePtrs * sizeof(int)) ; 
    cudaMalloc (&nodePtrs_cuda, numNodePtrs * sizeof(int));
    cudaMemcpy(nodePtrs_cuda, nodePtrs_h, numNodePtrs * sizeof(int), cudaMemcpyHostToDevice);

    int* currLevelNodes_cuda = (int*)malloc( numCurrLevelNodes * sizeof(int)) ; 
    cudaMalloc (&currLevelNodes_cuda, numCurrLevelNodes * sizeof(int));
    cudaMemcpy(currLevelNodes_cuda, currLevelNodes_h, numCurrLevelNodes * sizeof(int), cudaMemcpyHostToDevice);

    int* nodeNeighbors_cuda = (int*)malloc( numTotalNeighbors_h * sizeof(int)) ; 
    cudaMalloc (&nodeNeighbors_cuda, numTotalNeighbors_h * sizeof(int));
    cudaMemcpy(nodeNeighbors_cuda, nodeNeighbors_h, numTotalNeighbors_h * sizeof(int), cudaMemcpyHostToDevice);

    int* nodeVisited_cuda = (int*)malloc( numNodesSize) ; 
    cudaMalloc (&nodeVisited_cuda, numNodesSize);
    cudaMemcpy(nodeVisited_cuda, nodeVisited_h,numNodesSize, cudaMemcpyHostToDevice);

    int* nodeGate_cuda = (int*)malloc( numNodesSize) ; 
    cudaMalloc (&nodeGate_cuda, numNodesSize);
    cudaMemcpy(nodeGate_cuda, nodeGate_h, numNodesSize, cudaMemcpyHostToDevice);

    int* nodeInput_cuda = (int*)malloc( numNodesSize) ; 
    cudaMalloc (&nodeInput_cuda, numNodesSize);
    cudaMemcpy(nodeInput_cuda, nodeInput_h, numNodesSize, cudaMemcpyHostToDevice);

    int* nodeOutput_cuda = (int*)malloc(numNodesSize) ; 
    cudaMalloc (&nodeOutput_cuda, numNodesSize);
    cudaMemcpy(nodeOutput_cuda, nodeOutput_h, numNodesSize, cudaMemcpyHostToDevice);

    clock_t start = clock();

    // kernel call
    global_queuing_kernel <<< numBlocks, blockSize >>> (blockSize * numBlocks, numNodes, nodePtrs_cuda, currLevelNodes_cuda, nodeNeighbors_cuda, nodeVisited_cuda, nodeGate_cuda, nodeInput_cuda, nodeOutput_cuda);

    clock_t end = clock();

    checkCudaErr(cudaDeviceSynchronize(), "Synchronization");
    checkCudaErr(cudaGetLastError(), "GPU");

    cudaMemcpyFromSymbol(&numNextLevelNodes_h, numNextLevelNodes, sizeof(int), 0, cudaMemcpyDeviceToHost);
    checkCudaErr(cudaMemcpyFromSymbol(nextLevelNodes_h,globalQueue, numNodesSize), "Copying");

    int *outputBuffer;
    outputBuffer = (int*)malloc( numNodesSize); 
    checkCudaErr(cudaMemcpy(outputBuffer, nodeOutput_cuda, numNodesSize, cudaMemcpyDeviceToHost), "Copying");

    // write node output file
    FILE *nodeOutputFile = fopen(nodeOutput_fileName, "w");
    int counter = 0;
    fprintf(nodeOutputFile,"%d\n",numNodes);

    while (counter < numNodes) {
        fprintf(nodeOutputFile,"%d\n",(outputBuffer[counter]));
        counter++;
    }
    
    fclose(nodeOutputFile);
    
    // write next level output file
    FILE *nextLevelOutputFile = fopen(nextLevelNodes_fileName, "w");
    counter = 0;
    fprintf(nextLevelOutputFile,"%d\n",numNextLevelNodes_h);
    
    while (counter < numNextLevelNodes_h) {
        fprintf(nextLevelOutputFile,"%d\n",(nextLevelNodes_h[counter]));
        counter++;
    }
    
    fclose(nextLevelOutputFile);

    double runtime = (double) (end - start) / CLOCKS_PER_SEC * 1000;
    printf("Execution time: %f ms\n", runtime);

    // free variables
    free(nodePtrs_h);
    free(nodeNeighbors_h);
    free(nodeVisited_h);
    free(currLevelNodes_h);
    free(nodeGate_h);
    free(nodeInput_h);
    free(nodeOutput_h);

    // free cuda variables
    cudaFree(currLevelNodes_cuda);
    cudaFree(nodeNeighbors_cuda);
    cudaFree(nodePtrs_cuda);
    cudaFree(nodeVisited_cuda);
    cudaFree(nodeInput_cuda);
    cudaFree(nodeOutput_cuda);
    cudaFree(nodeGate_cuda);

    return 0;
}
	.file	"tmpxft_003793f6_00000000-6_global_queueing.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Error at runtime %s: %s\n"
	.text
	.type	_Z12checkCudaErr9cudaErrorPKc.isra.0, @function
_Z12checkCudaErr9cudaErrorPKc.isra.0:
.LFB2179:
	.cfi_startproc
	testl	%edi, %edi
	je	.L2
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rsi, %rbx
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rbx, %rcx
	popq	%rbx
	.cfi_restore 3
	.cfi_def_cfa_offset 8
	movq	%rax, %r8
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	jmp	__fprintf_chk@PLT
.L2:
	ret
	.cfi_endproc
.LFE2179:
	.size	_Z12checkCudaErr9cudaErrorPKc.isra.0, .-_Z12checkCudaErr9cudaErrorPKc.isra.0
	.section	.rodata.str1.1
.LC1:
	.string	"r"
.LC2:
	.string	"Couldn't open file for reading\n"
.LC3:
	.string	"%d"
	.text
	.globl	_Z23read_input_one_two_fourPPiPc
	.type	_Z23read_input_one_two_fourPPiPc, @function
_Z23read_input_one_two_fourPPiPc:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdi, %r12
	movq	%rsi, %rdi
	leaq	.LC1(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L9
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L15
	movq	stderr(%rip), %rdi
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	leaq	.LC2(%rip), %rdx
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	movl	$2, %esi
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	__fprintf_chk@PLT
.L9:
	.cfi_restore_state
	leaq	.LC3(%rip), %r13
	movq	%rax, %rdi
	movq	%rsp, %rdx
	movq	%rax, %rbx
	movq	%r13, %rsi
	xorl	%eax, %eax
	leaq	4(%rsp), %r14
	xorl	%ebp, %ebp
	call	__isoc23_fscanf@PLT
	movslq	(%rsp), %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, (%r12)
.L11:
	cmpl	%ebp, (%rsp)
	jle	.L16
	movq	%r14, %rdx
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	(%r12), %rax
	movl	4(%rsp), %edx
	movl	%edx, (%rax,%rbp,4)
	incq	%rbp
	jmp	.L11
.L16:
	movq	%rbx, %rdi
	call	fclose@PLT
	movl	(%rsp), %eax
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L13
.L15:
	call	__stack_chk_fail@PLT
.L13:
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z23read_input_one_two_fourPPiPc, .-_Z23read_input_one_two_fourPPiPc
	.section	.rodata.str1.1
.LC4:
	.string	"%d, %d, %d, %d"
	.text
	.globl	_Z16read_input_threePPiS0_S0_S0_Pc
	.type	_Z16read_input_threePPiS0_S0_S0_Pc, @function
_Z16read_input_threePPiS0_S0_S0_Pc:
.LFB2028:
	.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	%rcx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	leaq	.LC1(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	movq	%r8, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L18
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L24
	movq	stderr(%rip), %rdi
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	leaq	.LC2(%rip), %rdx
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	movl	$2, %esi
	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
	jmp	__fprintf_chk@PLT
.L18:
	.cfi_restore_state
	leaq	4(%rsp), %rdx
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	movq	%rax, %rbx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movslq	4(%rsp), %r15
	salq	$2, %r15
	movq	%r15, %rdi
	call	malloc@PLT
	movq	%r15, %rdi
	movq	%rax, 0(%rbp)
	call	malloc@PLT
	movq	%r15, %rdi
	movq	%rax, (%r12)
	call	malloc@PLT
	movq	%r15, %rdi
	xorl	%r15d, %r15d
	movq	%rax, 0(%r13)
	call	malloc@PLT
	movq	%rax, (%r14)
.L20:
	cmpl	%r15d, 4(%rsp)
	jle	.L25
	leaq	8(%rsp), %rdx
	leaq	12(%rsp), %rcx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	20(%rsp), %r9
	leaq	16(%rsp), %r8
	leaq	.LC4(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movq	0(%rbp), %rax
	movl	8(%rsp), %edx
	movl	%edx, (%rax,%r15,4)
	movq	(%r12), %rax
	movl	12(%rsp), %edx
	movl	%edx, (%rax,%r15,4)
	movq	0(%r13), %rax
	movl	16(%rsp), %edx
	movl	%edx, (%rax,%r15,4)
	movq	(%r14), %rax
	movl	20(%rsp), %edx
	movl	%edx, (%rax,%r15,4)
	incq	%r15
	jmp	.L20
.L25:
	movq	%rbx, %rdi
	call	fclose@PLT
	movl	4(%rsp), %eax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L22
.L24:
	call	__stack_chk_fail@PLT
.L22:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z16read_input_threePPiS0_S0_S0_Pc, .-_Z16read_input_threePPiS0_S0_S0_Pc
	.globl	_Z55__device_stub__Z21global_queuing_kerneliiPiS_S_S_S_S_S_iiPiS_S_S_S_S_S_
	.type	_Z55__device_stub__Z21global_queuing_kerneliiPiS_S_S_S_S_S_iiPiS_S_S_S_S_S_, @function
_Z55__device_stub__Z21global_queuing_kerneliiPiS_S_S_S_S_S_iiPiS_S_S_S_S_S_:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	224(%rsp), %rax
	movl	%edi, 60(%rsp)
	leaq	80(%rsp), %rdi
	movl	%esi, 56(%rsp)
	leaq	92(%rsp), %rsi
	movq	%rax, 16(%rsp)
	movq	232(%rsp), %rax
	movq	%rdx, 48(%rsp)
	leaq	64(%rsp), %rdx
	movq	%rax, 8(%rsp)
	movq	240(%rsp), %rax
	movq	%rcx, 40(%rsp)
	leaq	72(%rsp), %rcx
	movq	%r8, 32(%rsp)
	movq	%r9, 24(%rsp)
	movq	%rax, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	xorl	%eax, %eax
	leaq	60(%rsp), %rax
	movl	$1, 88(%rsp)
	movq	%rax, 128(%rsp)
	leaq	56(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 184(%rsp)
	movq	%rsp, %rax
	movq	%rax, 192(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movq	%rax, 92(%rsp)
	movl	$1, 100(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	pushq	72(%rsp)
	.cfi_def_cfa_offset 232
	leaq	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_(%rip), %rdi
	pushq	72(%rsp)
	.cfi_def_cfa_offset 240
	movq	108(%rsp), %rcx
	movl	116(%rsp), %r8d
	movq	96(%rsp), %rsi
	movl	104(%rsp), %edx
	leaq	144(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 232
	popq	%rdx
	.cfi_def_cfa_offset 224
.L26:
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$216, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z55__device_stub__Z21global_queuing_kerneliiPiS_S_S_S_S_S_iiPiS_S_S_S_S_S_, .-_Z55__device_stub__Z21global_queuing_kerneliiPiS_S_S_S_S_S_iiPiS_S_S_S_S_S_
	.globl	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_
	.type	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_, @function
_Z21global_queuing_kerneliiPiS_S_S_S_S_S_:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z55__device_stub__Z21global_queuing_kerneliiPiS_S_S_S_S_S_iiPiS_S_S_S_S_S_
	.cfi_endproc
.LFE2056:
	.size	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_, .-_Z21global_queuing_kerneliiPiS_S_S_S_S_S_
	.section	.rodata.str1.1
.LC5:
	.string	"Missing input argument(s)!\n"
.LC6:
	.string	"Copying"
.LC7:
	.string	"Synchronization"
.LC8:
	.string	"GPU"
.LC9:
	.string	"w"
.LC10:
	.string	"%d\n"
.LC13:
	.string	"Execution time: %f ms\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.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
	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
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$232, %rsp
	.cfi_def_cfa_offset 288
	movq	%fs:40, %rax
	movq	%rax, 216(%rsp)
	xorl	%eax, %eax
	cmpl	$6, %edi
	jg	.L32
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L41
	movq	stderr(%rip), %rdi
	addq	$232, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	$2, %esi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	leaq	.LC5(%rip), %rdx
	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
	jmp	__fprintf_chk@PLT
.L32:
	.cfi_restore_state
	movq	%rsi, %r12
	movq	8(%rsi), %rsi
	leaq	80(%rsp), %rdi
	call	_Z23read_input_one_two_fourPPiPc
	movq	16(%r12), %rsi
	leaq	88(%rsp), %rdi
	movslq	%eax, %r14
	call	_Z23read_input_one_two_fourPPiPc
	movq	24(%r12), %r8
	leaq	120(%rsp), %rdx
	leaq	128(%rsp), %rcx
	leaq	112(%rsp), %rsi
	leaq	96(%rsp), %rdi
	movslq	%eax, %rbx
	salq	$2, %r14
	call	_Z16read_input_threePPiS0_S0_S0_Pc
	movq	32(%r12), %rsi
	leaq	104(%rsp), %rdi
	salq	$2, %rbx
	movslq	%eax, %r15
	call	_Z23read_input_one_two_fourPPiPc
	movq	%r15, %rbp
	salq	$2, %r15
	movslq	%eax, %r13
	movq	40(%r12), %rax
	movq	%r15, %rdi
	salq	$2, %r13
	movq	%rax, (%rsp)
	movq	48(%r12), %rax
	movq	%rax, 64(%rsp)
	call	malloc@PLT
	movl	$1, %r8d
	xorl	%ecx, %ecx
	movq	%r15, %rdx
	movq	%rax, %rsi
	leaq	_ZL11globalQueue(%rip), %rdi
	movq	%rax, %r12
	call	cudaMemcpyToSymbol@PLT
	leaq	.LC6(%rip), %rsi
	movl	%eax, %edi
	call	_Z12checkCudaErr9cudaErrorPKc.isra.0
	movq	%r14, %rdi
	call	malloc@PLT
	movq	%r14, %rsi
	leaq	136(%rsp), %rdi
	movq	%rax, 136(%rsp)
	call	cudaMalloc@PLT
	movq	80(%rsp), %rax
	movq	%r14, %rdx
	movq	136(%rsp), %rdi
	movl	$1, %ecx
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMemcpy@PLT
	movq	%r13, %rdi
	call	malloc@PLT
	leaq	144(%rsp), %rdi
	movq	%r13, %rsi
	movq	%rax, 144(%rsp)
	call	cudaMalloc@PLT
	movq	104(%rsp), %rax
	movl	$1, %ecx
	movq	%r13, %rdx
	movq	144(%rsp), %rdi
	movq	%rax, %rsi
	movq	%rax, 16(%rsp)
	call	cudaMemcpy@PLT
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rsi
	leaq	152(%rsp), %rdi
	movq	%rax, 152(%rsp)
	call	cudaMalloc@PLT
	movq	88(%rsp), %rax
	movq	%rbx, %rdx
	movq	152(%rsp), %rdi
	leal	0(,%rbp,4), %ebx
	movl	$1, %ecx
	movslq	%ebx, %rbx
	movq	%rax, %rsi
	movq	%rax, 24(%rsp)
	call	cudaMemcpy@PLT
	movq	%rbx, %rdi
	call	malloc@PLT
	leaq	160(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rax, 160(%rsp)
	call	cudaMalloc@PLT
	movq	96(%rsp), %rax
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	160(%rsp), %rdi
	movq	%rax, %rsi
	movq	%rax, 32(%rsp)
	call	cudaMemcpy@PLT
	movq	%rbx, %rdi
	call	malloc@PLT
	leaq	168(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rax, 168(%rsp)
	call	cudaMalloc@PLT
	movq	112(%rsp), %rax
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	168(%rsp), %rdi
	movq	%rax, %rsi
	movq	%rax, 40(%rsp)
	call	cudaMemcpy@PLT
	movq	%rbx, %rdi
	call	malloc@PLT
	leaq	176(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rax, 176(%rsp)
	call	cudaMalloc@PLT
	movq	120(%rsp), %rax
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	176(%rsp), %rdi
	movq	%rax, %rsi
	movq	%rax, 48(%rsp)
	call	cudaMemcpy@PLT
	movq	%rbx, %rdi
	call	malloc@PLT
	leaq	184(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rax, 184(%rsp)
	call	cudaMalloc@PLT
	movq	128(%rsp), %rax
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	184(%rsp), %rdi
	movq	%rax, %rsi
	movq	%rax, 56(%rsp)
	call	cudaMemcpy@PLT
	call	clock@PLT
	movl	$33554433, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$7, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movq	%rax, %r14
	movabsq	$4294967331, %rdi
	movq	%rdx, 204(%rsp)
	movl	$1, 212(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	pushq	%rax
	.cfi_def_cfa_offset 296
	movl	%ebp, %esi
	movl	$4480, %edi
	pushq	192(%rsp)
	.cfi_def_cfa_offset 304
	pushq	192(%rsp)
	.cfi_def_cfa_offset 312
	pushq	192(%rsp)
	.cfi_def_cfa_offset 320
	movq	192(%rsp), %r9
	movq	184(%rsp), %r8
	movq	176(%rsp), %rcx
	movq	168(%rsp), %rdx
	call	_Z55__device_stub__Z21global_queuing_kerneliiPiS_S_S_S_S_S_iiPiS_S_S_S_S_S_
	addq	$32, %rsp
	.cfi_def_cfa_offset 288
.L34:
	call	clock@PLT
	leaq	.LC6(%rip), %r15
	movq	%rax, 72(%rsp)
	call	cudaDeviceSynchronize@PLT
	leaq	.LC7(%rip), %rsi
	movl	%eax, %edi
	call	_Z12checkCudaErr9cudaErrorPKc.isra.0
	call	cudaGetLastError@PLT
	leaq	.LC8(%rip), %rsi
	movl	%eax, %edi
	call	_Z12checkCudaErr9cudaErrorPKc.isra.0
	leaq	204(%rsp), %rdi
	movl	$2, %r8d
	xorl	%ecx, %ecx
	movl	$4, %edx
	leaq	_ZL17numNextLevelNodes(%rip), %rsi
	call	cudaMemcpyFromSymbol@PLT
	movl	$2, %r8d
	movq	%rbx, %rdx
	xorl	%ecx, %ecx
	leaq	_ZL11globalQueue(%rip), %rsi
	movq	%r12, %rdi
	call	cudaMemcpyFromSymbol@PLT
	movq	%r15, %rsi
	movl	%eax, %edi
	call	_Z12checkCudaErr9cudaErrorPKc.isra.0
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	184(%rsp), %rsi
	movq	%rbx, %rdx
	movl	$2, %ecx
	movq	%rax, %rdi
	movq	%rax, %r13
	xorl	%ebx, %ebx
	call	cudaMemcpy@PLT
	movq	%r15, %rsi
	leaq	.LC10(%rip), %r15
	movl	%eax, %edi
	call	_Z12checkCudaErr9cudaErrorPKc.isra.0
	movq	(%rsp), %rdi
	leaq	.LC9(%rip), %rsi
	call	fopen@PLT
	movl	%ebp, %ecx
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%rax, (%rsp)
	movq	%rax, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L35:
	cmpl	%ebx, %ebp
	jle	.L42
	movl	0(%r13,%rbx,4), %ecx
	movq	(%rsp), %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	incq	%rbx
	call	__fprintf_chk@PLT
	jmp	.L35
.L42:
	movq	(%rsp), %rdi
	leaq	.LC10(%rip), %rbp
	xorl	%r13d, %r13d
	call	fclose@PLT
	movq	64(%rsp), %rdi
	leaq	.LC9(%rip), %rsi
	call	fopen@PLT
	movl	204(%rsp), %ecx
	movq	%rbp, %rdx
	movl	$2, %esi
	movq	%rax, %rdi
	movq	%rax, %rbx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L37:
	cmpl	%r13d, 204(%rsp)
	jle	.L43
	movl	(%r12,%r13,4), %ecx
	movq	%rbp, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	incq	%r13
	call	__fprintf_chk@PLT
	jmp	.L37
.L43:
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	72(%rsp), %rax
	movl	$2, %edi
	leaq	.LC13(%rip), %rsi
	subq	%r14, %rax
	cvtsi2sdq	%rax, %xmm0
	divsd	.LC11(%rip), %xmm0
	movb	$1, %al
	mulsd	.LC12(%rip), %xmm0
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	free@PLT
	movq	48(%rsp), %rdi
	call	free@PLT
	movq	56(%rsp), %rdi
	call	free@PLT
	movq	144(%rsp), %rdi
	call	cudaFree@PLT
	movq	152(%rsp), %rdi
	call	cudaFree@PLT
	movq	136(%rsp), %rdi
	call	cudaFree@PLT
	movq	160(%rsp), %rdi
	call	cudaFree@PLT
	movq	176(%rsp), %rdi
	call	cudaFree@PLT
	movq	184(%rsp), %rdi
	call	cudaFree@PLT
	movq	168(%rsp), %rdi
	call	cudaFree@PLT
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
.L41:
	call	__stack_chk_fail@PLT
.L39:
	addq	$232, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z21global_queuing_kerneliiPiS_S_S_S_S_S_"
.LC15:
	.string	"globalQueue"
.LC16:
	.string	"numNextLevelNodes"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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	.LC14(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC15(%rip), %rdx
	movl	$28000000, %r9d
	leaq	_ZL11globalQueue(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC16(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL17numNextLevelNodes(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.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
.LFE2058:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZL17numNextLevelNodes
	.comm	_ZL17numNextLevelNodes,4,4
	.local	_ZL11globalQueue
	.comm	_ZL11globalQueue,28000000,32
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC11:
	.long	0
	.long	1093567616
	.align 8
.LC12:
	.long	0
	.long	1083129856
	.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 <stdlib.h>
#include <time.h>

// method to read the first, second and fourth input files
int read_input_one_two_four(int** input, char* filepath) {
    FILE* fp = fopen(filepath, "r");
    if (!fp) return fprintf(stderr, "Couldn't open file for reading\n");

    int file_length;
    fscanf(fp, "%d", &file_length);
    *input = (int*) malloc(file_length * sizeof(int));

    int next_int;

    for (int i = 0; i < file_length; i++) {
        fscanf(fp, "%d", &next_int);
        (*input)[i] = next_int;
    }

    fclose(fp);
    return file_length;
}

// method to read the third input file
int read_input_three(int** input1, int** input2, int** input3, int** input4, char* filepath) {
    FILE* fp = fopen(filepath, "r");
    if (!fp) return fprintf(stderr, "Couldn't open file for reading\n");

    int file_length;
    fscanf(fp, "%d", &file_length);

    *input1 = (int*) malloc(file_length * sizeof(int));
    *input2 = (int*) malloc(file_length * sizeof(int));
    *input3 = (int*) malloc(file_length * sizeof(int));
    *input4 = (int*) malloc(file_length * sizeof(int));

    int next_int1;
    int next_int2;
    int next_int3;
    int next_int4;

    for (int i = 0; i < file_length; i++) {
        fscanf(fp, "%d, %d, %d, %d", &next_int1, &next_int2, &next_int3, &next_int4);
        (*input1)[i] = next_int1;
        (*input2)[i] = next_int2;
        (*input3)[i] = next_int3;
        (*input4)[i] = next_int4;
    }

    fclose(fp);
    return file_length;

}

__device__ int globalQueue[7000000];
__device__ int numNextLevelNodes = 0;

__global__ void global_queuing_kernel(int totalThreads, int numNodes, int* nodePtrs, int* currLevelNodes, int* nodeNeighbors, int* nodeVisited, int* nodeGate, int* nodeInput, int* nodeOutput) {
    
    int nodesPerThread = numNodes / totalThreads;
    int threadIndex = threadIdx.x + (blockDim.x * blockIdx.x);
    int beginIndex = threadIndex * nodesPerThread;

    //Loop over all nodes in the current level
    for (int index = beginIndex; index < numNodes && index < beginIndex + nodesPerThread; index++) {
        
        int nodeIndex = currLevelNodes[index];

        //Loop over all neighbors of the node
        for (int secondIndex = nodePtrs[nodeIndex]; secondIndex < nodePtrs[nodeIndex+1]; secondIndex++) {   
            
            int neighborIndex = nodeNeighbors[secondIndex];
            const int alreadyVisited = atomicExch(&(nodeVisited[neighborIndex]),1);
            
            //If the neighbor hasn’t been visited yet
            if (!alreadyVisited) {
                
                int result = 0;
                int nInputV = nodeInput[neighborIndex];
                int nOutputV = nodeOutput[nodeIndex];
                int nGateV = nodeGate[neighborIndex];
                
                switch (nGateV) {
                case 0:
                  if (nInputV == 1 && nOutputV == 1) {
                      result = 1;
                  }
                  else {
                      result = 0;
                  }
                  break;
                case 1:
                  if (nInputV == 0 && nOutputV == 0) {
                      result = 0;
                  }
                  else {
                      result = 1;
                  }
                  break;
                case 2:
                  if (nInputV == 1 && nOutputV == 1) {
                      result = 0;
                  } else {
                      result = 1;
                  }
                  break;
                case 3:
                  if (nInputV == 0 && nOutputV == 0) {
                      result = 1; 
                  } else {
                      result = 0;
                  }
                  break;
                case 4:
                  if (nInputV == nOutputV) {
                      result = 0;
                  } else {
                      result = 1;
                  }
                  break;
                case 5:
                  if (nInputV == nOutputV) {
                      result = 1;
                  } else {
                      result = 0;
                  }
                  break;         
                }  

                //Update node output
                nodeOutput[neighborIndex] = result;
                int globalQueueIndex = atomicAdd(&numNextLevelNodes,1); 
               
                //Add it to the global queue
                globalQueue[globalQueueIndex] = neighborIndex; 
            }    
        }
         __syncthreads();
    }
}

inline hipError_t checkCudaErr(hipError_t err, const char* msg) {
  if (err != hipSuccess) {
    fprintf(stderr, "Error at runtime %s: %s\n", msg, hipGetErrorString(err));
  }
  return err;
}

int main(int argc, char *argv[]){
    
    if (argc < 7) {
        return fprintf(stderr, "Missing input argument(s)!\n");
    }
    
    // Variables
    int numNodePtrs;
    int numNodes;
    int *nodePtrs_h;
    int *nodeNeighbors_h;
    int *nodeVisited_h;
    int numTotalNeighbors_h;
    int *currLevelNodes_h;
    int numCurrLevelNodes;
    int numNextLevelNodes_h;
    int *nodeGate_h;
    int *nodeInput_h;
    int *nodeOutput_h;
    
    numNodePtrs = read_input_one_two_four(&nodePtrs_h, argv[1]);
    numTotalNeighbors_h = read_input_one_two_four(&nodeNeighbors_h, argv[2]);
    numNodes = read_input_three(&nodeVisited_h, &nodeGate_h, &nodeInput_h, &nodeOutput_h,argv[3]);
    numCurrLevelNodes = read_input_one_two_four(&currLevelNodes_h, argv[4]);
    
    char* nodeOutput_fileName = argv[5];
    char* nextLevelNodes_fileName = argv[6];
    
    // output
    int *nextLevelNodes_h = (int *)malloc(numNodes*sizeof(int));
    
    checkCudaErr(hipMemcpyToSymbol(HIP_SYMBOL(globalQueue),nextLevelNodes_h, numNodes * sizeof(int)), "Copying");
    
    int numNodesSize = numNodes * sizeof(int);
    int numBlocks = 35;
    int blockSize = 128;
    
    // Cuda variables
    int* nodePtrs_cuda = (int*)malloc( numNodePtrs * sizeof(int)) ; 
    hipMalloc (&nodePtrs_cuda, numNodePtrs * sizeof(int));
    hipMemcpy(nodePtrs_cuda, nodePtrs_h, numNodePtrs * sizeof(int), hipMemcpyHostToDevice);

    int* currLevelNodes_cuda = (int*)malloc( numCurrLevelNodes * sizeof(int)) ; 
    hipMalloc (&currLevelNodes_cuda, numCurrLevelNodes * sizeof(int));
    hipMemcpy(currLevelNodes_cuda, currLevelNodes_h, numCurrLevelNodes * sizeof(int), hipMemcpyHostToDevice);

    int* nodeNeighbors_cuda = (int*)malloc( numTotalNeighbors_h * sizeof(int)) ; 
    hipMalloc (&nodeNeighbors_cuda, numTotalNeighbors_h * sizeof(int));
    hipMemcpy(nodeNeighbors_cuda, nodeNeighbors_h, numTotalNeighbors_h * sizeof(int), hipMemcpyHostToDevice);

    int* nodeVisited_cuda = (int*)malloc( numNodesSize) ; 
    hipMalloc (&nodeVisited_cuda, numNodesSize);
    hipMemcpy(nodeVisited_cuda, nodeVisited_h,numNodesSize, hipMemcpyHostToDevice);

    int* nodeGate_cuda = (int*)malloc( numNodesSize) ; 
    hipMalloc (&nodeGate_cuda, numNodesSize);
    hipMemcpy(nodeGate_cuda, nodeGate_h, numNodesSize, hipMemcpyHostToDevice);

    int* nodeInput_cuda = (int*)malloc( numNodesSize) ; 
    hipMalloc (&nodeInput_cuda, numNodesSize);
    hipMemcpy(nodeInput_cuda, nodeInput_h, numNodesSize, hipMemcpyHostToDevice);

    int* nodeOutput_cuda = (int*)malloc(numNodesSize) ; 
    hipMalloc (&nodeOutput_cuda, numNodesSize);
    hipMemcpy(nodeOutput_cuda, nodeOutput_h, numNodesSize, hipMemcpyHostToDevice);

    clock_t start = clock();

    // kernel call
    global_queuing_kernel <<< numBlocks, blockSize >>> (blockSize * numBlocks, numNodes, nodePtrs_cuda, currLevelNodes_cuda, nodeNeighbors_cuda, nodeVisited_cuda, nodeGate_cuda, nodeInput_cuda, nodeOutput_cuda);

    clock_t end = clock();

    checkCudaErr(hipDeviceSynchronize(), "Synchronization");
    checkCudaErr(hipGetLastError(), "GPU");

    hipMemcpyFromSymbol(&numNextLevelNodes_h, HIP_SYMBOL(numNextLevelNodes), sizeof(int), 0, hipMemcpyDeviceToHost);
    checkCudaErr(hipMemcpyFromSymbol(nextLevelNodes_h,HIP_SYMBOL(globalQueue), numNodesSize), "Copying");

    int *outputBuffer;
    outputBuffer = (int*)malloc( numNodesSize); 
    checkCudaErr(hipMemcpy(outputBuffer, nodeOutput_cuda, numNodesSize, hipMemcpyDeviceToHost), "Copying");

    // write node output file
    FILE *nodeOutputFile = fopen(nodeOutput_fileName, "w");
    int counter = 0;
    fprintf(nodeOutputFile,"%d\n",numNodes);

    while (counter < numNodes) {
        fprintf(nodeOutputFile,"%d\n",(outputBuffer[counter]));
        counter++;
    }
    
    fclose(nodeOutputFile);
    
    // write next level output file
    FILE *nextLevelOutputFile = fopen(nextLevelNodes_fileName, "w");
    counter = 0;
    fprintf(nextLevelOutputFile,"%d\n",numNextLevelNodes_h);
    
    while (counter < numNextLevelNodes_h) {
        fprintf(nextLevelOutputFile,"%d\n",(nextLevelNodes_h[counter]));
        counter++;
    }
    
    fclose(nextLevelOutputFile);

    double runtime = (double) (end - start) / CLOCKS_PER_SEC * 1000;
    printf("Execution time: %f ms\n", runtime);

    // free variables
    free(nodePtrs_h);
    free(nodeNeighbors_h);
    free(nodeVisited_h);
    free(currLevelNodes_h);
    free(nodeGate_h);
    free(nodeInput_h);
    free(nodeOutput_h);

    // free cuda variables
    hipFree(currLevelNodes_cuda);
    hipFree(nodeNeighbors_cuda);
    hipFree(nodePtrs_cuda);
    hipFree(nodeVisited_cuda);
    hipFree(nodeInput_cuda);
    hipFree(nodeOutput_cuda);
    hipFree(nodeGate_cuda);

    return 0;
}
	.text
	.file	"global_queueing.hip"
	.globl	_Z23read_input_one_two_fourPPiPc # -- Begin function _Z23read_input_one_two_fourPPiPc
	.type	_Z23read_input_one_two_fourPPiPc,@function
_Z23read_input_one_two_fourPPiPc:       # @_Z23read_input_one_two_fourPPiPc
	.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
	movq	%rsi, %rax
	movq	%rdi, %rbx
	movl	$.L.str, %esi
	movq	%rax, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_5
# %bb.1:
	movq	%rax, %r14
	movq	%rsp, %r15
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	(%r15), %r15
	leaq	(,%r15,4), %rdi
	callq	malloc
	movq	%rax, (%rbx)
	testq	%r15, %r15
	jle	.LBB0_4
# %bb.2:                                # %.lr.ph.preheader
	leaq	4(%rsp), %r15
	xorl	%r12d, %r12d
.LBB0_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.2, %esi
	movq	%r14, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	4(%rsp), %eax
	movq	(%rbx), %rcx
	movl	%eax, (%rcx,%r12,4)
	incq	%r12
	movslq	(%rsp), %rax
	cmpq	%rax, %r12
	jl	.LBB0_3
.LBB0_4:                                # %._crit_edge
	movq	%r14, %rdi
	callq	fclose
	movl	(%rsp), %eax
	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
.LBB0_5:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rdi
	movl	$.L.str.1, %esi
	xorl	%eax, %eax
	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
	jmp	fprintf                         # TAILCALL
.Lfunc_end0:
	.size	_Z23read_input_one_two_fourPPiPc, .Lfunc_end0-_Z23read_input_one_two_fourPPiPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z16read_input_threePPiS0_S0_S0_Pc # -- Begin function _Z16read_input_threePPiS0_S0_S0_Pc
	.type	_Z16read_input_threePPiS0_S0_S0_Pc,@function
_Z16read_input_threePPiS0_S0_S0_Pc:     # @_Z16read_input_threePPiS0_S0_S0_Pc
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, %rbx
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %r12
	movl	$.L.str, %esi
	movq	%r8, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_5
# %bb.1:
	movq	%rax, %r13
	leaq	12(%rsp), %rbp
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	(%rbp), %rax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	leaq	(,%rax,4), %rbp
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, (%r12)
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, (%r15)
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, (%r14)
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, (%rbx)
	cmpq	$0, 32(%rsp)                    # 8-byte Folded Reload
	jle	.LBB1_4
# %bb.2:                                # %.lr.ph.preheader
	xorl	%ebp, %ebp
.LBB1_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.3, %esi
	movq	%r13, %rdi
	leaq	28(%rsp), %rdx
	leaq	24(%rsp), %rcx
	leaq	20(%rsp), %r8
	leaq	16(%rsp), %r9
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	28(%rsp), %eax
	movq	(%r12), %rcx
	movl	%eax, (%rcx,%rbp,4)
	movl	24(%rsp), %eax
	movq	(%r15), %rcx
	movl	%eax, (%rcx,%rbp,4)
	movl	20(%rsp), %eax
	movq	(%r14), %rcx
	movl	%eax, (%rcx,%rbp,4)
	movl	16(%rsp), %eax
	movq	(%rbx), %rcx
	movl	%eax, (%rcx,%rbp,4)
	incq	%rbp
	movslq	12(%rsp), %rax
	cmpq	%rax, %rbp
	jl	.LBB1_3
.LBB1_4:                                # %._crit_edge
	movq	%r13, %rdi
	callq	fclose
	movl	12(%rsp), %eax
	addq	$40, %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
.LBB1_5:
	.cfi_def_cfa_offset 96
	movq	stderr(%rip), %rdi
	movl	$.L.str.1, %esi
	xorl	%eax, %eax
	addq	$40, %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
	jmp	fprintf                         # TAILCALL
.Lfunc_end1:
	.size	_Z16read_input_threePPiS0_S0_S0_Pc, .Lfunc_end1-_Z16read_input_threePPiS0_S0_S0_Pc
	.cfi_endproc
                                        # -- End function
	.globl	_Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_ # -- Begin function _Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_
	.type	_Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_,@function
_Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_: # @_Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_
	.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	$176, %rsp
	.cfi_def_cfa_offset 224
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	8(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	56(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	48(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	32(%rsp), %r8
	movq	%r9, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	224(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	232(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	240(%rsp), %rax
	movq	%rax, 64(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z21global_queuing_kerneliiPiS_S_S_S_S_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$192, %rsp
	.cfi_adjust_cfa_offset -192
	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_end2:
	.size	_Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_, .Lfunc_end2-_Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI3_0:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI3_1:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	cmpl	$6, %edi
	jle	.LBB3_20
# %bb.1:
	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	$216, %rsp
	.cfi_def_cfa_offset 272
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movq	8(%rsi), %rsi
	leaq	208(%rsp), %rdi
	callq	_Z23read_input_one_two_fourPPiPc
	movl	%eax, %r15d
	movq	16(%rbx), %rsi
	leaq	200(%rsp), %rdi
	callq	_Z23read_input_one_two_fourPPiPc
	movl	%eax, %r14d
	movq	24(%rbx), %r8
	leaq	192(%rsp), %rdi
	leaq	176(%rsp), %rsi
	leaq	168(%rsp), %rdx
	leaq	160(%rsp), %rcx
	callq	_Z16read_input_threePPiS0_S0_S0_Pc
	movl	%eax, %ebp
	movq	32(%rbx), %rsi
	leaq	184(%rsp), %rdi
	callq	_Z23read_input_one_two_fourPPiPc
	movl	%eax, %r13d
	movq	40(%rbx), %rax
	movq	%rax, 120(%rsp)                 # 8-byte Spill
	movq	48(%rbx), %rax
	movq	%rax, 144(%rsp)                 # 8-byte Spill
	movl	%ebp, 28(%rsp)                  # 4-byte Spill
	movslq	%ebp, %r12
	leaq	(,%r12,4), %rbp
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %rbx
	movl	$globalQueue, %edi
	movq	%rax, %rsi
	movq	%rbp, %rdx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	testl	%eax, %eax
	jne	.LBB3_2
.LBB3_3:                                # %_Z12checkCudaErr10hipError_tPKc.exit
	movslq	%r15d, %r15
	shlq	$2, %r15
	movq	%r15, %rdi
	callq	malloc
	leaq	72(%rsp), %rbp
	movq	%rax, (%rbp)
	movq	%rbp, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%rbp), %rdi
	movq	208(%rsp), %rsi
	movq	%rsi, 152(%rsp)                 # 8-byte Spill
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	%r13d, %r15
	shlq	$2, %r15
	movq	%r15, %rdi
	callq	malloc
	leaq	64(%rsp), %r13
	movq	%rax, (%r13)
	movq	%r13, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%r13), %rdi
	movq	184(%rsp), %rsi
	movq	%rsi, 136(%rsp)                 # 8-byte Spill
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	%r14d, %r14
	shlq	$2, %r14
	movq	%r14, %rdi
	callq	malloc
	leaq	56(%rsp), %r15
	movq	%rax, (%r15)
	movq	%r15, %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	(%r15), %rdi
	movq	200(%rsp), %rsi
	movq	%rsi, 128(%rsp)                 # 8-byte Spill
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	shlq	$34, %r12
	sarq	$32, %r12
	movq	%r12, %rdi
	callq	malloc
	leaq	48(%rsp), %r14
	movq	%rax, (%r14)
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	192(%rsp), %rsi
	movq	%rsi, 112(%rsp)                 # 8-byte Spill
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r12, %rdi
	callq	malloc
	leaq	40(%rsp), %r14
	movq	%rax, (%r14)
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	176(%rsp), %rsi
	movq	%rsi, 104(%rsp)                 # 8-byte Spill
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r12, %rdi
	callq	malloc
	leaq	32(%rsp), %r14
	movq	%rax, (%r14)
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	168(%rsp), %rsi
	movq	%rsi, 96(%rsp)                  # 8-byte Spill
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r12, %rdi
	callq	malloc
	leaq	16(%rsp), %r14
	movq	%rax, (%r14)
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	160(%rsp), %rsi
	movq	%rsi, 88(%rsp)                  # 8-byte Spill
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	clock
	movq	%rax, 80(%rsp)                  # 8-byte Spill
	movabsq	$4294967331, %rdi               # imm = 0x100000023
	leaq	93(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	movl	28(%rsp), %ebp                  # 4-byte Reload
	jne	.LBB3_5
# %bb.4:
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rcx
	movq	56(%rsp), %r8
	movq	48(%rsp), %r9
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$4480, %edi                     # imm = 0x1180
	movl	%ebp, %esi
	pushq	24(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	48(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	64(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	_Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
.LBB3_5:
	callq	clock
	movq	%rax, %r14
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_6
.LBB3_7:                                # %_Z12checkCudaErr10hipError_tPKc.exit67
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB3_8
.LBB3_9:                                # %_Z12checkCudaErr10hipError_tPKc.exit69
	leaq	12(%rsp), %rdi
	movl	$numNextLevelNodes, %esi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$2, %r8d
	callq	hipMemcpyFromSymbol
	movl	$globalQueue, %esi
	movq	%rbx, %rdi
	movq	%r12, %rdx
	xorl	%ecx, %ecx
	movl	$2, %r8d
	callq	hipMemcpyFromSymbol
	testl	%eax, %eax
	jne	.LBB3_10
.LBB3_11:                               # %_Z12checkCudaErr10hipError_tPKc.exit71
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r13
	movq	16(%rsp), %rsi
	movq	%rax, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_12
.LBB3_13:                               # %_Z12checkCudaErr10hipError_tPKc.exit73
	movl	$.L.str.8, %esi
	movq	120(%rsp), %rdi                 # 8-byte Reload
	callq	fopen
	movq	%rax, %r12
	movl	$.L.str.9, %esi
	movq	%rax, %rdi
	movl	%ebp, %edx
	xorl	%eax, %eax
	callq	fprintf
	testl	%ebp, %ebp
	jle	.LBB3_16
# %bb.14:                               # %.lr.ph.preheader
	movl	%ebp, %ebp
	xorl	%r15d, %r15d
.LBB3_15:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r13,%r15,4), %edx
	movl	$.L.str.9, %esi
	movq	%r12, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r15
	cmpq	%r15, %rbp
	jne	.LBB3_15
.LBB3_16:                               # %._crit_edge
	movq	%r12, %rdi
	callq	fclose
	movl	$.L.str.8, %esi
	movq	144(%rsp), %rdi                 # 8-byte Reload
	callq	fopen
	movq	%rax, %r12
	movl	12(%rsp), %edx
	movl	$.L.str.9, %esi
	movq	%rax, %rdi
	xorl	%eax, %eax
	callq	fprintf
	cmpl	$0, 12(%rsp)
	jle	.LBB3_19
# %bb.17:                               # %.lr.ph80.preheader
	xorl	%r13d, %r13d
.LBB3_18:                               # %.lr.ph80
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r13,4), %edx
	movl	$.L.str.9, %esi
	movq	%r12, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r13
	movslq	12(%rsp), %rax
	cmpq	%rax, %r13
	jl	.LBB3_18
.LBB3_19:                               # %._crit_edge81
	movq	%r12, %rdi
	callq	fclose
	subq	80(%rsp), %r14                  # 8-byte Folded Reload
	cvtsi2sd	%r14, %xmm0
	divsd	.LCPI3_0(%rip), %xmm0
	mulsd	.LCPI3_1(%rip), %xmm0
	movl	$.L.str.10, %edi
	movb	$1, %al
	callq	printf
	movq	152(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	128(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	112(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	136(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	104(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	96(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	88(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	72(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$216, %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_20:
	.cfi_restore %rbx
	.cfi_restore %rbp
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
	movq	stderr(%rip), %rdi
	movl	$.L.str.4, %esi
	xorl	%eax, %eax
	jmp	fprintf                         # TAILCALL
.LBB3_2:
	.cfi_def_cfa_offset 272
	.cfi_offset %rbx, -56
	.cfi_offset %rbp, -16
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	stderr(%rip), %rbp
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.5, %edx
	movq	%rbp, %rdi
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_3
.LBB3_6:
	movq	stderr(%rip), %r13
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.6, %edx
	movq	%r13, %rdi
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_7
.LBB3_8:
	movq	stderr(%rip), %r13
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.7, %edx
	movq	%r13, %rdi
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_9
.LBB3_10:
	movq	stderr(%rip), %r13
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.5, %edx
	movq	%r13, %rdi
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_11
.LBB3_12:
	movq	stderr(%rip), %r12
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.5, %edx
	movq	%r12, %rdi
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_13
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.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:
	subq	$32, %rsp
	.cfi_adjust_cfa_offset 32
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z21global_queuing_kerneliiPiS_S_S_S_S_S_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movl	$globalQueue, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$28000000, %r9d                 # imm = 0x1AB3F00
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$0
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$numNextLevelNodes, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$0
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$__hip_module_dtor, %edi
	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	.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	"Couldn't open file for reading\n"
	.size	.L.str.1, 32

	.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, %d, %d"
	.size	.L.str.3, 15

	.type	globalQueue,@object             # @globalQueue
	.local	globalQueue
	.comm	globalQueue,28000000,16
	.type	numNextLevelNodes,@object       # @numNextLevelNodes
	.local	numNextLevelNodes
	.comm	numNextLevelNodes,4,4
	.type	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_,@object # @_Z21global_queuing_kerneliiPiS_S_S_S_S_S_
	.section	.rodata,"a",@progbits
	.globl	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_
	.p2align	3, 0x0
_Z21global_queuing_kerneliiPiS_S_S_S_S_S_:
	.quad	_Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_
	.size	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_, 8

	.type	.L.str.4,@object                # @.str.4
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.4:
	.asciz	"Missing input argument(s)!\n"
	.size	.L.str.4, 28

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Copying"
	.size	.L.str.5, 8

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Synchronization"
	.size	.L.str.6, 16

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"GPU"
	.size	.L.str.7, 4

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

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

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Execution time: %f ms\n"
	.size	.L.str.10, 23

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Error at runtime %s: %s\n"
	.size	.L.str.11, 25

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z21global_queuing_kerneliiPiS_S_S_S_S_S_"
	.size	.L__unnamed_1, 42

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"globalQueue"
	.size	.L__unnamed_2, 12

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"numNextLevelNodes"
	.size	.L__unnamed_3, 18

	.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 _Z36__device_stub__global_queuing_kerneliiPiS_S_S_S_S_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym globalQueue
	.addrsig_sym numNextLevelNodes
	.addrsig_sym _Z21global_queuing_kerneliiPiS_S_S_S_S_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_ ; -- Begin function _Z21global_queuing_kerneliiPiS_S_S_S_S_S_
	.globl	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_
	.p2align	8
	.type	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_,@function
_Z21global_queuing_kerneliiPiS_S_S_S_S_S_: ; @_Z21global_queuing_kerneliiPiS_S_S_S_S_S_
; %bb.0:
	s_clause 0x1
	s_load_b64 s[2:3], s[0:1], 0x0
	s_load_b32 s4, s[0:1], 0x4c
	s_mov_b32 s16, 0
	s_waitcnt lgkmcnt(0)
	s_ashr_i32 s5, s2, 31
	s_ashr_i32 s8, s3, 31
	s_add_i32 s2, s2, s5
	s_add_i32 s9, s3, s8
	s_xor_b32 s2, s2, s5
	s_xor_b32 s9, s9, s8
	v_cvt_f32_u32_e32 v1, s2
	s_sub_i32 s7, 0, s2
	s_xor_b32 s5, s8, s5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	v_cvt_u32_f32_e32 v1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_readfirstlane_b32 s6, v1
	s_mul_i32 s7, s7, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s7, s6, s7
	s_add_i32 s6, s6, s7
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s6, s9, s6
	s_mul_i32 s7, s6, s2
	s_add_i32 s8, s6, 1
	s_sub_i32 s7, s9, s7
	s_delay_alu instid0(SALU_CYCLE_1)
	s_sub_i32 s9, s7, s2
	s_cmp_ge_u32 s7, s2
	s_cselect_b32 s6, s8, s6
	s_cselect_b32 s7, s9, s7
	s_add_i32 s8, s6, 1
	s_cmp_ge_u32 s7, s2
	s_cselect_b32 s2, s8, s6
	s_and_b32 s4, s4, 0xffff
	s_xor_b32 s2, s2, s5
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_sub_i32 s2, s2, s5
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mul_lo_u32 v0, v1, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v1, s2, v0
	s_mov_b32 s2, exec_lo
	v_min_i32_e32 v11, s3, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_lt_i32_e64 v0, v11
	s_cbranch_execz .LBB0_34
; %bb.1:                                ; %.lr.ph78.preheader
	s_clause 0x2
	s_load_b256 s[4:11], s[0:1], 0x8
	s_load_b128 s[12:15], s[0:1], 0x28
	s_load_b64 s[2:3], s[0:1], 0x38
	v_dual_mov_b32 v12, 1 :: v_dual_mov_b32 v13, 0
.LBB0_2:                                ; %.lr.ph78
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	v_ashrrev_i32_e32 v1, 31, v0
	s_mov_b32 s1, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s6, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v2, vcc_lo
	global_load_b32 v1, v[1:2], off
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[5:6], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s4, v5
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v6, vcc_lo
	global_load_b64 v[3:4], v[1:2], off
	s_waitcnt vmcnt(0)
	v_cmpx_lt_i32_e64 v3, v4
	s_cbranch_execz .LBB0_33
; %bb.3:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_ashrrev_i32_e32 v4, 31, v3
	s_mov_b32 s17, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[7:8], 2, v[3:4]
	v_add_co_u32 v4, vcc_lo, s2, v5
	v_add_co_ci_u32_e32 v5, vcc_lo, s3, v6, vcc_lo
	v_add_co_u32 v6, vcc_lo, s8, v7
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v7, vcc_lo, s9, v8, vcc_lo
.LBB0_4:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_b32 v8, v[6:7], off
	s_mov_b32 s18, exec_lo
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v9, 31, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[9:10], 2, v[8:9]
	v_add_co_u32 v14, vcc_lo, s10, v9
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v15, vcc_lo, s11, v10, vcc_lo
	global_atomic_swap_b32 v14, v[14:15], v12, off glc
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u32_e32 0, v14
	s_cbranch_execz .LBB0_32
; %bb.5:                                ; %NodeBlock117
                                        ;   in Loop: Header=BB0_4 Depth=2
	v_add_co_u32 v14, vcc_lo, s12, v9
	v_add_co_ci_u32_e32 v15, vcc_lo, s13, v10, vcc_lo
	v_add_co_u32 v17, vcc_lo, s14, v9
	v_add_co_ci_u32_e32 v18, vcc_lo, s15, v10, vcc_lo
	s_mov_b32 s0, exec_lo
	global_load_b32 v16, v[14:15], off
	global_load_b32 v14, v[17:18], off
	global_load_b32 v15, v[4:5], off
                                        ; implicit-def: $sgpr19
	s_waitcnt vmcnt(2)
	v_cmpx_lt_i32_e32 2, v16
	s_xor_b32 s0, exec_lo, s0
	s_cbranch_execz .LBB0_17
; %bb.6:                                ; %NodeBlock115
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_mov_b32 s19, exec_lo
                                        ; implicit-def: $sgpr20
	v_cmpx_lt_i32_e32 3, v16
	s_xor_b32 s19, exec_lo, s19
	s_cbranch_execz .LBB0_14
; %bb.7:                                ; %NodeBlock113
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_mov_b32 s21, exec_lo
                                        ; implicit-def: $sgpr20
	v_cmpx_lt_i32_e32 4, v16
	s_xor_b32 s21, exec_lo, s21
	s_cbranch_execz .LBB0_11
; %bb.8:                                ; %LeafBlock111
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_mov_b32 s20, 0
	s_mov_b32 s22, exec_lo
	v_cmpx_eq_u32_e32 5, v16
	s_cbranch_execz .LBB0_10
; %bb.9:                                ;   in Loop: Header=BB0_4 Depth=2
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, v14, v15
	s_and_b32 s20, vcc_lo, exec_lo
.LBB0_10:                               ; %Flow
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s22
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 s20, s20, exec_lo
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr15
.LBB0_11:                               ; %Flow119
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_and_not1_saveexec_b32 s21, s21
	s_cbranch_execz .LBB0_13
; %bb.12:                               ;   in Loop: Header=BB0_4 Depth=2
	s_waitcnt vmcnt(0)
	v_cmp_ne_u32_e32 vcc_lo, v14, v15
	s_and_not1_b32 s20, s20, exec_lo
	s_and_b32 s22, vcc_lo, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s20, s20, s22
.LBB0_13:                               ; %Flow120
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s21
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 s20, s20, exec_lo
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr15
.LBB0_14:                               ; %Flow121
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_and_not1_saveexec_b32 s19, s19
	s_cbranch_execz .LBB0_16
; %bb.15:                               ;   in Loop: Header=BB0_4 Depth=2
	s_waitcnt vmcnt(0)
	v_or_b32_e32 v14, v14, v15
	s_and_not1_b32 s20, s20, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_eq_u32_e32 vcc_lo, 0, v14
	s_and_b32 s21, vcc_lo, exec_lo
	s_or_b32 s20, s20, s21
.LBB0_16:                               ; %Flow122
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s19
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 s19, s20, exec_lo
                                        ; implicit-def: $vgpr16
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr15
.LBB0_17:                               ; %Flow128
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_and_not1_saveexec_b32 s20, s0
	s_cbranch_execz .LBB0_29
; %bb.18:                               ; %NodeBlock109
                                        ;   in Loop: Header=BB0_4 Depth=2
                                        ; implicit-def: $sgpr22
	s_mov_b32 s0, exec_lo
	v_cmpx_lt_i32_e32 0, v16
	s_xor_b32 s21, exec_lo, s0
	s_cbranch_execz .LBB0_24
; %bb.19:                               ; %NodeBlock
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_mov_b32 s22, exec_lo
                                        ; implicit-def: $sgpr0
	v_cmpx_lt_i32_e32 1, v16
	s_xor_b32 s22, exec_lo, s22
	s_cbranch_execz .LBB0_21
; %bb.20:                               ;   in Loop: Header=BB0_4 Depth=2
	s_waitcnt vmcnt(1)
	v_cmp_ne_u32_e32 vcc_lo, 1, v14
	s_waitcnt vmcnt(0)
	v_cmp_ne_u32_e64 s0, 1, v15
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s0, vcc_lo, s0
	s_and_b32 s0, s0, exec_lo
.LBB0_21:                               ; %Flow123
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_and_not1_saveexec_b32 s22, s22
	s_cbranch_execz .LBB0_23
; %bb.22:                               ;   in Loop: Header=BB0_4 Depth=2
	s_waitcnt vmcnt(0)
	v_or_b32_e32 v14, v14, v15
	s_and_not1_b32 s0, s0, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ne_u32_e32 vcc_lo, 0, v14
	s_and_b32 s23, vcc_lo, exec_lo
	s_or_b32 s0, s0, s23
.LBB0_23:                               ; %Flow124
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s22
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 s22, s0, exec_lo
                                        ; implicit-def: $vgpr16
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr15
.LBB0_24:                               ; %Flow126
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_and_not1_saveexec_b32 s21, s21
	s_cbranch_execz .LBB0_28
; %bb.25:                               ; %LeafBlock
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_mov_b32 s0, 0
	s_mov_b32 s23, exec_lo
	v_cmpx_eq_u32_e32 0, v16
	s_cbranch_execz .LBB0_27
; %bb.26:                               ;   in Loop: Header=BB0_4 Depth=2
	s_waitcnt vmcnt(1)
	v_cmp_eq_u32_e32 vcc_lo, 1, v14
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e64 s0, 1, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, vcc_lo, s0
	s_and_b32 s0, s0, exec_lo
.LBB0_27:                               ; %Flow125
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s23
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	s_and_not1_b32 s22, s22, exec_lo
	s_and_b32 s0, s0, exec_lo
	s_or_b32 s22, s22, s0
.LBB0_28:                               ; %Flow127
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s21
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	s_and_not1_b32 s0, s19, exec_lo
	s_and_b32 s19, s22, exec_lo
	s_or_b32 s19, s0, s19
.LBB0_29:                               ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s20
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 s0, exec_lo
	v_add_co_u32 v9, vcc_lo, s2, v9
	s_waitcnt vmcnt(0)
	v_cndmask_b32_e64 v15, 0, 1, s19
	v_mbcnt_lo_u32_b32 v14, s0, 0
	v_add_co_ci_u32_e32 v10, vcc_lo, s3, v10, vcc_lo
	s_mov_b32 s19, exec_lo
	global_store_b32 v[9:10], v15, off
                                        ; implicit-def: $vgpr9
	v_cmpx_eq_u32_e32 0, v14
	s_cbranch_execz .LBB0_31
; %bb.30:                               ;   in Loop: Header=BB0_4 Depth=2
	s_bcnt1_i32_b32 s0, s0
	s_getpc_b64 s[20:21]
	s_add_u32 s20, s20, numNextLevelNodes@rel32@lo+4
	s_addc_u32 s21, s21, numNextLevelNodes@rel32@hi+12
	v_mov_b32_e32 v9, s0
	global_atomic_add_u32 v9, v13, v9, s[20:21] glc
.LBB0_31:                               ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s19
	s_waitcnt vmcnt(0)
	v_readfirstlane_b32 s0, v9
	s_getpc_b64 s[20:21]
	s_add_u32 s20, s20, globalQueue@rel32@lo+4
	s_addc_u32 s21, s21, globalQueue@rel32@hi+12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v9, s0, v14
	v_ashrrev_i32_e32 v10, 31, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	v_add_co_u32 v9, vcc_lo, v9, s20
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v10, vcc_lo, s21, v10, vcc_lo
	global_store_b32 v[9:10], v8, off
.LBB0_32:                               ; %Flow129
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s18
	global_load_b32 v8, v[1:2], off offset:4
	v_add_nc_u32_e32 v3, 1, v3
	v_add_co_u32 v6, s0, v6, 4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v7, s0, 0, v7, s0
	s_waitcnt vmcnt(0)
	v_cmp_ge_i32_e32 vcc_lo, v3, v8
	s_or_b32 s17, vcc_lo, s17
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s17
	s_cbranch_execnz .LBB0_4
.LBB0_33:                               ; %Flow131
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	v_add_nc_u32_e32 v0, 1, v0
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	v_cmp_ge_i32_e32 vcc_lo, v0, v11
	s_or_b32 s16, vcc_lo, s16
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s16
	s_cbranch_execnz .LBB0_2
.LBB0_34:                               ; %Flow133
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z21global_queuing_kerneliiPiS_S_S_S_S_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 320
		.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 19
		.amdhsa_next_free_sgpr 24
		.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	_Z21global_queuing_kerneliiPiS_S_S_S_S_S_, .Lfunc_end0-_Z21global_queuing_kerneliiPiS_S_S_S_S_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1224
; NumSgprs: 26
; NumVgprs: 19
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 3
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 26
; NumVGPRsForWavesPerEU: 19
; 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
	.protected	globalQueue             ; @globalQueue
	.type	globalQueue,@object
	.section	.bss,"aw",@nobits
	.globl	globalQueue
	.p2align	4, 0x0
globalQueue:
	.zero	28000000
	.size	globalQueue, 28000000

	.protected	numNextLevelNodes       ; @numNextLevelNodes
	.type	numNextLevelNodes,@object
	.globl	numNextLevelNodes
	.p2align	2, 0x0
numNextLevelNodes:
	.long	0                               ; 0x0
	.size	numNextLevelNodes, 4

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym globalQueue
	.addrsig_sym numNextLevelNodes
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         48
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         56
        .size:           8
        .value_kind:     global_buffer
      - .offset:         64
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         68
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         72
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         76
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         78
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         80
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         82
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         84
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         86
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         112
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         120
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         128
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 320
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z21global_queuing_kerneliiPiS_S_S_S_S_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     26
    .sgpr_spill_count: 0
    .symbol:         _Z21global_queuing_kerneliiPiS_S_S_S_S_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     19
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
