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

/* Initialize the two arrays referenced by the first two parameters in preparation for 
 * jacobi iteration. The width and height of the arrays are given by the integer parameters.
 * Border elements are set to 5.0 for both arrays, and the interior elements of a1 are
 * set to 1.0.  Interior elements of a2 are not initialized.
 */
void initializeArrays(int *a1, int width, int height){

   int i, j;

   for(i=0; i<height; i++){
      for(j=0; j<width; j++){
      
        if(i==0 || j ==0 || i==height-1 || j==width-1){ 
         
            a1[i*width + j] = 1;
         }
	else {
         
            a1[i*width + j] = 0;
         }
      }
   }
}

/* Print the 2D array of floats referenced by the first parameter. The second and third
 * parameters specify its dimensions, while the last argument indicates whether printing
 * is actually descired at all. No output is produced if shouldPrint == 0.
 */
void printArray(int *arr, int rows, int cols, int shouldPrint){
   if (!shouldPrint)
      return;
          
   int i,j;

   for(i=0; i<rows; i++){
      for(j=0; j<cols; j++){
      
         printf("%d ", arr[i*cols + j]);
      }
      printf("\n");
   }

   printf("\n");
}

int strToInt(char * str){
	int length = strlen(str);
	int integer = 0;
	for (int i=0; i<length; i++){
		integer = integer + (str[i]-'0')*pow((double)10, (double)(length-1-i));
	}
	return integer;
}



	.file	"tmpxft_0027ce2e_00000000-6_Methods.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z16initializeArraysPiii
	.type	_Z16initializeArraysPiii, @function
_Z16initializeArraysPiii:
.LFB2027:
	.cfi_startproc
	endbr64
	xorl	%r9d, %r9d
	leal	-1(%rdx), %r10d
	leal	-1(%rsi), %r11d
	xorl	%ecx, %ecx
.L3:
	cmpl	%edx, %ecx
	jge	.L2
	movslq	%r9d, %rax
	leaq	(%rdi,%rax,4), %r8
	xorl	%eax, %eax
.L9:
	cmpl	%esi, %eax
	jge	.L11
	testl	%ecx, %ecx
	je	.L4
	testl	%eax, %eax
	je	.L4
	cmpl	%ecx, %r10d
	je	.L4
	cmpl	%eax, %r11d
	jne	.L5
.L4:
	movl	$1, (%r8)
	jmp	.L6
.L5:
	movl	$0, (%r8)
.L6:
	incl	%eax
	addq	$4, %r8
	jmp	.L9
.L11:
	incl	%ecx
	addl	%esi, %r9d
	jmp	.L3
.L2:
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z16initializeArraysPiii, .-_Z16initializeArraysPiii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d "
.LC1:
	.string	"\n"
	.text
	.globl	_Z10printArrayPiiii
	.type	_Z10printArrayPiiii, @function
_Z10printArrayPiiii:
.LFB2028:
	.cfi_startproc
	endbr64
	testl	%ecx, %ecx
	je	.L12
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	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
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L14:
	cmpl	%r14d, %r13d
	jge	.L16
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,4), %r8
.L17:
	cmpl	%r15d, %ebx
	jle	.L21
	movl	(%r8,%r15,4), %edx
	leaq	.LC0(%rip), %rsi
	xorl	%eax, %eax
	incq	%r15
	movl	$2, %edi
	movq	%r8, 8(%rsp)
	call	__printf_chk@PLT
	movq	8(%rsp), %r8
	jmp	.L17
.L21:
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	incl	%r13d
	addl	%ebx, %r12d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L14
.L16:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_restore 3
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_restore 6
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_restore 12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_restore 13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_restore 14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_restore 15
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
.L12:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z10printArrayPiiii, .-_Z10printArrayPiiii
	.globl	_Z8strToIntPc
	.type	_Z8strToIntPc, @function
_Z8strToIntPc:
.LFB2029:
	.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
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	xorl	%ebx, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	call	strlen@PLT
	movq	%rax, %r12
	movl	%eax, %r14d
.L23:
	cmpl	%ebx, %r14d
	jle	.L26
	movsbl	0(%rbp,%rbx), %eax
	movsd	.LC2(%rip), %xmm0
	subl	$48, %eax
	cvtsi2sdl	%eax, %xmm2
	leal	-1(%r12), %eax
	subl	%ebx, %eax
	incq	%rbx
	cvtsi2sdl	%eax, %xmm1
	movsd	%xmm2, 8(%rsp)
	call	pow@PLT
	movaps	%xmm0, %xmm1
	cvtsi2sdl	%r13d, %xmm0
	mulsd	8(%rsp), %xmm1
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %r13d
	jmp	.L23
.L26:
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	movl	%r13d, %eax
	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
.LFE2029:
	.size	_Z8strToIntPc, .-_Z8strToIntPc
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.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
.LFE2055:
	.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
.LC2:
	.long	0
	.long	1076101120
	.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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

/* Initialize the two arrays referenced by the first two parameters in preparation for 
 * jacobi iteration. The width and height of the arrays are given by the integer parameters.
 * Border elements are set to 5.0 for both arrays, and the interior elements of a1 are
 * set to 1.0.  Interior elements of a2 are not initialized.
 */
void initializeArrays(int *a1, int width, int height){

   int i, j;

   for(i=0; i<height; i++){
      for(j=0; j<width; j++){
      
        if(i==0 || j ==0 || i==height-1 || j==width-1){ 
         
            a1[i*width + j] = 1;
         }
	else {
         
            a1[i*width + j] = 0;
         }
      }
   }
}

