/*

   Jaitirth Jacob - 13CO125      Vidit Bhargava - 13CO151

*/

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

#define cudaCheckError() {                                          \
 cudaError_t e=cudaGetLastError();                                 \
 if(e!=cudaSuccess) {                                              \
   printf("Cuda failure %s:%d: '%s'\n",__FILE__,__LINE__,cudaGetErrorString(e));           \
   exit(0); \
 }                                                                 \
}

__global__ void bf_2flags(int *Na, int *src, int *F1, int *F2, int *exists, int *Sa, int *Ea, int threadsPerBlock )
{
	
	int id = blockIdx.x * threadsPerBlock + threadIdx.x;
	
	if (exists[id]==1)
	{
		Na[id] = 65000; //MAX INT Value		
		F1[id] = 0;
		F2[id] = 0;
		
		if (id == *src)
		{	//Starting node conditions			
			Na[id] = 0;
			F1[id] = 1;
		}

		for (int i = 0; i < 103689; ++i)
		{			
			if (F1[Sa[id]] == 1)
			{
				if (Na[Ea[id]] > Na[Sa[id]] + 1)
				{
					//Relax
					// atomicAdd(&Na[Ea[id]], Na[Sa[id]] + 1 - Na[Ea[id]]);
					Na[Ea[id]] = Na[Sa[id]] + 1;
					F2[Ea[id]] = 1;					
				}
			}

			//Swap flags
			F1[id] = F2[id];
			F2[id] = 0;			
		}
	}
}

#define N 8300
#define ROWS 103689
#define min_threads 16
#define max_threads 1024

int main(void)
{

	int size = N * sizeof(int);
	int *F1 = (int *)malloc(size), *F2 = (int *)malloc(size), *Na = (int *)malloc(size);
	int *Sa = (int *)malloc(ROWS * sizeof(int)), *Ea = (int *)malloc(ROWS * sizeof(int));
	int *exists = (int*)malloc(size);
	
	//File Operations
	FILE *ptr_file;
	char *buf;
	size_t len = 0;

	ptr_file = fopen("Wiki-Vote.txt", "r");

	if (!ptr_file)
	{
		printf("File Open Failed\n");
		return 0;
	}

	int m_left, m_right;

	//Set up the adjacency matrix
	for (long int i = 0; i < ROWS; ++i)
	{
		buf = (char *)malloc(30);
		getline(&buf, &len, ptr_file);
		m_left = atoi(strsep(&buf, "\t"));
		m_right = atoi(strsep(&buf, "\n"));
		
		exists[m_left] = 1;
		exists[m_right] = 1;

		Sa[i] = m_left;
		Ea[i] = m_right;
	}

	
	int src;
	printf("Enter source node: ");
	scanf("%d", &src);
	int *d_src;
	cudaMalloc((void **)&d_src, sizeof(int));
	cudaMemcpy(d_src, &src, sizeof(int), cudaMemcpyHostToDevice);

	//Timing events
	cudaEvent_t start, stop;

	int numBlocks;
	int *d_F1, *d_F2, *d_Na, *d_Sa, *d_Ea, *d_exists;

	printf("Threads Per Block\tTime(ms)\n");
	for (int threadsPerBlock = min_threads; threadsPerBlock <= max_threads; threadsPerBlock*=2)
	{
		numBlocks = (N/1024 + 1) * 1024 / 16;

		//Allocate space for all inputs and copy them
		
		cudaMalloc((void **)&d_F1, size);
		cudaMalloc((void **)&d_F2, size);
		cudaMalloc((void **)&d_Na, size);
		cudaMalloc((void **)&d_Sa, ROWS*sizeof(int));
		cudaMalloc((void **)&d_Ea, ROWS*sizeof(int));
		cudaMalloc((void **)&d_exists, size);
		cudaMemcpy(d_F1, F1, size, cudaMemcpyHostToDevice);
		cudaMemcpy(d_F2, F2, size, cudaMemcpyHostToDevice);
		cudaMemcpy(d_Na, Na, size, cudaMemcpyHostToDevice);
		cudaMemcpy(d_Sa, Sa, ROWS*sizeof(int), cudaMemcpyHostToDevice);
		cudaMemcpy(d_Ea, Ea, ROWS*sizeof(int), cudaMemcpyHostToDevice);
		cudaMemcpy(d_exists, exists, size, cudaMemcpyHostToDevice);

		//Run kernel
		cudaEventCreate(&start);
		cudaEventCreate(&stop);

		cudaEventRecord(start);
		bf_2flags<<<numBlocks, threadsPerBlock>>>(d_Na, d_src, d_F1, d_F2, d_exists, d_Sa, d_Ea, threadsPerBlock);
		cudaEventRecord(stop);
		cudaEventSynchronize(stop);
		float t = 0;
		cudaEventElapsedTime(&t, start, stop);
		printf("%d\t\t%f\n", threadsPerBlock, t);
		cudaEventDestroy(start);
		cudaEventDestroy(stop);
	}

	

	//Copy result back from device to host
	cudaMemcpy(Na, d_Na, N*sizeof(int), cudaMemcpyDeviceToHost);
	
	//Output display
	
	printf("Nodes reachable from %d\n", src);
	for (int i = 0; i < N; ++i)
	{
		if (exists[i]==0)
		{
			continue;
		}
		if (Na[i] == 65000)
		{
			//printf("U ");
		}
		else
		{printf("%d : %d\n", i, Na[i]);}
	}

	//Check for errors in Cuda
	cudaCheckError();

	//Cleanup
	free(F1); free(F2); free(exists); free(Na); free(Sa); free(Ea);
	cudaFree(d_F1); cudaFree(d_F2); cudaFree(d_Na); cudaFree(d_Sa); cudaFree(d_Ea);

	return 0;

}

	.file	"tmpxft_002dc0c0_00000000-6_q5_adjList.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z41__device_stub__Z9bf_2flagsPiS_S_S_S_S_S_iPiS_S_S_S_S_S_i
	.type	_Z41__device_stub__Z9bf_2flagsPiS_S_S_S_S_S_iPiS_S_S_S_S_S_i, @function
