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

float random_number(int min, int max){
        /* 
         * Function: random_number 
         * -----------------------
         *  return a random number between min and max as a float 
         */
        float num = rand() % (max + 1 - min) + min; 
        return num;
}

unsigned long int getOffset(int * indices, int * dimensions, int num_dimensions){ 
        /*
         * Function: getOffset
         * -------------------
         *  compute the offset from the base address of an array for given indices corresponding
         *  to dimensions. 
         * indices: pointer to array of indices e.g A[1,2,3] 
         * dimensions: pointer to array of dimensions e.g dimensionality of A = 2x3x4
         * num_dimensions: number of dimensions e.g dimensions(A) = 3
         *
         * returns:
         * -------
         *  offset: the offset from the base memory address. (NOTE: independant of datatype)
         */

        unsigned long int offset = 0.0; 
        for(int indexIdx=0; indexIdx<num_dimensions; indexIdx++){
                unsigned long int product = indices[indexIdx]; 
                for(int dimIdx=indexIdx+1; dimIdx<num_dimensions; dimIdx ++){
                        product = product * dimensions[dimIdx]; 
                }
                offset = offset + product; 
        }

        return offset; 
}

void randFill(float * arr, int * dimensions, int num_dimensions){
	/* 
	 * Must be a recursable function 
	 */ 
	
	// 1. Base condition  
	if(num_dimensions==1){
		printf("Reached base condition\n");
		for(int i=0; i<dimensions[0]; i++){
			*(arr + i) = random_number(1,100);
		}
	}
	// 2. Recursive condition 
	else { 
		int first_dim = dimensions[0]; 
		int second_dim = dimensions[1];
		printf("First dim : %d | Second dim : %d", first_dim, second_dim);
		int * new_dims = dimensions + 1; 
		for(int dim=0; dim<first_dim; dim++){
			randFill( arr+second_dim , new_dims, num_dimensions-1);
		}
	}
}	


void randFill2d(float * arr, int * dimensions){
        /*
         * Function: randFill3d 
         * --------------------
         *  fills a 3d array with random numbers between 1,100 
         */
        int HEIGHT = dimensions[0]; 
        int WIDTH = dimensions[1];
	for(int row=0; row<HEIGHT; row++){
                        for(int col=0; col<WIDTH; col++){
                                int indices[2] = {row, col};
                                *(arr + getOffset(indices, dimensions, 2)) = random_number(1,100);
                    	}
	}
}

void randFill3d(float * arr, int * dimensions){
        /*
         * Function: randFill3d 
         * --------------------
         *  fills a 3d array with random numbers between 1,100 
         */
        int CHANNELS = dimensions[0]; 
        int HEIGHT = dimensions[1]; 
        int WIDTH = dimensions[2];
        for(int chan=0; chan<CHANNELS; chan++){
                for(int row=0; row<HEIGHT; row++){
                        for(int col=0; col<WIDTH; col++){
                                int indices[3] = {chan, row, col};
                                *(arr + getOffset(indices, dimensions, 3)) = random_number(1,100);
                        }
                }
        }
}

void printArr2d(float * arr, int * dimensions){
	int HEIGHT = dimensions[0]; 
	int WIDTH  = dimensions[1]; 

	printf("\n2d Array: \n");
	for(int r=0; r<HEIGHT; r++){
		printf("\n"); 
		for(int c=0; c<WIDTH; c++){
			int indices[] = {r,c}; 
			printf(" %.1f ", *(arr + getOffset(indices, dimensions, 2)));
		}
	}
	printf("\n");
}


void printArr3d(float * arr, int * dimensions){
        /* To print a 3d array - used multiple times 
         */
        int CHANNELS = dimensions[0]; 
        int HEIGHT = dimensions[1]; 
        int WIDTH = dimensions[2];
        for(int chan=0; chan<CHANNELS; chan++){
                printf("\nChannel %d", chan);
                for(int row=0; row<HEIGHT; row++){
                        printf("\n");
                        for(int col=0; col<WIDTH; col++){
                                int indices[3] = {chan, row, col};
                                printf(" %.1f ", *(arr + getOffset(indices, dimensions, 3)));
                        }
                }
		printf("\n");
        }
}

float * new3dArray(int DEPTH, int HEIGHT, int WIDTH){
	float * arr = (float*)malloc(DEPTH*HEIGHT*WIDTH*sizeof(float)); 
	return arr; 
}

float * new2dArray(int HEIGHT, int WIDTH){
	float * arr = (float*)malloc(HEIGHT*WIDTH*sizeof(float)); 
	return arr; 
}

