#include <assert.h>
#include <cuda_runtime.h>

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

	int main(int argc, char *argv[])
	{
	if(argc != 2)
		exit(2);
	int N = atoi(argv[1]);
	
	int first[N][N], second[N][N], multiply[N][N];

	for (int i = 0; i < N; i++){
	    for (int j = 0; j < N; j++){
		first[i][j] = rand()%10;
		second[i][j] = rand()%10;
		multiply[i][j] = 1;
	}
	}

		//clock_t begin = clock();
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);

cudaEventRecord(start);

		for (int i = 0; i < N; i++){
		    for (int j = 0; j < N; j++){
			int sum = 0;
			for (int k = 0; k < N; k++)
				sum += first[i][k] * second[k][j];
			multiply[i][j] = sum;
		}
		}
	//clock_t end = clock();
	//double time_spent = (double)(end - begin) / (CLOCKS_PER_SEC / 1000);
	//fprintf(stdout, "%f", time_spent);
cudaEventRecord(stop);

cudaEventSynchronize(stop);
float milliseconds = 0;
cudaEventElapsedTime(&milliseconds, start, stop);
fprintf(stdout, "%f", milliseconds);    

	
	return 0;
	}


	.file	"tmpxft_0023b444_00000000-6_c_code.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%f"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$88, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	je	.L3
	movl	$2, %edi
	call	exit@PLT
.L3:
	movq	8(%rsi), %rdi
	call	atoi@PLT
	movq	%rsp, %rcx
	movl	%eax, %ebx
	cltq
	leaq	0(,%rax,4), %r12
	imulq	%rax, %rax
	leaq	15(,%rax,4), %rax
	movq	%rax, %rsi
	movq	%rax, %rdx
	andq	$-4096, %rsi
	andq	$-16, %rdx
	subq	%rsi, %rcx
.L4:
	cmpq	%rcx, %rsp
	je	.L5
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L4
.L5:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	je	.L6
	orq	$0, -8(%rsp,%rdx)
.L6:
	movq	%rax, %rsi
	movq	%rsp, -88(%rbp)
	movq	%rax, %rdx
	movq	%rsp, %rcx
	andq	$-4096, %rsi
	andq	$-16, %rdx
	subq	%rsi, %rcx
.L7:
	cmpq	%rcx, %rsp
	je	.L8
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L7
.L8:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	je	.L9
	orq	$0, -8(%rsp,%rdx)
.L9:
	movq	%rsp, -96(%rbp)
	movq	%rax, %rdx
	movq	%rsp, %rcx
	andq	$-4096, %rax
	andq	$-16, %rdx
	subq	%rax, %rcx
.L10:
	cmpq	%rcx, %rsp
	je	.L11
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L10
.L11:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L12
	orq	$0, -8(%rsp,%rax)
.L12:
	movq	%r12, %rax
	movq	%rsp, %r14
	xorl	%edi, %edi
	xorl	%esi, %esi
	shrq	$2, %rax
	movl	$10, %r15d
	movq	%rax, -104(%rbp)
.L13:
	cmpl	%ebx, %esi
	jge	.L35
	movq	%rdi, %r13
	xorl	%r8d, %r8d
.L14:
	movq	%rdi, -120(%rbp)
	movl	%r8d, -112(%rbp)
	movl	%esi, -108(%rbp)
	call	rand@PLT
	cltd
	idivl	%r15d
	movq	-88(%rbp), %rax
	movl	%edx, (%rax,%r13)
	call	rand@PLT
	movl	-112(%rbp), %r8d
	movl	-108(%rbp), %esi
	movl	$1, (%r14,%r13)
	cltd
	movq	-120(%rbp), %rdi
	idivl	%r15d
	movq	-96(%rbp), %rax
	incl	%r8d
	movl	%edx, (%rax,%r13)
	addq	$4, %r13
	cmpl	%r8d, %ebx
	jne	.L14
	incl	%esi
	addq	%r12, %rdi
	jmp	.L13
