/*Done with cpu version of convolution which can be scaled to any number of filters of
size 5x5. Maxpooling done with size 2x2. */
/*Implemented 2 layers of conv2d and maxpool using single 1D array */
/*implemented two dense layers*/
/*To do: measure time taken*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "string.h"
#include<time.h>

int Maxpooling(int a, int b, int c, int d){
	int temp,i;
	temp = a;
	if(b> c && b>d && b> temp){
		temp = b;
	//	printf("temp is b\n");
	}
	if(c>b && c>d && c> temp){
		temp = c;
		//printf("temp is c\n");
	}
	if(d> c && d>b && d> temp){
		temp = d;
	//	printf("temp is d\n");
	}
//	printf("temp is a\n");
	return temp;
}
int main( int argc, char **argv )
{

	int xsize, filterdim, numfilters, numfilters1, numweights, numweights1;
  xsize = 28;
  filterdim =5;
  numfilters=32;
	numfilters1=64;
	numweights = 64;
	numweights1 = 10;
	/******num bytes required for the initial input********/
	int numbytes =  xsize * xsize * sizeof( int );
	/*******num bytes required for input to conv1********/
  int numbytes2 =  (xsize-filterdim + 1) * (xsize - filterdim +1);
	/*********num bytes required for the input to conv2****/
	int numbytes3 = ((xsize-filterdim + 1)/2 -filterdim + 1) * ((xsize-filterdim + 1)/2 -filterdim + 1);
	/************num of bytes required for first weight matrix**************/
	int numbytes4 =  numfilters1*numweights*numbytes3/4;
	/************num of bytes required for second weight matrix************/
	int numbytes5 = numweights*numweights1;

	/*****Original input - pic*************/
  unsigned int *pic = (unsigned int *)malloc(numbytes);
	/*****filter of the first conv layer*****/
  unsigned int filter[numfilters*filterdim*filterdim];
	/*******filter for the second conv layer*******/
	unsigned int filter2[numfilters1*numfilters*filterdim*filterdim];
	/*********weight matrix for the first dense layer**********/
	unsigned int weight1[numbytes4];
	/*********weight matrix for the second dense layer**********/
	unsigned int weight2[numbytes5];

	int result[numfilters*numbytes2];
	int result2[numfilters1*numbytes3];
	int maxpool[numfilters*(((xsize-filterdim + 1)*(xsize-filterdim + 1))/4)];
	int maxpool2[numfilters1*(numbytes3/4)];
	int dense1[numweights];
	int dense2[numweights1];

	int i, j;
  int count;
  int sum1,k,l;
	int dimx;
	dimx = numfilters1*(numbytes3/4);

	/*************Should read in input**********/
	for (i=0; i<xsize; i++) {
		for (j=0; j<xsize; j++) {
			pic[i*xsize + j] = 1;
    //  printf("pic[%d][%d] : %d\t",i,j,pic[i*xsize + j]);
		}
  //  printf("\n");
	}
	/******should read in filters*********/
  for(int k=0;k<numfilters;k++){
  	for (int i=0; i<filterdim; i++) {
    	for (int j=0; j<filterdim; j++){
        filter[k*(filterdim*filterdim) + i*filterdim + j] = 1;
	//			printf("filter[%d][%d]: %d\n",k, i*filterdim + j, filter[k*(filterdim*filterdim) + i*filterdim + j]);
    	}
  	 }
	}

	for(int k=0;k<numfilters1;k++){
		for(int m= 0; m<numfilters;m++){
			for (int i=0; i<filterdim; i++) {
	    	for (int j=0; j<filterdim; j++){
	        filter2[k*(numfilters*filterdim*filterdim)+ m*filterdim*filterdim + i*filterdim + j] = 1;
					// printf("filter2[%d][%d]: %d\t",k, m*filterdim*filterdim+i*filterdim + j, filter2[k*(numfilters*filterdim*filterdim)+ m*filterdim*filterdim + i*filterdim + j]);
	    	}
	  	}
		}
		// printf("\n");
	}
	/*********First weight matrix**************/
	for(l=0;l<numweights;l++){
		for(i=0;i<dimx;i++){
			weight1[l*dimx+i] = 1;
			// printf("element1 : %d\n", l*dimx+i);
		}
	}
	/**********Second weight matrix**************/
	for(l=0;l<numweights1;l++){
		for(i=0;i<numweights;i++){
			weight2[l*numweights+i] = 1;
			// printf("element2 : %d\n", l*numweights+i);
		}
	}
	clock_t start, end;
	start  = clock();
	/*****Operations of first convolutional layer******/
	for(l=0; l < numfilters; l++){
	  count = 0;
		for (i = 0;  i < xsize - filterdim +1; i++){
			for (j = 0; j < xsize - filterdim+1; j++){
	      k =0;

	    sum1 =  (filter[l*(filterdim*filterdim) + k])*pic[ xsize * (i) + j ] + (filter[l*(filterdim*filterdim) + k+1])*pic[ xsize*(i) + (j+1) ]
				+ filter[l*(filterdim*filterdim)+ k+2]*pic[ xsize * (i)+(j+2)] + filter[l*(filterdim*filterdim) +k+3]*pic[xsize * (i)+(j+3)]
				+ filter[l*(filterdim*filterdim) +k+4]*pic[ xsize * (i)+(j+4)]+ filter[l*(filterdim*filterdim) + k+5]*pic[ xsize*(i+1)+(j) ]
				+ filter[l*(filterdim*filterdim) +k+6]*pic[ xsize * (i+1) + (j+1) ] + filter[l*(filterdim*filterdim) + k+7]*pic[ xsize*(i+1) + (j+2) ] +
				filter[l*(filterdim*filterdim) +k+8]*pic[ xsize*(i+1) + (j+3) ] + filter[l*(filterdim*filterdim) +k+9]*pic[ xsize*(i+1) + (j+4) ] +
	      filter[l*(filterdim*filterdim) +k+10]*pic[ xsize*(i+2) + (j) ]	+ filter[l*(filterdim*filterdim) +k+11]*pic[ xsize * (i+2) + (j+1) ] +
	      filter[l*(filterdim*filterdim) +k+12]*pic[ xsize*(i+2) + (j+2)] + filter[l*(filterdim*filterdim) +k+13]*pic[ xsize*(i+2) + (j+3)]
				+filter[l*(filterdim*filterdim) +k+14]*pic[ xsize*(i+2) + (j+4)] + filter[l*(filterdim*filterdim) +k+15]*pic[ xsize*(i+3) + (j)]
				+ filter[l*(filterdim*filterdim) +k+16]*pic[ xsize*(i+3) + (j+1)] + filter[l*(filterdim*filterdim) +k+17]*pic[ xsize*(i+3) + (j+2)]
				+ filter[l*(filterdim*filterdim) +k+18]*pic[ xsize*(i+3) + (j+3)] + filter[l*(filterdim*filterdim) +k+19]*pic[ xsize*(i+3) + (j+4)]
				+ filter[l*(filterdim*filterdim) +k+20]*pic[ xsize*(i+4) + (j)] +filter[l*(filterdim*filterdim) +k+21]*pic[ xsize*(i+3) + (j+1)]
				+ filter[l*(filterdim*filterdim) +k+22]*pic[ xsize*(i+4) + (j+2)] + filter[l*(filterdim*filterdim) +k+23]*pic[ xsize*(i+4) + (j+3)]
				+ filter[l*(filterdim*filterdim) + k+24]*pic[ xsize*(i+4) + (j+4)];


	      result[l*numbytes2 +count] = sum1;
	     // printf("result[%d][%d]=%d\t",l,count,result[l*numbytes2 + count]);
	      count+=1;
			}
	  	// printf("\n");
		}
		// printf("\n\n\n");
	}
	/***************Maxpool***************************/
	for(l=0; l<numfilters; l++){
		count =0;
		for(j=0;j<(xsize-filterdim + 1);j+=2){
				for(i=0;i<(xsize-filterdim + 1);i+=2){
					maxpool[l*(numbytes2/4) + count] =
					Maxpooling(result[l*(xsize - filterdim +1)*(xsize - filterdim +1) + j*(xsize-filterdim+1)+i],
				result[l*(xsize - filterdim +1)*(xsize - filterdim +1) + j*(xsize-filterdim+1)+i+1],
				result[l*(xsize - filterdim +1)*(xsize - filterdim +1) + j*(xsize-filterdim+1)+i+(xsize-filterdim + 1)],
			result[l*(xsize - filterdim +1)*(xsize - filterdim +1) + j*(xsize-filterdim+1)+i+(xsize-filterdim + 1)+1]);
			printf("Maxpool[%d][%d] : %d \t",l,count ,maxpool[l*(numbytes2/4) + count]);
			count+=1;
				}
				printf("\n");
		}
		printf("\n\n\n");
	}
	/******Operations of second convolutional layer*******/
	int m;
	int dim = (xsize-filterdim + 1)/2;
	dimx = (xsize-filterdim + 1)/2 -filterdim + 1;
	printf("dim: %d ; dimx: %d\n", dim,dimx);
	for(l=0; l < numfilters1; l++){
		for (i = 0;  i < dimx; i++){
			for (j = 0; j < dimx; j++){
				k =0;
				sum1 =0;
				for(m=0;m<numfilters;m++){
					sum1 +=  (filter2[l*(numfilters*filterdim*filterdim) + k])*maxpool[ (m*dim*dim)+ dim * (i) + j ] + (filter2[l*(numfilters*filterdim*filterdim) + k+1])*maxpool[(m*dim*dim)+ dim*(i) + (j+1) ]
					+ filter2[l*(numfilters*filterdim*filterdim)+ k+2]*maxpool[(m*dim*dim)+ dim * (i)+(j+2)] + filter2[l*(numfilters*filterdim*filterdim) +k+3]*maxpool[(m*dim*dim)+dim * (i)+(j+3)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+4]*maxpool[ (m*dim*dim)+dim * (i)+(j+4)]+ filter2[l*(numfilters*filterdim*filterdim) + k+5]*maxpool[(m*dim*dim)+ dim*(i+1)+(j) ]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+6]*maxpool[(m*dim*dim)+ dim * (i+1) + (j+1) ] + filter2[l*(numfilters*filterdim*filterdim) + k+7]*maxpool[(m*dim*dim)+ dim*(i+1) + (j+2) ] +
					filter2[l*(numfilters*filterdim*filterdim) +k+8]*maxpool[(m*dim*dim)+ dim*(i+1) + (j+3) ] + filter2[l*(numfilters*filterdim*filterdim) +k+9]*maxpool[(m*dim*dim)+ dim*(i+1) + (j+4) ] +
					filter2[l*(numfilters*filterdim*filterdim) +k+10]*maxpool[(m*dim*dim)+ dim*(i+2) + (j) ]	+ filter2[l*(numfilters*filterdim*filterdim) +k+11]*maxpool[(m*dim*dim)+ dim * (i+2) + (j+1) ] +
					filter2[l*(numfilters*filterdim*filterdim) +k+12]*maxpool[(m*dim*dim)+ dim*(i+2) + (j+2)] + filter2[l*(numfilters*filterdim*filterdim) +k+13]*maxpool[(m*dim*dim)+ dim*(i+2) + (j+3)]
					+filter2[l*(numfilters*filterdim*filterdim) +k+14]*maxpool[(m*dim*dim)+ dim*(i+2) + (j+4)] + filter2[l*(numfilters*filterdim*filterdim) +k+15]*maxpool[(m*dim*dim)+ dim*(i+3) + (j)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+16]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+1)] + filter2[l*(numfilters*filterdim*filterdim) +k+17]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+2)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+18]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+3)] + filter2[l*(numfilters*filterdim*filterdim) +k+19]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+4)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+20]*maxpool[(m*dim*dim)+ dim*(i+4) + (j)] +filter2[l*(numfilters*filterdim*filterdim) +k+21]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+1)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+22]*maxpool[(m*dim*dim)+ dim*(i+4) + (j+2)] + filter2[l*(numfilters*filterdim*filterdim) +k+23]*maxpool[(m*dim*dim)+ dim*(i+4) + (j+3)]
					+ filter2[l*(numfilters*filterdim*filterdim) + k+24]*maxpool[(m*dim*dim)+ dim*(i+4) + (j+4)];
				}
				result2[l*numbytes3 +i*dimx+j] = sum1;
				k+=1;
				printf("result2[%d][%d]=%d\t",l,i*dimx+j,result2[l*numbytes3 + i*dimx + j]);
			}
			printf("\n");
		}
		printf("\n\n\n");
	}
	/******Second Maxpool Layer******/
	dim =((xsize-filterdim + 1)/2 -filterdim + 1)/2;
	printf("dim: %d ;dimx: %d; numbytes3: %d", dim, dimx, numbytes3);
	for(l=0; l<numfilters1; l++){
		count =0;
		for(j=0;j<dimx;j+=2){
				for(i=0;i<dimx;i+=2){
					maxpool2[l*(numbytes3/4) + count] =
					(Maxpooling(result2[l*numbytes3 + j*dimx+i],
					result2[l*numbytes3 + j*dimx+i+1],
					result2[l*numbytes3 + j*dimx+i+dimx],
					result2[l*numbytes3 + j*dimx+i+dimx+1]))/625;

				//	printf("Maxpool2[%d][%d] : %d \t",l,count ,maxpool2[l*(numbytes3/4) + count]);
					count+=1;
				}
				// printf("\n");
		}
		// printf("\n\n\n");
	}
	/********************First Dense layer**********************/
	dimx = numfilters1*(numbytes3/4);

	for(l=0;l<numweights;l++){
		for(i=0;i<dimx;i++){
			dense1[l]+= weight1[l*dimx+i]*maxpool2[i];
		}
		// printf("dense1[%d]:%d\n",l,dense1[l]);
	}

	/*************Second Dense Layer***************/
	dimx = numweights;
	for(l=0;l<numweights1;l++){
		for(i=0;i<dimx;i++){
			dense2[l]+= weight2[l*dimx+i]*dense1[i];
		}
		// printf("dense2[%d]:%d\n",l,dense2[l]);
	}
	end = clock();
	printf("time taken by cpu : %f seconds",((double) (end - start)) );
}

	.file	"tmpxft_0025de26_00000000-6_Cpuv9.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z10Maxpoolingiiii
	.type	_Z10Maxpoolingiiii, @function