/*
int main()
{
        // Test this! 
        float arr[4][3] = { {1,2,3}, {4,5,6}, {7,8,9}, {10,11,12} }; // 4x3 array 
        float * arr_ptr = &arr[0][0];
        int indices[] = {2,1}; 
        int dimensions[] = {4,3};
        int num_dimensions = 2;

        unsigned long int offset = getOffset( indices, dimensions, num_dimensions );
        printf("value at ( %d , %d ) is %f \n", indices[0], indices[1], arr[indices[0]][indices[1]]);
        printf("value at ( %d , %d ) is %f \n", indices[0], indices[1], *(arr_ptr + offset) );

        // Test fillArr and printArr 
        srand(time(0));
        const int HEIGHT=2;
        const int WIDTH=3; 
        const int DEPTH=4; 

        float * multiArr = (float *)malloc(HEIGHT*WIDTH*DEPTH*sizeof(float));
        int dimensions2[] = {DEPTH, HEIGHT, WIDTH};
        randFill3d(multiArr, dimensions2); 
        printArr3d(multiArr, dimensions2);
        
        return 0;
}
*/

	.file	"tmpxft_002a522a_00000000-6_utils.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2038:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2038:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z13random_numberii
	.type	_Z13random_numberii, @function
_Z13random_numberii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%esi, %ebx
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	rand@PLT
	leal	1(%rbx), %esi
	subl	%ebp, %esi
	cltd
	idivl	%esi
	addl	%ebp, %edx
	cvtsi2ssl	%edx, %xmm0
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z13random_numberii, .-_Z13random_numberii
	.globl	_Z9getOffsetPiS_i
	.type	_Z9getOffsetPiS_i, @function
_Z9getOffsetPiS_i:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	$1, %eax
	xorl	%r8d, %r8d
.L5:
	leal	-1(%rax), %ecx
	cmpl	%ecx, %edx
	jle	.L10
	movslq	-4(%rdi,%rax,4), %r9
	movq	%rax, %rcx
.L6:
	cmpl	%ecx, %edx
	jle	.L11
	movslq	(%rsi,%rcx,4), %r10
	incq	%rcx
	imulq	%r10, %r9
	jmp	.L6
.L11:
	addq	%r9, %r8
	incq	%rax
	jmp	.L5
.L10:
	movq	%r8, %rax
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9getOffsetPiS_i, .-_Z9getOffsetPiS_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Reached base condition\n"
.LC1:
	.string	"First dim : %d | Second dim : %d"
	.text
	.globl	_Z8randFillPfPii
	.type	_Z8randFillPfPii, @function
_Z8randFillPfPii:
.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
	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
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	cmpl	$1, %edx
	jne	.L13
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
.L14:
	cmpl	%ebx, 0(%rbp)
	jle	.L12
	movl	$100, %esi
	movl	$1, %edi
	call	_Z13random_numberii
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L14
.L13:
	movslq	4(%rsi), %r14
	movl	(%rsi), %r13d
	movl	%edx, %ebx
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	addq	$4, %rbp
	decl	%ebx
	movl	%r14d, %ecx
	movl	%r13d, %edx
	leaq	(%r12,%r14,4), %r14
	xorl	%r12d, %r12d
	call	__printf_chk@PLT
.L16:
	cmpl	%r13d, %r12d
	jge	.L12
	movl	%ebx, %edx
	movq	%rbp, %rsi
	movq	%r14, %rdi
	incl	%r12d
	call	_Z8randFillPfPii
	jmp	.L16
.L12:
	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	_Z8randFillPfPii, .-_Z8randFillPfPii
	.globl	_Z10randFill2dPfPi
	.type	_Z10randFill2dPfPi, @function
_Z10randFill2dPfPi:
.LFB2030:
	.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
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movl	(%rsi), %r15d
	movl	4(%rsi), %r14d
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rax
	movq	%rax, 8(%rsp)
.L21:
	cmpl	%r15d, %ebp
	jge	.L27
	xorl	%r12d, %r12d
.L23:
	cmpl	%r14d, %r12d
	jge	.L28
	movl	$100, %esi
	movl	$1, %edi
	movl	%r12d, 20(%rsp)
	incl	%r12d
	movl	%ebp, 16(%rsp)
	call	_Z13random_numberii
	movq	8(%rsp), %rdi
	movl	$2, %edx
	movq	%rbx, %rsi
	call	_Z9getOffsetPiS_i
	movss	%xmm0, 0(%r13,%rax,4)
	jmp	.L23
.L28:
	incl	%ebp
	jmp	.L21
.L27:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$40, %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
.LFE2030:
	.size	_Z10randFill2dPfPi, .-_Z10randFill2dPfPi
	.globl	_Z10randFill3dPfPi
	.type	_Z10randFill3dPfPi, @function
_Z10randFill3dPfPi:
.LFB2031:
	.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
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movl	(%rsi), %r15d
	movl	4(%rsi), %r8d
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	8(%rsi), %r9d
	movq	%rax, (%rsp)
.L30:
	cmpl	%r15d, %ebp
	jge	.L38
	xorl	%r12d, %r12d