.L35:
	leaq	-72(%rbp), %rdi
	call	cudaEventCreate@PLT
	leaq	-64(%rbp), %rdi
	call	cudaEventCreate@PLT
	movq	-72(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	xorl	%esi, %esi
	xorl	%edi, %edi
.L15:
	cmpl	%ebx, %edi
	jge	.L36
	movq	-88(%rbp), %rcx
	xorl	%eax, %eax
	leaq	(%r14,%rsi), %r15
	leaq	(%rcx,%rsi), %r11
.L18:
	xorl	%edx, %edx
	xorl	%r8d, %r8d
	movslq	%eax, %r10
.L16:
	movq	-104(%rbp), %r9
	movslq	%edx, %rcx
	movq	-96(%rbp), %r13
	imulq	%r9, %rcx
	movl	(%r11,%rdx,4), %r9d
	incq	%rdx
	addq	%r10, %rcx
	imull	0(%r13,%rcx,4), %r9d
	addl	%r9d, %r8d
	cmpl	%edx, %ebx
	jg	.L16
	movl	%r8d, (%r15,%rax,4)
	incq	%rax
	cmpl	%eax, %ebx
	jg	.L18
	incl	%edi
	addq	%r12, %rsi
	jmp	.L15
.L36:
	movq	-64(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	-64(%rbp), %rdi
	call	cudaEventSynchronize@PLT
	movq	-64(%rbp), %rdx
	movq	-72(%rbp), %rsi
	leaq	-76(%rbp), %rdi
	movl	$0x00000000, -76(%rbp)
	call	cudaEventElapsedTime@PLT
	movq	stdout(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movb	$1, %al
	movl	$2, %esi
	cvtss2sd	-76(%rbp), %xmm0
	call	__fprintf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2053:
	.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
.LFE2053:
	.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 <assert.h>
#include <hip/hip_runtime.h>

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

	int main(int argc, char *argv[])
	{
	if(argc != 2)
		exit(2);
	int N = atoi(argv[1]);
	
	int first[N][N], second[N][N], multiply[N][N];

	for (int i = 0; i < N; i++){
	    for (int j = 0; j < N; j++){
		first[i][j] = rand()%10;
		second[i][j] = rand()%10;
		multiply[i][j] = 1;
	}
	}

		//clock_t begin = clock();
hipEvent_t start, stop;
hipEventCreate(&start);
hipEventCreate(&stop);

hipEventRecord(start);

		for (int i = 0; i < N; i++){
		    for (int j = 0; j < N; j++){
			int sum = 0;
			for (int k = 0; k < N; k++)
				sum += first[i][k] * second[k][j];
			multiply[i][j] = sum;
		}
		}
	//clock_t end = clock();
	//double time_spent = (double)(end - begin) / (CLOCKS_PER_SEC / 1000);
	//fprintf(stdout, "%f", time_spent);
hipEventRecord(stop);

hipEventSynchronize(stop);
float milliseconds = 0;
hipEventElapsedTime(&milliseconds, start, stop);
fprintf(stdout, "%f", milliseconds);    

	
	return 0;
	}


	.text
	.file	"c_code.hip"
	.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	%rbx
	.cfi_def_cfa_offset 40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$2, %edi
	jne	.LBB0_7
# %bb.1:
	movq	8(%rsi), %rdi
	callq	atoi
	testl	%eax, %eax
	jle	.LBB0_6
# %bb.2:                                # %.lr.ph.preheader.preheader
	movl	%eax, %ebx
	xorl	%ebp, %ebp
.LBB0_3:                                # %.lr.ph.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
	movl	%ebx, %r14d
.LBB0_4:                                # %.lr.ph
                                        #   Parent Loop BB0_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	callq	rand
	decl	%r14d
	jne	.LBB0_4
# %bb.5:                                # %._crit_edge
                                        #   in Loop: Header=BB0_3 Depth=1
	incl	%ebp
	cmpl	%ebx, %ebp
	jne	.LBB0_3
.LBB0_6:                                # %._crit_edge48
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r14), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r14), %rdi
	callq	hipEventSynchronize
	leaq	4(%rsp), %r15
	movl	$0, (%r15)
	movq	(%rbx), %rsi
	movq	(%r14), %rdx
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movq	stdout(%rip), %rdi
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str, %esi
	movb	$1, %al
	callq	fprintf
	xorl	%eax, %eax
	addq	$24, %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
.LBB0_7:
	.cfi_def_cfa_offset 64
	movl	$2, %edi
	callq	exit
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%f"
	.size	.L.str, 3

	.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 __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
