// Code adapted from MATLAB implementation at https://people.ece.cornell.edu/land/courses/ece5760/LABS/s2016/lab3.html
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define N 512 // grid side length
#define RHO 0.5 // related to pitch
#define ETA 2e-4 // related to duration of sound
#define BOUNDARY_GAIN 0.75 // clamped edge vs free edge

void print_grid(float **grid) {
	int i,j;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			printf("(%d,%d): %f ", i,j,grid[i][j]);
		}
		printf("\n");
	}
	printf("\n");
}

int main(int argc, char** argv) {
	// get number of iterations to perform
	int T = atoi(argv[1]);
	struct timeval start_time, end_time;

	// initialize grid
	float **u = (float **) malloc(N * sizeof(float *));
	float **u1 = (float **) malloc(N * sizeof(float *));
	float **u2 = (float **) malloc(N * sizeof(float *));
	int i,j;
	for (i = 0; i < N; i++) {
		u[i] = (float *)malloc(N * sizeof(float)); 
		u1[i] = (float *)malloc(N * sizeof(float));
		u2[i] = (float *)malloc(N * sizeof(float));
		for (j = 0; j < N; j++) {
			u[i][j] = 0;
			u1[i][j] = 0;
			u2[i][j] = 0;
		}
	}
	printf("Size of grid: %d nodes\n", N*N);
	gettimeofday(&start_time, NULL);

	// simulate drum strike
	u1[N/2][N/2] = 1;
	float *audio = (float *)malloc(T * sizeof(float));
	float sum_of_neighbors, previous_value, previous_previous_value;
	float **temp;
	int t;
	for (t = 0; t < T; t++) {

		// update interior points
		int i,j;
		for (i = 1; i < N-1; i++) {
			for (j = 1; j < N-1; j++) {
				sum_of_neighbors = u1[i-1][j] + u1[i+1][j] + u1[i][j-1] + u1[i][j+1];
				previous_value = u1[i][j];
				previous_previous_value = u2[i][j];
				u[i][j] = (RHO * (sum_of_neighbors -4*previous_value) + 2*previous_value -(1-ETA)*previous_previous_value)/(1+ETA);
			}
		}

		// update side points
		for (i = 1; i < N-1; i++) {
			u[0][i] = BOUNDARY_GAIN * u[1][i]; // top
			u[N-1][i] = BOUNDARY_GAIN * u[N-2][i]; // bottom
			u[i][0] = BOUNDARY_GAIN * u[i][1]; // left
			u[i][N-1] = BOUNDARY_GAIN * u[i][N-2]; // right
		}

		// update corners
		u[0][0] = BOUNDARY_GAIN * u[1][0];
	    	u[N-1][0] = BOUNDARY_GAIN * u[N-2][0];
    		u[0][N-1] = BOUNDARY_GAIN * u[0][N-2];
    		u[N-1][N-1] = BOUNDARY_GAIN * u[N-1][N-2];

		

		// shift u1 into u2, u into u1
		// this is expensive!
		/*
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				u2[i][j] = u1[i][j];
				u1[i][j] = u[i][j];
			}
		}
		*/

//		print_grid(u);

		audio[t] = u[N/2][N/2];
		printf("%f,\n", audio[t]);

		temp = u2;
		u2 = u1;
		u1 = u;
		u = temp;

		// record displacement at node (N-1,N-1)
	}
	gettimeofday(&end_time, NULL);

	unsigned long long time_elapsed = 1000 * (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_usec - start_time.tv_usec) / 1000;

	printf("Time Elapsed [%llu ms]\n", time_elapsed);

	// free grid memory
	for (i = 0; i < N; i++) {
		free(u[i]);
		free(u1[i]);
		free(u2[i]);
	}

	free(u);
	free(u1);
	free(u2);
	free(audio);
}

	.file	"tmpxft_0022bda3_00000000-6_grid_sequential.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"(%d,%d): %f "
