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

struct node{
	int dst;
	struct node* next;
};

struct list{
	struct node *head;
};

struct graph{
	int n;
	struct list* set;
};

struct node* new_node(int dst){
	struct node* newnode = (struct node*)malloc(sizeof(struct node));
	newnode -> dst = dst;
	newnode -> next = NULL;

	return newnode;
}

struct graph* new_graph(int n){
	struct graph* newgraph = (struct graph*)malloc(sizeof(struct node));
	newgraph -> n = n;
	
	newgraph -> set = (struct list*)malloc(n * sizeof(struct list)) ;

	int i;
	for(i=0;i<n;i++)
		newgraph->set[i].head = NULL;

	return newgraph;

}

void addEdge(struct graph* gph, int src, int dst){
	struct node* newnode = new_node(dst);
	newnode->next = gph->set[src].head;
	gph->set[src].head = newnode;

	newnode = new_node(src);
        newnode->next = gph->set[dst].head;
        gph->set[dst].head = newnode;
}


__global__ void add( int *a, int *b, int *c, int vector_size ) {
    
    // Calculate the index in the vector for the thread using the internal variables
    int tid = blockIdx.x * blockDim.x + threadIdx.x; // HERE
    
    // This if statement is added in case we have more threads executing
    // Than number of elements in the vectors. How can this help?
    if (tid < vector_size){
        
        // Compute the addition
        c[tid] = a[tid] + b[tid];
        
    }
}

long get_vert(char *str){
	char vert[20];
	int space_count = 0;
	int num_vert=0;	
	
	int i=0, j=0;
	while(str[i] != '\n'){
	
		if(str[i] == ' ')
			space_count++;
		if(space_count == 2){
			vert[j] = str[i];
			j++;
		}
		else if(space_count>2)	
			break;
		i++;
	}
	vert[j] = '\0';
    	//printf("%s\n", vert);
	num_vert = atoi(vert);
    	//printf("%d\n", num_vert);
	return num_vert;
	
}

int get_src(char *str){
	char s[20];
        int space_count = 0;
        int src=0;

        int i=0, j=0;
        while(str[i] != '\n'){

                if(str[i] == ' ')
                        space_count++;
                if(space_count == 0){
                        s[j] = str[i];
                        j++;
                }
		else
			break;
                i++;
        }
        s[j] = '\0';
        //printf("%s\n", s);
        src = atoi(s);
        //printf("%d\n", src);
        return src;
}

int get_dst(char *str){
	char d[20];
        int space_count = 0;
        int dst=0;

        int i=0, j=0;
        while(str[i] != '\n'){

                if(str[i] == ' ')
                        space_count++;
                if(space_count == 1){
                        d[j] = str[i];
                        j++;
                }
		else if(space_count>1)
			break;
                i++;
        }
        d[j] = '\0';
        //printf("%s\n", d);
        dst = atoi(d);
        //printf("%d\n", dst);
        return dst;
}

int compare (const void * a, const void * b)
{
  return ( *(int*)b - *(int*)a );
}