_Z10Maxpoolingiiii:
.LFB2031:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	cmpl	%ecx, %edx
	movl	%ecx, %edi
	cmovge	%edx, %edi
	cmpl	%esi, %edi
	jge	.L3
	cmpl	%esi, %eax
	cmovl	%esi, %eax
.L3:
	cmpl	%ecx, %esi
	movl	%ecx, %edi
	cmovge	%esi, %edi
	cmpl	%edi, %edx
	jle	.L4
	cmpl	%edx, %eax
	cmovl	%edx, %eax
.L4:
	cmpl	%edx, %esi
	cmovl	%edx, %esi
	cmpl	%esi, %ecx
	jle	.L5
	cmpl	%ecx, %eax
	cmovl	%ecx, %eax
.L5:
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z10Maxpoolingiiii, .-_Z10Maxpoolingiiii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Maxpool[%d][%d] : %d \t"
.LC1:
	.string	"\n"
.LC2:
	.string	"\n\n\n"
.LC3:
	.string	"dim: %d ; dimx: %d\n"
.LC4:
	.string	"result2[%d][%d]=%d\t"
.LC5:
	.string	"dim: %d ;dimx: %d; numbytes3: %d"
.LC6:
	.string	"time taken by cpu : %f seconds"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	$3136, %edi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$200, %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
	call	malloc@PLT
	movq	%rax, %r13
	movq	%rsp, %rax
.L8:
	cmpq	%rax, %rsp
	je	.L9
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L8
.L9:
	subq	$3200, %rsp
	orq	$0, 3192(%rsp)
	movq	%rsp, %r12
	leaq	-204800(%rsp), %rax
.L11:
	cmpq	%rax, %rsp
	je	.L12
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L11
.L12:
	movq	%rsp, %rbx
	leaq	-262144(%rsp), %rax
.L14:
	cmpq	%rax, %rsp
	je	.L15
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L14
.L15:
	movq	%rsp, %rcx
	movq	%rsp, %rax
.L17:
	cmpq	%rax, %rsp
	je	.L18
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L17
.L18:
	subq	$2560, %rsp
	orq	$0, 2552(%rsp)
	movq	%rsp, %rdx
	leaq	-73728(%rsp), %rax
.L20:
	cmpq	%rax, %rsp
	je	.L21
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L20
.L21:
	movq	%rsp, -80(%rbp)
	leaq	-16384(%rsp), %rax
.L23:
	cmpq	%rax, %rsp
	je	.L24
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L23
.L24:
	movq	%rsp, -192(%rbp)
	leaq	-16384(%rsp), %rax
.L26:
	cmpq	%rax, %rsp
	je	.L27
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L26
.L27:
	subq	$2048, %rsp
	orq	$0, 2040(%rsp)
	movq	%rsp, -104(%rbp)
	leaq	-4096(%rsp), %rax
.L29:
	cmpq	%rax, %rsp
	je	.L30
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L29
.L30:
	xorl	%edi, %edi
	movq	%rsp, -232(%rbp)
	movq	%r13, %rsi
.L32:
	xorl	%eax, %eax
.L33:
	movl	$1, (%rsi,%rax,4)
	incq	%rax
	cmpq	$28, %rax
	jne	.L33
	addl	$28, %edi
	addq	$112, %rsi
	cmpl	$784, %edi
	jne	.L32
	movq	%r12, %rdi
	xorl	%r8d, %r8d
.L36:
	movq	%rdi, %rax
	xorl	%esi, %esi
.L35:
	incl	%esi
	movl	$1, (%rax)
	addq	$20, %rax
	movl	$1, -16(%rax)
	movl	$1, -12(%rax)
	movl	$1, -8(%rax)
	movl	$1, -4(%rax)
	cmpl	$5, %esi
	jne	.L35
	addl	$25, %r8d
	addq	$100, %rdi
	cmpl	$800, %r8d
	jne	.L36
	movq	%rbx, %r8
	xorl	%r9d, %r9d
.L37:
	movq	%r8, %rdi
	xorl	%esi, %esi
.L41:
	movq	%rdi, %rax
	xorl	%r10d, %r10d
.L38:
	incl	%r10d
	movl	$1, (%rax)
	addq	$20, %rax
	movl	$1, -16(%rax)
	movl	$1, -12(%rax)
	movl	$1, -8(%rax)
	movl	$1, -4(%rax)
	cmpl	$5, %r10d
	jne	.L38
	incl	%esi
	addq	$100, %rdi
	cmpl	$32, %esi
	jne	.L41
	addl	$800, %r9d
	addq	$3200, %r8
	cmpl	$51200, %r9d
	jne	.L37
	xorl	%esi, %esi
.L43:
	xorl	%eax, %eax
.L42:
	movl	$1, (%rcx,%rax,4)
	incq	%rax
	cmpq	$1024, %rax
	jne	.L42
	addl	$1024, %esi
	addq	$4096, %rcx
	cmpl	$65536, %esi
	jne	.L43
	xorl	%ecx, %ecx
.L44:
	xorl	%eax, %eax
.L45:
	movl	$1, (%rdx,%rax,4)
	incq	%rax
	cmpq	$64, %rax
	jne	.L45
	addl	$64, %ecx
	addq	$256, %rdx
	cmpl	$640, %ecx
	jne	.L44
	call	clock@PLT
	movq	-80(%rbp), %r9
	xorl	%r10d, %r10d
	movq	%rax, -208(%rbp)