.LC1:
	.string	"\n"
	.text
	.globl	_Z10print_gridPPf
	.type	_Z10print_gridPPf, @function
_Z10print_gridPPf:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
.L3:
	movl	%ebp, %r13d
	xorl	%ebx, %ebx
.L4:
	movq	(%r12,%rbp,8), %rax
	movl	%ebx, %ecx
	movl	%r13d, %edx
	movq	%r14, %rsi
	movl	$2, %edi
	cvtss2sd	(%rax,%rbx,4), %xmm0
	movb	$1, %al
	incq	%rbx
	call	__printf_chk@PLT
	cmpq	$512, %rbx
	jne	.L4
	leaq	.LC1(%rip), %rbx
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbp
	movq	%rbx, %rsi
	call	__printf_chk@PLT
	cmpq	$512, %rbp
	jne	.L3
	movq	%rbx, %rsi
	movl	$2, %edi
	popq	%rbx
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z10print_gridPPf, .-_Z10print_gridPPf
	.section	.rodata.str1.1
.LC2:
	.string	"Size of grid: %d nodes\n"
.LC9:
	.string	"%f,\n"
.LC10:
	.string	"Time Elapsed [%llu ms]\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.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
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movl	$4096, %edi
	movl	%eax, %r13d
	call	malloc@PLT
	movl	$4096, %edi
	movq	%rax, %r14
	call	malloc@PLT
	movl	$4096, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movq	%rax, %rbp
.L10:
	movl	$2048, %edi
	call	malloc@PLT
	movl	$2048, %edi
	movq	%rax, (%r14,%r12)
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movl	$2048, %edi
	movq	%rax, (%rbx,%r12)
	movq	%rax, %r15
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movl	$512, %ecx
	movq	%rax, 0(%rbp,%r12)
	movq	%rax, %rdx
	xorl	%eax, %eax
	addq	$8, %r12
	rep stosl
	movl	$512, %ecx
	movq	%r15, %rdi
	rep stosl
	movl	$512, %ecx
	movq	%rdx, %rdi
	rep stosl
	cmpq	$4096, %r12
	jne	.L10
	movl	$262144, %edx
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%r15d, %r15d
	call	__printf_chk@PLT
	leaq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	2048(%rbx), %rax
	movslq	%r13d, %rdi
	salq	$2, %rdi
	movl	$0x3f800000, 1024(%rax)
	call	malloc@PLT
	movq	%rax, %r12
.L11:
	cmpl	%r15d, %r13d
	jle	.L24
	movsd	.LC5(%rip), %xmm3
	movsd	.LC6(%rip), %xmm4
	movl	$8, %edx
	movsd	.LC7(%rip), %xmm5
.L15:
	movq	-8(%rbx,%rdx), %r9
	movq	8(%rbx,%rdx), %r8
	movl	$4, %eax
	movq	(%rbx,%rdx), %rcx
	movq	0(%rbp,%rdx), %rdi
	movq	(%r14,%rdx), %rsi
.L12:
	movss	(%r9,%rax), %xmm1
	addss	(%r8,%rax), %xmm1
	movss	-4(%rcx,%rax), %xmm0
	movss	(%rcx,%rax), %xmm2
	addss	%xmm1, %xmm0
	movss	.LC4(%rip), %xmm1
	addss	4(%rcx,%rax), %xmm0
	mulss	%xmm2, %xmm1
	addss	%xmm2, %xmm2
	cvtss2sd	%xmm2, %xmm2
	subss	%xmm1, %xmm0
	cvtss2sd	(%rdi,%rax), %xmm1
	mulsd	%xmm4, %xmm1
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm3, %xmm0
	addsd	%xmm2, %xmm0
	subsd	%xmm1, %xmm0
	divsd	%xmm5, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rsi,%rax)
	addq	$4, %rax
	cmpq	$2044, %rax
	jne	.L12
	addq	$8, %rdx
	cmpq	$4088, %rdx
	jne	.L15
	movq	8(%r14), %r8
	movq	(%r14), %rcx
	movl	$4, %eax
	movq	4080(%r14), %rdi
	movq	4088(%r14), %rdx
	movss	.LC8(%rip), %xmm0