.L33:
	cmpl	%r8d, %r12d
	jge	.L39
	xorl	%r13d, %r13d
.L32:
	cmpl	%r9d, %r13d
	jge	.L40
	movl	$100, %esi
	movl	$1, %edi
	movl	%r9d, 12(%rsp)
	movl	%r8d, 8(%rsp)
	movl	%r13d, 36(%rsp)
	incl	%r13d
	movl	%ebp, 28(%rsp)
	movl	%r12d, 32(%rsp)
	call	_Z13random_numberii
	movq	(%rsp), %rdi
	movl	$3, %edx
	movq	%rbx, %rsi
	call	_Z9getOffsetPiS_i
	movl	8(%rsp), %r8d
	movl	12(%rsp), %r9d
	movss	%xmm0, (%r14,%rax,4)
	jmp	.L32
.L40:
	incl	%r12d
	jmp	.L33
.L39:
	incl	%ebp
	jmp	.L30
.L38:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	addq	$56, %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
.LFE2031:
	.size	_Z10randFill3dPfPi, .-_Z10randFill3dPfPi
	.section	.rodata.str1.1
.LC2:
	.string	"\n2d Array: \n"
.LC3:
	.string	"\n"
.LC4:
	.string	" %.1f "
	.text
	.globl	_Z10printArr2dPfPi
	.type	_Z10printArr2dPfPi, @function
_Z10printArr2dPfPi:
.LFB2032:
	.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
	movl	$2, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	(%rsi), %r13d
	movl	4(%rsi), %r14d
	leaq	.LC2(%rip), %rsi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L42:
	cmpl	%r13d, %ebp
	jge	.L49
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	call	__printf_chk@PLT
.L43:
	cmpl	%r14d, %r15d
	jge	.L50
	movq	%rsp, %rdi
	movl	$2, %edx
	movq	%rbx, %rsi
	movl	%r15d, 4(%rsp)
	movl	%ebp, (%rsp)
	incl	%r15d
	call	_Z9getOffsetPiS_i
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	(%r12,%rax,4), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	jmp	.L43
.L50:
	incl	%ebp
	jmp	.L42
.L49:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L46
	call	__stack_chk_fail@PLT
.L46:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	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
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2032:
	.size	_Z10printArr2dPfPi, .-_Z10printArr2dPfPi
	.section	.rodata.str1.1
.LC5:
	.string	"\nChannel %d"
	.text
	.globl	_Z10printArr3dPfPi
	.type	_Z10printArr3dPfPi, @function
_Z10printArr3dPfPi:
.LFB2033:
	.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
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movl	4(%rsi), %r14d
	movl	8(%rsi), %r15d
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	movl	(%rsi), %eax
	movl	%eax, 8(%rsp)
.L52:
	movl	8(%rsp), %eax
	cmpl	%eax, %ebp
	jge	.L60
	movl	%ebp, %edx
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%r12d, %r12d
.L53:
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	cmpl	%r14d, %r12d
	jge	.L61
	call	__printf_chk@PLT
	xorl	%ecx, %ecx
.L54:
	cmpl	%r15d, %ecx
	jge	.L62
	leaq	28(%rsp), %rdi
	movl	$3, %edx
	movq	%rbx, %rsi
	movl	%ecx, 36(%rsp)
	movl	%ecx, 12(%rsp)
	movl	%ebp, 28(%rsp)
	movl	%r12d, 32(%rsp)
	call	_Z9getOffsetPiS_i
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	0(%r13,%rax,4), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	movl	12(%rsp), %ecx
	incl	%ecx
	jmp	.L54
.L62:
	incl	%r12d
	jmp	.L53
.L61:
	call	__printf_chk@PLT
	incl	%ebp
	jmp	.L52
.L60:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L58
	call	__stack_chk_fail@PLT
.L58:
	addq	$56, %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
.LFE2033:
	.size	_Z10printArr3dPfPi, .-_Z10printArr3dPfPi
	.globl	_Z10new3dArrayiii
	.type	_Z10new3dArrayiii, @function
_Z10new3dArrayiii:
.LFB2034:
	.cfi_startproc
	endbr64
	imull	%esi, %edi
	imull	%edx, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	jmp	malloc@PLT
	.cfi_endproc
.LFE2034:
	.size	_Z10new3dArrayiii, .-_Z10new3dArrayiii
	.globl	_Z10new2dArrayii
	.type	_Z10new2dArrayii, @function
_Z10new2dArrayii:
.LFB2035:
	.cfi_startproc
	endbr64
	imull	%esi, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	jmp	malloc@PLT
	.cfi_endproc
.LFE2035:
	.size	_Z10new2dArrayii, .-_Z10new2dArrayii
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.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
.LFE2061:
	.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 <hip/hip_runtime.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

float random_number(int min, int max){
        /* 
         * Function: random_number 
         * -----------------------
         *  return a random number between min and max as a float 
         */
        float num = rand() % (max + 1 - min) + min; 
        return num;
}