.L47:
	movl	(%r12), %eax
	movq	%r9, %r8
	xorl	%edi, %edi
	xorl	%esi, %esi
	movl	%eax, -72(%rbp)
	movl	4(%r12), %eax
	movl	%eax, -88(%rbp)
	movl	12(%r12), %eax
	movl	%eax, -96(%rbp)
	movl	8(%r12), %eax
	movl	%eax, -108(%rbp)
	movl	20(%r12), %eax
	movl	%eax, -112(%rbp)
	movl	16(%r12), %eax
	movl	%eax, -116(%rbp)
	movl	28(%r12), %eax
	movl	%eax, -120(%rbp)
	movl	24(%r12), %eax
	movl	%eax, -124(%rbp)
	movl	36(%r12), %eax
	movl	%eax, -128(%rbp)
	movl	32(%r12), %eax
	movl	%eax, -132(%rbp)
	movl	44(%r12), %eax
	movl	%eax, -136(%rbp)
	movl	40(%r12), %eax
	movl	%eax, -140(%rbp)
	movl	52(%r12), %eax
	movl	%eax, -144(%rbp)
	movl	48(%r12), %eax
	movl	%eax, -148(%rbp)
	movl	60(%r12), %eax
	movl	%eax, -152(%rbp)
	movl	56(%r12), %eax
	movl	%eax, -156(%rbp)
	movl	68(%r12), %eax
	movl	88(%r12), %r14d
	movl	96(%r12), %r11d
	movl	%eax, -160(%rbp)
	movl	76(%r12), %eax
	movl	%eax, -164(%rbp)
	movl	72(%r12), %eax
	movl	%eax, -168(%rbp)
	movl	84(%r12), %eax
	addl	64(%r12), %eax
	movl	%eax, -180(%rbp)
	movl	80(%r12), %eax
	movl	%eax, -172(%rbp)
	movl	92(%r12), %eax
	movl	%eax, -176(%rbp)
.L51:
	imulq	$112, %rsi, %rax
	addl	$28, %edi
	xorl	%ecx, %ecx
	addq	%r13, %rax
.L48:
	movl	-72(%rbp), %edx
	movl	-88(%rbp), %r15d
	imull	(%rax), %edx
	imull	4(%rax), %r15d
	addl	%edx, %r15d
	movl	-96(%rbp), %edx
	imull	12(%rax), %edx
	addl	%r15d, %edx
	movl	-108(%rbp), %r15d
	imull	8(%rax), %r15d
	addl	%edx, %r15d
	movl	-112(%rbp), %edx
	imull	112(%rax), %edx
	addl	%r15d, %edx
	movl	-116(%rbp), %r15d
	imull	16(%rax), %r15d
	addl	%edx, %r15d
	movl	-120(%rbp), %edx
	imull	120(%rax), %edx
	addl	%r15d, %edx
	movl	-124(%rbp), %r15d
	imull	116(%rax), %r15d
	addl	%edx, %r15d
	movl	-128(%rbp), %edx
	imull	128(%rax), %edx
	addl	%r15d, %edx
	movl	-132(%rbp), %r15d
	imull	124(%rax), %r15d
	addl	%edx, %r15d
	movl	-136(%rbp), %edx
	imull	228(%rax), %edx
	addl	%r15d, %edx
	movl	-140(%rbp), %r15d
	imull	224(%rax), %r15d
	addl	%edx, %r15d
	movl	-144(%rbp), %edx
	imull	236(%rax), %edx
	addl	%r15d, %edx
	movl	-148(%rbp), %r15d
	imull	232(%rax), %r15d
	addl	%edx, %r15d
	movl	-152(%rbp), %edx
	imull	336(%rax), %edx
	addl	%r15d, %edx
	movl	-156(%rbp), %r15d
	imull	240(%rax), %r15d
	addl	%edx, %r15d
	movl	-160(%rbp), %edx
	imull	344(%rax), %edx
	addl	%r15d, %edx
	movl	-164(%rbp), %r15d
	addq	$4, %rax
	imull	348(%rax), %r15d
	addl	%edx, %r15d
	movl	-168(%rbp), %edx
	imull	344(%rax), %edx
	addl	%r15d, %edx
	movl	-180(%rbp), %r15d
	imull	336(%rax), %r15d
	addl	%edx, %r15d
	movl	-172(%rbp), %edx
	imull	444(%rax), %edx
	addl	%r15d, %edx
	movl	-176(%rbp), %r15d
	imull	456(%rax), %r15d
	addl	%edx, %r15d
	movl	452(%rax), %edx
	imull	%r14d, %edx
	addl	%r15d, %edx
	movl	460(%rax), %r15d
	imull	%r11d, %r15d
	addl	%r15d, %edx
	movl	%edx, (%r8,%rcx)
	addq	$4, %rcx
	cmpq	$96, %rcx
	jne	.L48
	incq	%rsi
	addq	$96, %r8
	cmpl	$672, %edi
	jne	.L51
	addl	$576, %r10d
	addq	$100, %r12
	addq	$2304, %r9
	cmpl	$18432, %r10d
	jne	.L47
	xorl	%r12d, %r12d
.L50:
	imulq	$2304, %r12, %r14
	movq	-80(%rbp), %rax
	movl	%r12d, -88(%rbp)
	xorl	%r15d, %r15d
	imulq	$576, %r12, %r13
	addq	%r14, %rax
	movq	%rax, -72(%rbp)
	movq	-104(%rbp), %rax
	addq	%rax, %r13
.L55:
	movq	-72(%rbp), %r9
	xorl	%r14d, %r14d
.L52:
	movl	100(%r9), %ecx
	movl	96(%r9), %edx
	movq	%r9, -96(%rbp)
	leal	(%r15,%r14), %r11d
	movl	4(%r9), %esi
	movl	(%r9), %edi
	call	_Z10Maxpoolingiiii
	movl	-88(%rbp), %edx
	movl	%r11d, %ecx
	movl	$2, %edi
	movl	%eax, 0(%r13,%r14,4)
	movl	%eax, %r8d
	xorl	%eax, %eax
	incq	%r14
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	movq	-96(%rbp), %r9
	addq	$8, %r9
	cmpq	$12, %r14
	jne	.L52
	movl	$2, %edi
	xorl	%eax, %eax
	addl	$12, %r15d
	addq	$48, %r13
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	addq	$192, -72(%rbp)
	cmpl	$144, %r15d
	jne	.L55
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%r12
	call	__printf_chk@PLT
	cmpq	$32, %r12
	jne	.L50
	movl	$12, %edx
	movl	$8, %ecx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	-192(%rbp), %rax
	xorl	%edx, %edx
	movl	%edx, -72(%rbp)
	movq	%rax, -80(%rbp)
	movq	%rax, -88(%rbp)
.L56:
	xorl	%eax, %eax
	movq	-88(%rbp), %r14
	xorl	%r13d, %r13d
	movl	%eax, -96(%rbp)
.L62:
	imulq	$48, %r13, %r12
	movq	-104(%rbp), %rax
	addl	$12, -96(%rbp)
	xorl	%r15d, %r15d
	addq	%rax, %r12
	leal	0(,%r13,8), %eax
	movl	%eax, -216(%rbp)
.L60:
	movl	(%rbx), %eax
	movl	%r15d, -220(%rbp)
	xorl	%r10d, %r10d
	xorl	%r8d, %r8d
	leaq	48(%r12), %rsi
	leaq	96(%r12), %rcx
	movl	%eax, -108(%rbp)
	movl	4(%rbx), %eax
	leaq	144(%r12), %rdx
	leaq	192(%r12), %rdi
	movl	%eax, -112(%rbp)
	movl	12(%rbx), %eax
	movl	%eax, -116(%rbp)
	movl	8(%rbx), %eax
	movl	%eax, -120(%rbp)
	movl	20(%rbx), %eax
	movl	%eax, -124(%rbp)
	movl	16(%rbx), %eax
	movl	%eax, -128(%rbp)
	movl	28(%rbx), %eax
	movl	%eax, -132(%rbp)
	movl	24(%rbx), %eax
	movl	%eax, -136(%rbp)
	movl	36(%rbx), %eax
	movl	%eax, -140(%rbp)
	movl	32(%rbx), %eax
	movl	%eax, -144(%rbp)
	movl	44(%rbx), %eax
	movl	%eax, -148(%rbp)
	movl	40(%rbx), %eax
	movl	%eax, -152(%rbp)
	movl	52(%rbx), %eax
	movl	%eax, -156(%rbp)
	movl	48(%rbx), %eax
	movl	%eax, -160(%rbp)
	movl	60(%rbx), %eax
	movl	%eax, -164(%rbp)
	movl	56(%rbx), %eax
	movl	%eax, -168(%rbp)
	movl	68(%rbx), %eax
	movl	%eax, -172(%rbp)
	movl	76(%rbx), %eax
	movl	%eax, -176(%rbp)
	movl	72(%rbx), %eax
	movl	%eax, -180(%rbp)
	movl	84(%rbx), %eax
	addl	64(%rbx), %eax
	movl	%eax, -212(%rbp)
	movl	80(%rbx), %eax
	movl	%eax, -192(%rbp)
	movl	92(%rbx), %eax
	movl	%eax, -184(%rbp)
	movl	88(%rbx), %eax
	movl	%eax, -196(%rbp)
	movl	96(%rbx), %eax
	movl	%eax, -200(%rbp)
	movq	%r12, %rax