int main( int argc, char* argv[] ) { 

    // Parse Input arguments

    // Check the number of arguments
    if (argc != 3) {
        // Tell the user how to run the program
        printf ("Usage: %s vector_size block_size\n", argv[0]);
        // "Usage messages" are a conventional way of telling the user
        // how to run a program if they enter the command incorrectly.
        return 1;
    }
    
    // Set GPU Variables based on input arguments
    int vector_size = atoi(argv[1]);
    int block_size  = atoi(argv[2]);
    int grid_size   = ((vector_size-1)/block_size) + 1;

    // Set device that we will use for our cuda code
    cudaSetDevice(0);
        
    // Time Variables
    cudaEvent_t start, stop;
    float time;
    cudaEventCreate (&start);
    cudaEventCreate (&stop);

    // Input Arrays and variables
    int *a        = new int [vector_size]; 
    int *b        = new int [vector_size]; 
    int *c_cpu    = new int [vector_size]; 
    int *c_gpu    = new int [vector_size];

    // Pointers in GPU memory
    int *dev_a;
    int *dev_b;
    int *dev_c;

    // fill the arrays 'a' and 'b' on the CPU
    printf("Initializing input arrays.\n");
    for (int i = 0; i < vector_size; i++) {
        a[i] = rand()%10;
        b[i] = rand()%10;
    }

    //
    // CPU Calculation
    //////////////////

    printf("Running sequential job.\n");
    cudaEventRecord(start,0);

    // Calculate C in the CPU
    for (int i = 0; i < vector_size; i++) {
            c_cpu[i] = a[i] + b[i];
    }

    cudaEventRecord(stop,0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&time, start, stop);
    printf("\tSequential Job Time: %.2f ms\n", time);

    int actual_size = vector_size * sizeof(int);

    // allocate the memory on the GPU
    cudaMalloc(&dev_a,actual_size);
    cudaMalloc(&dev_b,actual_size);
    cudaMalloc(&dev_c,actual_size);

    // copy the arrays 'a' and 'b' to the GPU
    cudaMemcpy(dev_a,a,actual_size,cudaMemcpyHostToDevice);
    cudaMemcpy(dev_b,b,actual_size,cudaMemcpyHostToDevice);

    //
    // GPU Calculation
    ////////////////////////

    printf("Running parallel job.\n");

    cudaEventRecord(start,0);

    // call the kernel
    //add<<<grid_size,block_size>>>(dev_a,dev_b,dev_c,actual_size);
    add<<<vector_size,1>>>(dev_a,dev_b,dev_c,actual_size);
    
    cudaEventRecord(stop,0);
    cudaEventSynchronize(stop);

    cudaEventElapsedTime(&time, start, stop);
    printf("\tParallel Job Time: %.2f ms\n", time);

    // copy the array 'c' back from the GPU to the CPU
    // HERE (there's one more at the end, don't miss it!)
    cudaMemcpy(c_gpu,dev_c,actual_size,cudaMemcpyDeviceToHost);
    
    // compare the results
    int error = 0;
    for (int i = 0; i < vector_size; i++) {
        if (c_cpu[i] != c_gpu[i]){
            error = 1;
            printf( "Error starting element %d, %d != %d\n", i, c_gpu[i], c_cpu[i] );    
        }
        if (error) break; 
    }

    if (error == 0){
        printf ("Correct result. No errors were found.\n");
    }

    // free CPU data
    free (a);
    free (b);
    free (c_cpu);
    free (c_gpu);

    // free the memory allocated on the GPU
    // HERE
    cudaFree(dev_a);
    cudaFree(dev_b);
    cudaFree(dev_c);

    return 0;
}


	.file	"tmpxft_00353252_00000000-6_p2a_authors.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2037:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2037:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z8new_nodei
	.type	_Z8new_nodei, @function
_Z8new_nodei:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %ebx
	movl	$16, %edi
	call	malloc@PLT
	xorl	%edx, %edx
	movl	%ebx, (%rax)
	movq	%rdx, 8(%rax)
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z8new_nodei, .-_Z8new_nodei
	.globl	_Z9new_graphi
	.type	_Z9new_graphi, @function
_Z9new_graphi:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%edi, %ebp
	movl	$16, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	pushq	%rsi
	.cfi_def_cfa_offset 32
	call	malloc@PLT
	movslq	%ebp, %rdi
	movl	%ebp, (%rax)
	salq	$3, %rdi
	movq	%rax, %rbx
	call	malloc@PLT
	xorl	%edx, %edx
	movq	%rax, 8(%rbx)
.L5:
	cmpl	%edx, %ebp
	jle	.L9
	xorl	%ecx, %ecx
	movq	%rcx, (%rax,%rdx,8)
	incq	%rdx
	jmp	.L5
.L9:
	movq	%rbx, %rax
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9new_graphi, .-_Z9new_graphi
	.globl	_Z7addEdgeP5graphii
	.type	_Z7addEdgeP5graphii, @function
_Z7addEdgeP5graphii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movslq	%edx, %rbx
	movl	%ebx, %edi
	call	_Z8new_nodei
	movq	8(%r12), %r12
	movslq	%ebp, %rdx
	movl	%ebp, %edi
	leaq	(%r12,%rdx,8), %rdx
	movq	(%rdx), %rcx
	movq	%rcx, 8(%rax)
	movq	%rax, (%rdx)
	call	_Z8new_nodei
	leaq	(%r12,%rbx,8), %rdx
	movq	(%rdx), %rcx
	movq	%rcx, 8(%rax)
	movq	%rax, (%rdx)
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z7addEdgeP5graphii, .-_Z7addEdgeP5graphii
	.globl	_Z8get_vertPc
	.type	_Z8get_vertPc, @function