.L14:
	movss	(%r8,%rax), %xmm1
	movq	(%r14,%rax,2), %rsi
	mulss	%xmm0, %xmm1
	movss	%xmm1, (%rcx,%rax)
	movss	(%rdi,%rax), %xmm1
	mulss	%xmm0, %xmm1
	movss	%xmm1, (%rdx,%rax)
	movss	4(%rsi), %xmm1
	addq	$4, %rax
	mulss	%xmm0, %xmm1
	movss	%xmm1, (%rsi)
	movss	2040(%rsi), %xmm1
	mulss	%xmm0, %xmm1
	movss	%xmm1, 2044(%rsi)
	cmpq	$2044, %rax
	jne	.L14
	movss	(%r8), %xmm1
	movq	2048(%r14), %rax
	leaq	.LC9(%rip), %rsi
	mulss	%xmm0, %xmm1
	movss	%xmm1, (%rcx)
	movss	(%rdi), %xmm1
	movl	$2, %edi
	mulss	%xmm0, %xmm1
	movss	%xmm1, (%rdx)
	movss	2040(%rcx), %xmm1
	mulss	%xmm0, %xmm1
	movss	%xmm1, 2044(%rcx)
	mulss	2040(%rdx), %xmm0
	movss	%xmm0, 2044(%rdx)
	movss	1024(%rax), %xmm0
	movb	$1, %al
	movss	%xmm0, (%r12,%r15,4)
	cvtss2sd	%xmm0, %xmm0
	incq	%r15
	call	__printf_chk@PLT
	movq	%r14, %rax
	movq	%rbp, %r14
	movq	%rbx, %rbp
	movq	%rax, %rbx
	jmp	.L11
.L24:
	leaq	40(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%r13d, %r13d
	call	gettimeofday@PLT
	movq	48(%rsp), %rax
	subq	32(%rsp), %rax
	movl	$1000, %esi
	cqto
	movq	40(%rsp), %rcx
	subq	24(%rsp), %rcx
	movl	$2, %edi
	idivq	%rsi
	imulq	$1000, %rcx, %rcx
	leaq	.LC10(%rip), %rsi
	leaq	(%rcx,%rax), %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L16:
	movq	(%r14,%r13), %rdi
	call	free@PLT
	movq	(%rbx,%r13), %rdi
	call	free@PLT
	movq	0(%rbp,%r13), %rdi
	addq	$8, %r13
	call	free@PLT
	cmpq	$4096, %r13
	jne	.L16
	movq	%r14, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	addq	$72, %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
.LFE2028:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.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
.LFE2054:
	.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
.LC4:
	.long	1082130432
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC5:
	.long	0
	.long	1071644672
	.align 8
.LC6:
	.long	-1848553924
	.long	1072692828
	.align 8
.LC7:
	.long	-1223206686
	.long	1072693457
	.section	.rodata.cst4
	.align 4
.LC8:
	.long	1061158912
	.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:

// Code adapted from MATLAB implementation at https://people.ece.cornell.edu/land/courses/ece5760/LABS/s2016/lab3.html

#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define N 512 // grid side length
#define RHO 0.5 // related to pitch
#define ETA 2e-4 // related to duration of sound
#define BOUNDARY_GAIN 0.75 // clamped edge vs free edge

void print_grid(float **grid) {
	int i,j;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			printf("(%d,%d): %f ", i,j,grid[i][j]);
		}
		printf("\n");
	}
	printf("\n");
}

