#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/time.h>

using namespace std;

#include "bfs_kernel.cu"

/*
 * gpu_bfs.cu
 *
 *	Usage: ./executable <graph_file> <output file>
 *
 *	Input: Name of the file containing the graph. Expected format
 *			is binary with the following data (with no newlines)
 *			number of nodes (4 bytes)
 *			cumulative list of node degrees (4 bytes * numer of nodes)
 *			edge list (4 bytes * number of links)
 *			
 *			example: 4 nodes; node 0 edges: 1,2; node 1 edges: 0; node 1 edges: 3
 *			4
 *			0,2,3
 *			1,2,0,3
 *			written in binary with no newlines or commas
 *
 *	Output:
 *		stdout: Time it took kernel to run, in microseconds
 *		output file: Each node and its distance from starting node
 *					(0) cost:0
 *					(1) cost:3
 *		
 */

const int MAX_THREADS_PER_BLOCK = 256;
char *infile = NULL;

int starting_node_id;

int nb_nodes;
int nb_links;
int *degrees;
int *starting;
int *links;


void readFile(char *filename)
{
	ifstream finput(filename, ios::in | ios::binary);
	if(!finput.is_open())
	{
		cout << "Unable to open file" << endl;
		exit(EXIT_FAILURE);
	}

	// Read number of nodes, first 4 bytes of file
	finput.read((char*)&nb_nodes, 4);

	if (starting_node_id < 0 || starting_node_id > nb_nodes)
	{
		cerr << "Starting position is invalid" << endl;
		exit(EXIT_FAILURE);
	}

	// Read cumulative degrees, 4 bytes per node
	degrees = new int[nb_nodes];
	finput.read((char*) degrees, nb_nodes * 4);
	
	starting = new int[nb_nodes];
	memset(starting, 0, sizeof(int) * nb_nodes);
	for (int i = 1; i < nb_nodes; i++)
	{
		starting[i] = degrees[i - 1];
	}

	// Read links, 4 bytes per link
	nb_links = degrees[nb_nodes - 1];
	links = new int[nb_links];
	finput.read((char*) links, nb_links * 4);

	finput.close();
}


void bfsGraph(char *outFile)
{
	// allocate host memory
	Node *h_graph_nodes = (Node *) malloc(sizeof(Node) * nb_nodes);
	bool* h_graph_visited = (bool *) malloc(sizeof(bool) * nb_nodes);

	// Initialize memory of nodes
	h_graph_nodes[0].starting = 0;
	h_graph_nodes[0].no_of_edges = degrees[0];
	h_graph_visited[0] = false;
	for (unsigned int i = 1; i < nb_nodes; i++)
	{
		h_graph_nodes[i].starting = starting[i];
		h_graph_nodes[i].no_of_edges = degrees[i] - degrees[i-1];
		h_graph_visited[i] = false;
	}
	h_graph_visited[starting_node_id] = true;

	// Copy node list to cuda memory
	Node *d_graph_nodes;
	cudaMalloc((void **) &d_graph_nodes, sizeof(Node) * nb_nodes);
	cudaMemcpy(d_graph_nodes, h_graph_nodes, sizeof(Node) *
		nb_nodes, cudaMemcpyHostToDevice);

	// Copy edge list to device memory
	int *d_edge_list;
	cudaMalloc((void **) &d_edge_list, sizeof(int) * nb_links);
	cudaMemcpy(d_edge_list, links, sizeof(int) * nb_links,
		cudaMemcpyHostToDevice);

	// Copy the visted array to device memory
	bool *d_graph_visited;
	cudaMalloc((void **) &d_graph_visited, sizeof(bool) * nb_nodes);
	cudaMemcpy(d_graph_visited, h_graph_visited, sizeof(bool) *
		nb_nodes, cudaMemcpyHostToDevice);

	// Allocate memory for the result on host
	int *h_cost = (int *) malloc(sizeof(int) * nb_nodes);
	for (int i = 0; i < nb_nodes; i++)
	{
		h_cost[i] = -1;
	}
	h_cost[starting_node_id] = 0;

	// Allocate device memory for result
	int *d_cost;
	cudaMalloc((void **) &d_cost, sizeof(int) * nb_nodes);
	cudaMemcpy(d_cost, h_cost, sizeof(int) * nb_nodes,
		cudaMemcpyHostToDevice);

	// Determine number of blocks and threads
	int num_of_blocks = 1;	// at least 1
	int num_of_threads_per_block = nb_nodes;
	if (nb_nodes > MAX_THREADS_PER_BLOCK)
	{
		num_of_blocks = (int) ceil((double) nb_nodes/
			(double) MAX_THREADS_PER_BLOCK);
		num_of_threads_per_block = MAX_THREADS_PER_BLOCK;
	}

	bool *d_over;
	cudaMalloc((void **) &d_over, sizeof(bool));
	bool stop;
	int level = 0;

	// Call the kernel at each level iteration
	struct timeval start, end;    
	gettimeofday(&start, NULL);
	do 
	{
		stop = false;
		cudaMemcpy(d_over, &stop, sizeof(bool), 
			cudaMemcpyHostToDevice);

		bfs_kernel<<<num_of_blocks, 
		num_of_threads_per_block>>>(d_graph_nodes, d_edge_list,
			 d_graph_visited, d_cost, level, d_over, nb_nodes);
		
		cudaThreadSynchronize();

		cudaMemcpy(&stop, d_over, sizeof(bool),
			cudaMemcpyDeviceToHost);
		level++;

	} while(stop);

	gettimeofday(&end, NULL);

	// print duration of all iterations of kernel execution
	printf("%ld\n",
           (end.tv_sec * 1000000 + end.tv_usec)
           - (start.tv_sec * 1000000 + start.tv_usec));
	
	cudaMemcpy(h_cost, d_cost, sizeof(int) * nb_nodes,
		cudaMemcpyDeviceToHost);
	
	cudaMemcpy(h_graph_visited, d_graph_visited, sizeof(bool) *
			nb_nodes, cudaMemcpyDeviceToHost);

	// Store results into a file
	FILE *fpo = fopen(outFile, "w");
	for (int i = 0; i < nb_nodes; i++)
	{
		fprintf(fpo, "(%d) cost:%d\n", i, h_cost[i]);
	}
	fclose(fpo);
	
	// clean up memory
	free(h_graph_nodes);
	free(links);
	free(h_graph_visited);
	free(h_cost);
	cudaFree(d_graph_nodes);
	cudaFree(d_edge_list);
	cudaFree(d_graph_visited);
	cudaFree(d_cost);

}