unsigned long int getOffset(int * indices, int * dimensions, int num_dimensions){ 
        /*
         * Function: getOffset
         * -------------------
         *  compute the offset from the base address of an array for given indices corresponding
         *  to dimensions. 
         * indices: pointer to array of indices e.g A[1,2,3] 
         * dimensions: pointer to array of dimensions e.g dimensionality of A = 2x3x4
         * num_dimensions: number of dimensions e.g dimensions(A) = 3
         *
         * returns:
         * -------
         *  offset: the offset from the base memory address. (NOTE: independant of datatype)
         */

        unsigned long int offset = 0.0; 
        for(int indexIdx=0; indexIdx<num_dimensions; indexIdx++){
                unsigned long int product = indices[indexIdx]; 
                for(int dimIdx=indexIdx+1; dimIdx<num_dimensions; dimIdx ++){
                        product = product * dimensions[dimIdx]; 
                }
                offset = offset + product; 
        }

        return offset; 
}

void randFill(float * arr, int * dimensions, int num_dimensions){
	/* 
	 * Must be a recursable function 
	 */ 
	
	// 1. Base condition  
	if(num_dimensions==1){
		printf("Reached base condition\n");
		for(int i=0; i<dimensions[0]; i++){
			*(arr + i) = random_number(1,100);
		}
	}
	// 2. Recursive condition 
	else { 
		int first_dim = dimensions[0]; 
		int second_dim = dimensions[1];
		printf("First dim : %d | Second dim : %d", first_dim, second_dim);
		int * new_dims = dimensions + 1; 
		for(int dim=0; dim<first_dim; dim++){
			randFill( arr+second_dim , new_dims, num_dimensions-1);
		}
	}
}	


void randFill2d(float * arr, int * dimensions){
        /*
         * Function: randFill3d 
         * --------------------
         *  fills a 3d array with random numbers between 1,100 
         */
        int HEIGHT = dimensions[0]; 
        int WIDTH = dimensions[1];
	for(int row=0; row<HEIGHT; row++){
                        for(int col=0; col<WIDTH; col++){
                                int indices[2] = {row, col};
                                *(arr + getOffset(indices, dimensions, 2)) = random_number(1,100);
                    	}
	}
}

void randFill3d(float * arr, int * dimensions){
        /*
         * Function: randFill3d 
         * --------------------
         *  fills a 3d array with random numbers between 1,100 
         */
        int CHANNELS = dimensions[0]; 
        int HEIGHT = dimensions[1]; 
        int WIDTH = dimensions[2];
        for(int chan=0; chan<CHANNELS; chan++){
                for(int row=0; row<HEIGHT; row++){
                        for(int col=0; col<WIDTH; col++){
                                int indices[3] = {chan, row, col};
                                *(arr + getOffset(indices, dimensions, 3)) = random_number(1,100);
                        }
                }
        }
}

void printArr2d(float * arr, int * dimensions){
	int HEIGHT = dimensions[0]; 
	int WIDTH  = dimensions[1]; 

	printf("\n2d Array: \n");
	for(int r=0; r<HEIGHT; r++){
		printf("\n"); 
		for(int c=0; c<WIDTH; c++){
			int indices[] = {r,c}; 
			printf(" %.1f ", *(arr + getOffset(indices, dimensions, 2)));
		}
	}
	printf("\n");
}


void printArr3d(float * arr, int * dimensions){
        /* To print a 3d array - used multiple times 
         */
        int CHANNELS = dimensions[0]; 
        int HEIGHT = dimensions[1]; 
        int WIDTH = dimensions[2];
        for(int chan=0; chan<CHANNELS; chan++){
                printf("\nChannel %d", chan);
                for(int row=0; row<HEIGHT; row++){
                        printf("\n");
                        for(int col=0; col<WIDTH; col++){
                                int indices[3] = {chan, row, col};
                                printf(" %.1f ", *(arr + getOffset(indices, dimensions, 3)));
                        }
                }
		printf("\n");
        }
}

float * new3dArray(int DEPTH, int HEIGHT, int WIDTH){
	float * arr = (float*)malloc(DEPTH*HEIGHT*WIDTH*sizeof(float)); 
	return arr; 
}

float * new2dArray(int HEIGHT, int WIDTH){
	float * arr = (float*)malloc(HEIGHT*WIDTH*sizeof(float)); 
	return arr; 
}