_Z41__device_stub__Z9bf_2flagsPiS_S_S_S_S_S_iPiS_S_S_S_S_S_i:
.LFB2052:
	.cfi_startproc
	endbr64
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	224(%rsp), %rax
	movq	%rdi, 56(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movq	%rcx, 32(%rsp)
	leaq	80(%rsp), %rcx
	movq	%r8, 24(%rsp)
	movq	%r9, 16(%rsp)
	movq	%rax, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 96(%rsp)
	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)
	leaq	232(%rsp), %rax
	movq	%rax, 192(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 88(%rsp)
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	80(%rsp)
	.cfi_def_cfa_offset 232
	leaq	_Z9bf_2flagsPiS_S_S_S_S_S_i(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 240
	movq	116(%rsp), %rcx
	movl	124(%rsp), %r8d
	movq	104(%rsp), %rsi
	movl	112(%rsp), %edx
	leaq	152(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 232
	popq	%rdx
	.cfi_def_cfa_offset 224
.L2:
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$216, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z41__device_stub__Z9bf_2flagsPiS_S_S_S_S_S_iPiS_S_S_S_S_S_i, .-_Z41__device_stub__Z9bf_2flagsPiS_S_S_S_S_S_iPiS_S_S_S_S_S_i
	.globl	_Z9bf_2flagsPiS_S_S_S_S_S_i
	.type	_Z9bf_2flagsPiS_S_S_S_S_S_i, @function
_Z9bf_2flagsPiS_S_S_S_S_S_i:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z9bf_2flagsPiS_S_S_S_S_S_iPiS_S_S_S_S_S_i
	.cfi_endproc
.LFE2053:
	.size	_Z9bf_2flagsPiS_S_S_S_S_S_i, .-_Z9bf_2flagsPiS_S_S_S_S_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"Wiki-Vote.txt"
.LC2:
	.string	"File Open Failed\n"
.LC3:
	.string	"\t"
.LC4:
	.string	"\n"
.LC5:
	.string	"Enter source node: "
.LC6:
	.string	"%d"
.LC7:
	.string	"Threads Per Block\tTime(ms)\n"
.LC9:
	.string	"%d\t\t%f\n"
.LC10:
	.string	"Nodes reachable from %d\n"
.LC11:
	.string	"%d : %d\n"
.LC12:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/vidit23/ParallelProgramming/master/Assignment-3/q5/q5_adjList.cu"
.LC13:
	.string	"Cuda failure %s:%d: '%s'\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$33200, %edi
	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	$168, %rsp
	.cfi_def_cfa_offset 224
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$33200, %edi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movl	$33200, %edi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	movl	$414756, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$414756, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movl	$33200, %edi
	movq	%rax, (%rsp)
	call	malloc@PLT
	xorl	%ecx, %ecx
	leaq	.LC0(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	movq	%rcx, 48(%rsp)
	movq	%rax, %rbx
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L25
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
.L25:
	movq	%rax, %r13
	xorl	%r14d, %r14d
.L9:
	movl	$30, %edi
	call	malloc@PLT
	movq	%r13, %rdx
	leaq	48(%rsp), %rsi
	movq	%rax, 40(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	getline@PLT
	movq	8(%rsp), %rdi
	leaq	.LC3(%rip), %rsi
	call	strsep@PLT
	movq	%rax, %rdi
	call	atoi@PLT
	movq	8(%rsp), %rdi
	leaq	.LC4(%rip), %rsi
	movl	%eax, %r15d
	call	strsep@PLT
	movq	%rax, %rdi
	call	atoi@PLT
	movq	(%rsp), %rcx
	movslq	%r15d, %rsi
	movl	%r15d, (%r12,%r14,4)
	movl	$1, (%rbx,%rsi,4)
	movslq	%eax, %rsi
	movl	%eax, (%rcx,%r14,4)
	incq	%r14
	movl	$1, (%rbx,%rsi,4)
	cmpq	$103689, %r14
	jne	.L9
	leaq	36(%rsp), %r13
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r13, %rsi
	leaq	.LC6(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	56(%rsp), %rdi
	movl	$4, %esi
	movl	$7, %r14d
	call	cudaMalloc@PLT
	movq	56(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %ecx
	movl	$4, %edx
	movl	$16, %r13d
	movabsq	$4294967297, %r15
	call	cudaMemcpy@PLT
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L12:
	leaq	80(%rsp), %rdi
	movl	$33200, %esi
	call	cudaMalloc@PLT
	leaq	88(%rsp), %rdi
	movl	$33200, %esi
	call	cudaMalloc@PLT
	leaq	96(%rsp), %rdi
	movl	$33200, %esi
	call	cudaMalloc@PLT
	leaq	104(%rsp), %rdi
	movl	$414756, %esi
	call	cudaMalloc@PLT
	leaq	112(%rsp), %rdi
	movl	$414756, %esi
	call	cudaMalloc@PLT
	leaq	120(%rsp), %rdi
	movl	$33200, %esi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rsi
	movq	80(%rsp), %rdi
	movl	$1, %ecx
	movl	$33200, %edx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rsi
	movq	88(%rsp), %rdi
	movl	$1, %ecx
	movl	$33200, %edx
	call	cudaMemcpy@PLT
	movq	96(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$33200, %edx
	call	cudaMemcpy@PLT
	movq	104(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$414756, %edx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	movq	112(%rsp), %rdi
	movl	$1, %ecx
	movl	$414756, %edx
	call	cudaMemcpy@PLT
	movq	120(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$33200, %edx
	call	cudaMemcpy@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	72(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$67108873, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r15, 144(%rsp)
	movl	148(%rsp), %ecx
	salq	$6, %rdi
	movl	$1, %esi
	movl	%r13d, 140(%rsp)
	movq	140(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	pushq	%r13
	.cfi_def_cfa_offset 232
	pushq	120(%rsp)
	.cfi_def_cfa_offset 240
	movq	120(%rsp), %r9
	movq	136(%rsp), %r8
	movq	104(%rsp), %rcx
	movq	96(%rsp), %rdx
	movq	72(%rsp), %rsi
	movq	112(%rsp), %rdi
	call	_Z41__device_stub__Z9bf_2flagsPiS_S_S_S_S_S_iPiS_S_S_S_S_S_i
	popq	%rax
	.cfi_def_cfa_offset 232
	popq	%rdx
	.cfi_def_cfa_offset 224
.L11:
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	leaq	140(%rsp), %rdi
	movl	$0x00000000, 140(%rsp)
	call	cudaEventElapsedTime@PLT
	movl	%r13d, %edx
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC9(%rip), %rsi
	addl	%r13d, %r13d
	cvtss2sd	140(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	64(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	72(%rsp), %rdi
	call	cudaEventDestroy@PLT
	decl	%r14d
	jne	.L12
	movq	96(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	xorl	%r14d, %r14d
	movl	$33200, %edx
	leaq	.LC11(%rip), %r13
	call	cudaMemcpy@PLT
	movl	36(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC10(%rip), %rsi
	call	__printf_chk@PLT
.L14:
	cmpl	$0, (%rbx,%r14,4)
	je	.L13
	movl	0(%rbp,%r14,4), %ecx
	cmpl	$65000, %ecx
	je	.L13
	movl	%r14d, %edx
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L13:
	incq	%r14
	cmpq	$8300, %r14
	jne	.L14
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L15
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	movl	$171, %ecx
	leaq	.LC12(%rip), %rdx
	movq	%rax, %r8
	leaq	.LC13(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	exit@PLT
.L15:
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	free@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rdi
	call	cudaFree@PLT
	movq	112(%rsp), %rdi
	call	cudaFree@PLT
.L10:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$168, %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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z9bf_2flagsPiS_S_S_S_S_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.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	.LC14(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9bf_2flagsPiS_S_S_S_S_S_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
.LFE2055:
	.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
	.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:

/*

   Jaitirth Jacob - 13CO125      Vidit Bhargava - 13CO151

*/


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

#define cudaCheckError() {                                          \
 hipError_t e=hipGetLastError();                                 \
 if(e!=hipSuccess) {                                              \
   printf("Cuda failure %s:%d: '%s'\n",__FILE__,__LINE__,hipGetErrorString(e));           \
   exit(0); \
 }                                                                 \
}

__global__ void bf_2flags(int *Na, int *src, int *F1, int *F2, int *exists, int *Sa, int *Ea, int threadsPerBlock )
{
	
	int id = blockIdx.x * threadsPerBlock + threadIdx.x;
	
	if (exists[id]==1)
	{
		Na[id] = 65000; //MAX INT Value		
		F1[id] = 0;
		F2[id] = 0;
		
		if (id == *src)
		{	//Starting node conditions			
			Na[id] = 0;
			F1[id] = 1;
		}

		for (int i = 0; i < 103689; ++i)
		{			
			if (F1[Sa[id]] == 1)
			{
				if (Na[Ea[id]] > Na[Sa[id]] + 1)
				{
					//Relax
					// atomicAdd(&Na[Ea[id]], Na[Sa[id]] + 1 - Na[Ea[id]]);
					Na[Ea[id]] = Na[Sa[id]] + 1;
					F2[Ea[id]] = 1;					
				}
			}

			//Swap flags
			F1[id] = F2[id];
			F2[id] = 0;			
		}
	}
}

#define N 8300
#define ROWS 103689
#define min_threads 16
#define max_threads 1024

int main(void)
{

	int size = N * sizeof(int);
	int *F1 = (int *)malloc(size), *F2 = (int *)malloc(size), *Na = (int *)malloc(size);
	int *Sa = (int *)malloc(ROWS * sizeof(int)), *Ea = (int *)malloc(ROWS * sizeof(int));
	int *exists = (int*)malloc(size);
	
	//File Operations
	FILE *ptr_file;
	char *buf;
	size_t len = 0;

	ptr_file = fopen("Wiki-Vote.txt", "r");

	if (!ptr_file)
	{
		printf("File Open Failed\n");
		return 0;
	}

	int m_left, m_right;

	//Set up the adjacency matrix
	for (long int i = 0; i < ROWS; ++i)
	{
		buf = (char *)malloc(30);
		getline(&buf, &len, ptr_file);
		m_left = atoi(strsep(&buf, "\t"));
		m_right = atoi(strsep(&buf, "\n"));
		
		exists[m_left] = 1;
		exists[m_right] = 1;

		Sa[i] = m_left;
		Ea[i] = m_right;
	}

	
	int src;
	printf("Enter source node: ");
	scanf("%d", &src);
	int *d_src;
	hipMalloc((void **)&d_src, sizeof(int));
	hipMemcpy(d_src, &src, sizeof(int), hipMemcpyHostToDevice);

	//Timing events
	hipEvent_t start, stop;

	int numBlocks;
	int *d_F1, *d_F2, *d_Na, *d_Sa, *d_Ea, *d_exists;

	printf("Threads Per Block\tTime(ms)\n");
	for (int threadsPerBlock = min_threads; threadsPerBlock <= max_threads; threadsPerBlock*=2)
	{
		numBlocks = (N/1024 + 1) * 1024 / 16;

		//Allocate space for all inputs and copy them
		
		hipMalloc((void **)&d_F1, size);
		hipMalloc((void **)&d_F2, size);
		hipMalloc((void **)&d_Na, size);
		hipMalloc((void **)&d_Sa, ROWS*sizeof(int));
		hipMalloc((void **)&d_Ea, ROWS*sizeof(int));
		hipMalloc((void **)&d_exists, size);
		hipMemcpy(d_F1, F1, size, hipMemcpyHostToDevice);
		hipMemcpy(d_F2, F2, size, hipMemcpyHostToDevice);
		hipMemcpy(d_Na, Na, size, hipMemcpyHostToDevice);
		hipMemcpy(d_Sa, Sa, ROWS*sizeof(int), hipMemcpyHostToDevice);
		hipMemcpy(d_Ea, Ea, ROWS*sizeof(int), hipMemcpyHostToDevice);
		hipMemcpy(d_exists, exists, size, hipMemcpyHostToDevice);

		//Run kernel
		hipEventCreate(&start);
		hipEventCreate(&stop);

		hipEventRecord(start);
		bf_2flags<<<numBlocks, threadsPerBlock>>>(d_Na, d_src, d_F1, d_F2, d_exists, d_Sa, d_Ea, threadsPerBlock);
		hipEventRecord(stop);
		hipEventSynchronize(stop);
		float t = 0;
		hipEventElapsedTime(&t, start, stop);
		printf("%d\t\t%f\n", threadsPerBlock, t);
		hipEventDestroy(start);
		hipEventDestroy(stop);
	}

	

	//Copy result back from device to host
	hipMemcpy(Na, d_Na, N*sizeof(int), hipMemcpyDeviceToHost);
	
	//Output display
	
	printf("Nodes reachable from %d\n", src);
	for (int i = 0; i < N; ++i)
	{
		if (exists[i]==0)
		{
			continue;
		}
		if (Na[i] == 65000)
		{
			//printf("U ");
		}
		else
		{printf("%d : %d\n", i, Na[i]);}
	}

	//Check for errors in Cuda
	cudaCheckError();

	//Cleanup
	free(F1); free(F2); free(exists); free(Na); free(Sa); free(Ea);
	hipFree(d_F1); hipFree(d_F2); hipFree(d_Na); hipFree(d_Sa); hipFree(d_Ea);

	return 0;

}

	.text
	.file	"q5_adjList.hip"
	.globl	_Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_i # -- Begin function _Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_i
	.type	_Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_i,@function
_Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_i: # @_Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_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	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	16(%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	216(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z9bf_2flagsPiS_S_S_S_S_S_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	_Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_i, .Lfunc_end0-_Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_i
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$33200, %edi                    # imm = 0x81B0
	callq	malloc
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	movl	$33200, %edi                    # imm = 0x81B0
	callq	malloc
	movq	%rax, %r12
	movl	$33200, %edi                    # imm = 0x81B0
	callq	malloc
	movq	%rax, %rbx
	movl	$414756, %edi                   # imm = 0x65424
	callq	malloc
	movq	%rax, %r15
	movl	$414756, %edi                   # imm = 0x65424
	callq	malloc
	movq	%rax, %r13
	movl	$33200, %edi                    # imm = 0x81B0
	callq	malloc
	movq	%rax, %r14
	movq	$0, 136(%rsp)
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_16
# %bb.1:                                # %.preheader.preheader
	movq	%r12, 112(%rsp)                 # 8-byte Spill
	movq	%rbx, 120(%rsp)                 # 8-byte Spill
	movq	%r15, 32(%rsp)                  # 8-byte Spill
	movq	%r13, 40(%rsp)                  # 8-byte Spill
	xorl	%r13d, %r13d
	leaq	144(%rsp), %r12
	movl	$1, %ebx
	movq	%rax, %rbp
.LBB1_2:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movl	$30, %edi
	callq	malloc
	movq	%rax, 144(%rsp)
	movq	%r12, %rdi
	leaq	136(%rsp), %rsi
	movq	%rbp, %rdx
	callq	getline
	movl	$.L.str.3, %esi
	movq	%r12, %rdi
	callq	strsep
	movq	%rax, %rdi
	callq	atoi
	movl	%eax, %r15d
	movl	$.L.str.4, %esi
	movq	%r12, %rdi
	callq	strsep
	movq	%rax, %rdi
	callq	atoi
	movslq	%r15d, %rcx
	movl	%ebx, (%r14,%rcx,4)
	cltq
	movl	%ebx, (%r14,%rax,4)
	movq	32(%rsp), %rdx                  # 8-byte Reload
	movl	%ecx, (%rdx,%r13,4)
	movq	40(%rsp), %rcx                  # 8-byte Reload
	movl	%eax, (%rcx,%r13,4)
	incq	%r13
	cmpq	$103689, %r13                   # imm = 0x19509
	jne	.LBB1_2
# %bb.3:
	movq	%r14, %r15
	movabsq	$4294967296, %r12               # imm = 0x100000000
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	92(%rsp), %rbx
	movl	$.L.str.6, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	leaq	128(%rsp), %r14
	movl	$4, %esi
	movq	%r14, %rdi
	callq	hipMalloc
	movq	(%r14), %rdi
	movl	$4, %edx
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$16, %r14d
	addq	$576, %r12                      # imm = 0x240
	movq	120(%rsp), %r13                 # 8-byte Reload
	movq	96(%rsp), %rbx                  # 8-byte Reload
	movq	112(%rsp), %rbp                 # 8-byte Reload
.LBB1_4:                                # =>This Inner Loop Header: Depth=1
	movl	$33200, %esi                    # imm = 0x81B0
	leaq	72(%rsp), %rdi
	callq	hipMalloc
	movl	$33200, %esi                    # imm = 0x81B0
	leaq	64(%rsp), %rdi
	callq	hipMalloc
	movl	$33200, %esi                    # imm = 0x81B0
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	movl	$414756, %esi                   # imm = 0x65424
	leaq	56(%rsp), %rdi
	callq	hipMalloc
	movl	$414756, %esi                   # imm = 0x65424
	leaq	48(%rsp), %rdi
	callq	hipMalloc
	movl	$33200, %esi                    # imm = 0x81B0
	leaq	104(%rsp), %rdi
	callq	hipMalloc
	movq	72(%rsp), %rdi
	movl	$33200, %edx                    # imm = 0x81B0
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	64(%rsp), %rdi
	movl	$33200, %edx                    # imm = 0x81B0
	movq	%rbp, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	movl	$33200, %edx                    # imm = 0x81B0
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	56(%rsp), %rdi
	movl	$414756, %edx                   # imm = 0x65424
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	movq	48(%rsp), %rdi
	movl	$414756, %edx                   # imm = 0x65424
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	movq	104(%rsp), %rdi
	movl	$33200, %edx                    # imm = 0x81B0
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	80(%rsp), %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	%r14d, %edx
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdx
	movq	%r12, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_6
# %bb.5:                                #   in Loop: Header=BB1_4 Depth=1
	movq	16(%rsp), %rdi
	movq	128(%rsp), %rsi
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rcx
	movq	104(%rsp), %r8
	movq	56(%rsp), %r9
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	_Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_i
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.LBB1_6:                                #   in Loop: Header=BB1_4 Depth=1
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	24(%rsp), %rdi
	callq	hipEventSynchronize
	movl	$0, 12(%rsp)
	movq	80(%rsp), %rsi
	movq	24(%rsp), %rdx
	leaq	12(%rsp), %rdi
	callq	hipEventElapsedTime
	cvtss2sd	12(%rsp), %xmm0
	movl	$.L.str.8, %edi
	movl	%r14d, %esi
	movb	$1, %al
	callq	printf
	movq	80(%rsp), %rdi
	callq	hipEventDestroy
	movq	24(%rsp), %rdi
	callq	hipEventDestroy
	leal	(%r14,%r14), %eax
	cmpl	$513, %r14d                     # imm = 0x201
	movl	%eax, %r14d
	jb	.LBB1_4
# %bb.7:
	movq	16(%rsp), %rsi
	movl	$33200, %edx                    # imm = 0x81B0
	movq	%r13, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	92(%rsp), %esi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%ebx, %ebx
.LBB1_8:                                # =>This Inner Loop Header: Depth=1
	cmpl	$0, (%r15,%rbx,4)
	je	.LBB1_11
# %bb.9:                                #   in Loop: Header=BB1_8 Depth=1
	movl	(%r13,%rbx,4), %edx
	cmpl	$65000, %edx                    # imm = 0xFDE8
	je	.LBB1_11
# %bb.10:                               #   in Loop: Header=BB1_8 Depth=1
	movl	$.L.str.10, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
.LBB1_11:                               #   in Loop: Header=BB1_8 Depth=1
	incq	%rbx
	cmpq	$8300, %rbx                     # imm = 0x206C
	jne	.LBB1_8
# %bb.12:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_15
# %bb.13:
	movq	96(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%rbp, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	40(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	72(%rsp), %rdi
	callq	hipFree
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	jmp	.LBB1_14
.LBB1_16:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB1_14:
	xorl	%eax, %eax
	addq	$152, %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_15:
	.cfi_def_cfa_offset 208
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %edi
	movl	$.L.str.12, %esi
	movl	$173, %edx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	printf
	xorl	%edi, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9bf_2flagsPiS_S_S_S_S_S_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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9bf_2flagsPiS_S_S_S_S_S_i,@object # @_Z9bf_2flagsPiS_S_S_S_S_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z9bf_2flagsPiS_S_S_S_S_S_i
	.p2align	3, 0x0
_Z9bf_2flagsPiS_S_S_S_S_S_i:
	.quad	_Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_i
	.size	_Z9bf_2flagsPiS_S_S_S_S_S_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Wiki-Vote.txt"
	.size	.L.str, 14

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"r"
	.size	.L.str.1, 2

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\n"
	.size	.L.str.4, 2

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Enter source node: "
	.size	.L.str.5, 20

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"%d\t\t%f\n"
	.size	.L.str.8, 8

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Nodes reachable from %d\n"
	.size	.L.str.9, 25

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

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Cuda failure %s:%d: '%s'\n"
	.size	.L.str.11, 26

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/vidit23/ParallelProgramming/master/Assignment-3/q5/q5_adjList.hip"
	.size	.L.str.12, 128

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9bf_2flagsPiS_S_S_S_S_S_i"
	.size	.L__unnamed_1, 28

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

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"File Open Failed"
	.size	.Lstr, 17

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Threads Per Block\tTime(ms)"
	.size	.Lstr.1, 27

	.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 _Z24__device_stub__bf_2flagsPiS_S_S_S_S_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9bf_2flagsPiS_S_S_S_S_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9bf_2flagsPiS_S_S_S_S_S_i ; -- Begin function _Z9bf_2flagsPiS_S_S_S_S_S_i
	.globl	_Z9bf_2flagsPiS_S_S_S_S_S_i
	.p2align	8
	.type	_Z9bf_2flagsPiS_S_S_S_S_S_i,@function
_Z9bf_2flagsPiS_S_S_S_S_S_i:            ; @_Z9bf_2flagsPiS_S_S_S_S_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x38
	s_load_b128 s[16:19], s[0:1], 0x20
	s_waitcnt lgkmcnt(0)
	v_mad_u64_u32 v[4:5], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[6:7], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s16, v6
	v_add_co_ci_u32_e32 v1, vcc_lo, s17, v7, vcc_lo
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u32_e32 1, v0
	s_cbranch_execz .LBB0_8
; %bb.1:
	s_load_b256 s[4:11], s[0:1], 0x0
	v_dual_mov_b32 v5, 0xfde8 :: v_dual_mov_b32 v10, 0
	s_load_b128 s[0:3], s[0:1], 0x30
	s_waitcnt lgkmcnt(0)
	s_mov_b32 s2, exec_lo
	v_add_co_u32 v8, vcc_lo, s4, v6
	v_add_co_ci_u32_e32 v9, vcc_lo, s5, v7, vcc_lo
	v_add_co_u32 v0, vcc_lo, s8, v6
	v_add_co_ci_u32_e32 v1, vcc_lo, s9, v7, vcc_lo
	v_add_co_u32 v2, vcc_lo, s10, v6
	v_add_co_ci_u32_e32 v3, vcc_lo, s11, v7, vcc_lo
	global_store_b32 v[8:9], v5, off
	global_store_b32 v[0:1], v10, off
	global_store_b32 v[2:3], v10, off
	global_load_b32 v5, v10, s[6:7]
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u32_e64 v4, v5
	s_cbranch_execz .LBB0_3
; %bb.2:
	v_mov_b32_e32 v4, 1
	global_store_b32 v[8:9], v10, off
	global_store_b32 v[0:1], v4, off
.LBB0_3:
	s_or_b32 exec_lo, exec_lo, s2
	v_add_co_u32 v4, vcc_lo, s18, v6
	v_add_co_ci_u32_e32 v5, vcc_lo, s19, v7, vcc_lo
	v_add_co_u32 v6, vcc_lo, s0, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s1, v7, vcc_lo
	v_mov_b32_e32 v11, 1
	s_mov_b32 s0, 0x19509
.LBB0_4:                                ; =>This Inner Loop Header: Depth=1
	global_load_b32 v8, v[4:5], off
	s_mov_b32 s1, 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[8:9], 2, v[8:9]
	v_add_co_u32 v12, vcc_lo, s8, v8
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v13, vcc_lo, s9, v9, vcc_lo
	global_load_b32 v12, v[12:13], off
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u32_e32 1, v12
	s_cbranch_execz .LBB0_7
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=1
	global_load_b32 v12, v[6:7], off
	v_add_co_u32 v14, vcc_lo, s4, v8
	v_add_co_ci_u32_e32 v15, vcc_lo, s5, v9, vcc_lo
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v13, 31, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[12:13], 2, v[12:13]
	v_add_co_u32 v8, vcc_lo, s4, v12
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v9, vcc_lo, s5, v13, vcc_lo
	s_clause 0x1
	global_load_b32 v12, v[14:15], off
	global_load_b32 v13, v[8:9], off
	s_waitcnt vmcnt(1)
	v_add_nc_u32_e32 v12, 1, v12
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_gt_i32_e32 vcc_lo, v13, v12
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_7
; %bb.6:                                ;   in Loop: Header=BB0_4 Depth=1
	global_store_b32 v[8:9], v12, off
	global_load_b32 v8, v[6:7], off
	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[8:9], 2, v[8:9]
	v_add_co_u32 v8, vcc_lo, s10, v8
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v9, vcc_lo, s11, v9, vcc_lo
	global_store_b32 v[8:9], v11, off
.LBB0_7:                                ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	global_load_b32 v8, v[2:3], off
	s_add_i32 s0, s0, -1
	s_waitcnt vmcnt(0)
	global_store_b32 v[0:1], v8, off
	global_store_b32 v[2:3], v10, off
	s_cmp_lg_u32 s0, 0
	s_cbranch_scc1 .LBB0_4
.LBB0_8:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9bf_2flagsPiS_S_S_S_S_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 60
		.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 20
		.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	_Z9bf_2flagsPiS_S_S_S_S_S_i, .Lfunc_end0-_Z9bf_2flagsPiS_S_S_S_S_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 556
; NumSgprs: 22
; NumVgprs: 16
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 22
; 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
      - .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
      - .offset:         56
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 60
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9bf_2flagsPiS_S_S_S_S_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z9bf_2flagsPiS_S_S_S_S_S_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