/* Print the 2D array of floats referenced by the first parameter. The second and third
 * parameters specify its dimensions, while the last argument indicates whether printing
 * is actually descired at all. No output is produced if shouldPrint == 0.
 */
void printArray(int *arr, int rows, int cols, int shouldPrint){
   if (!shouldPrint)
      return;
          
   int i,j;

   for(i=0; i<rows; i++){
      for(j=0; j<cols; j++){
      
         printf("%d ", arr[i*cols + j]);
      }
      printf("\n");
   }

   printf("\n");
}

int strToInt(char * str){
	int length = strlen(str);
	int integer = 0;
	for (int i=0; i<length; i++){
		integer = integer + (str[i]-'0')*pow((double)10, (double)(length-1-i));
	}
	return integer;
}



	.text
	.file	"Methods.hip"
	.globl	_Z16initializeArraysPiii        # -- Begin function _Z16initializeArraysPiii
	.type	_Z16initializeArraysPiii,@function
_Z16initializeArraysPiii:               # @_Z16initializeArraysPiii
	.cfi_startproc
# %bb.0:
                                        # kill: def $edx killed $edx def $rdx
                                        # kill: def $esi killed $esi def $rsi
	testl	%edx, %edx
	jle	.LBB0_7
# %bb.1:                                # %.preheader.lr.ph
	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
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leal	-1(%rdx), %eax
	leal	-1(%rsi), %ecx
	movl	%edx, %edx
	movl	%esi, %r8d
	xorl	%r9d, %r9d
	xorl	%r10d, %r10d
.LBB0_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
	testl	%esi, %esi
	jle	.LBB0_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	%r9d, %r11d
	leaq	(%rdi,%r11,4), %r11
	xorl	%ebx, %ebx
.LBB0_4:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpq	%rax, %r10
	sete	%bpl
	testq	%r10, %r10
	sete	%r14b
	testq	%rbx, %rbx
	sete	%r15b
	orb	%r14b, %r15b
	cmpq	%rbx, %rcx
	sete	%r14b
	orb	%bpl, %r14b
	orb	%r15b, %r14b
	movzbl	%r14b, %ebp
	movl	%ebp, (%r11,%rbx,4)
	incq	%rbx
	cmpq	%rbx, %r8
	jne	.LBB0_4
.LBB0_5:                                # %._crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	incq	%r10
	addl	%esi, %r9d
	cmpq	%rdx, %r10
	jne	.LBB0_2
# %bb.6:
	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
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
	.cfi_restore %rbp
.LBB0_7:                                # %._crit_edge29
	retq
.Lfunc_end0:
	.size	_Z16initializeArraysPiii, .Lfunc_end0-_Z16initializeArraysPiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z10printArrayPiiii             # -- Begin function _Z10printArrayPiiii
	.type	_Z10printArrayPiiii,@function
_Z10printArrayPiiii:                    # @_Z10printArrayPiiii
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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	%rdi, 8(%rsp)                   # 8-byte Spill
	testl	%ecx, %ecx
	je	.LBB1_8
# %bb.1:                                # %.preheader13
	testl	%esi, %esi
	jle	.LBB1_7
# %bb.2:                                # %.preheader.lr.ph
	movl	%edx, %ebx
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%edx, %r12d
	xorl	%ebp, %ebp
	xorl	%r13d, %r13d
.LBB1_3:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_5 Depth 2
	testl	%ebx, %ebx
	jle	.LBB1_6
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB1_3 Depth=1
	movl	%ebp, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB1_5:                                #   Parent Loop BB1_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r14,%r15,4), %esi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB1_5
.LBB1_6:                                # %._crit_edge
                                        #   in Loop: Header=BB1_3 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r13
	addl	%ebx, %ebp
	cmpq	16(%rsp), %r13                  # 8-byte Folded Reload
	jne	.LBB1_3
.LBB1_7:                                # %._crit_edge16
	movl	$10, %edi
	addq	$24, %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
	jmp	putchar@PLT                     # TAILCALL
.LBB1_8:
	.cfi_def_cfa_offset 80
	addq	$24, %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	_Z10printArrayPiiii, .Lfunc_end1-_Z10printArrayPiiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z8strToIntPc
.LCPI2_0:
	.quad	0x4024000000000000              # double 10
	.text
	.globl	_Z8strToIntPc
	.type	_Z8strToIntPc,@function
_Z8strToIntPc:                          # @_Z8strToIntPc
	.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
	movq	%rdi, %rbx
	callq	strlen
	testl	%eax, %eax
	jle	.LBB2_1
# %bb.3:                                # %.lr.ph.preheader
	movl	%eax, %r14d
	leal	-1(%rax), %ebp
	xorl	%r15d, %r15d
	xorl	%eax, %eax
.LBB2_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	movsbl	(%rbx,%r15), %eax
	addl	$-48, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	xorps	%xmm1, %xmm1
	cvtsi2sd	%ebp, %xmm1
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	callq	pow
	mulsd	8(%rsp), %xmm0                  # 8-byte Folded Reload
	addsd	16(%rsp), %xmm0                 # 8-byte Folded Reload
	cvttsd2si	%xmm0, %eax
	incq	%r15
	decl	%ebp
	cmpq	%r15, %r14
	jne	.LBB2_4
	jmp	.LBB2_2
.LBB2_1:
	xorl	%eax, %eax
.LBB2_2:                                # %._crit_edge
	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
.Lfunc_end2:
	.size	_Z8strToIntPc, .Lfunc_end2-_Z8strToIntPc
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%d "
	.size	.L.str, 4

	.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