/*
int main()
{
        // Test this! 
        float arr[4][3] = { {1,2,3}, {4,5,6}, {7,8,9}, {10,11,12} }; // 4x3 array 
        float * arr_ptr = &arr[0][0];
        int indices[] = {2,1}; 
        int dimensions[] = {4,3};
        int num_dimensions = 2;

        unsigned long int offset = getOffset( indices, dimensions, num_dimensions );
        printf("value at ( %d , %d ) is %f \n", indices[0], indices[1], arr[indices[0]][indices[1]]);
        printf("value at ( %d , %d ) is %f \n", indices[0], indices[1], *(arr_ptr + offset) );

        // Test fillArr and printArr 
        srand(time(0));
        const int HEIGHT=2;
        const int WIDTH=3; 
        const int DEPTH=4; 

        float * multiArr = (float *)malloc(HEIGHT*WIDTH*DEPTH*sizeof(float));
        int dimensions2[] = {DEPTH, HEIGHT, WIDTH};
        randFill3d(multiArr, dimensions2); 
        printArr3d(multiArr, dimensions2);
        
        return 0;
}
*/

	.text
	.file	"utils.hip"
	.globl	_Z13random_numberii             # -- Begin function _Z13random_numberii
	.type	_Z13random_numberii,@function
_Z13random_numberii:                    # @_Z13random_numberii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movl	%edi, %ebp
	callq	rand
	subl	%ebp, %ebx
	incl	%ebx
	cltd
	idivl	%ebx
	addl	%ebp, %edx
	cvtsi2ss	%edx, %xmm0
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z13random_numberii, .Lfunc_end0-_Z13random_numberii
	.cfi_endproc
                                        # -- End function
	.globl	_Z9getOffsetPiS_i               # -- Begin function _Z9getOffsetPiS_i
	.type	_Z9getOffsetPiS_i,@function
_Z9getOffsetPiS_i:                      # @_Z9getOffsetPiS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB1_1
# %bb.3:                                # %.lr.ph23.preheader
	movl	%edx, %ecx
	xorl	%edx, %edx
	movq	%rcx, %r8
	xorl	%eax, %eax
.LBB1_4:                                # %.lr.ph23
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_6 Depth 2
	movslq	(%rdi,%rdx,4), %r9
	incq	%rdx
	cmpq	%rcx, %rdx
	jae	.LBB1_7
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB1_4 Depth=1
	movl	$1, %r10d
.LBB1_6:                                # %.lr.ph
                                        #   Parent Loop BB1_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movslq	(%rsi,%r10,4), %r11
	imulq	%r11, %r9
	incq	%r10
	cmpq	%r10, %r8
	jne	.LBB1_6
.LBB1_7:                                # %._crit_edge
                                        #   in Loop: Header=BB1_4 Depth=1
	addq	%r9, %rax
	addq	$4, %rsi
	decq	%r8
	cmpq	%rcx, %rdx
	jne	.LBB1_4
# %bb.2:                                # %._crit_edge24
	retq
.LBB1_1:
	xorl	%eax, %eax
	retq
.Lfunc_end1:
	.size	_Z9getOffsetPiS_i, .Lfunc_end1-_Z9getOffsetPiS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z8randFillPfPii                # -- Begin function _Z8randFillPfPii
	.type	_Z8randFillPfPii,@function
_Z8randFillPfPii:                       # @_Z8randFillPfPii
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	cmpl	$1, %edx
	jne	.LBB2_4
# %bb.1:
	movl	$.Lstr, %edi
	callq	puts@PLT
	cmpl	$0, (%rbx)
	jle	.LBB2_7
# %bb.2:                                # %.lr.ph22.preheader
	xorl	%r15d, %r15d
.LBB2_3:                                # %.lr.ph22
                                        # =>This Inner Loop Header: Depth=1
	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
	negl	%ecx
	addl	%ecx, %eax
	incl	%eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	movslq	(%rbx), %rax
	cmpq	%rax, %r15
	jl	.LBB2_3
	jmp	.LBB2_7
.LBB2_4:
	movl	%edx, %ebp
	movl	(%rbx), %r15d
	movl	4(%rbx), %r12d
	movl	$.L.str.1, %edi
	movl	%r15d, %esi
	movl	%r12d, %edx
	xorl	%eax, %eax
	callq	printf
	testl	%r15d, %r15d
	jle	.LBB2_7
# %bb.5:                                # %.lr.ph
	addq	$4, %rbx
	movslq	%r12d, %rax
	leaq	(%r14,%rax,4), %r14
	decl	%ebp
.LBB2_6:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movq	%rbx, %rsi
	movl	%ebp, %edx
	callq	_Z8randFillPfPii
	decl	%r15d
	jne	.LBB2_6
.LBB2_7:                                # %.loopexit
	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_end2:
	.size	_Z8randFillPfPii, .Lfunc_end2-_Z8randFillPfPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z10randFill2dPfPi              # -- Begin function _Z10randFill2dPfPi
	.type	_Z10randFill2dPfPi,@function
_Z10randFill2dPfPi:                     # @_Z10randFill2dPfPi
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	(%rsi), %ebp
	testl	%ebp, %ebp
	jle	.LBB3_9