int main(int argc, char** argv) {
	// get number of iterations to perform
	int T = atoi(argv[1]);
	struct timeval start_time, end_time;

	// initialize grid
	float **u = (float **) malloc(N * sizeof(float *));
	float **u1 = (float **) malloc(N * sizeof(float *));
	float **u2 = (float **) malloc(N * sizeof(float *));
	int i,j;
	for (i = 0; i < N; i++) {
		u[i] = (float *)malloc(N * sizeof(float)); 
		u1[i] = (float *)malloc(N * sizeof(float));
		u2[i] = (float *)malloc(N * sizeof(float));
		for (j = 0; j < N; j++) {
			u[i][j] = 0;
			u1[i][j] = 0;
			u2[i][j] = 0;
		}
	}
	printf("Size of grid: %d nodes\n", N*N);
	gettimeofday(&start_time, NULL);

	// simulate drum strike
	u1[N/2][N/2] = 1;
	float *audio = (float *)malloc(T * sizeof(float));
	float sum_of_neighbors, previous_value, previous_previous_value;
	float **temp;
	int t;
	for (t = 0; t < T; t++) {

		// update interior points
		int i,j;
		for (i = 1; i < N-1; i++) {
			for (j = 1; j < N-1; j++) {
				sum_of_neighbors = u1[i-1][j] + u1[i+1][j] + u1[i][j-1] + u1[i][j+1];
				previous_value = u1[i][j];
				previous_previous_value = u2[i][j];
				u[i][j] = (RHO * (sum_of_neighbors -4*previous_value) + 2*previous_value -(1-ETA)*previous_previous_value)/(1+ETA);
			}
		}

		// update side points
		for (i = 1; i < N-1; i++) {
			u[0][i] = BOUNDARY_GAIN * u[1][i]; // top
			u[N-1][i] = BOUNDARY_GAIN * u[N-2][i]; // bottom
			u[i][0] = BOUNDARY_GAIN * u[i][1]; // left
			u[i][N-1] = BOUNDARY_GAIN * u[i][N-2]; // right
		}

		// update corners
		u[0][0] = BOUNDARY_GAIN * u[1][0];
	    	u[N-1][0] = BOUNDARY_GAIN * u[N-2][0];
    		u[0][N-1] = BOUNDARY_GAIN * u[0][N-2];
    		u[N-1][N-1] = BOUNDARY_GAIN * u[N-1][N-2];

		

		// shift u1 into u2, u into u1
		// this is expensive!
		/*
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				u2[i][j] = u1[i][j];
				u1[i][j] = u[i][j];
			}
		}
		*/

//		print_grid(u);

		audio[t] = u[N/2][N/2];
		printf("%f,\n", audio[t]);

		temp = u2;
		u2 = u1;
		u1 = u;
		u = temp;

		// record displacement at node (N-1,N-1)
	}
	gettimeofday(&end_time, NULL);

	unsigned long long time_elapsed = 1000 * (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_usec - start_time.tv_usec) / 1000;

	printf("Time Elapsed [%llu ms]\n", time_elapsed);

	// free grid memory
	for (i = 0; i < N; i++) {
		free(u[i]);
		free(u1[i]);
		free(u2[i]);
	}

	free(u);
	free(u1);
	free(u2);
	free(audio);
}

	.text
	.file	"grid_sequential.hip"
	.globl	_Z10print_gridPPf               # -- Begin function _Z10print_gridPPf
	.type	_Z10print_gridPPf,@function
_Z10print_gridPPf:                      # @_Z10print_gridPPf
	.cfi_startproc
# %bb.0:
	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
.LBB0_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_2 Depth 2
	xorl	%r15d, %r15d
.LBB0_2:                                #   Parent Loop BB0_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%rbx,%r14,8), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax,%r15,4), %xmm0
	movl	$.L.str, %edi
	movl	%r14d, %esi
	movl	%r15d, %edx
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	$512, %r15                      # imm = 0x200
	jne	.LBB0_2
# %bb.3:                                #   in Loop: Header=BB0_1 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r14
	cmpq	$512, %r14                      # imm = 0x200
	jne	.LBB0_1