.L57:
	movl	-108(%rbp), %r9d
	movl	-112(%rbp), %r11d
	imull	(%rax), %r9d
	imull	4(%rax), %r11d
	addl	%r9d, %r11d
	movl	-116(%rbp), %r9d
	imull	12(%rax), %r9d
	addl	%r11d, %r9d
	movl	-120(%rbp), %r11d
	imull	8(%rax), %r11d
	addl	%r9d, %r11d
	movl	-124(%rbp), %r9d
	imull	(%rsi), %r9d
	addl	%r11d, %r9d
	movl	-128(%rbp), %r11d
	imull	16(%rax), %r11d
	addl	%r9d, %r11d
	movl	-132(%rbp), %r9d
	imull	8(%rsi), %r9d
	addl	%r11d, %r9d
	movl	-136(%rbp), %r11d
	imull	4(%rsi), %r11d
	addl	%r9d, %r11d
	movl	-140(%rbp), %r9d
	imull	16(%rsi), %r9d
	addl	%r11d, %r9d
	movl	-144(%rbp), %r11d
	imull	12(%rsi), %r11d
	addl	%r9d, %r11d
	movl	-148(%rbp), %r9d
	imull	4(%rcx), %r9d
	addl	%r11d, %r9d
	movl	-152(%rbp), %r11d
	imull	(%rcx), %r11d
	addl	%r9d, %r11d
	movl	-156(%rbp), %r9d
	imull	12(%rcx), %r9d
	addl	%r11d, %r9d
	movl	-160(%rbp), %r11d
	imull	8(%rcx), %r11d
	addl	%r9d, %r11d
	movl	-164(%rbp), %r9d
	imull	(%rdx), %r9d
	addl	%r11d, %r9d
	movl	-168(%rbp), %r11d
	imull	16(%rcx), %r11d
	addl	%r9d, %r11d
	movl	-172(%rbp), %r9d
	imull	8(%rdx), %r9d
	addl	%r11d, %r9d
	movl	-176(%rbp), %r11d
	imull	16(%rdx), %r11d
	incl	%r10d
	addq	$576, %rax
	addq	$576, %rsi
	addq	$576, %rcx
	addq	$576, %rdx
	addq	$576, %rdi
	addl	%r9d, %r11d
	movl	-180(%rbp), %r9d
	imull	-564(%rdx), %r9d
	addl	%r11d, %r9d
	movl	-212(%rbp), %r11d
	imull	-572(%rdx), %r11d
	addl	%r9d, %r11d
	movl	-192(%rbp), %r9d
	imull	-576(%rdi), %r9d
	addl	%r11d, %r9d
	movl	-184(%rbp), %r11d
	imull	-564(%rdi), %r11d
	addl	%r9d, %r11d
	movl	-196(%rbp), %r9d
	imull	-568(%rdi), %r9d
	addl	%r11d, %r9d
	movl	-200(%rbp), %r11d
	imull	-560(%rdi), %r11d
	addl	%r11d, %r9d
	addl	%r9d, %r8d
	cmpl	$32, %r10d
	jne	.L57
	movl	%r8d, (%r14,%r15,4)
	movl	-72(%rbp), %edx
	movl	$2, %edi
	incq	%r15
	movl	-216(%rbp), %eax
	movl	-220(%rbp), %ecx
	leaq	.LC4(%rip), %rsi
	addq	$4, %r12
	addl	%eax, %ecx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	cmpq	$8, %r15
	jne	.L60
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	incq	%r13
	addq	$32, %r14
	movl	$2, %edi
	call	__printf_chk@PLT
	cmpl	$96, -96(%rbp)
	jne	.L62
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	addq	$3200, %rbx
	call	__printf_chk@PLT
	incl	-72(%rbp)
	addq	$256, -88(%rbp)
	cmpl	$64, -72(%rbp)
	jne	.L56
	movl	$64, %r8d
	movl	$8, %ecx
	xorl	%eax, %eax
	xorl	%r13d, %r13d
	movl	$4, %edx
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	movl	$625, %r14d
	call	__printf_chk@PLT
	movq	-232(%rbp), %r9
.L63:
	movq	-80(%rbp), %rbx
	movq	%r9, %r12
	xorl	%r11d, %r11d
.L67:
	movq	%rbx, %r8
	xorl	%r10d, %r10d
.L64:
	movl	32(%r8), %edx
	movl	36(%r8), %ecx
	addq	$8, %r8
	movl	-4(%r8), %esi
	movl	-8(%r8), %edi
	call	_Z10Maxpoolingiiii
	cltd
	idivl	%r14d
	movl	%eax, (%r12,%r10,4)
	incq	%r10
	cmpq	$4, %r10
	jne	.L64
	addl	$4, %r11d
	addq	$64, %rbx
	addq	$16, %r12
	cmpl	$16, %r11d
	jne	.L67
	addl	$16, %r13d
	addq	$256, -80(%rbp)
	addq	$64, %r9
	cmpl	$1024, %r13d
	jne	.L63
	call	clock@PLT
	movq	-208(%rbp), %rdi
	leaq	.LC6(%rip), %rsi
	subq	%rdi, %rax
	movl	$2, %edi
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L68
	call	__stack_chk_fail@PLT
.L68:
	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
.LFE2032:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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
.LFE2058:
	.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:

/*Done with cpu version of convolution which can be scaled to any number of filters of
size 5x5. Maxpooling done with size 2x2. */
/*Implemented 2 layers of conv2d and maxpool using single 1D array */
/*implemented two dense layers*/
/*To do: measure time taken*/

#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "string.h"
#include<time.h>