# %bb.1:                                # %.preheader.lr.ph
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movl	4(%rsi), %r15d
	xorl	%r12d, %r12d
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
                                        #       Child Loop BB3_5 Depth 3
                                        #         Child Loop BB3_10 Depth 4
	testl	%r15d, %r15d
	jle	.LBB3_8
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB3_2 Depth=1
	xorl	%r13d, %r13d
.LBB3_4:                                # %.lr.ph
                                        #   Parent Loop BB3_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_5 Depth 3
                                        #         Child Loop BB3_10 Depth 4
	movl	%r12d, (%rsp)
	movl	%r13d, 4(%rsp)
	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
	negl	%ecx
	addl	%ecx, %eax
	incl	%eax
	xorl	%edx, %edx
	xorl	%ecx, %ecx
.LBB3_5:                                # %.lr.ph23.i
                                        #   Parent Loop BB3_2 Depth=1
                                        #     Parent Loop BB3_4 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB3_10 Depth 4
	movslq	(%rsp,%rdx,4), %rsi
	movq	%rdx, %rdi
	testq	%rdx, %rdx
	jne	.LBB3_6
.LBB3_10:                               # %.lr.ph.i
                                        #   Parent Loop BB3_2 Depth=1
                                        #     Parent Loop BB3_4 Depth=2
                                        #       Parent Loop BB3_5 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	movslq	4(%rbx,%rdi,4), %r8
	imulq	%r8, %rsi
	incq	%rdi
	cmpq	$1, %rdi
	jne	.LBB3_10
.LBB3_6:                                # %._crit_edge.i
                                        #   in Loop: Header=BB3_5 Depth=3
	incq	%rdx
	addq	%rsi, %rcx
	cmpq	$2, %rdx
	jne	.LBB3_5
# %bb.7:                                # %_Z9getOffsetPiS_i.exit
                                        #   in Loop: Header=BB3_4 Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r14,%rcx,4)
	incl	%r13d
	cmpl	%r15d, %r13d
	jne	.LBB3_4
.LBB3_8:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	incl	%r12d
	cmpl	%ebp, %r12d
	jne	.LBB3_2
.LBB3_9:                                # %._crit_edge15
	addq	$8, %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_end3:
	.size	_Z10randFill2dPfPi, .Lfunc_end3-_Z10randFill2dPfPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10randFill3dPfPi              # -- Begin function _Z10randFill3dPfPi
	.type	_Z10randFill3dPfPi,@function
_Z10randFill3dPfPi:                     # @_Z10randFill3dPfPi
	.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
	movl	(%rsi), %eax
	movl	%eax, 8(%rsp)                   # 4-byte Spill
	testl	%eax, %eax
	jle	.LBB4_12
# %bb.1:                                # %.preheader18.lr.ph
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movl	4(%rsi), %eax
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	movl	8(%rsi), %r12d
	xorl	%r13d, %r13d
.LBB4_2:                                # %.preheader18
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_4 Depth 2
                                        #       Child Loop BB4_6 Depth 3
                                        #         Child Loop BB4_7 Depth 4
                                        #           Child Loop BB4_13 Depth 5
	cmpl	$0, 4(%rsp)                     # 4-byte Folded Reload
	jle	.LBB4_11
# %bb.3:                                # %.preheader.preheader
                                        #   in Loop: Header=BB4_2 Depth=1
	xorl	%ebp, %ebp
.LBB4_4:                                # %.preheader
                                        #   Parent Loop BB4_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB4_6 Depth 3
                                        #         Child Loop BB4_7 Depth 4
                                        #           Child Loop BB4_13 Depth 5
	testl	%r12d, %r12d
	jle	.LBB4_10
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB4_4 Depth=2
	xorl	%r15d, %r15d
.LBB4_6:                                # %.lr.ph
                                        #   Parent Loop BB4_2 Depth=1
                                        #     Parent Loop BB4_4 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB4_7 Depth 4
                                        #           Child Loop BB4_13 Depth 5
	movl	%r13d, 12(%rsp)
	movl	%ebp, 16(%rsp)
	movl	%r15d, 20(%rsp)
	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
	negl	%ecx
	addl	%ecx, %eax
	incl	%eax
	xorl	%edx, %edx
	xorl	%ecx, %ecx
.LBB4_7:                                # %.lr.ph23.i
                                        #   Parent Loop BB4_2 Depth=1
                                        #     Parent Loop BB4_4 Depth=2
                                        #       Parent Loop BB4_6 Depth=3
                                        # =>      This Loop Header: Depth=4
                                        #           Child Loop BB4_13 Depth 5
	movslq	12(%rsp,%rdx,4), %rsi
	movq	%rdx, %rdi
	cmpq	$1, %rdx
	ja	.LBB4_8
