#include <iostream>
#define N 2048*2048
#include <chrono>
void dot(int *a, int *b, int *c){
    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += a[i] * b[i];
    }
    *c = sum;
}

int main(){
    int *a = new int[N];
    int *b = new int[N];
    int *c = new int;

    *c = 0;

    for(int i = 0; i < N; i++){
        a[i] = 1;
        b[i] = 1;
    }

    auto start = std::chrono::high_resolution_clock::now();
    dot(a, b, c);
    auto end = std::chrono::high_resolution_clock::now();

    double time_taken =  std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count(); 
    time_taken *= 1e-9;
    
    std::cout << "dot product: " << *c << std::endl;
    std::cout << "Time taken by program is : " << time_taken; 
    std::cout << " sec" << std::endl; 

    delete(a);
    delete(b);
    delete(c);

    return 0;
}
	.file	"tmpxft_0022ae04_00000000-6_dotCPU.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3740:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3740:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z3dotPiS_S_
	.type	_Z3dotPiS_S_, @function
_Z3dotPiS_S_:
.LFB3734:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.L3:
	movl	(%rdi,%rax), %r8d
	imull	(%rsi,%rax), %r8d
	addq	$4, %rax
	addl	%r8d, %ecx
	cmpq	$16777216, %rax
	jne	.L3
	movl	%ecx, (%rdx)
	ret
	.cfi_endproc
.LFE3734:
	.size	_Z3dotPiS_S_, .-_Z3dotPiS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"dot product: "
.LC2:
	.string	"Time taken by program is : "
.LC3:
	.string	" sec"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3735:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$16777216, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	call	_Znam@PLT
	movl	$16777216, %edi
	movq	%rax, %r12
	call	_Znam@PLT
	movl	$4, %edi
	movq	%rax, %rbp
	call	_Znwm@PLT
	movq	%rax, %rbx
	xorl	%eax, %eax
.L7:
	movl	$1, (%r12,%rax)
	movl	$1, 0(%rbp,%rax)
	addq	$4, %rax
	cmpq	$16777216, %rax
	jne	.L7
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	movq	%r12, %rdi
	movq	%rax, %r13
	call	_Z3dotPiS_S_
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	leaq	.LC1(%rip), %rsi
	subq	%r13, %rax
	leaq	_ZSt4cout(%rip), %r13
	cvtsi2sdq	%rax, %xmm0
	mulsd	.LC0(%rip), %xmm0
	movq	%r13, %rdi
	movsd	%xmm0, 8(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	(%rbx), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	.LC2(%rip), %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC3(%rip), %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	%r12, %rdi
	movl	$4, %esi
	call	_ZdlPvm@PLT
	movq	%rbp, %rdi
	movl	$4, %esi
	call	_ZdlPvm@PLT
	movq	%rbx, %rdi
	movl	$4, %esi
	call	_ZdlPvm@PLT
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3735:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3763:
	.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
.LFE3763:
	.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.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	-400107883
	.long	1041313291
	.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>
#define N 2048*2048
#include <chrono>
void dot(int *a, int *b, int *c){
    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += a[i] * b[i];
    }
    *c = sum;
}

int main(){
    int *a = new int[N];
    int *b = new int[N];
    int *c = new int;

    *c = 0;

    for(int i = 0; i < N; i++){
        a[i] = 1;
        b[i] = 1;
    }

    auto start = std::chrono::high_resolution_clock::now();
    dot(a, b, c);
    auto end = std::chrono::high_resolution_clock::now();

    double time_taken =  std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count(); 
    time_taken *= 1e-9;
    
    std::cout << "dot product: " << *c << std::endl;
    std::cout << "Time taken by program is : " << time_taken; 
    std::cout << " sec" << std::endl; 

    delete(a);
    delete(b);
    delete(c);

    return 0;
}
	.text
	.file	"dotCPU.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z3dotPiS_S_                    # -- Begin function _Z3dotPiS_S_
	.type	_Z3dotPiS_S_,@function
_Z3dotPiS_S_:                           # @_Z3dotPiS_S_
	.cfi_startproc
# %bb.0:
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	movl	(%rsi,%rax,4), %r8d
	imull	(%rdi,%rax,4), %r8d
	addl	%r8d, %ecx
	incq	%rax
	cmpq	$4194304, %rax                  # imm = 0x400000
	jne	.LBB0_1
# %bb.2:
	movl	%ecx, (%rdx)
	retq
.Lfunc_end0:
	.size	_Z3dotPiS_S_, .Lfunc_end0-_Z3dotPiS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI1_0:
	.quad	0x3e112e0be826d695              # double 1.0000000000000001E-9
	.text
	.globl	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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$16777216, %edi                 # imm = 0x1000000
	callq	_Znam
	movq	%rax, %rbx
	movl	$16777216, %edi                 # imm = 0x1000000
	callq	_Znam
	movq	%rax, %r14
	xorl	%eax, %eax
	movl	$1, %ecx
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movl	%ecx, (%rbx,%rax,4)
	movl	%ecx, (%r14,%rax,4)
	incq	%rax
	cmpq	$4194304, %rax                  # imm = 0x400000
	jne	.LBB1_1
# %bb.2:
	xorl	%r12d, %r12d
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r15
	xorl	%ebp, %ebp
.LBB1_3:                                # =>This Inner Loop Header: Depth=1
	movl	(%r14,%r12,4), %eax
	imull	(%rbx,%r12,4), %eax
	addl	%eax, %ebp
	incq	%r12
	cmpq	$4194304, %r12                  # imm = 0x400000
	jne	.LBB1_3
# %bb.4:                                # %_Z3dotPiS_S_.exit
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%r15, %rax
	cvtsi2sd	%rax, %xmm0
	mulsd	.LCPI1_0(%rip), %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movl	$_ZSt4cout, %r12d
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$13, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$27, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$4, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rbx, %rdi
	callq	_ZdlPv
	movq	%r14, %rdi
	callq	_ZdlPv
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"dot product: "
	.size	.L.str, 14

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Time taken by program is : "
	.size	.L.str.1, 28

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	" sec"
	.size	.L.str.2, 5

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _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