# %bb.4:
	movl	$10, %edi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end0:
	.size	_Z10print_gridPPf, .Lfunc_end0-_Z10print_gridPPf
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0xc0800000                      # float -4
.LCPI1_4:
	.long	0x3f400000                      # float 0.75
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_1:
	.quad	0x3fe0000000000000              # double 0.5
.LCPI1_2:
	.quad	0xbfeffe5c91d14e3c              # double -0.99980000000000002
.LCPI1_3:
	.quad	0x3ff000d1b71758e2              # double 1.0002
	.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	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movl	$4096, %edi                     # imm = 0x1000
	callq	malloc
	movq	%rax, %r12
	movl	$4096, %edi                     # imm = 0x1000
	callq	malloc
	movq	%rax, %rbx
	movl	$4096, %edi                     # imm = 0x1000
	callq	malloc
	movq	%rax, %r14
	xorl	%r15d, %r15d
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movl	$1, %edi
	movl	$2048, %esi                     # imm = 0x800
	callq	calloc@PLT
	movq	%rax, (%r12,%r15,8)
	movl	$1, %edi
	movl	$2048, %esi                     # imm = 0x800
	callq	calloc@PLT
	movq	%rax, (%rbx,%r15,8)
	movl	$1, %edi
	movl	$2048, %esi                     # imm = 0x800
	callq	calloc@PLT
	movq	%rax, (%r14,%r15,8)
	incq	%r15
	cmpq	$512, %r15                      # imm = 0x200
	jne	.LBB1_1
# %bb.2:
	xorl	%r13d, %r13d
	movl	$.L.str.2, %edi
	movl	$262144, %esi                   # imm = 0x40000
	xorl	%eax, %eax
	callq	printf
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	2048(%rbx), %rax
	movl	$1065353216, 1024(%rax)         # imm = 0x3F800000
	testl	%ebp, %ebp
	jle	.LBB1_3