_Z8get_vertPc:
.LFB2030:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%edx, %edx
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
.L13:
	movb	(%rdi), %cl
	cmpb	$10, %cl
	je	.L18
	cmpb	$32, %cl
	jne	.L14
	incl	%edx
	cmpl	$2, %edx
	jne	.L15
.L19:
	movslq	%eax, %rdx
	incl	%eax
	movb	%cl, 4(%rsp,%rdx)
	movl	$2, %edx
	jmp	.L16
.L15:
	cmpl	$3, %edx
	jne	.L16
.L18:
	cltq
	leaq	4(%rsp), %rdi
	movb	$0, 4(%rsp,%rax)
	call	atoi@PLT
	cltq
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L20
	call	__stack_chk_fail@PLT
.L14:
	cmpl	$2, %edx
	je	.L19
.L16:
	incq	%rdi
	jmp	.L13
.L20:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z8get_vertPc, .-_Z8get_vertPc
	.globl	_Z7get_srcPc
	.type	_Z7get_srcPc, @function
_Z7get_srcPc:
.LFB2031:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
.L27:
	movb	(%rdi,%rax), %dl
	cmpb	$32, %dl
	je	.L31
	cmpb	$10, %dl
	je	.L31
	movb	%dl, 4(%rsp,%rax)
	incq	%rax
	jmp	.L27
.L31:
	cltq
	leaq	4(%rsp), %rdi
	movb	$0, 4(%rsp,%rax)
	call	atoi@PLT
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z7get_srcPc, .-_Z7get_srcPc
	.globl	_Z7get_dstPc
	.type	_Z7get_dstPc, @function
_Z7get_dstPc:
.LFB2032:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%edx, %edx
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
.L34:
	movb	(%rdi), %cl
	cmpb	$10, %cl
	je	.L39
	cmpb	$32, %cl
	jne	.L35
	incl	%edx
	cmpl	$1, %edx
	jne	.L36
.L40:
	movslq	%eax, %rdx
	incl	%eax
	movb	%cl, 4(%rsp,%rdx)
	movl	$1, %edx
	jmp	.L37
.L36:
	cmpl	$2, %edx
	jne	.L37
.L39:
	cltq
	leaq	4(%rsp), %rdi
	movb	$0, 4(%rsp,%rax)
	call	atoi@PLT
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L41
	call	__stack_chk_fail@PLT
.L35:
	cmpl	$1, %edx
	je	.L40
.L37:
	incq	%rdi
	jmp	.L34
.L41:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z7get_dstPc, .-_Z7get_dstPc
	.globl	_Z7comparePKvS0_
	.type	_Z7comparePKvS0_, @function
_Z7comparePKvS0_:
.LFB2033:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	subl	(%rdi), %eax
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z7comparePKvS0_, .-_Z7comparePKvS0_
	.globl	_Z27__device_stub__Z3addPiS_S_iPiS_S_i
	.type	_Z27__device_stub__Z3addPiS_S_iPiS_S_i, @function
_Z27__device_stub__Z3addPiS_S_iPiS_S_i:
.LFB2059:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L48
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z3addPiS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L48:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L50
	call	__stack_chk_fail@PLT
.L50:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2059:
	.size	_Z27__device_stub__Z3addPiS_S_iPiS_S_i, .-_Z27__device_stub__Z3addPiS_S_iPiS_S_i
	.globl	_Z3addPiS_S_i
	.type	_Z3addPiS_S_i, @function
_Z3addPiS_S_i:
.LFB2060:
	.cfi_startproc
	endbr64
	jmp	_Z27__device_stub__Z3addPiS_S_iPiS_S_i
	.cfi_endproc
.LFE2060:
	.size	_Z3addPiS_S_i, .-_Z3addPiS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Usage: %s vector_size block_size\n"
.LC1:
	.string	"Initializing input arrays.\n"
.LC2:
	.string	"Running sequential job.\n"
.LC3:
	.string	"\tSequential Job Time: %.2f ms\n"
.LC4:
	.string	"Running parallel job.\n"
.LC5:
	.string	"\tParallel Job Time: %.2f ms\n"
.LC6:
	.string	"Error starting element %d, %d != %d\n"