int Maxpooling(int a, int b, int c, int d){
	int temp,i;
	temp = a;
	if(b> c && b>d && b> temp){
		temp = b;
	//	printf("temp is b\n");
	}
	if(c>b && c>d && c> temp){
		temp = c;
		//printf("temp is c\n");
	}
	if(d> c && d>b && d> temp){
		temp = d;
	//	printf("temp is d\n");
	}
//	printf("temp is a\n");
	return temp;
}
int main( int argc, char **argv )
{

	int xsize, filterdim, numfilters, numfilters1, numweights, numweights1;
  xsize = 28;
  filterdim =5;
  numfilters=32;
	numfilters1=64;
	numweights = 64;
	numweights1 = 10;
	/******num bytes required for the initial input********/
	int numbytes =  xsize * xsize * sizeof( int );
	/*******num bytes required for input to conv1********/
  int numbytes2 =  (xsize-filterdim + 1) * (xsize - filterdim +1);
	/*********num bytes required for the input to conv2****/
	int numbytes3 = ((xsize-filterdim + 1)/2 -filterdim + 1) * ((xsize-filterdim + 1)/2 -filterdim + 1);
	/************num of bytes required for first weight matrix**************/
	int numbytes4 =  numfilters1*numweights*numbytes3/4;
	/************num of bytes required for second weight matrix************/
	int numbytes5 = numweights*numweights1;

	/*****Original input - pic*************/
  unsigned int *pic = (unsigned int *)malloc(numbytes);
	/*****filter of the first conv layer*****/
  unsigned int filter[numfilters*filterdim*filterdim];
	/*******filter for the second conv layer*******/
	unsigned int filter2[numfilters1*numfilters*filterdim*filterdim];
	/*********weight matrix for the first dense layer**********/
	unsigned int weight1[numbytes4];
	/*********weight matrix for the second dense layer**********/
	unsigned int weight2[numbytes5];

	int result[numfilters*numbytes2];
	int result2[numfilters1*numbytes3];
	int maxpool[numfilters*(((xsize-filterdim + 1)*(xsize-filterdim + 1))/4)];
	int maxpool2[numfilters1*(numbytes3/4)];
	int dense1[numweights];
	int dense2[numweights1];

	int i, j;
  int count;
  int sum1,k,l;
	int dimx;
	dimx = numfilters1*(numbytes3/4);

	/*************Should read in input**********/
	for (i=0; i<xsize; i++) {
		for (j=0; j<xsize; j++) {
			pic[i*xsize + j] = 1;
    //  printf("pic[%d][%d] : %d\t",i,j,pic[i*xsize + j]);
		}
  //  printf("\n");
	}
	/******should read in filters*********/
  for(int k=0;k<numfilters;k++){
  	for (int i=0; i<filterdim; i++) {
    	for (int j=0; j<filterdim; j++){
        filter[k*(filterdim*filterdim) + i*filterdim + j] = 1;
	//			printf("filter[%d][%d]: %d\n",k, i*filterdim + j, filter[k*(filterdim*filterdim) + i*filterdim + j]);
    	}
  	 }
	}

	for(int k=0;k<numfilters1;k++){
		for(int m= 0; m<numfilters;m++){
			for (int i=0; i<filterdim; i++) {
	    	for (int j=0; j<filterdim; j++){
	        filter2[k*(numfilters*filterdim*filterdim)+ m*filterdim*filterdim + i*filterdim + j] = 1;
					// printf("filter2[%d][%d]: %d\t",k, m*filterdim*filterdim+i*filterdim + j, filter2[k*(numfilters*filterdim*filterdim)+ m*filterdim*filterdim + i*filterdim + j]);
	    	}
	  	}
		}
		// printf("\n");
	}
	/*********First weight matrix**************/
	for(l=0;l<numweights;l++){
		for(i=0;i<dimx;i++){
			weight1[l*dimx+i] = 1;
			// printf("element1 : %d\n", l*dimx+i);
		}
	}
	/**********Second weight matrix**************/
	for(l=0;l<numweights1;l++){
		for(i=0;i<numweights;i++){
			weight2[l*numweights+i] = 1;
			// printf("element2 : %d\n", l*numweights+i);
		}
	}
	clock_t start, end;
	start  = clock();
	/*****Operations of first convolutional layer******/
	for(l=0; l < numfilters; l++){
	  count = 0;
		for (i = 0;  i < xsize - filterdim +1; i++){
			for (j = 0; j < xsize - filterdim+1; j++){
	      k =0;

	    sum1 =  (filter[l*(filterdim*filterdim) + k])*pic[ xsize * (i) + j ] + (filter[l*(filterdim*filterdim) + k+1])*pic[ xsize*(i) + (j+1) ]
				+ filter[l*(filterdim*filterdim)+ k+2]*pic[ xsize * (i)+(j+2)] + filter[l*(filterdim*filterdim) +k+3]*pic[xsize * (i)+(j+3)]
				+ filter[l*(filterdim*filterdim) +k+4]*pic[ xsize * (i)+(j+4)]+ filter[l*(filterdim*filterdim) + k+5]*pic[ xsize*(i+1)+(j) ]
				+ filter[l*(filterdim*filterdim) +k+6]*pic[ xsize * (i+1) + (j+1) ] + filter[l*(filterdim*filterdim) + k+7]*pic[ xsize*(i+1) + (j+2) ] +
				filter[l*(filterdim*filterdim) +k+8]*pic[ xsize*(i+1) + (j+3) ] + filter[l*(filterdim*filterdim) +k+9]*pic[ xsize*(i+1) + (j+4) ] +
	      filter[l*(filterdim*filterdim) +k+10]*pic[ xsize*(i+2) + (j) ]	+ filter[l*(filterdim*filterdim) +k+11]*pic[ xsize * (i+2) + (j+1) ] +
	      filter[l*(filterdim*filterdim) +k+12]*pic[ xsize*(i+2) + (j+2)] + filter[l*(filterdim*filterdim) +k+13]*pic[ xsize*(i+2) + (j+3)]
				+filter[l*(filterdim*filterdim) +k+14]*pic[ xsize*(i+2) + (j+4)] + filter[l*(filterdim*filterdim) +k+15]*pic[ xsize*(i+3) + (j)]
				+ filter[l*(filterdim*filterdim) +k+16]*pic[ xsize*(i+3) + (j+1)] + filter[l*(filterdim*filterdim) +k+17]*pic[ xsize*(i+3) + (j+2)]
				+ filter[l*(filterdim*filterdim) +k+18]*pic[ xsize*(i+3) + (j+3)] + filter[l*(filterdim*filterdim) +k+19]*pic[ xsize*(i+3) + (j+4)]
				+ filter[l*(filterdim*filterdim) +k+20]*pic[ xsize*(i+4) + (j)] +filter[l*(filterdim*filterdim) +k+21]*pic[ xsize*(i+3) + (j+1)]
				+ filter[l*(filterdim*filterdim) +k+22]*pic[ xsize*(i+4) + (j+2)] + filter[l*(filterdim*filterdim) +k+23]*pic[ xsize*(i+4) + (j+3)]
				+ filter[l*(filterdim*filterdim) + k+24]*pic[ xsize*(i+4) + (j+4)];


	      result[l*numbytes2 +count] = sum1;
	     // printf("result[%d][%d]=%d\t",l,count,result[l*numbytes2 + count]);
	      count+=1;
			}
	  	// printf("\n");
		}
		// printf("\n\n\n");
	}
	/***************Maxpool***************************/
	for(l=0; l<numfilters; l++){
		count =0;
		for(j=0;j<(xsize-filterdim + 1);j+=2){
				for(i=0;i<(xsize-filterdim + 1);i+=2){
					maxpool[l*(numbytes2/4) + count] =
					Maxpooling(result[l*(xsize - filterdim +1)*(xsize - filterdim +1) + j*(xsize-filterdim+1)+i],
				result[l*(xsize - filterdim +1)*(xsize - filterdim +1) + j*(xsize-filterdim+1)+i+1],
				result[l*(xsize - filterdim +1)*(xsize - filterdim +1) + j*(xsize-filterdim+1)+i+(xsize-filterdim + 1)],
			result[l*(xsize - filterdim +1)*(xsize - filterdim +1) + j*(xsize-filterdim+1)+i+(xsize-filterdim + 1)+1]);
			printf("Maxpool[%d][%d] : %d \t",l,count ,maxpool[l*(numbytes2/4) + count]);
			count+=1;
				}
				printf("\n");
		}
		printf("\n\n\n");
	}
	/******Operations of second convolutional layer*******/
	int m;
	int dim = (xsize-filterdim + 1)/2;
	dimx = (xsize-filterdim + 1)/2 -filterdim + 1;
	printf("dim: %d ; dimx: %d\n", dim,dimx);
	for(l=0; l < numfilters1; l++){
		for (i = 0;  i < dimx; i++){
			for (j = 0; j < dimx; j++){
				k =0;
				sum1 =0;
				for(m=0;m<numfilters;m++){
					sum1 +=  (filter2[l*(numfilters*filterdim*filterdim) + k])*maxpool[ (m*dim*dim)+ dim * (i) + j ] + (filter2[l*(numfilters*filterdim*filterdim) + k+1])*maxpool[(m*dim*dim)+ dim*(i) + (j+1) ]
					+ filter2[l*(numfilters*filterdim*filterdim)+ k+2]*maxpool[(m*dim*dim)+ dim * (i)+(j+2)] + filter2[l*(numfilters*filterdim*filterdim) +k+3]*maxpool[(m*dim*dim)+dim * (i)+(j+3)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+4]*maxpool[ (m*dim*dim)+dim * (i)+(j+4)]+ filter2[l*(numfilters*filterdim*filterdim) + k+5]*maxpool[(m*dim*dim)+ dim*(i+1)+(j) ]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+6]*maxpool[(m*dim*dim)+ dim * (i+1) + (j+1) ] + filter2[l*(numfilters*filterdim*filterdim) + k+7]*maxpool[(m*dim*dim)+ dim*(i+1) + (j+2) ] +
					filter2[l*(numfilters*filterdim*filterdim) +k+8]*maxpool[(m*dim*dim)+ dim*(i+1) + (j+3) ] + filter2[l*(numfilters*filterdim*filterdim) +k+9]*maxpool[(m*dim*dim)+ dim*(i+1) + (j+4) ] +
					filter2[l*(numfilters*filterdim*filterdim) +k+10]*maxpool[(m*dim*dim)+ dim*(i+2) + (j) ]	+ filter2[l*(numfilters*filterdim*filterdim) +k+11]*maxpool[(m*dim*dim)+ dim * (i+2) + (j+1) ] +
					filter2[l*(numfilters*filterdim*filterdim) +k+12]*maxpool[(m*dim*dim)+ dim*(i+2) + (j+2)] + filter2[l*(numfilters*filterdim*filterdim) +k+13]*maxpool[(m*dim*dim)+ dim*(i+2) + (j+3)]
					+filter2[l*(numfilters*filterdim*filterdim) +k+14]*maxpool[(m*dim*dim)+ dim*(i+2) + (j+4)] + filter2[l*(numfilters*filterdim*filterdim) +k+15]*maxpool[(m*dim*dim)+ dim*(i+3) + (j)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+16]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+1)] + filter2[l*(numfilters*filterdim*filterdim) +k+17]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+2)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+18]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+3)] + filter2[l*(numfilters*filterdim*filterdim) +k+19]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+4)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+20]*maxpool[(m*dim*dim)+ dim*(i+4) + (j)] +filter2[l*(numfilters*filterdim*filterdim) +k+21]*maxpool[(m*dim*dim)+ dim*(i+3) + (j+1)]
					+ filter2[l*(numfilters*filterdim*filterdim) +k+22]*maxpool[(m*dim*dim)+ dim*(i+4) + (j+2)] + filter2[l*(numfilters*filterdim*filterdim) +k+23]*maxpool[(m*dim*dim)+ dim*(i+4) + (j+3)]
					+ filter2[l*(numfilters*filterdim*filterdim) + k+24]*maxpool[(m*dim*dim)+ dim*(i+4) + (j+4)];
				}
				result2[l*numbytes3 +i*dimx+j] = sum1;
				k+=1;
				printf("result2[%d][%d]=%d\t",l,i*dimx+j,result2[l*numbytes3 + i*dimx + j]);
			}
			printf("\n");
		}
		printf("\n\n\n");
	}
	/******Second Maxpool Layer******/
	dim =((xsize-filterdim + 1)/2 -filterdim + 1)/2;
	printf("dim: %d ;dimx: %d; numbytes3: %d", dim, dimx, numbytes3);
	for(l=0; l<numfilters1; l++){
		count =0;
		for(j=0;j<dimx;j+=2){
				for(i=0;i<dimx;i+=2){
					maxpool2[l*(numbytes3/4) + count] =
					(Maxpooling(result2[l*numbytes3 + j*dimx+i],
					result2[l*numbytes3 + j*dimx+i+1],
					result2[l*numbytes3 + j*dimx+i+dimx],
					result2[l*numbytes3 + j*dimx+i+dimx+1]))/625;

				//	printf("Maxpool2[%d][%d] : %d \t",l,count ,maxpool2[l*(numbytes3/4) + count]);
					count+=1;
				}
				// printf("\n");
		}
		// printf("\n\n\n");
	}
	/********************First Dense layer**********************/
	dimx = numfilters1*(numbytes3/4);

	for(l=0;l<numweights;l++){
		for(i=0;i<dimx;i++){
			dense1[l]+= weight1[l*dimx+i]*maxpool2[i];
		}
		// printf("dense1[%d]:%d\n",l,dense1[l]);
	}

	/*************Second Dense Layer***************/
	dimx = numweights;
	for(l=0;l<numweights1;l++){
		for(i=0;i<dimx;i++){
			dense2[l]+= weight2[l*dimx+i]*dense1[i];
		}
		// printf("dense2[%d]:%d\n",l,dense2[l]);
	}
	end = clock();
	printf("time taken by cpu : %f seconds",((double) (end - start)) );
}

	.text
	.file	"Cpuv9.hip"
	.globl	_Z10Maxpoolingiiii              # -- Begin function _Z10Maxpoolingiiii
	.type	_Z10Maxpoolingiiii,@function
_Z10Maxpoolingiiii:                     # @_Z10Maxpoolingiiii
	.cfi_startproc
# %bb.0:
	cmpl	%edi, %esi
	movl	%edi, %eax
	cmovgl	%esi, %eax
	cmpl	%ecx, %esi
	cmovlel	%edi, %eax
	cmpl	%edx, %esi
	cmovlel	%edi, %eax
	cmpl	%edx, %eax
	movl	%edx, %edi
	cmovgl	%eax, %edi
	cmpl	%ecx, %edx
	cmovlel	%eax, %edi
	cmpl	%esi, %edx
	cmovlel	%eax, %edi
	cmpl	%ecx, %edi
	movl	%ecx, %eax
	cmovgl	%edi, %eax
	cmpl	%esi, %ecx
	cmovlel	%edi, %eax
	cmpl	%edx, %ecx
	cmovlel	%edi, %eax
	retq
.Lfunc_end0:
	.size	_Z10Maxpoolingiiii, .Lfunc_end0-_Z10Maxpoolingiiii
	.cfi_endproc
                                        # -- End function
	.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	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$585848, %rsp                   # imm = 0x8F078
	.cfi_def_cfa_offset 585904
	.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	$3136, %edi                     # imm = 0xC40
	callq	malloc
	movq	%rax, %rcx
	xorl	%eax, %eax
	movq	%rcx, 112(%rsp)                 # 8-byte Spill
.LBB1_1:                                # %.preheader825
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_2 Depth 2
	xorl	%edx, %edx
.LBB1_2:                                #   Parent Loop BB1_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$1, (%rcx,%rdx,4)
	incq	%rdx
	cmpq	$28, %rdx
	jne	.LBB1_2
# %bb.3:                                #   in Loop: Header=BB1_1 Depth=1
	incq	%rax
	addq	$112, %rcx
	cmpq	$28, %rax
	jne	.LBB1_1
# %bb.4:                                # %.preheader823.preheader
	leaq	496(%rsp), %rax
	xorl	%ecx, %ecx
.LBB1_5:                                # %.preheader823
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_6 Depth 2
                                        #       Child Loop BB1_7 Depth 3
	movq	%rax, %rdx
	xorl	%esi, %esi
.LBB1_6:                                # %.preheader822
                                        #   Parent Loop BB1_5 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_7 Depth 3
	xorl	%edi, %edi