# %bb.4:                                # %.preheader111.preheader
	movss	.LCPI1_0(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movsd	.LCPI1_1(%rip), %xmm4           # xmm4 = mem[0],zero
	movsd	.LCPI1_2(%rip), %xmm5           # xmm5 = mem[0],zero
	movsd	.LCPI1_3(%rip), %xmm6           # xmm6 = mem[0],zero
	movss	.LCPI1_4(%rip), %xmm7           # xmm7 = mem[0],zero,zero,zero
.LBB1_5:                                # %.preheader111
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_6 Depth 2
                                        #       Child Loop BB1_7 Depth 3
                                        #     Child Loop BB1_10 Depth 2
	movq	%r14, %r15
	movq	%rbx, %r14
	movq	%r12, %rbx
	movq	(%r14), %rcx
	movq	8(%r14), %rax
	movl	$1, %edx
.LBB1_6:                                # %.preheader
                                        #   Parent Loop BB1_5 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_7 Depth 3
	movq	%rax, %rsi
	movq	8(%r14,%rdx,8), %rdi
	movq	(%r15,%rdx,8), %r8
	movq	(%rbx,%rdx,8), %r9
	incq	%rdx
	xorl	%r10d, %r10d
.LBB1_7:                                #   Parent Loop BB1_5 Depth=1
                                        #     Parent Loop BB1_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	4(%rcx,%r10), %xmm0             # xmm0 = mem[0],zero,zero,zero
	addss	4(%rdi,%r10), %xmm0
	addss	(%rax,%r10), %xmm0
	addss	8(%rax,%r10), %xmm0
	movss	4(%rax,%r10), %xmm1             # xmm1 = mem[0],zero,zero,zero
	movaps	%xmm1, %xmm2
	mulss	%xmm3, %xmm2
	addss	%xmm0, %xmm2
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm2, %xmm0
	mulsd	%xmm4, %xmm0
	addss	%xmm1, %xmm1
	cvtss2sd	%xmm1, %xmm1
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtss2sd	4(%r8,%r10), %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	divsd	%xmm6, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 4(%r9,%r10)
	addq	$4, %r10
	cmpq	$2040, %r10                     # imm = 0x7F8
	jne	.LBB1_7
# %bb.8:                                #   in Loop: Header=BB1_6 Depth=2
	movq	%rdi, %rax
	movq	%rsi, %rcx
	cmpq	$511, %rdx                      # imm = 0x1FF
	jne	.LBB1_6
# %bb.9:                                # %.preheader110
                                        #   in Loop: Header=BB1_5 Depth=1
	movq	(%rbx), %rcx
	movq	8(%rbx), %rsi
	movq	4080(%rbx), %rdx
	movq	4088(%rbx), %rax
	xorl	%edi, %edi
.LBB1_10:                               #   Parent Loop BB1_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	4(%rsi,%rdi), %xmm0             # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm7, %xmm0
	movss	%xmm0, 4(%rcx,%rdi)
	movss	4(%rdx,%rdi), %xmm0             # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm7, %xmm0
	movss	%xmm0, 4(%rax,%rdi)
	movq	8(%rbx,%rdi,2), %r8
	movss	4(%r8), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm7, %xmm0
	movss	%xmm0, (%r8)
	movss	2040(%r8), %xmm0                # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm7, %xmm0
	movss	%xmm0, 2044(%r8)
	addq	$4, %rdi
	cmpq	$2040, %rdi                     # imm = 0x7F8
	jne	.LBB1_10
# %bb.11:                               #   in Loop: Header=BB1_5 Depth=1
	movss	(%rsi), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm7, %xmm0
	movss	%xmm0, (%rcx)
	movss	(%rdx), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm7, %xmm0
	movss	%xmm0, (%rax)
	movss	2040(%rcx), %xmm0               # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm7, %xmm0
	movss	%xmm0, 2044(%rcx)
	movss	2040(%rax), %xmm0               # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm7, %xmm0
	movss	%xmm0, 2044(%rax)
	movq	2048(%rbx), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	1024(%rax), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	movss	.LCPI1_4(%rip), %xmm7           # xmm7 = mem[0],zero,zero,zero
	incl	%r13d
	movq	%r15, %r12
	cmpl	%ebp, %r13d
	movss	.LCPI1_0(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movsd	.LCPI1_1(%rip), %xmm4           # xmm4 = mem[0],zero
	movsd	.LCPI1_2(%rip), %xmm5           # xmm5 = mem[0],zero
	movsd	.LCPI1_3(%rip), %xmm6           # xmm6 = mem[0],zero
	jne	.LBB1_5
	jmp	.LBB1_12
.LBB1_3:
	movq	%r12, %r15
.LBB1_12:                               # %._crit_edge
	xorl	%r13d, %r13d
	leaq	24(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r12), %rcx
	movq	8(%r12), %rax
	subq	8(%rsp), %rcx
	imulq	$1000, %rcx, %rcx               # imm = 0x3E8
	subq	16(%rsp), %rax
	movabsq	$2361183241434822607, %rdx      # imm = 0x20C49BA5E353F7CF
	imulq	%rdx
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$7, %rdx
	addq	%rdx, %rsi
	addq	%rcx, %rsi
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
.LBB1_13:                               # =>This Inner Loop Header: Depth=1
	movq	(%r15,%r13,8), %rdi
	callq	free
	movq	(%rbx,%r13,8), %rdi
	callq	free
	movq	(%r14,%r13,8), %rdi
	callq	free
	incq	%r13
	cmpq	$512, %r13                      # imm = 0x200
	jne	.LBB1_13
# %bb.14:
	movq	%r15, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$40, %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_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	"(%d,%d): %f "
	.size	.L.str, 13

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Size of grid: %d nodes\n"
	.size	.L.str.2, 24

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%f,\n"
	.size	.L.str.3, 5

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Time Elapsed [%llu ms]\n"
	.size	.L.str.4, 24

	.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