.LC7:
	.string	"Correct result. No errors were found.\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2034:
	.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	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	je	.L54
	movq	(%rsi), %rdx
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L53
.L54:
	movq	8(%rsi), %rdi
	call	atoi@PLT
	xorl	%edi, %edi
	movslq	%eax, %r13
	call	cudaSetDevice@PLT
	leaq	24(%rsp), %rdi
	movq	%r13, %rbx
	call	cudaEventCreate@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movabsq	$2305843009213693950, %rax
	cmpq	%r13, %rax
	jb	.L56
	salq	$2, %r13
	movl	$10, %r15d
	movq	%r13, %rdi
	call	_Znam@PLT
	movq	%r13, %rdi
	movq	%rax, %r12
	call	_Znam@PLT
	movq	%r13, %rdi
	movq	%rax, %rbp
	call	_Znam@PLT
	movq	%r13, %rdi
	xorl	%r13d, %r13d
	movq	%rax, %r14
	call	_Znam@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movq	%rax, (%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L57
.L56:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L69
	call	__cxa_throw_bad_array_new_length@PLT
.L57:
	cmpl	%r13d, %ebx
	jle	.L70
	call	rand@PLT
	cltd
	idivl	%r15d
	movl	%edx, (%r12,%r13,4)
	call	rand@PLT
	cltd
	idivl	%r15d
	movl	%edx, 0(%rbp,%r13,4)
	incq	%r13
	jmp	.L57
.L70:
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	xorl	%eax, %eax
.L60:
	cmpl	%eax, %ebx
	jle	.L71
	movl	0(%rbp,%rax,4), %edx
	addl	(%r12,%rax,4), %edx
	movl	%edx, (%r14,%rax,4)
	incq	%rax
	jmp	.L60
.L71:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	leal	0(,%rbx,4), %r15d
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	32(%rsp), %rdx
	leaq	20(%rsp), %rax
	movq	24(%rsp), %rsi
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	cudaEventElapsedTime@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	20(%rsp), %xmm0
	call	__printf_chk@PLT
	movslq	%r15d, %rax
	leaq	40(%rsp), %rdi
	movq	%rax, %r13
	movq	%rax, %rsi
	call	cudaMalloc@PLT
	leaq	48(%rsp), %rdi
	movq	%r13, %rsi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movq	%r13, %rsi
	call	cudaMalloc@PLT
	movq	40(%rsp), %rdi
	movq	%r13, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	48(%rsp), %rdi
	movq	%r13, %rdx
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%ebx, 64(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rdx
	movl	$1, %ecx
	movq	%rdx, 68(%rsp)
	movq	64(%rsp), %rdi
	movl	72(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L62
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	%r15d, %ecx
	movq	40(%rsp), %rdi
	call	_Z27__device_stub__Z3addPiS_S_iPiS_S_i
.L62:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	20(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	56(%rsp), %rsi
	movq	(%rsp), %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	xorl	%edx, %edx
.L63:
	cmpl	%edx, %ebx
	jle	.L72
	movq	(%rsp), %rcx
	leaq	1(%rdx), %rax
	movl	(%r14,%rdx,4), %r8d
	movl	-4(%rcx,%rax,4), %ecx
	cmpl	%ecx, %r8d
	je	.L67
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L64
.L67:
	movq	%rax, %rdx
	jmp	.L63
.L72:
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L64:
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%eax, %eax
.L53:
	movq	88(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L66
.L69:
	call	__stack_chk_fail@PLT
.L66:
	addq	$104, %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
.LFE2034:
	.size	main, .-main
	.section	.rodata.str1.1
.LC8:
	.string	"_Z3addPiS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2062:
	.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	.LC8(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z3addPiS_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
.LFE2062:
	.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:


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

struct node{
	int dst;
	struct node* next;
};

struct list{
	struct node *head;
};

struct graph{
	int n;
	struct list* set;
};

struct node* new_node(int dst){
	struct node* newnode = (struct node*)malloc(sizeof(struct node));
	newnode -> dst = dst;
	newnode -> next = NULL;

	return newnode;
}

struct graph* new_graph(int n){
	struct graph* newgraph = (struct graph*)malloc(sizeof(struct node));
	newgraph -> n = n;
	
	newgraph -> set = (struct list*)malloc(n * sizeof(struct list)) ;

	int i;
	for(i=0;i<n;i++)
		newgraph->set[i].head = NULL;

	return newgraph;

}

void addEdge(struct graph* gph, int src, int dst){
	struct node* newnode = new_node(dst);
	newnode->next = gph->set[src].head;
	gph->set[src].head = newnode;

	newnode = new_node(src);
        newnode->next = gph->set[dst].head;
        gph->set[dst].head = newnode;
}


__global__ void add( int *a, int *b, int *c, int vector_size ) {
    
    // Calculate the index in the vector for the thread using the internal variables
    int tid = blockIdx.x * blockDim.x + threadIdx.x; // HERE
    
    // This if statement is added in case we have more threads executing
    // Than number of elements in the vectors. How can this help?
    if (tid < vector_size){
        
        // Compute the addition
        c[tid] = a[tid] + b[tid];
        
    }
}

long get_vert(char *str){
	char vert[20];
	int space_count = 0;
	int num_vert=0;	
	
	int i=0, j=0;
	while(str[i] != '\n'){
	
		if(str[i] == ' ')
			space_count++;
		if(space_count == 2){
			vert[j] = str[i];
			j++;
		}
		else if(space_count>2)	
			break;
		i++;
	}
	vert[j] = '\0';
    	//printf("%s\n", vert);
	num_vert = atoi(vert);
    	//printf("%d\n", num_vert);
	return num_vert;
	
}

int get_src(char *str){
	char s[20];
        int space_count = 0;
        int src=0;

        int i=0, j=0;
        while(str[i] != '\n'){

                if(str[i] == ' ')
                        space_count++;
                if(space_count == 0){
                        s[j] = str[i];
                        j++;
                }
		else
			break;
                i++;
        }
        s[j] = '\0';
        //printf("%s\n", s);
        src = atoi(s);
        //printf("%d\n", src);
        return src;
}

int get_dst(char *str){
	char d[20];
        int space_count = 0;
        int dst=0;

        int i=0, j=0;
        while(str[i] != '\n'){

                if(str[i] == ' ')
                        space_count++;
                if(space_count == 1){
                        d[j] = str[i];
                        j++;
                }
		else if(space_count>1)
			break;
                i++;
        }
        d[j] = '\0';
        //printf("%s\n", d);
        dst = atoi(d);
        //printf("%d\n", dst);
        return dst;
}

int compare (const void * a, const void * b)
{
  return ( *(int*)b - *(int*)a );
}


int main( int argc, char* argv[] ) { 

    // Parse Input arguments

    // Check the number of arguments
    if (argc != 3) {
        // Tell the user how to run the program
        printf ("Usage: %s vector_size block_size\n", argv[0]);
        // "Usage messages" are a conventional way of telling the user
        // how to run a program if they enter the command incorrectly.
        return 1;
    }
    
    // Set GPU Variables based on input arguments
    int vector_size = atoi(argv[1]);
    int block_size  = atoi(argv[2]);
    int grid_size   = ((vector_size-1)/block_size) + 1;

    // Set device that we will use for our cuda code
    hipSetDevice(0);
        
    // Time Variables
    hipEvent_t start, stop;
    float time;
    hipEventCreate (&start);
    hipEventCreate (&stop);

    // Input Arrays and variables
    int *a        = new int [vector_size]; 
    int *b        = new int [vector_size]; 
    int *c_cpu    = new int [vector_size]; 
    int *c_gpu    = new int [vector_size];

    // Pointers in GPU memory
    int *dev_a;
    int *dev_b;
    int *dev_c;

    // fill the arrays 'a' and 'b' on the CPU
    printf("Initializing input arrays.\n");
    for (int i = 0; i < vector_size; i++) {
        a[i] = rand()%10;
        b[i] = rand()%10;
    }

    //
    // CPU Calculation
    //////////////////

    printf("Running sequential job.\n");
    hipEventRecord(start,0);

    // Calculate C in the CPU
    for (int i = 0; i < vector_size; i++) {
            c_cpu[i] = a[i] + b[i];
    }

    hipEventRecord(stop,0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&time, start, stop);
    printf("\tSequential Job Time: %.2f ms\n", time);

    int actual_size = vector_size * sizeof(int);

    // allocate the memory on the GPU
    hipMalloc(&dev_a,actual_size);
    hipMalloc(&dev_b,actual_size);
    hipMalloc(&dev_c,actual_size);

    // copy the arrays 'a' and 'b' to the GPU
    hipMemcpy(dev_a,a,actual_size,hipMemcpyHostToDevice);
    hipMemcpy(dev_b,b,actual_size,hipMemcpyHostToDevice);

    //
    // GPU Calculation
    ////////////////////////

    printf("Running parallel job.\n");

    hipEventRecord(start,0);

    // call the kernel
    //add<<<grid_size,block_size>>>(dev_a,dev_b,dev_c,actual_size);
    add<<<vector_size,1>>>(dev_a,dev_b,dev_c,actual_size);
    
    hipEventRecord(stop,0);
    hipEventSynchronize(stop);

    hipEventElapsedTime(&time, start, stop);
    printf("\tParallel Job Time: %.2f ms\n", time);

    // copy the array 'c' back from the GPU to the CPU
    // HERE (there's one more at the end, don't miss it!)
    hipMemcpy(c_gpu,dev_c,actual_size,hipMemcpyDeviceToHost);
    
    // compare the results
    int error = 0;
    for (int i = 0; i < vector_size; i++) {
        if (c_cpu[i] != c_gpu[i]){
            error = 1;
            printf( "Error starting element %d, %d != %d\n", i, c_gpu[i], c_cpu[i] );    
        }
        if (error) break; 
    }

    if (error == 0){
        printf ("Correct result. No errors were found.\n");
    }

    // free CPU data
    free (a);
    free (b);
    free (c_cpu);
    free (c_gpu);

    // free the memory allocated on the GPU
    // HERE
    hipFree(dev_a);
    hipFree(dev_b);
    hipFree(dev_c);

    return 0;
}


	.text
	.file	"p2a_authors.hip"
	.globl	_Z8new_nodei                    # -- Begin function _Z8new_nodei
	.type	_Z8new_nodei,@function
_Z8new_nodei:                           # @_Z8new_nodei
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edi, %ebx
	movl	$16, %edi
	callq	malloc
	movl	%ebx, (%rax)
	movq	$0, 8(%rax)
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z8new_nodei, .Lfunc_end0-_Z8new_nodei
	.cfi_endproc
                                        # -- End function
	.globl	_Z9new_graphi                   # -- Begin function _Z9new_graphi
	.type	_Z9new_graphi,@function
_Z9new_graphi:                          # @_Z9new_graphi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	%edi, %ebp
	movl	$16, %edi
	callq	malloc
	movq	%rax, %rbx
	movl	%ebp, (%rax)
	movslq	%ebp, %r14
	leaq	(,%r14,8), %rdi
	callq	malloc
	movq	%rax, 8(%rbx)
	testl	%r14d, %r14d
	jle	.LBB1_2
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %edx
	shlq	$3, %rdx
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB1_2:                                # %._crit_edge
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z9new_graphi, .Lfunc_end1-_Z9new_graphi
	.cfi_endproc
                                        # -- End function
	.globl	_Z7addEdgeP5graphii             # -- Begin function _Z7addEdgeP5graphii
	.type	_Z7addEdgeP5graphii,@function
_Z7addEdgeP5graphii:                    # @_Z7addEdgeP5graphii
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, %r14
	movl	$16, %edi
	callq	malloc
	movl	%ebx, (%rax)
	movq	8(%r14), %r14
	movslq	%ebp, %r15
	movq	(%r14,%r15,8), %rcx
	movq	%rcx, 8(%rax)
	movq	%rax, (%r14,%r15,8)
	movl	$16, %edi
	callq	malloc
	movl	%r15d, (%rax)
	movslq	%ebx, %rcx
	movq	(%r14,%rcx,8), %rdx
	movq	%rdx, 8(%rax)
	movq	%rax, (%r14,%rcx,8)
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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	_Z7addEdgeP5graphii, .Lfunc_end2-_Z7addEdgeP5graphii
	.cfi_endproc
                                        # -- End function
	.globl	_Z18__device_stub__addPiS_S_i   # -- Begin function _Z18__device_stub__addPiS_S_i
	.type	_Z18__device_stub__addPiS_S_i,@function
_Z18__device_stub__addPiS_S_i:          # @_Z18__device_stub__addPiS_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	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z3addPiS_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z18__device_stub__addPiS_S_i, .Lfunc_end3-_Z18__device_stub__addPiS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z8get_vertPc                   # -- Begin function _Z8get_vertPc
	.type	_Z8get_vertPc,@function
_Z8get_vertPc:                          # @_Z8get_vertPc
	.cfi_startproc
# %bb.0:
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	movzbl	(%rdi), %edx
	cmpl	$32, %edx
	je	.LBB4_4
# %bb.2:                                #   in Loop: Header=BB4_1 Depth=1
	cmpl	$10, %edx
	jne	.LBB4_5
	jmp	.LBB4_3
.LBB4_4:                                #   in Loop: Header=BB4_1 Depth=1
	incl	%eax
.LBB4_5:                                #   in Loop: Header=BB4_1 Depth=1
	cmpl	$2, %eax
	jne	.LBB4_7
# %bb.6:                                #   in Loop: Header=BB4_1 Depth=1
	movslq	%ecx, %rsi
	movb	%dl, (%rsp,%rsi)
	incl	%ecx
	jmp	.LBB4_8
.LBB4_7:                                #   in Loop: Header=BB4_1 Depth=1
	jg	.LBB4_3
.LBB4_8:                                #   in Loop: Header=BB4_1 Depth=1
	incq	%rdi
	jmp	.LBB4_1
.LBB4_3:
	movslq	%ecx, %rax
	movb	$0, (%rsp,%rax)
	movq	%rsp, %rdi
	callq	atoi
	cltq
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z8get_vertPc, .Lfunc_end4-_Z8get_vertPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z7get_srcPc                    # -- Begin function _Z7get_srcPc
	.type	_Z7get_srcPc,@function
_Z7get_srcPc:                           # @_Z7get_srcPc
	.cfi_startproc
# %bb.0:
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
.LBB5_1:                                # =>This Inner Loop Header: Depth=1
	movzbl	(%rdi,%rax), %ecx
	cmpl	$10, %ecx
	je	.LBB5_4
# %bb.2:                                #   in Loop: Header=BB5_1 Depth=1
	cmpl	$32, %ecx
	je	.LBB5_4
# %bb.3:                                #   in Loop: Header=BB5_1 Depth=1
	movb	%cl, (%rsp,%rax)
	incq	%rax
	jmp	.LBB5_1
.LBB5_4:
	movl	%eax, %eax
	movb	$0, (%rsp,%rax)
	movq	%rsp, %rdi
	callq	atoi
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z7get_srcPc, .Lfunc_end5-_Z7get_srcPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z7get_dstPc                    # -- Begin function _Z7get_dstPc
	.type	_Z7get_dstPc,@function
_Z7get_dstPc:                           # @_Z7get_dstPc
	.cfi_startproc
# %bb.0:
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.LBB6_1:                                # =>This Inner Loop Header: Depth=1
	movzbl	(%rdi), %edx
	cmpl	$32, %edx
	je	.LBB6_4
# %bb.2:                                #   in Loop: Header=BB6_1 Depth=1
	cmpl	$10, %edx
	jne	.LBB6_5
	jmp	.LBB6_3
.LBB6_4:                                #   in Loop: Header=BB6_1 Depth=1
	incl	%eax
.LBB6_5:                                #   in Loop: Header=BB6_1 Depth=1
	cmpl	$1, %eax
	jne	.LBB6_7
# %bb.6:                                #   in Loop: Header=BB6_1 Depth=1
	movslq	%ecx, %rsi
	movb	%dl, (%rsp,%rsi)
	incl	%ecx
	jmp	.LBB6_8
.LBB6_7:                                #   in Loop: Header=BB6_1 Depth=1
	jg	.LBB6_3
.LBB6_8:                                #   in Loop: Header=BB6_1 Depth=1
	incq	%rdi
	jmp	.LBB6_1
.LBB6_3:
	movslq	%ecx, %rax
	movb	$0, (%rsp,%rax)
	movq	%rsp, %rdi
	callq	atoi
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z7get_dstPc, .Lfunc_end6-_Z7get_dstPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z7comparePKvS0_                # -- Begin function _Z7comparePKvS0_
	.type	_Z7comparePKvS0_,@function
_Z7comparePKvS0_:                       # @_Z7comparePKvS0_
	.cfi_startproc
# %bb.0:
	movl	(%rsi), %eax
	subl	(%rdi), %eax
	retq
.Lfunc_end7:
	.size	_Z7comparePKvS0_, .Lfunc_end7-_Z7comparePKvS0_
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$3, %edi
	jne	.LBB8_1
# %bb.2:
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	movslq	%ebp, %r13
	leaq	(,%r13,4), %rax
	testl	%r13d, %r13d
	movq	$-1, %r12
	cmovnsq	%rax, %r12
	movq	%r12, %rdi
	callq	_Znam
	movq	%rax, %rbx
	movq	%r12, %rdi
	callq	_Znam
	movq	%rax, %r14
	movq	%r12, %rdi
	callq	_Znam
	movq	%rax, %r15
	movq	%r12, %rdi
	callq	_Znam
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	%r13d, %r12d
	testl	%r13d, %r13d
	jle	.LBB8_5
# %bb.3:                                # %.lr.ph.preheader
	xorl	%r13d, %r13d
.LBB8_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	movl	%eax, (%rbx,%r13,4)
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	movl	%eax, (%r14,%r13,4)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB8_4
.LBB8_5:                                # %._crit_edge
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%ebp, %ebp
	jle	.LBB8_8
# %bb.6:                                # %.lr.ph82.preheader
	xorl	%eax, %eax
.LBB8_7:                                # %.lr.ph82
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r14,%rax,4), %ecx
	addl	(%rbx,%rax,4), %ecx
	movl	%ecx, (%r15,%rax,4)
	incq	%rax
	cmpq	%rax, %r12
	jne	.LBB8_7
.LBB8_8:                                # %._crit_edge83
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	44(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%r13), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	leal	(,%rbp,4), %eax
	movq	%rbp, 56(%rsp)                  # 8-byte Spill
	movl	%eax, 40(%rsp)                  # 4-byte Spill
	movslq	%eax, %rbp
	leaq	48(%rsp), %r13
	movq	%r13, %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	movq	(%r13), %rdi
	movq	%rbx, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	32(%rsp), %rax
	movq	(%rax), %rdi
	movq	%r14, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%r12, %rdi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$1, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_10
# %bb.9:
	movq	48(%rsp), %rdi
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdx
	movl	40(%rsp), %ecx                  # 4-byte Reload
	callq	_Z18__device_stub__addPiS_S_i
.LBB8_10:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	44(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r13), %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movq	24(%rsp), %rsi
	movq	64(%rsp), %r13                  # 8-byte Reload
	movq	%r13, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	cmpl	$0, 56(%rsp)                    # 4-byte Folded Reload
	jle	.LBB8_15
# %bb.11:                               # %.lr.ph87.preheader
	xorl	%esi, %esi
.LBB8_12:                               # %.lr.ph87
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r15,%rsi,4), %ecx
	movl	(%r13,%rsi,4), %edx
	cmpl	%edx, %ecx
	jne	.LBB8_13
# %bb.14:                               # %.critedge
                                        #   in Loop: Header=BB8_12 Depth=1
	incq	%rsi
	cmpq	%rsi, %r12
	jne	.LBB8_12
.LBB8_15:                               # %.critedge73
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	jmp	.LBB8_16
.LBB8_1:
	movq	(%rsi), %rsi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %eax
	jmp	.LBB8_17
.LBB8_13:
	movl	$.L.str.6, %edi
                                        # kill: def $esi killed $esi killed $rsi
	xorl	%eax, %eax
	callq	printf
.LBB8_16:
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
.LBB8_17:
	addq	$72, %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_end8:
	.size	main, .Lfunc_end8-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	.LBB9_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB9_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z3addPiS_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_end9:
	.size	__hip_module_ctor, .Lfunc_end9-__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	.LBB10_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
.LBB10_2:
	retq
.Lfunc_end10:
	.size	__hip_module_dtor, .Lfunc_end10-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z3addPiS_S_i,@object           # @_Z3addPiS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z3addPiS_S_i
	.p2align	3, 0x0
_Z3addPiS_S_i:
	.quad	_Z18__device_stub__addPiS_S_i
	.size	_Z3addPiS_S_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Usage: %s vector_size block_size\n"
	.size	.L.str, 34

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\tSequential Job Time: %.2f ms\n"
	.size	.L.str.3, 31

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\tParallel Job Time: %.2f ms\n"
	.size	.L.str.5, 29

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Error starting element %d, %d != %d\n"
	.size	.L.str.6, 37

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z3addPiS_S_i"
	.size	.L__unnamed_1, 14

	.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	"Initializing input arrays."
	.size	.Lstr, 27

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Running sequential job."
	.size	.Lstr.1, 24

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Running parallel job."
	.size	.Lstr.2, 22

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Correct result. No errors were found."
	.size	.Lstr.3, 38

	.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 _Z18__device_stub__addPiS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z3addPiS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z3addPiS_S_i           ; -- Begin function _Z3addPiS_S_i
	.globl	_Z3addPiS_S_i
	.p2align	8
	.type	_Z3addPiS_S_i,@function
_Z3addPiS_S_i:                          ; @_Z3addPiS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s3, s[0:1], 0x18
	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[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v1, vcc_lo
	v_add_co_u32 v4, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	global_load_b32 v2, v[2:3], off
	global_load_b32 v3, v[4:5], off
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v2, v3, v2
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z3addPiS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 6
		.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	_Z3addPiS_S_i, .Lfunc_end0-_Z3addPiS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 180
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