.LBB1_7:                                #   Parent Loop BB1_5 Depth=1
                                        #     Parent Loop BB1_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	$1, (%rdx,%rdi,4)
	incq	%rdi
	cmpq	$5, %rdi
	jne	.LBB1_7
# %bb.8:                                #   in Loop: Header=BB1_6 Depth=2
	incq	%rsi
	addq	$20, %rdx
	cmpq	$5, %rsi
	jne	.LBB1_6
# %bb.9:                                #   in Loop: Header=BB1_5 Depth=1
	incq	%rcx
	addq	$100, %rax
	cmpq	$32, %rcx
	jne	.LBB1_5
# %bb.10:                               # %.preheader820.preheader
	leaq	10352(%rsp), %rax
	xorl	%ecx, %ecx
.LBB1_11:                               # %.preheader820
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_12 Depth 2
                                        #       Child Loop BB1_13 Depth 3
                                        #         Child Loop BB1_14 Depth 4
	movq	%rax, %rdx
	xorl	%esi, %esi
.LBB1_12:                               # %.preheader819
                                        #   Parent Loop BB1_11 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_13 Depth 3
                                        #         Child Loop BB1_14 Depth 4
	movq	%rdx, %rdi
	xorl	%r8d, %r8d
.LBB1_13:                               # %.preheader818
                                        #   Parent Loop BB1_11 Depth=1
                                        #     Parent Loop BB1_12 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB1_14 Depth 4
	xorl	%r9d, %r9d
.LBB1_14:                               #   Parent Loop BB1_11 Depth=1
                                        #     Parent Loop BB1_12 Depth=2
                                        #       Parent Loop BB1_13 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	movl	$1, (%rdi,%r9,4)
	incq	%r9
	cmpq	$5, %r9
	jne	.LBB1_14
# %bb.15:                               #   in Loop: Header=BB1_13 Depth=3
	incq	%r8
	addq	$20, %rdi
	cmpq	$5, %r8
	jne	.LBB1_13
# %bb.16:                               #   in Loop: Header=BB1_12 Depth=2
	incq	%rsi
	addq	$100, %rdx
	cmpq	$32, %rsi
	jne	.LBB1_12
# %bb.17:                               #   in Loop: Header=BB1_11 Depth=1
	incq	%rcx
	addq	$3200, %rax                     # imm = 0xC80
	cmpq	$64, %rcx
	jne	.LBB1_11
# %bb.18:                               # %.preheader816.preheader
	leaq	323696(%rsp), %rax
	xorl	%ecx, %ecx
.LBB1_19:                               # %.preheader816
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_20 Depth 2
	xorl	%edx, %edx
.LBB1_20:                               #   Parent Loop BB1_19 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$1, (%rax,%rdx,4)
	incq	%rdx
	cmpq	$1024, %rdx                     # imm = 0x400
	jne	.LBB1_20
# %bb.21:                               #   in Loop: Header=BB1_19 Depth=1
	incq	%rcx
	addq	$4096, %rax                     # imm = 0x1000
	cmpq	$64, %rcx
	jne	.LBB1_19
# %bb.22:                               # %.preheader814.preheader
	leaq	3696(%rsp), %rax
	xorl	%ecx, %ecx
.LBB1_23:                               # %.preheader814
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_24 Depth 2
	xorl	%edx, %edx
.LBB1_24:                               #   Parent Loop BB1_23 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$1, (%rax,%rdx,4)
	incq	%rdx
	cmpq	$64, %rdx
	jne	.LBB1_24
# %bb.25:                               #   in Loop: Header=BB1_23 Depth=1
	incq	%rcx
	addq	$256, %rax                      # imm = 0x100
	cmpq	$10, %rcx
	jne	.LBB1_23
# %bb.26:
	leaq	249968(%rsp), %rax
	movq	%rax, 104(%rsp)                 # 8-byte Spill
	xorl	%ebx, %ebx
	callq	clock
	movq	%rax, 160(%rsp)                 # 8-byte Spill
.LBB1_27:                               # %.preheader813
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_28 Depth 2
                                        #       Child Loop BB1_29 Depth 3
	movq	%rbx, 120(%rsp)                 # 8-byte Spill
	imulq	$100, %rbx, %r11
	movl	496(%rsp,%r11), %ecx
	movl	500(%rsp,%r11), %edx
	movl	504(%rsp,%r11), %esi
	movl	508(%rsp,%r11), %eax
	movl	%eax, 80(%rsp)                  # 4-byte Spill
	movl	512(%rsp,%r11), %eax
	movl	%eax, 76(%rsp)                  # 4-byte Spill
	movl	516(%rsp,%r11), %eax
	movl	%eax, 72(%rsp)                  # 4-byte Spill
	movl	520(%rsp,%r11), %eax
	movl	%eax, 68(%rsp)                  # 4-byte Spill
	movl	524(%rsp,%r11), %eax
	movl	%eax, 64(%rsp)                  # 4-byte Spill
	movl	528(%rsp,%r11), %eax
	movl	%eax, 60(%rsp)                  # 4-byte Spill
	movl	532(%rsp,%r11), %eax
	movl	%eax, 56(%rsp)                  # 4-byte Spill
	movl	536(%rsp,%r11), %eax
	movl	%eax, 52(%rsp)                  # 4-byte Spill
	movl	540(%rsp,%r11), %eax
	movl	%eax, 48(%rsp)                  # 4-byte Spill
	movl	544(%rsp,%r11), %eax
	movl	%eax, 44(%rsp)                  # 4-byte Spill
	movl	580(%rsp,%r11), %eax
	addl	560(%rsp,%r11), %eax
	movl	%eax, 40(%rsp)                  # 4-byte Spill
	movl	548(%rsp,%r11), %eax
	movl	%eax, 36(%rsp)                  # 4-byte Spill
	movl	552(%rsp,%r11), %eax
	movl	%eax, 32(%rsp)                  # 4-byte Spill
	movl	556(%rsp,%r11), %eax
	movl	%eax, 28(%rsp)                  # 4-byte Spill
	movl	564(%rsp,%r11), %eax
	movl	%eax, 24(%rsp)                  # 4-byte Spill
	movl	568(%rsp,%r11), %eax
	movl	%eax, 128(%rsp)                 # 4-byte Spill
	movl	572(%rsp,%r11), %eax
	movl	%eax, 96(%rsp)                  # 4-byte Spill
	movl	576(%rsp,%r11), %eax
	movl	%eax, 20(%rsp)                  # 4-byte Spill
	movl	584(%rsp,%r11), %eax
	movl	%eax, 16(%rsp)                  # 4-byte Spill
	movl	588(%rsp,%r11), %eax
	movl	%eax, 12(%rsp)                  # 4-byte Spill
	movl	592(%rsp,%r11), %eax
	movl	%eax, 8(%rsp)                   # 4-byte Spill
	movq	112(%rsp), %rbp                 # 8-byte Reload
	xorl	%eax, %eax
	xorl	%edi, %edi
.LBB1_28:                               # %.preheader812
                                        #   Parent Loop BB1_27 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_29 Depth 3
	movq	%rax, 144(%rsp)                 # 8-byte Spill
	movslq	%edi, %rdi
	movq	104(%rsp), %rax                 # 8-byte Reload
	movq	%rdi, 136(%rsp)                 # 8-byte Spill
	leaq	(%rax,%rdi,4), %rax
	movq	%rax, 88(%rsp)                  # 8-byte Spill
	xorl	%r13d, %r13d
	movl	128(%rsp), %r10d                # 4-byte Reload
	movl	96(%rsp), %r11d                 # 4-byte Reload
	movl	20(%rsp), %r12d                 # 4-byte Reload
	movl	16(%rsp), %edi                  # 4-byte Reload
	movl	12(%rsp), %r8d                  # 4-byte Reload
	movl	8(%rsp), %r9d                   # 4-byte Reload
.LBB1_29:                               #   Parent Loop BB1_27 Depth=1
                                        #     Parent Loop BB1_28 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	(%rbp,%r13,4), %r14d
	imull	%ecx, %r14d
	movl	4(%rbp,%r13,4), %r15d
	imull	%edx, %r15d
	addl	%r14d, %r15d
	movl	8(%rbp,%r13,4), %r14d
	imull	%esi, %r14d
	movl	12(%rbp,%r13,4), %ebx
	imull	80(%rsp), %ebx                  # 4-byte Folded Reload
	addl	%r14d, %ebx
	addl	%r15d, %ebx
	movl	16(%rbp,%r13,4), %r14d
	imull	76(%rsp), %r14d                 # 4-byte Folded Reload
	movl	112(%rbp,%r13,4), %r15d
	imull	72(%rsp), %r15d                 # 4-byte Folded Reload
	addl	%r14d, %r15d
	movl	116(%rbp,%r13,4), %r14d
	imull	68(%rsp), %r14d                 # 4-byte Folded Reload
	addl	%r15d, %r14d
	addl	%ebx, %r14d
	movl	120(%rbp,%r13,4), %ebx
	imull	64(%rsp), %ebx                  # 4-byte Folded Reload
	movl	124(%rbp,%r13,4), %r15d
	imull	60(%rsp), %r15d                 # 4-byte Folded Reload
	addl	%ebx, %r15d
	movl	128(%rbp,%r13,4), %ebx
	imull	56(%rsp), %ebx                  # 4-byte Folded Reload
	addl	%r15d, %ebx
	movl	224(%rbp,%r13,4), %r15d
	imull	52(%rsp), %r15d                 # 4-byte Folded Reload
	addl	%ebx, %r15d
	addl	%r14d, %r15d
	movl	228(%rbp,%r13,4), %ebx
	imull	48(%rsp), %ebx                  # 4-byte Folded Reload
	movl	232(%rbp,%r13,4), %r14d
	imull	44(%rsp), %r14d                 # 4-byte Folded Reload
	addl	%ebx, %r14d
	movl	236(%rbp,%r13,4), %ebx
	imull	36(%rsp), %ebx                  # 4-byte Folded Reload
	addl	%r14d, %ebx
	movl	240(%rbp,%r13,4), %eax
	imull	32(%rsp), %eax                  # 4-byte Folded Reload
	addl	%ebx, %eax
	movl	336(%rbp,%r13,4), %r14d
	imull	28(%rsp), %r14d                 # 4-byte Folded Reload
	addl	%eax, %r14d
	addl	%r15d, %r14d
	movl	344(%rbp,%r13,4), %eax
	imull	24(%rsp), %eax                  # 4-byte Folded Reload
	movl	348(%rbp,%r13,4), %ebx
	imull	%r10d, %ebx
	addl	%eax, %ebx
	movl	352(%rbp,%r13,4), %eax
	imull	%r11d, %eax
	addl	%ebx, %eax
	movl	448(%rbp,%r13,4), %ebx
	imull	%r12d, %ebx
	addl	%eax, %ebx
	movl	460(%rbp,%r13,4), %eax
	imull	%r8d, %eax
	movl	464(%rbp,%r13,4), %r15d
	imull	%r9d, %r15d
	addl	%eax, %r15d
	movl	340(%rbp,%r13,4), %eax
	imull	40(%rsp), %eax                  # 4-byte Folded Reload
	addl	%ebx, %eax
	movl	456(%rbp,%r13,4), %ebx
	imull	%edi, %ebx
	addl	%ebx, %eax
	addl	%r14d, %eax
	addl	%r15d, %eax
	movq	88(%rsp), %rbx                  # 8-byte Reload
	movl	%eax, (%rbx,%r13,4)
	incq	%r13
	cmpq	$24, %r13
	jne	.LBB1_29