int main(int argc, char **argv)
{
	// Code for printing distances to an output file
	if (argc != 3)
	{
		printf("Usage: %s <input file> <output file>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	char *filename = argv[1];
	char*outFile = argv[2];
	
	readFile(filename);
	
	starting_node_id = rand() % nb_nodes;

	bfsGraph(outFile);
	return 0;
}
	.file	"tmpxft_0027b72e_00000000-6_gpu_bfs.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3771:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3771:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z46__device_stub__Z10bfs_kernelP4NodePiPbS1_iS2_iP4NodePiPbS1_iS2_i
	.type	_Z46__device_stub__Z10bfs_kernelP4NodePiPbS1_iS2_iP4NodePiPbS1_iS2_i, @function
_Z46__device_stub__Z10bfs_kernelP4NodePiPbS1_iS2_iP4NodePiPbS1_iS2_i:
.LFB3793:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movq	%r9, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 144(%rsp)
	movq	%rsp, %rax
	movq	%rax, 152(%rsp)
	leaq	192(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	56(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z10bfs_kernelP4NodePiPbS1_iS2_i(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 208
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L2:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3793:
	.size	_Z46__device_stub__Z10bfs_kernelP4NodePiPbS1_iS2_iP4NodePiPbS1_iS2_i, .-_Z46__device_stub__Z10bfs_kernelP4NodePiPbS1_iS2_iP4NodePiPbS1_iS2_i
	.globl	_Z10bfs_kernelP4NodePiPbS1_iS2_i
	.type	_Z10bfs_kernelP4NodePiPbS1_iS2_i, @function
_Z10bfs_kernelP4NodePiPbS1_iS2_i:
.LFB3794:
	.cfi_startproc
	endbr64
	jmp	_Z46__device_stub__Z10bfs_kernelP4NodePiPbS1_iS2_iP4NodePiPbS1_iS2_i
	.cfi_endproc
.LFE3794:
	.size	_Z10bfs_kernelP4NodePiPbS1_iS2_i, .-_Z10bfs_kernelP4NodePiPbS1_iS2_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%ld\n"
.LC2:
	.string	"w"
.LC3:
	.string	"(%d) cost:%d\n"
	.text
	.globl	_Z8bfsGraphPc
	.type	_Z8bfsGraphPc, @function
_Z8bfsGraphPc:
.LFB3767:
	.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	$152, %rsp
	.cfi_def_cfa_offset 208
	movslq	nb_nodes(%rip), %rbp
	movq	%rdi, 24(%rsp)
	leaq	0(,%rbp,8), %rbx
	movq	%rbp, %r13
	movq	%rbx, %rdi
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	degrees(%rip), %rdx
	xorl	%r8d, %r8d
	movq	starting(%rip), %rsi
	movq	%rax, %rbp
	movl	%r8d, (%r12)
	movl	(%rdx), %eax
	movb	$0, 0(%rbp)
	movl	%eax, 4(%r12)
	xorl	%eax, %eax
.L9:
	incq	%rax
	cmpl	%r13d, %eax
	jnb	.L22
	movl	(%rsi,%rax,4), %ecx
	movl	%ecx, (%r12,%rax,8)
	movl	(%rdx,%rax,4), %ecx
	subl	-4(%rdx,%rax,4), %ecx
	movb	$0, 0(%rbp,%rax)
	movl	%ecx, 4(%r12,%rax,8)
	jmp	.L9
.L22:
	movslq	starting_node_id(%rip), %rax
	movq	%rbx, %rsi
	leaq	48(%rsp), %rdi
	movb	$1, 0(%rbp,%rax)
	call	cudaMalloc@PLT
	movslq	nb_nodes(%rip), %rdx
	movq	48(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %ecx
	salq	$3, %rdx
	call	cudaMemcpy@PLT
	movslq	nb_links(%rip), %rsi
	leaq	56(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movq	56(%rsp), %rdi
	movl	$1, %ecx
	movslq	nb_links(%rip), %rdx
	movq	links(%rip), %rsi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movslq	nb_nodes(%rip), %rsi
	leaq	64(%rsp), %rdi
	call	cudaMalloc@PLT
	movslq	nb_nodes(%rip), %rdx
	movq	64(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movslq	nb_nodes(%rip), %r13
	movq	%r13, %r14
	salq	$2, %r13
	movq	%r13, %rdi
	call	malloc@PLT
	movq	%rax, %rbx
	xorl	%eax, %eax
.L11:
	cmpl	%eax, %r14d
	jle	.L23
	movl	$-1, (%rbx,%rax,4)
	incq	%rax
	jmp	.L11
.L23:
	movslq	starting_node_id(%rip), %rax
	xorl	%edi, %edi
	movq	%r13, %rsi
	movl	$1, %r14d
	movl	%edi, (%rbx,%rax,4)
	leaq	72(%rsp), %rdi
	call	cudaMalloc@PLT
	movslq	nb_nodes(%rip), %rdx
	movq	72(%rsp), %rdi
	movq	%rbx, %rsi
	movl	$1, %ecx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	nb_nodes(%rip), %r13d
	cmpl	$256, %r13d
	jle	.L13
	cvtsi2sdl	%r13d, %xmm0
	mulsd	.LC0(%rip), %xmm0
	movl	$256, %r13d
	call	ceil@PLT
	cvttsd2sil	%xmm0, %r14d
.L13:
	leaq	80(%rsp), %rdi
	movl	$1, %esi
	movabsq	$4294967297, %r15
	call	cudaMalloc@PLT
	xorl	%esi, %esi
	leaq	104(%rsp), %rdi
	call	gettimeofday@PLT
	xorl	%esi, %esi
	movl	%esi, 12(%rsp)
.L15:
	leaq	47(%rsp), %rax
	movq	80(%rsp), %rdi
	movl	$1, %ecx
	movl	$1, %edx
	movq	%rax, %rsi
	movb	$0, 47(%rsp)
	movq	%rax, 16(%rsp)
	call	cudaMemcpy@PLT
	movq	%r15, 124(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r15, 96(%rsp)
	movl	128(%rsp), %ecx
	movl	%r13d, 120(%rsp)
	movl	100(%rsp), %esi
	movl	%r14d, 92(%rsp)
	movq	120(%rsp), %rdx
	movq	92(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	pushq	%rax
	.cfi_def_cfa_offset 216
	movl	nb_nodes(%rip), %eax
	pushq	%rax
	.cfi_def_cfa_offset 224
	movq	96(%rsp), %r9
	movl	28(%rsp), %r8d
	movq	88(%rsp), %rcx
	movq	80(%rsp), %rdx
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdi
	call	_Z46__device_stub__Z10bfs_kernelP4NodePiPbS1_iS2_iP4NodePiPbS1_iS2_i
	popq	%rdx
	.cfi_def_cfa_offset 216
	popq	%rcx
	.cfi_def_cfa_offset 208
.L14:
	call	cudaThreadSynchronize@PLT
	movq	80(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	$2, %ecx
	movl	$1, %edx
	call	cudaMemcpy@PLT
	incl	12(%rsp)
	cmpb	$0, 47(%rsp)
	jne	.L15
	leaq	120(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%r13d, %r13d
	call	gettimeofday@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	leaq	.LC3(%rip), %r15
	imulq	$1000000, 120(%rsp), %rdx
	addq	128(%rsp), %rdx
	imulq	$1000000, 104(%rsp), %rax
	addq	112(%rsp), %rax
	subq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movslq	nb_nodes(%rip), %rdx
	movq	72(%rsp), %rsi
	movq	%rbx, %rdi
	movl	$2, %ecx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movslq	nb_nodes(%rip), %rdx
	movq	64(%rsp), %rsi
	movq	%rbp, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	leaq	.LC2(%rip), %rsi
	call	fopen@PLT
	movq	%rax, %r14
.L16:
	cmpl	%r13d, nb_nodes(%rip)
	movl	%r13d, %ecx
	jle	.L24
	movl	(%rbx,%r13,4), %r8d
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	incq	%r13
	call	__fprintf_chk@PLT
	jmp	.L16
.L24:
	movq	%r14, %rdi
	call	fclose@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	links(%rip), %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$152, %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
.LFE3767:
	.size	_Z8bfsGraphPc, .-_Z8bfsGraphPc
	.section	.rodata.str1.1
.LC4:
	.string	"_Z10bfs_kernelP4NodePiPbS1_iS2_i"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3796:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC4(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z10bfs_kernelP4NodePiPbS1_iS2_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3796:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.rodata.str1.1
.LC5:
	.string	"Unable to open file"
.LC6:
	.string	"Starting position is invalid"
	.text
	.globl	_Z8readFilePc
	.type	_Z8readFilePc, @function
_Z8readFilePc:
.LFB3766:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3766
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdi, %rsi
	movl	$12, %edx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$536, %rsp
	.cfi_def_cfa_offset 576
	movq	%fs:40, %rax
	movq	%rax, 520(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbx
	movq	%rbx, %rdi
.LEHB0:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT
.LEHE0:
	leaq	120(%rsp), %rdi
	call	_ZNKSt12__basic_fileIcE7is_openEv@PLT
	testb	%al, %al
	jne	.L28
	leaq	.LC5(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
.L51:
.LEHB1:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %edi
	call	exit@PLT
.L28:
	movl	$4, %edx
	leaq	nb_nodes(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZNSi4readEPcl@PLT
	movl	starting_node_id(%rip), %eax
	testl	%eax, %eax
	js	.L29
	movslq	nb_nodes(%rip), %rdi
	cmpl	%edi, %eax
	jle	.L30
.L29:
	leaq	.LC6(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	jmp	.L51
.L30:
	salq	$2, %rdi
	call	_Znam@PLT
	movq	%rax, degrees(%rip)
	movq	%rax, %rsi
	movl	nb_nodes(%rip), %eax
	movq	%rbx, %rdi
	leal	0(,%rax,4), %edx
	movslq	%edx, %rdx
	call	_ZNSi4readEPcl@PLT
	movslq	nb_nodes(%rip), %rbp
	movabsq	$2305843009213693950, %rax
	cmpq	%rbp, %rax
	jb	.L32
	salq	$2, %rbp
	movq	%rbp, %rdi
	call	_Znam@PLT
	movslq	nb_nodes(%rip), %r12
	movq	%rax, %rdi
	movq	%rbp, %rcx
	xorl	%esi, %esi
	movq	%rax, starting(%rip)
	movq	%r12, %r13
	salq	$2, %r12
	movq	%r12, %rdx
	call	__memset_chk@PLT
	xorl	%edx, %edx
	movq	%rax, %rdi
	movq	degrees(%rip), %rax
	jmp	.L35
.L32:
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L45
	call	__cxa_throw_bad_array_new_length@PLT
.L35:
	incq	%rdx
	cmpl	%edx, %r13d
	jle	.L52
	movl	-4(%rax,%rdx,4), %ecx
	movl	%ecx, (%rdi,%rdx,4)
	jmp	.L35
.L52:
	movslq	-4(%rax,%r12), %rdi
	movabsq	$2305843009213693950, %rax
	movl	%edi, nb_links(%rip)
	cmpq	%rdi, %rax
	jb	.L37
	salq	$2, %rdi
	call	_Znam@PLT
	movq	%rax, links(%rip)
	movq	%rax, %rsi
	movl	nb_links(%rip), %eax
	movq	%rbx, %rdi
	leal	0(,%rax,4), %edx
	movslq	%edx, %rdx
	call	_ZNSi4readEPcl@PLT
	jmp	.L53
.L37:
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L45
	call	__cxa_throw_bad_array_new_length@PLT
.L53:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv@PLT
.LEHE1:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	je	.L42
	jmp	.L45
.L43:
	endbr64
	movq	%rax, %rbp
.L40:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L45
	movq	%rbp, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L45:
	call	__stack_chk_fail@PLT
.L42:
	addq	$536, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3766:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3766:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3766-.LLSDACSB3766
.LLSDACSB3766:
	.uleb128 .LEHB0-.LFB3766
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3766
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L43-.LFB3766
	.uleb128 0
	.uleb128 .LEHB2-.LFB3766
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE3766:
	.text
	.size	_Z8readFilePc, .-_Z8readFilePc
	.section	.rodata.str1.1
.LC7:
	.string	"Usage: %s <input file> <output file>\n"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3768:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	cmpl	$3, %edi
	je	.L55
	movq	(%rsi), %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC7(%rip), %rsi
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L55:
	movq	8(%rsi), %rdi
	movq	16(%rsi), %rbx
	call	_Z8readFilePc
	call	rand@PLT
	movq	%rbx, %rdi
	cltd
	idivl	nb_nodes(%rip)
	movl	%edx, starting_node_id(%rip)
	call	_Z8bfsGraphPc
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3768:
	.size	main, .-main
	.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	links
	.bss
	.align 8
	.type	links, @object
	.size	links, 8
links:
	.zero	8
	.globl	starting
	.align 8
	.type	starting, @object
	.size	starting, 8
starting:
	.zero	8
	.globl	degrees
	.align 8
	.type	degrees, @object
	.size	degrees, 8
degrees:
	.zero	8
	.globl	nb_links
	.align 4
	.type	nb_links, @object
	.size	nb_links, 4
nb_links:
	.zero	4
	.globl	nb_nodes
	.align 4
	.type	nb_nodes, @object
	.size	nb_nodes, 4
nb_nodes:
	.zero	4
	.globl	starting_node_id
	.align 4
	.type	starting_node_id, @object
	.size	starting_node_id, 4
starting_node_id:
	.zero	4
	.globl	infile
	.align 8
	.type	infile, @object
	.size	infile, 8
infile:
	.zero	8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1064304640
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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 <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/time.h>

using namespace std;

#include "bfs_kernel.cu"

/*
 * gpu_bfs.cu
 *
 *	Usage: ./executable <graph_file> <output file>
 *
 *	Input: Name of the file containing the graph. Expected format
 *			is binary with the following data (with no newlines)
 *			number of nodes (4 bytes)
 *			cumulative list of node degrees (4 bytes * numer of nodes)
 *			edge list (4 bytes * number of links)
 *			
 *			example: 4 nodes; node 0 edges: 1,2; node 1 edges: 0; node 1 edges: 3
 *			4
 *			0,2,3
 *			1,2,0,3
 *			written in binary with no newlines or commas
 *
 *	Output:
 *		stdout: Time it took kernel to run, in microseconds
 *		output file: Each node and its distance from starting node
 *					(0) cost:0
 *					(1) cost:3
 *		
 */

const int MAX_THREADS_PER_BLOCK = 256;
char *infile = NULL;

int starting_node_id;

int nb_nodes;
int nb_links;
int *degrees;
int *starting;
int *links;


void readFile(char *filename)
{
	ifstream finput(filename, ios::in | ios::binary);
	if(!finput.is_open())
	{
		cout << "Unable to open file" << endl;
		exit(EXIT_FAILURE);
	}

	// Read number of nodes, first 4 bytes of file
	finput.read((char*)&nb_nodes, 4);

	if (starting_node_id < 0 || starting_node_id > nb_nodes)
	{
		cerr << "Starting position is invalid" << endl;
		exit(EXIT_FAILURE);
	}

	// Read cumulative degrees, 4 bytes per node
	degrees = new int[nb_nodes];
	finput.read((char*) degrees, nb_nodes * 4);
	
	starting = new int[nb_nodes];
	memset(starting, 0, sizeof(int) * nb_nodes);
	for (int i = 1; i < nb_nodes; i++)
	{
		starting[i] = degrees[i - 1];
	}

	// Read links, 4 bytes per link
	nb_links = degrees[nb_nodes - 1];
	links = new int[nb_links];
	finput.read((char*) links, nb_links * 4);

	finput.close();
}


void bfsGraph(char *outFile)
{
	// allocate host memory
	Node *h_graph_nodes = (Node *) malloc(sizeof(Node) * nb_nodes);
	bool* h_graph_visited = (bool *) malloc(sizeof(bool) * nb_nodes);

	// Initialize memory of nodes
	h_graph_nodes[0].starting = 0;
	h_graph_nodes[0].no_of_edges = degrees[0];
	h_graph_visited[0] = false;
	for (unsigned int i = 1; i < nb_nodes; i++)
	{
		h_graph_nodes[i].starting = starting[i];
		h_graph_nodes[i].no_of_edges = degrees[i] - degrees[i-1];
		h_graph_visited[i] = false;
	}
	h_graph_visited[starting_node_id] = true;

	// Copy node list to cuda memory
	Node *d_graph_nodes;
	hipMalloc((void **) &d_graph_nodes, sizeof(Node) * nb_nodes);
	hipMemcpy(d_graph_nodes, h_graph_nodes, sizeof(Node) *
		nb_nodes, hipMemcpyHostToDevice);

	// Copy edge list to device memory
	int *d_edge_list;
	hipMalloc((void **) &d_edge_list, sizeof(int) * nb_links);
	hipMemcpy(d_edge_list, links, sizeof(int) * nb_links,
		hipMemcpyHostToDevice);

	// Copy the visted array to device memory
	bool *d_graph_visited;
	hipMalloc((void **) &d_graph_visited, sizeof(bool) * nb_nodes);
	hipMemcpy(d_graph_visited, h_graph_visited, sizeof(bool) *
		nb_nodes, hipMemcpyHostToDevice);

	// Allocate memory for the result on host
	int *h_cost = (int *) malloc(sizeof(int) * nb_nodes);
	for (int i = 0; i < nb_nodes; i++)
	{
		h_cost[i] = -1;
	}
	h_cost[starting_node_id] = 0;

	// Allocate device memory for result
	int *d_cost;
	hipMalloc((void **) &d_cost, sizeof(int) * nb_nodes);
	hipMemcpy(d_cost, h_cost, sizeof(int) * nb_nodes,
		hipMemcpyHostToDevice);

	// Determine number of blocks and threads
	int num_of_blocks = 1;	// at least 1
	int num_of_threads_per_block = nb_nodes;
	if (nb_nodes > MAX_THREADS_PER_BLOCK)
	{
		num_of_blocks = (int) ceil((double) nb_nodes/
			(double) MAX_THREADS_PER_BLOCK);
		num_of_threads_per_block = MAX_THREADS_PER_BLOCK;
	}

	bool *d_over;
	hipMalloc((void **) &d_over, sizeof(bool));
	bool stop;
	int level = 0;

	// Call the kernel at each level iteration
	struct timeval start, end;    
	gettimeofday(&start, NULL);
	do 
	{
		stop = false;
		hipMemcpy(d_over, &stop, sizeof(bool), 
			hipMemcpyHostToDevice);

		bfs_kernel<<<num_of_blocks, 
		num_of_threads_per_block>>>(d_graph_nodes, d_edge_list,
			 d_graph_visited, d_cost, level, d_over, nb_nodes);
		
		hipDeviceSynchronize();

		hipMemcpy(&stop, d_over, sizeof(bool),
			hipMemcpyDeviceToHost);
		level++;

	} while(stop);

	gettimeofday(&end, NULL);

	// print duration of all iterations of kernel execution
	printf("%ld\n",
           (end.tv_sec * 1000000 + end.tv_usec)
           - (start.tv_sec * 1000000 + start.tv_usec));
	
	hipMemcpy(h_cost, d_cost, sizeof(int) * nb_nodes,
		hipMemcpyDeviceToHost);
	
	hipMemcpy(h_graph_visited, d_graph_visited, sizeof(bool) *
			nb_nodes, hipMemcpyDeviceToHost);

	// Store results into a file
	FILE *fpo = fopen(outFile, "w");
	for (int i = 0; i < nb_nodes; i++)
	{
		fprintf(fpo, "(%d) cost:%d\n", i, h_cost[i]);
	}
	fclose(fpo);
	
	// clean up memory
	free(h_graph_nodes);
	free(links);
	free(h_graph_visited);
	free(h_cost);
	hipFree(d_graph_nodes);
	hipFree(d_edge_list);
	hipFree(d_graph_visited);
	hipFree(d_cost);

}

int main(int argc, char **argv)
{
	// Code for printing distances to an output file
	if (argc != 3)
	{
		printf("Usage: %s <input file> <output file>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	char *filename = argv[1];
	char*outFile = argv[2];
	
	readFile(filename);
	
	starting_node_id = rand() % nb_nodes;

	bfsGraph(outFile);
	return 0;
}
	.text
	.file	"gpu_bfs.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i # -- Begin function _Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i
	.type	_Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i,@function
_Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i: # @_Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i
	.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	$160, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	24(%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	208(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%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	$_Z10bfs_kernelP4NodePiPbS1_iS2_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	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	_Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i, .Lfunc_end0-_Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z8readFilePc                   # -- Begin function _Z8readFilePc
	.type	_Z8readFilePc,@function
_Z8readFilePc:                          # @_Z8readFilePc
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$528, %rsp                      # imm = 0x210
	.cfi_def_cfa_offset 560
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rsi
	leaq	8(%rsp), %rdi
	movl	$12, %edx
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode
	leaq	128(%rsp), %rdi
	callq	_ZNKSt12__basic_fileIcE7is_openEv
	testb	%al, %al
	je	.LBB1_1
# %bb.5:
.Ltmp4:
	leaq	8(%rsp), %rdi
	movl	$nb_nodes, %esi
	movl	$4, %edx
	callq	_ZNSi4readEPcl
.Ltmp5:
# %bb.6:
	movl	starting_node_id(%rip), %eax
	testl	%eax, %eax
	js	.LBB1_8
# %bb.7:
	movl	nb_nodes(%rip), %ebx
	cmpl	%ebx, %eax
	jg	.LBB1_8
# %bb.10:
	leaq	(,%rbx,4), %rdi
.Ltmp6:
	callq	_Znam
.Ltmp7:
# %bb.11:
	movq	%rax, degrees(%rip)
	shll	$2, %ebx
	movslq	%ebx, %rdx
.Ltmp8:
	leaq	8(%rsp), %rdi
	movq	%rax, %rsi
	callq	_ZNSi4readEPcl
.Ltmp9:
# %bb.12:
	movslq	nb_nodes(%rip), %r15
	leaq	(,%r15,4), %r14
	testq	%r15, %r15
	movq	$-1, %rdi
	cmovnsq	%r14, %rdi
.Ltmp10:
	callq	_Znam
.Ltmp11:
# %bb.13:
	movq	%rax, %rbx
	movq	%rax, starting(%rip)
	movq	%rax, %rdi
	xorl	%esi, %esi
	movq	%r14, %rdx
	callq	memset@PLT
	movq	degrees(%rip), %rax
	cmpl	$2, %r15d
	jl	.LBB1_16
# %bb.14:                               # %.lr.ph
	movl	%r15d, %ecx
	decq	%rcx
	xorl	%edx, %edx
.LBB1_15:                               # =>This Inner Loop Header: Depth=1
	movl	(%rax,%rdx,4), %esi
	movl	%esi, 4(%rbx,%rdx,4)
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB1_15
.LBB1_16:                               # %._crit_edge
	movslq	-4(%rax,%r15,4), %rax
	leaq	(,%rax,4), %rbx
	testq	%rax, %rax
	movl	%eax, nb_links(%rip)
	movq	$-1, %rdi
	cmovnsq	%rbx, %rdi
.Ltmp12:
	callq	_Znam
.Ltmp13:
# %bb.17:
	movq	%rax, links(%rip)
.Ltmp14:
	leaq	8(%rsp), %rdi
	movq	%rax, %rsi
	movq	%rbx, %rdx
	callq	_ZNSi4readEPcl
.Ltmp15:
# %bb.18:
.Ltmp16:
	leaq	8(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv
.Ltmp17:
# %bb.19:
	leaq	8(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	addq	$528, %rsp                      # imm = 0x210
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB1_8:
	.cfi_def_cfa_offset 560
.Ltmp18:
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.1, %esi
	movl	$28, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp19:
# %bb.9:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit9
.Ltmp20:
	movl	$_ZSt4cerr, %edi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
.Ltmp21:
	jmp	.LBB1_3
.LBB1_1:
.Ltmp0:
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$19, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp1:
# %bb.2:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
.Ltmp2:
	movl	$_ZSt4cout, %edi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
.Ltmp3:
.LBB1_3:                                # %_ZNSolsEPFRSoS_E.exit
	movl	$1, %edi
	callq	exit
.LBB1_4:
.Ltmp22:
	movq	%rax, %rbx
	leaq	8(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end1:
	.size	_Z8readFilePc, .Lfunc_end1-_Z8readFilePc
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table1:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp4-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp4
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp4-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp11-.Ltmp4                 #   Call between .Ltmp4 and .Ltmp11
	.uleb128 .Ltmp22-.Lfunc_begin0          #     jumps to .Ltmp22
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp11-.Lfunc_begin0          # >> Call Site 3 <<
	.uleb128 .Ltmp12-.Ltmp11                #   Call between .Ltmp11 and .Ltmp12
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp12-.Lfunc_begin0          # >> Call Site 4 <<
	.uleb128 .Ltmp3-.Ltmp12                 #   Call between .Ltmp12 and .Ltmp3
	.uleb128 .Ltmp22-.Lfunc_begin0          #     jumps to .Ltmp22
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 5 <<
	.uleb128 .Lfunc_end1-.Ltmp3             #   Call between .Ltmp3 and .Lfunc_end1
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z8bfsGraphPc
.LCPI2_0:
	.quad	0x3f70000000000000              # double 0.00390625
	.text
	.globl	_Z8bfsGraphPc
	.type	_Z8bfsGraphPc,@function
_Z8bfsGraphPc:                          # @_Z8bfsGraphPc
	.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	$104, %rsp
	.cfi_def_cfa_offset 160
	.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	%rdi, 56(%rsp)                  # 8-byte Spill
	movslq	nb_nodes(%rip), %r15
	leaq	(,%r15,8), %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %r13
	movl	$0, (%r14)
	movq	degrees(%rip), %rax
	movl	(%rax), %ecx
	movl	%ecx, 4(%r14)
	movb	$0, (%r13)
	cmpq	$2, %r15
	jb	.LBB2_3
# %bb.1:                                # %.lr.ph
	movl	%r15d, %edx
	movq	starting(%rip), %rsi
	decq	%rdx
	xorl	%edi, %edi
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	movl	4(%rsi,%rdi,4), %r8d
	movl	%r8d, 8(%r14,%rdi,8)
	movl	4(%rax,%rdi,4), %r8d
	movl	%r8d, %r9d
	subl	%ecx, %r9d
	movl	%r9d, 12(%r14,%rdi,8)
	movb	$0, 1(%r13,%rdi)
	incq	%rdi
	movl	%r8d, %ecx
	cmpq	%rdi, %rdx
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	movslq	starting_node_id(%rip), %rax
	movb	$1, (%r13,%rax)
	leaq	48(%rsp), %r15
	movq	%r15, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%r15), %rdi
	movslq	nb_nodes(%rip), %rdx
	shlq	$3, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	nb_links(%rip), %rsi
	shlq	$2, %rsi
	leaq	40(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movq	links(%rip), %rsi
	movslq	nb_links(%rip), %rdx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	nb_nodes(%rip), %rsi
	leaq	32(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movslq	nb_nodes(%rip), %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	nb_nodes(%rip), %r15
	leaq	(,%r15,4), %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r12
	testq	%r15, %r15
	jle	.LBB2_5
# %bb.4:                                # %.lr.ph56.preheader
	movl	%r15d, %edx
	shlq	$2, %rdx
	movq	%r12, %rdi
	movl	$255, %esi
	callq	memset@PLT
.LBB2_5:                                # %._crit_edge57
	movq	%r13, 64(%rsp)                  # 8-byte Spill
	movabsq	$4294967296, %rbp               # imm = 0x100000000
	movslq	starting_node_id(%rip), %rax
	movl	$0, (%r12,%rax,4)
	leaq	24(%rsp), %r15
	movq	%r15, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%r15), %rdi
	movslq	nb_nodes(%rip), %rdx
	shlq	$2, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	nb_nodes(%rip), %ebx
	cmpl	$257, %ebx                      # imm = 0x101
	jl	.LBB2_6
# %bb.7:
	cvtsi2sd	%ebx, %xmm0
	mulsd	.LCPI2_0(%rip), %xmm0
	callq	ceil@PLT
	cvttsd2si	%xmm0, %r13d
	orq	%rbp, %r13
	movl	$256, %ebx                      # imm = 0x100
	jmp	.LBB2_8
.LBB2_6:
	leaq	1(%rbp), %r13
.LBB2_8:
	leaq	16(%rsp), %rdi
	movl	$1, %esi
	callq	hipMalloc
	xorl	%ebp, %ebp
	leaq	72(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	%ebx, %r15d
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %r15
	leaq	15(%rsp), %rbx
.LBB2_9:                                # =>This Inner Loop Header: Depth=1
	movb	$0, 15(%rsp)
	movq	16(%rsp), %rdi
	movl	$1, %edx
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_11
# %bb.10:                               #   in Loop: Header=BB2_9 Depth=1
	movq	48(%rsp), %rdi
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rcx
	movq	16(%rsp), %r9
	movl	nb_nodes(%rip), %eax
	movl	%eax, (%rsp)
	movl	%ebp, %r8d
	callq	_Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i
.LBB2_11:                               #   in Loop: Header=BB2_9 Depth=1
	callq	hipDeviceSynchronize
	movq	16(%rsp), %rsi
	movl	$1, %edx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	incl	%ebp
	cmpb	$0, 15(%rsp)
	jne	.LBB2_9
# %bb.12:
	leaq	88(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx), %rax
	movq	8(%rbx), %rsi
	subq	72(%rsp), %rax
	imulq	$1000000, %rax, %rax            # imm = 0xF4240
	subq	80(%rsp), %rsi
	addq	%rax, %rsi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	movq	24(%rsp), %rsi
	movslq	nb_nodes(%rip), %rdx
	shlq	$2, %rdx
	movq	%r12, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rsi
	movslq	nb_nodes(%rip), %rdx
	movq	64(%rsp), %r13                  # 8-byte Reload
	movq	%r13, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.3, %esi
	movq	56(%rsp), %rdi                  # 8-byte Reload
	callq	fopen
	movq	%rax, %rbx
	cmpl	$0, nb_nodes(%rip)
	jle	.LBB2_15
# %bb.13:                               # %.lr.ph60.preheader
	xorl	%r15d, %r15d
.LBB2_14:                               # %.lr.ph60
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r12,%r15,4), %ecx
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movl	%r15d, %edx
	xorl	%eax, %eax
	callq	fprintf
	incq	%r15
	movslq	nb_nodes(%rip), %rax
	cmpq	%rax, %r15
	jl	.LBB2_14
.LBB2_15:                               # %._crit_edge61
	movq	%rbx, %rdi
	callq	fclose
	movq	%r14, %rdi
	callq	free
	movq	links(%rip), %rdi
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z8bfsGraphPc, .Lfunc_end2-_Z8bfsGraphPc
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	cmpl	$3, %edi
	jne	.LBB3_2
# %bb.1:
	movq	8(%rsi), %rdi
	movq	16(%rsi), %rbx
	callq	_Z8readFilePc
	callq	rand
	cltd
	idivl	nb_nodes(%rip)
	movl	%edx, starting_node_id(%rip)
	movq	%rbx, %rdi
	callq	_Z8bfsGraphPc
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB3_2:
	.cfi_def_cfa_offset 16
	movq	(%rsi), %rsi
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10bfs_kernelP4NodePiPbS1_iS2_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_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	_Z10bfs_kernelP4NodePiPbS1_iS2_i,@object # @_Z10bfs_kernelP4NodePiPbS1_iS2_i
	.section	.rodata,"a",@progbits
	.globl	_Z10bfs_kernelP4NodePiPbS1_iS2_i
	.p2align	3, 0x0
_Z10bfs_kernelP4NodePiPbS1_iS2_i:
	.quad	_Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i
	.size	_Z10bfs_kernelP4NodePiPbS1_iS2_i, 8

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

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

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

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

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

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

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Unable to open file"
	.size	.L.str, 20

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Starting position is invalid"
	.size	.L.str.1, 29

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%ld\n"
	.size	.L.str.2, 5

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"(%d) cost:%d\n"
	.size	.L.str.4, 14

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Usage: %s <input file> <output file>\n"
	.size	.L.str.5, 38

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10bfs_kernelP4NodePiPbS1_iS2_i"
	.size	.L__unnamed_1, 33

	.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 _Z25__device_stub__bfs_kernelP4NodePiPbS1_iS2_i
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z10bfs_kernelP4NodePiPbS1_iS2_i
	.addrsig_sym nb_nodes
	.addrsig_sym _ZSt4cout
	.addrsig_sym _ZSt4cerr
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10bfs_kernelP4NodePiPbS1_iS2_i ; -- Begin function _Z10bfs_kernelP4NodePiPbS1_iS2_i
	.globl	_Z10bfs_kernelP4NodePiPbS1_iS2_i
	.p2align	8
	.type	_Z10bfs_kernelP4NodePiPbS1_iS2_i,@function
_Z10bfs_kernelP4NodePiPbS1_iS2_i:       ; @_Z10bfs_kernelP4NodePiPbS1_iS2_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x44
	s_load_b32 s3, s[0:1], 0x30
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v2
	s_cbranch_execz .LBB0_7
; %bb.1:
	s_load_b256 s[4:11], s[0:1], 0x0
	v_ashrrev_i32_e32 v3, 31, v2
	s_load_b32 s2, s[0:1], 0x20
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s10, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v1, vcc_lo
	global_load_b32 v4, v[0:1], off
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, s2, v4
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_7
; %bb.2:
	v_lshlrev_b64 v[2:3], 3, v[2:3]
	s_mov_b32 s12, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v3, vcc_lo
	global_load_b32 v5, v[4:5], off offset:4
	s_waitcnt vmcnt(0)
	v_cmp_lt_i32_e32 vcc_lo, 0, v5
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_7
; %bb.3:                                ; %.lr.ph.preheader
	v_add_co_u32 v2, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	s_load_b64 s[2:3], s[0:1], 0x28
	v_dual_mov_b32 v13, 0 :: v_dual_mov_b32 v14, 1
	global_load_b32 v6, v[2:3], off
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v7, 31, v6
	v_mov_b32_e32 v4, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[7:8], 2, v[6:7]
	v_add_co_u32 v7, vcc_lo, s6, v7
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v8, vcc_lo, s7, v8, vcc_lo
.LBB0_4:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b32 v11, v[7:8], off
	s_mov_b32 s0, exec_lo
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v12, 31, v11
	v_add_co_u32 v9, vcc_lo, s8, v11
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v10, vcc_lo, s9, v12, vcc_lo
	global_load_u8 v15, v[9:10], off
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u16_e32 0, v15
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=1
	global_load_b32 v15, v[0:1], off
	v_lshlrev_b64 v[4:5], 2, v[11:12]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s10, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s11, v5, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v11, 1, v15
	global_store_b32 v[4:5], v11, off
	global_load_b64 v[4:5], v[2:3], off
	global_store_b8 v[9:10], v14, off
	s_waitcnt lgkmcnt(0)
	global_store_b8 v13, v14, s[2:3]
.LBB0_6:                                ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	v_add_nc_u32_e32 v6, 1, v6
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v9, v4, v5
	v_add_co_u32 v7, s0, v7, 4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v8, s0, 0, v8, s0
	v_cmp_ge_i32_e32 vcc_lo, v6, v9
	s_or_b32 s12, vcc_lo, s12
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s12
	s_cbranch_execnz .LBB0_4
.LBB0_7:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10bfs_kernelP4NodePiPbS1_iS2_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 312
		.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 16
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z10bfs_kernelP4NodePiPbS1_iS2_i, .Lfunc_end0-_Z10bfs_kernelP4NodePiPbS1_iS2_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 464
; NumSgprs: 18
; NumVgprs: 16
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 16
; 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .offset:         48
        .size:           4
        .value_kind:     by_value
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         60
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         64
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         68
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         70
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         72
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         74
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         76
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         78
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         112
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         120
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 312
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10bfs_kernelP4NodePiPbS1_iS2_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10bfs_kernelP4NodePiPbS1_iS2_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     16
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