.LBB4_13:                               # %.lr.ph.i
                                        #   Parent Loop BB4_2 Depth=1
                                        #     Parent Loop BB4_4 Depth=2
                                        #       Parent Loop BB4_6 Depth=3
                                        #         Parent Loop BB4_7 Depth=4
                                        # =>        This Inner Loop Header: Depth=5
	movslq	4(%rbx,%rdi,4), %r8
	imulq	%r8, %rsi
	incq	%rdi
	cmpq	$2, %rdi
	jne	.LBB4_13
.LBB4_8:                                # %._crit_edge.i
                                        #   in Loop: Header=BB4_7 Depth=4
	incq	%rdx
	addq	%rsi, %rcx
	cmpq	$3, %rdx
	jne	.LBB4_7
# %bb.9:                                # %_Z9getOffsetPiS_i.exit
                                        #   in Loop: Header=BB4_6 Depth=3
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r14,%rcx,4)
	incl	%r15d
	cmpl	%r12d, %r15d
	jne	.LBB4_6
.LBB4_10:                               # %._crit_edge
                                        #   in Loop: Header=BB4_4 Depth=2
	incl	%ebp
	cmpl	4(%rsp), %ebp                   # 4-byte Folded Reload
	jne	.LBB4_4
.LBB4_11:                               # %._crit_edge22
                                        #   in Loop: Header=BB4_2 Depth=1
	incl	%r13d
	cmpl	8(%rsp), %r13d                  # 4-byte Folded Reload
	jne	.LBB4_2
.LBB4_12:                               # %._crit_edge24
	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_end4:
	.size	_Z10randFill3dPfPi, .Lfunc_end4-_Z10randFill3dPfPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10printArr2dPfPi              # -- Begin function _Z10printArr2dPfPi
	.type	_Z10printArr2dPfPi,@function
_Z10printArr2dPfPi:                     # @_Z10printArr2dPfPi
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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	%rsi, %rbx
	movq	%rdi, %r14
	movl	(%rsi), %ebp
	movl	4(%rsi), %r15d
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	testl	%ebp, %ebp
	jle	.LBB5_9
# %bb.1:                                # %.lr.ph17
	xorl	%r12d, %r12d
.LBB5_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_4 Depth 2
                                        #       Child Loop BB5_5 Depth 3
                                        #         Child Loop BB5_10 Depth 4
	movl	$10, %edi
	callq	putchar@PLT
	testl	%r15d, %r15d
	jle	.LBB5_8
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB5_2 Depth=1
	xorl	%r13d, %r13d
.LBB5_4:                                # %.lr.ph
                                        #   Parent Loop BB5_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB5_5 Depth 3
                                        #         Child Loop BB5_10 Depth 4
	movl	%r12d, (%rsp)
	movl	%r13d, 4(%rsp)
	xorl	%ecx, %ecx
	xorl	%eax, %eax
.LBB5_5:                                # %.lr.ph23.i
                                        #   Parent Loop BB5_2 Depth=1
                                        #     Parent Loop BB5_4 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB5_10 Depth 4
	movslq	(%rsp,%rcx,4), %rdx
	movq	%rcx, %rsi
	testq	%rcx, %rcx
	jne	.LBB5_6
.LBB5_10:                               # %.lr.ph.i
                                        #   Parent Loop BB5_2 Depth=1
                                        #     Parent Loop BB5_4 Depth=2
                                        #       Parent Loop BB5_5 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	movslq	4(%rbx,%rsi,4), %rdi
	imulq	%rdi, %rdx
	incq	%rsi
	cmpq	$1, %rsi
	jne	.LBB5_10
.LBB5_6:                                # %._crit_edge.i
                                        #   in Loop: Header=BB5_5 Depth=3
	incq	%rcx
	addq	%rdx, %rax
	cmpq	$2, %rcx
	jne	.LBB5_5
# %bb.7:                                # %_Z9getOffsetPiS_i.exit
                                        #   in Loop: Header=BB5_4 Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rax,4), %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	incl	%r13d
	cmpl	%r15d, %r13d
	jne	.LBB5_4
.LBB5_8:                                # %._crit_edge
                                        #   in Loop: Header=BB5_2 Depth=1
	incl	%r12d
	cmpl	%ebp, %r12d
	jne	.LBB5_2
.LBB5_9:                                # %._crit_edge18
	movl	$10, %edi
	addq	$8, %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
.Lfunc_end5:
	.size	_Z10printArr2dPfPi, .Lfunc_end5-_Z10printArr2dPfPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10printArr3dPfPi              # -- Begin function _Z10printArr3dPfPi
	.type	_Z10printArr3dPfPi,@function
_Z10printArr3dPfPi:                     # @_Z10printArr3dPfPi
	.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
	movl	(%rsi), %eax
	movl	%eax, 8(%rsp)                   # 4-byte Spill
	testl	%eax, %eax
	jle	.LBB6_12
# %bb.1:                                # %.lr.ph28
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movl	4(%rsi), %eax
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	movl	8(%rsi), %r13d
	xorl	%ebp, %ebp