# %bb.30:                               #   in Loop: Header=BB1_28 Depth=2
	movq	144(%rsp), %rax                 # 8-byte Reload
	incq	%rax
	movq	136(%rsp), %rdi                 # 8-byte Reload
	addq	%r13, %rdi
	addq	$112, %rbp
	cmpq	$24, %rax
	jne	.LBB1_28
# %bb.31:                               #   in Loop: Header=BB1_27 Depth=1
	movq	120(%rsp), %rbx                 # 8-byte Reload
	incq	%rbx
	addq	$2304, 104(%rsp)                # 8-byte Folded Spill
                                        # imm = 0x900
	cmpq	$32, %rbx
	jne	.LBB1_27
# %bb.32:                               # %.preheader811
	leaq	231536(%rsp), %rbp
	leaq	250068(%rsp), %r12
	xorl	%r14d, %r14d
.LBB1_33:                               # %.preheader810
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_34 Depth 2
                                        #       Child Loop BB1_35 Depth 3
	movq	%r12, 80(%rsp)                  # 8-byte Spill
	xorl	%r13d, %r13d
	movq	%rbp, 88(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
.LBB1_34:                               # %.preheader809
                                        #   Parent Loop BB1_33 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_35 Depth 3
	xorl	%r15d, %r15d
.LBB1_35:                               #   Parent Loop BB1_33 Depth=1
                                        #     Parent Loop BB1_34 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	-100(%r12,%r15,8), %ecx
	movl	-96(%r12,%r15,8), %eax
	cmpl	%ecx, %eax
	movl	%ecx, %r8d
	cmovgl	%eax, %r8d
	movl	(%r12,%r15,8), %edx
	cmpl	%edx, %eax
	cmovlel	%ecx, %r8d
	movl	-4(%r12,%r15,8), %esi
	cmpl	%esi, %eax
	cmovlel	%ecx, %r8d
	cmpl	%esi, %r8d
	movl	%esi, %edi
	cmovgl	%r8d, %edi
	cmpl	%edx, %esi
	cmovlel	%r8d, %edi
	cmpl	%eax, %esi
	cmovlel	%r8d, %edi
	movl	%edi, %ecx
	cmpl	%edx, %edi
	jg	.LBB1_37
# %bb.36:                               #   in Loop: Header=BB1_35 Depth=3
	movl	%edx, %ecx
.LBB1_37:                               #   in Loop: Header=BB1_35 Depth=3
	cmpl	%eax, %edx
	cmovlel	%edi, %ecx
	cmpl	%esi, %edx
	cmovlel	%edi, %ecx
	movl	%ecx, (%rbp,%r15,4)
	leal	(%r15,%r13), %edx
	movl	$.L.str, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpl	$12, %r15d
	jne	.LBB1_35
# %bb.38:                               #   in Loop: Header=BB1_34 Depth=2
	movl	$10, %edi
	callq	putchar@PLT
	leaq	2(%rbx), %rax
	addq	$48, %rbp
	addq	$12, %r13
	addq	$192, %r12
	cmpq	$22, %rbx
	movq	%rax, %rbx
	jb	.LBB1_34
# %bb.39:                               #   in Loop: Header=BB1_33 Depth=1
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	incq	%r14
	movq	88(%rsp), %rbp                  # 8-byte Reload
	addq	$576, %rbp                      # imm = 0x240
	movq	80(%rsp), %r12                  # 8-byte Reload
	addq	$2304, %r12                     # imm = 0x900
	cmpq	$32, %r14
	jne	.LBB1_33
# %bb.40:
	movl	$.L.str.3, %edi
	movl	$12, %esi
	movl	$8, %edx
	xorl	%eax, %eax
	callq	printf
	xorl	%ecx, %ecx
.LBB1_41:                               # %.preheader808
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_42 Depth 2
                                        #       Child Loop BB1_43 Depth 3
                                        #         Child Loop BB1_44 Depth 4
	imulq	$3200, %rcx, %rax               # imm = 0xC80
	movl	10352(%rsp,%rax), %edx
	movl	%edx, 88(%rsp)                  # 4-byte Spill
	movl	10356(%rsp,%rax), %edx
	movl	%edx, 80(%rsp)                  # 4-byte Spill
	movl	10360(%rsp,%rax), %edx
	movl	%edx, 76(%rsp)                  # 4-byte Spill
	movl	10364(%rsp,%rax), %edx
	movl	%edx, 72(%rsp)                  # 4-byte Spill
	movl	10368(%rsp,%rax), %edx
	movl	%edx, 68(%rsp)                  # 4-byte Spill
	movl	10372(%rsp,%rax), %edx
	movl	%edx, 64(%rsp)                  # 4-byte Spill
	movl	10376(%rsp,%rax), %edx
	movl	%edx, 60(%rsp)                  # 4-byte Spill
	movl	10380(%rsp,%rax), %edx
	movl	%edx, 56(%rsp)                  # 4-byte Spill
	movl	10384(%rsp,%rax), %edx
	movl	%edx, 52(%rsp)                  # 4-byte Spill
	movl	10388(%rsp,%rax), %edx
	movl	%edx, 48(%rsp)                  # 4-byte Spill
	movl	10392(%rsp,%rax), %edx
	movl	%edx, 44(%rsp)                  # 4-byte Spill
	movl	10396(%rsp,%rax), %edx
	movl	%edx, 40(%rsp)                  # 4-byte Spill
	movl	10436(%rsp,%rax), %edx
	addl	10416(%rsp,%rax), %edx
	movl	%edx, 36(%rsp)                  # 4-byte Spill
	movl	10400(%rsp,%rax), %edx
	movl	%edx, 32(%rsp)                  # 4-byte Spill
	movl	10404(%rsp,%rax), %edx
	movl	%edx, 28(%rsp)                  # 4-byte Spill
	movl	10408(%rsp,%rax), %edx
	movl	%edx, 24(%rsp)                  # 4-byte Spill
	movl	10412(%rsp,%rax), %edx
	movl	%edx, 20(%rsp)                  # 4-byte Spill
	movl	10420(%rsp,%rax), %edx
	movl	%edx, 16(%rsp)                  # 4-byte Spill
	movl	10424(%rsp,%rax), %edx
	movl	%edx, 12(%rsp)                  # 4-byte Spill
	movl	10428(%rsp,%rax), %edx
	movl	%edx, 8(%rsp)                   # 4-byte Spill
	movl	10432(%rsp,%rax), %edx
	movl	%edx, 120(%rsp)                 # 4-byte Spill
	movl	10440(%rsp,%rax), %edx
	movl	%edx, 112(%rsp)                 # 4-byte Spill
	movl	10444(%rsp,%rax), %edx
	movl	%edx, 156(%rsp)                 # 4-byte Spill
	movl	10448(%rsp,%rax), %eax
	movl	%eax, 152(%rsp)                 # 4-byte Spill
	movq	%rcx, 96(%rsp)                  # 8-byte Spill
	movq	%rcx, %rax
	shlq	$8, %rax
	addq	%rsp, %rax
	addq	$215152, %rax                   # imm = 0x34870
	movq	%rax, 168(%rsp)                 # 8-byte Spill
	leaq	231536(%rsp), %rbp
	xorl	%eax, %eax
.LBB1_42:                               # %.preheader807
                                        #   Parent Loop BB1_41 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_43 Depth 3
                                        #         Child Loop BB1_44 Depth 4
	leaq	(,%rax,8), %rcx
	movq	%rcx, 104(%rsp)                 # 8-byte Spill
	movq	%rax, 176(%rsp)                 # 8-byte Spill
	shlq	$5, %rax
	addq	168(%rsp), %rax                 # 8-byte Folded Reload
	movq	%rax, 128(%rsp)                 # 8-byte Spill
	movq	%rbp, 184(%rsp)                 # 8-byte Spill
	xorl	%ecx, %ecx
.LBB1_43:                               # %.preheader806
                                        #   Parent Loop BB1_41 Depth=1
                                        #     Parent Loop BB1_42 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB1_44 Depth 4
	movq	%rcx, 136(%rsp)                 # 8-byte Spill
	leaq	1(%rcx), %rax
	movq	%rax, 144(%rsp)                 # 8-byte Spill
	xorl	%ecx, %ecx
	movl	$208, %eax
	movl	20(%rsp), %edx                  # 4-byte Reload
	movl	16(%rsp), %r11d                 # 4-byte Reload
	movl	12(%rsp), %r12d                 # 4-byte Reload
	movl	8(%rsp), %r13d                  # 4-byte Reload
	movl	120(%rsp), %ebx                 # 4-byte Reload
	movl	112(%rsp), %r15d                # 4-byte Reload
	movl	156(%rsp), %r14d                # 4-byte Reload
	movl	152(%rsp), %r10d                # 4-byte Reload
.LBB1_44:                               #   Parent Loop BB1_41 Depth=1
                                        #     Parent Loop BB1_42 Depth=2
                                        #       Parent Loop BB1_43 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	movl	-208(%rbp,%rax), %esi
	imull	88(%rsp), %esi                  # 4-byte Folded Reload
	addl	%ecx, %esi
	movl	-204(%rbp,%rax), %ecx
	imull	80(%rsp), %ecx                  # 4-byte Folded Reload
	movl	-200(%rbp,%rax), %edi
	imull	76(%rsp), %edi                  # 4-byte Folded Reload
	addl	%ecx, %edi
	addl	%esi, %edi
	movl	-196(%rbp,%rax), %ecx
	imull	72(%rsp), %ecx                  # 4-byte Folded Reload
	movl	-192(%rbp,%rax), %esi
	imull	68(%rsp), %esi                  # 4-byte Folded Reload
	addl	%ecx, %esi
	movl	-160(%rbp,%rax), %r8d
	imull	64(%rsp), %r8d                  # 4-byte Folded Reload
	addl	%esi, %r8d
	addl	%edi, %r8d
	movl	-156(%rbp,%rax), %ecx
	imull	60(%rsp), %ecx                  # 4-byte Folded Reload
	movl	-152(%rbp,%rax), %esi
	imull	56(%rsp), %esi                  # 4-byte Folded Reload
	addl	%ecx, %esi
	movl	-148(%rbp,%rax), %edi
	imull	52(%rsp), %edi                  # 4-byte Folded Reload
	addl	%esi, %edi
	movl	-144(%rbp,%rax), %ecx
	imull	48(%rsp), %ecx                  # 4-byte Folded Reload
	addl	%edi, %ecx
	addl	%r8d, %ecx
	movl	-112(%rbp,%rax), %esi
	imull	44(%rsp), %esi                  # 4-byte Folded Reload
	movl	-108(%rbp,%rax), %edi
	imull	40(%rsp), %edi                  # 4-byte Folded Reload
	addl	%esi, %edi
	movl	-104(%rbp,%rax), %esi
	imull	32(%rsp), %esi                  # 4-byte Folded Reload
	addl	%edi, %esi
	movl	-100(%rbp,%rax), %edi
	imull	28(%rsp), %edi                  # 4-byte Folded Reload
	addl	%esi, %edi
	movl	-96(%rbp,%rax), %esi
	imull	24(%rsp), %esi                  # 4-byte Folded Reload
	addl	%edi, %esi
	addl	%ecx, %esi
	movl	-64(%rbp,%rax), %ecx
	imull	%edx, %ecx
	movl	-56(%rbp,%rax), %edi
	imull	%r11d, %edi
	addl	%ecx, %edi
	movl	-52(%rbp,%rax), %ecx
	imull	%r12d, %ecx
	addl	%edi, %ecx
	movl	-48(%rbp,%rax), %edi
	imull	%r13d, %edi
	addl	%ecx, %edi
	movl	-16(%rbp,%rax), %r8d
	imull	%ebx, %r8d
	addl	%edi, %r8d
	movl	-8(%rbp,%rax), %ecx
	imull	%r15d, %ecx
	movl	-4(%rbp,%rax), %edi
	imull	%r14d, %edi
	addl	%ecx, %edi
	movl	(%rbp,%rax), %r9d
	imull	%r10d, %r9d
	addl	%edi, %r9d
	movl	-60(%rbp,%rax), %ecx
	imull	36(%rsp), %ecx                  # 4-byte Folded Reload
	addl	%r8d, %ecx
	addl	%esi, %ecx
	addl	%r9d, %ecx
	addq	$576, %rax                      # imm = 0x240
	cmpq	$18640, %rax                    # imm = 0x48D0
	jne	.LBB1_44
# %bb.45:                               #   in Loop: Header=BB1_43 Depth=3
	movq	128(%rsp), %rax                 # 8-byte Reload
	movq	136(%rsp), %rdx                 # 8-byte Reload
	movl	%ecx, (%rax,%rdx,4)
	orl	104(%rsp), %edx                 # 4-byte Folded Reload
	movl	$.L.str.4, %edi
	movq	96(%rsp), %rsi                  # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
                                        # kill: def $edx killed $edx killed $rdx
	xorl	%eax, %eax
	callq	printf
	addq	$4, %rbp
	movq	144(%rsp), %rax                 # 8-byte Reload
	movq	%rax, %rcx
	cmpq	$8, %rax
	jne	.LBB1_43
# %bb.46:                               #   in Loop: Header=BB1_42 Depth=2
	movl	$10, %edi
	callq	putchar@PLT
	movq	176(%rsp), %rax                 # 8-byte Reload
	incq	%rax
	movq	184(%rsp), %rbp                 # 8-byte Reload
	addq	$48, %rbp
	cmpq	$8, %rax
	jne	.LBB1_42
# %bb.47:                               #   in Loop: Header=BB1_41 Depth=1
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movq	96(%rsp), %rcx                  # 8-byte Reload
	incq	%rcx
	cmpq	$64, %rcx
	jne	.LBB1_41
# %bb.48:
	xorl	%ebx, %ebx
	movl	$.L.str.5, %edi
	movl	$4, %esi
	movl	$8, %edx
	movl	$64, %ecx
	xorl	%eax, %eax
	callq	printf
	leaq	6256(%rsp), %rax
	leaq	215188(%rsp), %rcx
.LBB1_49:                               # %.preheader805
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_50 Depth 2
                                        #       Child Loop BB1_51 Depth 3
	movq	%rcx, %rdx
	movq	%rax, %rsi
	xorl	%edi, %edi
.LBB1_50:                               # %.preheader804
                                        #   Parent Loop BB1_49 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_51 Depth 3
	xorl	%r8d, %r8d
.LBB1_51:                               #   Parent Loop BB1_49 Depth=1
                                        #     Parent Loop BB1_50 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	-36(%rdx,%r8,8), %ebp
	movl	-32(%rdx,%r8,8), %r9d
	cmpl	%ebp, %r9d
	movl	%ebp, %r14d
	cmovgl	%r9d, %r14d
	movl	(%rdx,%r8,8), %r10d
	cmpl	%r10d, %r9d
	cmovlel	%ebp, %r14d
	movl	-4(%rdx,%r8,8), %r11d
	cmpl	%r11d, %r9d
	cmovlel	%ebp, %r14d
	cmpl	%r11d, %r14d
	movl	%r11d, %ebp
	cmovgl	%r14d, %ebp
	cmpl	%r10d, %r11d
	cmovlel	%r14d, %ebp
	cmpl	%r9d, %r11d
	cmovlel	%r14d, %ebp
	movl	%ebp, %r14d
	cmpl	%r10d, %ebp
	jg	.LBB1_53
# %bb.52:                               #   in Loop: Header=BB1_51 Depth=3
	movl	%r10d, %r14d
.LBB1_53:                               #   in Loop: Header=BB1_51 Depth=3
	cmpl	%r9d, %r10d
	cmovlel	%ebp, %r14d
	cmpl	%r11d, %r10d
	cmovlel	%ebp, %r14d
	movslq	%r14d, %r9
	imulq	$1759218605, %r9, %r9           # imm = 0x68DB8BAD
	movq	%r9, %r10
	shrq	$63, %r10
	sarq	$40, %r9
	addl	%r10d, %r9d
	movl	%r9d, (%rsi,%r8,4)
	incq	%r8
	cmpl	$4, %r8d
	jne	.LBB1_51
# %bb.54:                               #   in Loop: Header=BB1_50 Depth=2
	leaq	2(%rdi), %r8
	addq	$16, %rsi
	addq	$64, %rdx
	cmpq	$6, %rdi
	movq	%r8, %rdi
	jb	.LBB1_50
# %bb.55:                               #   in Loop: Header=BB1_49 Depth=1
	incq	%rbx
	addq	$64, %rax
	addq	$256, %rcx                      # imm = 0x100
	cmpq	$64, %rbx
	jne	.LBB1_49
# %bb.56:                               # %.preheader802.preheader
	leaq	323696(%rsp), %rax
	xorl	%ecx, %ecx
.LBB1_57:                               # %.preheader802
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_58 Depth 2
	movl	240(%rsp,%rcx,4), %edx
	xorl	%esi, %esi
.LBB1_58:                               #   Parent Loop BB1_57 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	6256(%rsp,%rsi,4), %edi
	imull	(%rax,%rsi,4), %edi
	addl	%edi, %edx
	incq	%rsi
	cmpq	$1024, %rsi                     # imm = 0x400
	jne	.LBB1_58
# %bb.59:                               #   in Loop: Header=BB1_57 Depth=1
	movl	%edx, 240(%rsp,%rcx,4)
	incq	%rcx
	addq	$4096, %rax                     # imm = 0x1000
	cmpq	$64, %rcx
	jne	.LBB1_57
# %bb.60:                               # %.preheader.preheader
	leaq	3696(%rsp), %rax
	xorl	%ecx, %ecx
.LBB1_61:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_62 Depth 2
	movl	192(%rsp,%rcx,4), %edx
	xorl	%esi, %esi
.LBB1_62:                               #   Parent Loop BB1_61 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	240(%rsp,%rsi,4), %edi
	imull	(%rax,%rsi,4), %edi
	addl	%edi, %edx
	incq	%rsi
	cmpq	$64, %rsi
	jne	.LBB1_62
# %bb.63:                               #   in Loop: Header=BB1_61 Depth=1
	movl	%edx, 192(%rsp,%rcx,4)
	incq	%rcx
	addq	$256, %rax                      # imm = 0x100
	cmpq	$10, %rcx
	jne	.LBB1_61
# %bb.64:
	callq	clock
	subq	160(%rsp), %rax                 # 8-byte Folded Reload
	cvtsi2sd	%rax, %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$585848, %rsp                   # imm = 0x8F078
	.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	"Maxpool[%d][%d] : %d \t"
	.size	.L.str, 23

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"dim: %d ; dimx: %d\n"
	.size	.L.str.3, 20

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"result2[%d][%d]=%d\t"
	.size	.L.str.4, 20

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"dim: %d ;dimx: %d; numbytes3: %d"
	.size	.L.str.5, 33

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"time taken by cpu : %f seconds"
	.size	.L.str.6, 31

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

	.type	.Lstr.1,@object                 # @str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr.1:
	.asciz	"\n\n"
	.size	.Lstr.1, 3

	.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
