#include<iostream>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "../inc/WeightedGraph.cuh"

WeightedGraph::WeightedGraph(int s,int p){
    size=s;   
    cudaMallocManaged(&adjmat,size*sizeof(float*));
    
    srand(time(NULL));
    for(int i=0;i<size;i++){

        cudaMallocManaged(&adjmat[i],size*sizeof(float));

        for(int j=0;j<size;j++){

            //Graph is supposed to be undirected
            if(j<i){ adjmat[i][j]=adjmat[j][i]; }

            else{

                if(rand()%100<p){  adjmat[i][j]=(float)rand()/(float)RAND_MAX; }
                else{ adjmat[i][j]=0; }

            }
        }
    }
}

float **WeightedGraph::getAdjmat(){ return adjmat;}
int WeightedGraph::getSize(){ return size;}

void WeightedGraph::print(){

    for(int i=0;i<size;i++){
        for(int j=0;j<size;j++)
            std::cout<<adjmat[i][j]<<" ";
        std::cout<<"\n";
    }
}

	.file	"tmpxft_003649dd_00000000-6_WeightedGraph.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3643:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3643:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.globl	_ZN13WeightedGraphC2Eii
	.type	_ZN13WeightedGraphC2Eii, @function
_ZN13WeightedGraphC2Eii:
.LFB3636:
	.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
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	%esi, 8(%rdi)
	movslq	%esi, %rsi
	salq	$3, %rsi
	movl	%edx, 12(%rsp)
	movl	$1, %edx
	call	cudaMallocManaged@PLT
	xorl	%edi, %edi
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
.L3:
	movslq	8(%r12), %rsi
	movl	%ebx, 8(%rsp)
	cmpl	%ebx, %esi
	jle	.L12
	movq	(%r12), %rdi
	salq	$2, %rsi
	movl	$1, %edx
	xorl	%r14d, %r14d
	leaq	0(,%rbx,8), %rbp
	leaq	0(,%rbx,4), %r15
	addq	%rbp, %rdi
	call	cudaMallocManaged@PLT
.L4:
	cmpl	8(%r12), %r14d
	jge	.L13
	movl	8(%rsp), %eax
	leaq	0(,%r14,4), %r13
	cmpl	%eax, %r14d
	jge	.L5
	movq	(%r12), %rax
	movq	(%rax,%r14,8), %rdx
	movq	(%rax,%rbp), %rax
	movss	(%rdx,%r15), %xmm0
	movss	%xmm0, (%rax,%r14,4)
	jmp	.L6
.L5:
	call	rand@PLT
	movl	$100, %ecx
	cltd
	idivl	%ecx
	movl	12(%rsp), %eax
	cmpl	%eax, %edx
	jge	.L7
	call	rand@PLT
	movl	%eax, %edx
	movq	(%r12), %rax
	cvtsi2ssl	%edx, %xmm0
	mulss	.LC0(%rip), %xmm0
	movq	(%rax,%rbp), %rax
	movss	%xmm0, (%rax,%r13)
	jmp	.L6
.L7:
	movq	(%r12), %rax
	movq	(%rax,%rbp), %rax
	movl	$0x00000000, (%rax,%r13)
.L6:
	incq	%r14
	jmp	.L4
.L13:
	incq	%rbx
	jmp	.L3
.L12:
	addq	$24, %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
.LFE3636:
	.size	_ZN13WeightedGraphC2Eii, .-_ZN13WeightedGraphC2Eii
	.globl	_ZN13WeightedGraphC1Eii
	.set	_ZN13WeightedGraphC1Eii,_ZN13WeightedGraphC2Eii
	.align 2
	.globl	_ZN13WeightedGraph9getAdjmatEv
	.type	_ZN13WeightedGraph9getAdjmatEv, @function
_ZN13WeightedGraph9getAdjmatEv:
.LFB3638:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	ret
	.cfi_endproc
.LFE3638:
	.size	_ZN13WeightedGraph9getAdjmatEv, .-_ZN13WeightedGraph9getAdjmatEv
	.align 2
	.globl	_ZN13WeightedGraph7getSizeEv
	.type	_ZN13WeightedGraph7getSizeEv, @function