.LBB6_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_4 Depth 2
                                        #       Child Loop BB6_6 Depth 3
                                        #         Child Loop BB6_7 Depth 4
                                        #           Child Loop BB6_13 Depth 5
	movl	$.L.str.5, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, 4(%rsp)                     # 4-byte Folded Reload
	jle	.LBB6_11
# %bb.3:                                # %.lr.ph24.preheader
                                        #   in Loop: Header=BB6_2 Depth=1
	xorl	%r15d, %r15d
.LBB6_4:                                # %.lr.ph24
                                        #   Parent Loop BB6_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB6_6 Depth 3
                                        #         Child Loop BB6_7 Depth 4
                                        #           Child Loop BB6_13 Depth 5
	movl	$10, %edi
	callq	putchar@PLT
	testl	%r13d, %r13d
	jle	.LBB6_10
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB6_4 Depth=2
	xorl	%r12d, %r12d
.LBB6_6:                                # %.lr.ph
                                        #   Parent Loop BB6_2 Depth=1
                                        #     Parent Loop BB6_4 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB6_7 Depth 4
                                        #           Child Loop BB6_13 Depth 5
	movl	%ebp, 12(%rsp)
	movl	%r15d, 16(%rsp)
	movl	%r12d, 20(%rsp)
	xorl	%ecx, %ecx
	xorl	%eax, %eax
.LBB6_7:                                # %.lr.ph23.i
                                        #   Parent Loop BB6_2 Depth=1
                                        #     Parent Loop BB6_4 Depth=2
                                        #       Parent Loop BB6_6 Depth=3
                                        # =>      This Loop Header: Depth=4
                                        #           Child Loop BB6_13 Depth 5
	movslq	12(%rsp,%rcx,4), %rdx
	movq	%rcx, %rsi
	cmpq	$1, %rcx
	ja	.LBB6_8
.LBB6_13:                               # %.lr.ph.i
                                        #   Parent Loop BB6_2 Depth=1
                                        #     Parent Loop BB6_4 Depth=2
                                        #       Parent Loop BB6_6 Depth=3
                                        #         Parent Loop BB6_7 Depth=4
                                        # =>        This Inner Loop Header: Depth=5
	movslq	4(%rbx,%rsi,4), %rdi
	imulq	%rdi, %rdx
	incq	%rsi
	cmpq	$2, %rsi
	jne	.LBB6_13
.LBB6_8:                                # %._crit_edge.i
                                        #   in Loop: Header=BB6_7 Depth=4
	incq	%rcx
	addq	%rdx, %rax
	cmpq	$3, %rcx
	jne	.LBB6_7
# %bb.9:                                # %_Z9getOffsetPiS_i.exit
                                        #   in Loop: Header=BB6_6 Depth=3
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rax,4), %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	incl	%r12d
	cmpl	%r13d, %r12d
	jne	.LBB6_6
.LBB6_10:                               # %._crit_edge
                                        #   in Loop: Header=BB6_4 Depth=2
	incl	%r15d
	cmpl	4(%rsp), %r15d                  # 4-byte Folded Reload
	jne	.LBB6_4
.LBB6_11:                               # %._crit_edge25
                                        #   in Loop: Header=BB6_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incl	%ebp
	cmpl	8(%rsp), %ebp                   # 4-byte Folded Reload
	jne	.LBB6_2
.LBB6_12:                               # %._crit_edge29
	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_end6:
	.size	_Z10printArr3dPfPi, .Lfunc_end6-_Z10printArr3dPfPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10new3dArrayiii               # -- Begin function _Z10new3dArrayiii
	.type	_Z10new3dArrayiii,@function
_Z10new3dArrayiii:                      # @_Z10new3dArrayiii
	.cfi_startproc
# %bb.0:
	imull	%esi, %edi
	imull	%edx, %edi
	movslq	%edi, %rdi
	shlq	$2, %rdi
	jmp	malloc                          # TAILCALL
.Lfunc_end7:
	.size	_Z10new3dArrayiii, .Lfunc_end7-_Z10new3dArrayiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z10new2dArrayii                # -- Begin function _Z10new2dArrayii
	.type	_Z10new2dArrayii,@function
_Z10new2dArrayii:                       # @_Z10new2dArrayii
	.cfi_startproc
# %bb.0:
	imull	%esi, %edi
	movslq	%edi, %rdi
	shlq	$2, %rdi
	jmp	malloc                          # TAILCALL
.Lfunc_end8:
	.size	_Z10new2dArrayii, .Lfunc_end8-_Z10new2dArrayii
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"First dim : %d | Second dim : %d"
	.size	.L.str.1, 33

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	" %.1f "
	.size	.L.str.4, 7

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\nChannel %d"
	.size	.L.str.5, 12

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Reached base condition"
	.size	.Lstr, 23

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\n2d Array: "
	.size	.Lstr.1, 12

	.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