_ZN13WeightedGraph7getSizeEv:
.LFB3639:
	.cfi_startproc
	endbr64
	movl	8(%rdi), %eax
	ret
	.cfi_endproc
.LFE3639:
	.size	_ZN13WeightedGraph7getSizeEv, .-_ZN13WeightedGraph7getSizeEv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	" "
.LC3:
	.string	"\n"
	.text
	.align 2
	.globl	_ZN13WeightedGraph5printEv
	.type	_ZN13WeightedGraph5printEv, @function
_ZN13WeightedGraph5printEv:
.LFB3640:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	leaq	_ZSt4cout(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdi, %rbx
.L17:
	cmpl	%r12d, 8(%rbx)
	jle	.L16
	leaq	0(,%r12,8), %r14
	xorl	%ebp, %ebp
.L20:
	cmpl	%ebp, 8(%rbx)
	jle	.L22
	movq	(%rbx), %rax
	movq	%r13, %rdi
	movq	(%rax,%r14), %rax
	cvtss2sd	(%rax,%rbp,4), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movl	$1, %edx
	incq	%rbp
	movq	%rax, %rdi
	leaq	.LC2(%rip), %rsi
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	jmp	.L20
.L22:
	movl	$1, %edx
	leaq	.LC3(%rip), %rsi
	movq	%r13, %rdi
	incq	%r12
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	jmp	.L17
.L16:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3640:
	.size	_ZN13WeightedGraph5printEv, .-_ZN13WeightedGraph5printEv
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3666:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3666:
	.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
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.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 <stdlib.h>
#include <time.h>
#include <math.h>
#include "../inc/WeightedGraph.cuh"

WeightedGraph::WeightedGraph(int s,int p){
    size=s;   
    hipMallocManaged(&adjmat,size*sizeof(float*));
    
    srand(time(NULL));
    for(int i=0;i<size;i++){

        hipMallocManaged(&adjmat[i],size*sizeof(float));

        for(int j=0;j<size;j++){

            //Graph is supposed to be undirected
            if(j<i){ adjmat[i][j]=adjmat[j][i]; }

            else{

                if(rand()%100<p){  adjmat[i][j]=(float)rand()/(float)RAND_MAX; }
                else{ adjmat[i][j]=0; }

            }
        }
    }
}

float **WeightedGraph::getAdjmat(){ return adjmat;}
int WeightedGraph::getSize(){ return size;}

void WeightedGraph::print(){

    for(int i=0;i<size;i++){
        for(int j=0;j<size;j++)
            std::cout<<adjmat[i][j]<<" ";
        std::cout<<"\n";
    }
}

	.text
	.file	"WeightedGraph.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _ZN13WeightedGraphC2Eii
.LCPI0_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	_ZN13WeightedGraphC2Eii
	.p2align	1, 0x90
	.type	_ZN13WeightedGraphC2Eii,@function
_ZN13WeightedGraphC2Eii:                # @_ZN13WeightedGraphC2Eii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edx, %ebx
	movq	%rdi, %r14
	movl	%esi, 8(%rdi)
	movslq	%esi, %rsi
	shlq	$3, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movl	8(%r14), %eax
	testl	%eax, %eax
	jle	.LBB0_8
# %bb.1:                                # %.lr.ph22.preheader
	xorl	%r15d, %r15d
.LBB0_2:                                # %.lr.ph22
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
	leaq	(,%r15,8), %rdi
	addq	(%r14), %rdi
	movslq	%eax, %rsi
	shlq	$2, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	movslq	8(%r14), %rcx
	testq	%rcx, %rcx
	jle	.LBB0_6
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB0_2 Depth=1
	xorl	%r12d, %r12d
.LBB0_4:                                # %.lr.ph
                                        #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpq	%r15, %r12
	jae	.LBB0_9
# %bb.5:                                #   in Loop: Header=BB0_4 Depth=2
	movq	(%r14), %rax
	movq	(%rax,%r12,8), %rcx
	movss	(%rcx,%r15,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	jmp	.LBB0_12
.LBB0_9:                                #   in Loop: Header=BB0_4 Depth=2
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	subl	%ecx, %eax
	cmpl	%ebx, %eax
	jge	.LBB0_11
# %bb.10:                               #   in Loop: Header=BB0_4 Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	movq	(%r14), %rax
	jmp	.LBB0_12
.LBB0_11:                               #   in Loop: Header=BB0_4 Depth=2
	movq	(%r14), %rax
	xorps	%xmm0, %xmm0
.LBB0_12:                               #   in Loop: Header=BB0_4 Depth=2
	movq	(%rax,%r15,8), %rax
	movss	%xmm0, (%rax,%r12,4)
	incq	%r12
	movl	8(%r14), %eax
	movslq	%eax, %rcx
	cmpq	%rcx, %r12
	jl	.LBB0_4
	jmp	.LBB0_7
.LBB0_6:                                # %.lr.ph22.._crit_edge_crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	%ecx, %eax
.LBB0_7:                                # %._crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	incq	%r15
	cmpq	%rcx, %r15
	jl	.LBB0_2
.LBB0_8:                                # %._crit_edge23
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_ZN13WeightedGraphC2Eii, .Lfunc_end0-_ZN13WeightedGraphC2Eii
	.cfi_endproc
                                        # -- End function
	.globl	_ZN13WeightedGraph9getAdjmatEv  # -- Begin function _ZN13WeightedGraph9getAdjmatEv
	.p2align	1, 0x90
	.type	_ZN13WeightedGraph9getAdjmatEv,@function
_ZN13WeightedGraph9getAdjmatEv:         # @_ZN13WeightedGraph9getAdjmatEv
	.cfi_startproc
# %bb.0:
	movq	(%rdi), %rax
	retq
.Lfunc_end1:
	.size	_ZN13WeightedGraph9getAdjmatEv, .Lfunc_end1-_ZN13WeightedGraph9getAdjmatEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN13WeightedGraph7getSizeEv    # -- Begin function _ZN13WeightedGraph7getSizeEv
	.p2align	1, 0x90
	.type	_ZN13WeightedGraph7getSizeEv,@function
_ZN13WeightedGraph7getSizeEv:           # @_ZN13WeightedGraph7getSizeEv
	.cfi_startproc
# %bb.0:
	movl	8(%rdi), %eax
	retq
.Lfunc_end2:
	.size	_ZN13WeightedGraph7getSizeEv, .Lfunc_end2-_ZN13WeightedGraph7getSizeEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN13WeightedGraph5printEv      # -- Begin function _ZN13WeightedGraph5printEv
	.p2align	1, 0x90
	.type	_ZN13WeightedGraph5printEv,@function
_ZN13WeightedGraph5printEv:             # @_ZN13WeightedGraph5printEv
	.cfi_startproc
# %bb.0:
	movl	8(%rdi), %eax
	testl	%eax, %eax
	jle	.LBB3_7
# %bb.1:                                # %.preheader.preheader
	pushq	%r15
	.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 %r15, -16
	movq	%rdi, %rbx
	xorl	%r14d, %r14d
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
	testl	%eax, %eax
	jle	.LBB3_5
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB3_2 Depth=1
	xorl	%r15d, %r15d
.LBB3_4:                                # %.lr.ph
                                        #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%rbx), %rax
	movq	(%rax,%r14,8), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax,%r15,4), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r15
	movslq	8(%rbx), %rax
	cmpq	%rax, %r15
	jl	.LBB3_4
.LBB3_5:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r14
	movslq	8(%rbx), %rax
	cmpq	%rax, %r14
	jl	.LBB3_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB3_7:                                # %._crit_edge9
	retq
.Lfunc_end3:
	.size	_ZN13WeightedGraph5printEv, .Lfunc_end3-_ZN13WeightedGraph5printEv
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	" "
	.size	.L.str, 2

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

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

	.globl	_ZN13WeightedGraphC1Eii
	.type	_ZN13WeightedGraphC1Eii,@function
.set _ZN13WeightedGraphC1Eii, _ZN13WeightedGraphC2Eii
	.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 _ZSt4cout
	.addrsig_sym __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
