#include <stdio.h>

typedef struct NET_T {
  int nb_layers;
  int* size0;//size of output
  int* size1;//size of input
  double** layers;
  double** biases;
} net_t;

typedef struct IMG_T{
  int l;
  int ll;
  double* pixels;
} img_t;

net_t load_coeffs(char* file_address){
  FILE* f = fopen(file_address, "r");
  //printf("Opened\n");
  
  net_t network;
  int current_layer;
  int size0, size1;

  char garbage;
  fscanf(f, "%c:", &garbage);
  fscanf(f, "%d", &(network.nb_layers));

  double** n = (double**) malloc(network.nb_layers*sizeof(double*));
  int* s0 = (int*) malloc(network.nb_layers*sizeof(int));
  int* s1 = (int*) malloc(network.nb_layers*sizeof(int));
  double** b = (double**) malloc(network.nb_layers*sizeof(double*));
  network.layers = n;
  network.biases = b;
  network.size0 = s0;
  network.size1 = s1;
  //printf("Entering loop, nb_layers:%d\n", network.nb_layers);
  int old_layer =-1;
  while(!feof(f)){
    fscanf(f, " %c", &garbage); //"L"
    fscanf(f, " %d", &current_layer);
    if(current_layer == old_layer)
      break;
    old_layer=current_layer;
    fscanf(f, " %c", &garbage); // ":"
    fscanf(f, " %d", &size0);
    s0[current_layer] = size0;
    fscanf(f, " %d", &size1);
    s1[current_layer] = size1;
    //printf("Current Layer %d, size0 = %d, size1 = %d\n", current_layer, size0, size1);
    double* tab = (double*) malloc(size0 * size1 * sizeof(double));
    network.layers[current_layer] = tab;
    for(int i = 0; i < size0*size1; i++){
      fscanf(f, "%lf", &(tab[i]));
      //printf("%lf",tab[i]);
    }

    fscanf(f, " %c", &garbage); //"L"
    fscanf(f, " %d", &current_layer);
    fscanf(f, " %c", &garbage); // ":"
    fscanf(f, " %d", &size0);
    //printf("Current Bias %d, size0 = %d\n", current_layer, size0);
    double* tab2 = (double*) malloc(size0 * sizeof(double));
    network.biases[current_layer] = tab2;
    for(int i = 0; i < size0; i++){
      fscanf(f, " %lf", &(tab2[i]));
    }

  }
  fclose(f);
  return network;
}


img_t* load_image(FILE* f){
  img_t* image = (img_t*)malloc(sizeof(img_t));
  image->l = 28;
  image->ll = 28;
  double* img = (double*) malloc(image->l*image->ll*sizeof(double));
  image->pixels = img;
  char garbage;
  fscanf(f, " %c", &garbage);
  for(int i=0; i<image->l*image->ll; i++){
    fscanf(f, " %lf", &(img[i]));
  }
  return image;
}




double relu(double in){
  if(in > 0)
    return in;
  return 0;
}

double* forward(net_t net, img_t img){
  double* in, *out;
  in = (double*)malloc(net.size1[0]*sizeof(double));
  for(int i = 0; i<net.size1[0]; i++){
    in[i]= img.pixels[i];
  //printf("in[%d]=%lf\n", i, in[i]);
  }
  //for(int i=0;i<28;i++)
  //  for(int j =0; j<28; j++)
  //    in[i*8+j] = img.pixels[j*8+i];
  
  for(int l = 0; l <net.nb_layers; l++){
    int size_o = net.size0[l];
    int size_i = net.size1[l];
    out = (double*) malloc(size_o*sizeof(double));
    for(int ligne = 0; ligne < size_o; ligne++){
      out[ligne] = 0;
      for(int col = 0; col < size_i; col++){
	//printf("net.layers[l][ligne+col*]=%lf\n",net.layers[l][ligne+col*size_o]);
	out[ligne]+=in[col]*net.layers[l][ligne*size_i+col];
      }
      out[ligne] = relu(out[ligne]+net.biases[l][ligne]);
    }
    free(in);
    in = out;
   
  }
  return in;
}


void print_image(img_t* im){
  for(int i = 0; i<28*28;i++){
    printf( "%lf ",im->pixels[i]);
  }
  printf("\n\n");
}


int main(){
  char address[256] = "test.txt";
  net_t test = load_coeffs(address);
  char garbage;
  int res[64];

  printf("Reseau ok\n");
  
  FILE* f = fopen("images3.txt", "r");
  img_t* images[64];

  for(int i=0; i<64; i++){
    images[i]=load_image(f);
    //print_image(images[i]);
  }
  printf("Images chargees\n");
  fscanf(f, " %c", &garbage);
  for(int i=0; i<64; i++){
    fscanf(f, "%d", &res[i]);
  }
  
  double* result ;
  int max =-1,i_max=-1;
  int found = 0;
  for(int k =0; k<64; k++){
    result = forward(test, *images[k]);
    max=-1;
    i_max=-1;
    for(int i =0; i < 10; i++){
      printf("proba %d: %lf\n", i, result[i]);
      if(result[i]>max){
	i_max=i;
	max=result[i];
      }
    }
    if(i_max == res[k]){
      found+=1;
    }
  }

  printf("Percentage = %lf\n", (float)found/64);
  // printf("Expected: %d\n", res[0]);
  free(result);
  
  
  return 0;
}

	.file	"tmpxft_00389317_00000000-6_classifier.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"%c:"
.LC2:
	.string	"%d"
.LC3:
	.string	" %c"
.LC4:
	.string	" %d"
.LC5:
	.string	"%lf"
.LC6:
	.string	" %lf"
	.text
	.globl	_Z11load_coeffsPc
	.type	_Z11load_coeffsPc, @function
_Z11load_coeffsPc:
.LFB2027:
	.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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	movq	%rsi, %rdi
	leaq	.LC0(%rip), %rsi
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, 8(%rsp)
	leaq	43(%rsp), %rax
	movq	8(%rsp), %rdi
	movq	%rax, %rdx
	movq	%rax, 16(%rsp)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	8(%rsp), %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movslq	(%rbx), %r13
	leaq	0(,%r13,8), %rbp
	salq	$2, %r13
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%r13, %rdi
	movq	%rax, %r14
	call	malloc@PLT
	movq	%r13, %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	%r12, 8(%rbx)
	movq	%rax, 32(%rbx)
	movq	%r13, 16(%rbx)
	movq	%r14, 24(%rbx)
	orl	$-1, %r14d
.L3:
	movq	8(%rsp), %rdi
	call	feof@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	jne	.L10
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rdi
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	8(%rsp), %rdi
	leaq	44(%rsp), %rdx
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movl	44(%rsp), %r15d
	cmpl	%r14d, %r15d
	jne	.L4
.L10:
	movq	8(%rsp), %rdi
	call	fclose@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L4:
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rdi
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	8(%rsp), %rdi
	leaq	48(%rsp), %rdx
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movslq	44(%rsp), %rax
	movl	48(%rsp), %edx
	leaq	.LC4(%rip), %rsi
	movq	8(%rsp), %rdi
	movl	%edx, (%r12,%rax,4)
	leaq	52(%rsp), %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movslq	44(%rsp), %r14
	movl	52(%rsp), %edi
	movl	%edi, 0(%r13,%r14,4)
	imull	48(%rsp), %edi
	movslq	%edi, %rdi
	salq	$3, %rdi
	call	malloc@PLT
	movq	%rax, %rdx
	movq	24(%rbx), %rax
	movq	%rdx, (%rax,%r14,8)
	xorl	%r14d, %r14d
.L5:
	movl	48(%rsp), %eax
	imull	52(%rsp), %eax
	cmpl	%r14d, %eax
	jle	.L15
	movq	8(%rsp), %rdi
	xorl	%eax, %eax
	movq	%rdx, 24(%rsp)
	incl	%r14d
	leaq	.LC5(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movq	24(%rsp), %rdx
	addq	$8, %rdx
	jmp	.L5
.L15:
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rdi
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %r14
	call	__isoc23_fscanf@PLT
	movq	8(%rsp), %rdi
	movq	%r14, %rsi
	xorl	%eax, %eax
	leaq	44(%rsp), %rdx
	call	__isoc23_fscanf@PLT
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rdi
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movq	8(%rsp), %rdi
	movq	%r14, %rsi
	xorl	%eax, %eax
	leaq	48(%rsp), %rdx
	leaq	.LC6(%rip), %r14
	call	__isoc23_fscanf@PLT
	movslq	48(%rsp), %rdi
	salq	$3, %rdi
	call	malloc@PLT
	movslq	44(%rsp), %rcx
	movq	%rax, %rdx
	movq	32(%rbx), %rax
	movq	%rdx, (%rax,%rcx,8)
.L7:
	cmpl	%ebp, 48(%rsp)
	jle	.L16
	movq	8(%rsp), %rdi
	movq	%r14, %rsi
	xorl	%eax, %eax
	movq	%rdx, 24(%rsp)
	incl	%ebp
	call	__isoc23_fscanf@PLT
	movq	24(%rsp), %rdx
	addq	$8, %rdx
	jmp	.L7
.L16:
	movl	%r15d, %r14d
	jmp	.L3
.L11:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rax
	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
.LFE2027:
	.size	_Z11load_coeffsPc, .-_Z11load_coeffsPc
	.globl	_Z10load_imageP8_IO_FILE
	.type	_Z10load_imageP8_IO_FILE, @function
_Z10load_imageP8_IO_FILE:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC6(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdi, %r12
	movl	$16, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$6272, %edi
	movq	%rax, %rbp
	movabsq	$120259084316, %rax
	movq	%rax, 0(%rbp)
	call	malloc@PLT
	leaq	7(%rsp), %rdx
	leaq	.LC3(%rip), %rsi
	movq	%r12, %rdi
	movq	%rax, 8(%rbp)
	movq	%rax, %rbx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
.L18:
	movl	0(%rbp), %eax
	imull	4(%rbp), %eax
	cmpl	%r13d, %eax
	jle	.L22
	movq	%rbx, %rdx
	movq	%r14, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	incl	%r13d
	addq	$8, %rbx
	jmp	.L18
.L22:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%rbp, %rax
	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
.LFE2028:
	.size	_Z10load_imageP8_IO_FILE, .-_Z10load_imageP8_IO_FILE
	.globl	_Z4relud
	.type	_Z4relud, @function
_Z4relud:
.LFB2029:
	.cfi_startproc
	endbr64
	xorps	%xmm1, %xmm1
	comisd	%xmm1, %xmm0
	ja	.L24
	movaps	%xmm1, %xmm0
.L24:
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z4relud, .-_Z4relud
	.globl	_Z7forward5NET_T5IMG_T
	.type	_Z7forward5NET_T5IMG_T, @function
_Z7forward5NET_T5IMG_T:
.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
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%rcx
	.cfi_def_cfa_offset 64
	movq	80(%rsp), %r13
	movslq	0(%r13), %rdi
	salq	$3, %rdi
	call	malloc@PLT
	movl	0(%r13), %edx
	movq	%rax, %rbx
	xorl	%eax, %eax
.L26:
	cmpl	%eax, %edx
	jle	.L36
	movsd	0(%rbp,%rax,8), %xmm0
	movsd	%xmm0, (%rbx,%rax,8)
	incq	%rax
	jmp	.L26
.L36:
	xorl	%ebp, %ebp
.L28:
	cmpl	%ebp, 64(%rsp)
	jle	.L37
	movq	72(%rsp), %rax
	movl	0(%r13,%rbp,4), %r15d
	movslq	(%rax,%rbp,4), %rdi
	movq	%rdi, %r14
	salq	$3, %rdi
	call	malloc@PLT
	movq	96(%rsp), %rdi
	xorl	%r8d, %r8d
	movq	%rax, %r12
	leaq	0(,%rbp,8), %rax
	addq	%rax, %rdi
	addq	88(%rsp), %rax
	movq	%rax, %rsi
	xorl	%eax, %eax
.L29:
	cmpl	%eax, %r14d
	jle	.L38
	movslq	%r8d, %rdx
	leaq	0(,%rax,8), %r9
	xorps	%xmm0, %xmm0
	xorl	%ecx, %ecx
	salq	$3, %rdx
.L30:
	movsd	%xmm0, (%r12,%rax,8)
	cmpl	%ecx, %r15d
	jle	.L39
	movq	(%rsi), %r10
	movsd	(%r10,%rdx), %xmm1
	mulsd	(%rbx,%rcx,8), %xmm1
	addq	$8, %rdx
	incq	%rcx
	addsd	%xmm1, %xmm0
	jmp	.L30
.L39:
	movq	(%rdi), %rdx
	xorps	%xmm2, %xmm2
	addsd	(%rdx,%r9), %xmm0
	comisd	%xmm2, %xmm0
	ja	.L32
	xorps	%xmm0, %xmm0
.L32:
	movsd	%xmm0, (%r12,%rax,8)
	addl	%r15d, %r8d
	incq	%rax
	jmp	.L29
.L38:
	movq	%rbx, %rdi
	incq	%rbp
	movq	%r12, %rbx
	call	free@PLT
	jmp	.L28
.L37:
	popq	%rdx
	.cfi_def_cfa_offset 56
	movq	%rbx, %rax
	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	_Z7forward5NET_T5IMG_T, .-_Z7forward5NET_T5IMG_T
	.section	.rodata.str1.1
.LC8:
	.string	"%lf "
.LC9:
	.string	"\n\n"
	.text
	.globl	_Z11print_imageP5IMG_T
	.type	_Z11print_imageP5IMG_T, @function
_Z11print_imageP5IMG_T:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC8(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L41:
	movq	8(%rbp), %rax
	movq	%r12, %rsi
	movl	$2, %edi
	movsd	(%rax,%rbx), %xmm0
	movb	$1, %al
	addq	$8, %rbx
	call	__printf_chk@PLT
	cmpq	$6272, %rbx
	jne	.L41
	popq	%rbx
	.cfi_def_cfa_offset 24
	leaq	.LC9(%rip), %rsi
	popq	%rbp
	.cfi_def_cfa_offset 16
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2031:
	.size	_Z11print_imageP5IMG_T, .-_Z11print_imageP5IMG_T
	.section	.rodata.str1.1
.LC10:
	.string	"Reseau ok\n"
.LC11:
	.string	"images3.txt"
.LC12:
	.string	"Images chargees\n"
.LC13:
	.string	"proba %d: %lf\n"
.LC15:
	.string	"Percentage = %lf\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$60, %ecx
	xorl	%edx, %edx
	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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$1112, %rsp
	.cfi_def_cfa_offset 1168
	movq	%fs:40, %rax
	movq	%rax, 1096(%rsp)
	movabsq	$8392585648475956596, %rax
	leaq	856(%rsp), %rdi
	leaq	840(%rsp), %rsi
	movq	%rdx, 848(%rsp)
	leaq	328(%rsp), %r13
	movq	%rax, 840(%rsp)
	xorl	%eax, %eax
	rep stosl
	leaq	32(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	_Z11load_coeffsPc
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC0(%rip), %rsi
	leaq	.LC11(%rip), %rdi
	call	fopen@PLT
	movq	%rax, %rbp
.L45:
	movq	%rbp, %rdi
	call	_Z10load_imageP8_IO_FILE
	movq	%rax, 0(%r13,%rbx,8)
	incq	%rbx
	cmpq	$64, %rbx
	jne	.L45
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	72(%rsp), %rbx
	movq	%rbp, %rdi
	xorl	%eax, %eax
	leaq	31(%rsp), %rdx
	leaq	.LC3(%rip), %rsi
	movq	%rbx, %r14
	call	__isoc23_fscanf@PLT
	leaq	.LC2(%rip), %r15
.L46:
	movq	%rbx, %rdx
	movq	%r15, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	addq	$4, %rbx
	cmpq	%rbx, %r13
	jne	.L46
	xorl	%r15d, %r15d
	xorl	%ebp, %ebp
.L51:
	movq	0(%r13,%r15,8), %rax
	subq	$48, %rsp
	.cfi_def_cfa_offset 1216
	movl	$10, %ecx
	xorl	%ebx, %ebx
	movq	48(%rsp), %rsi
	movq	%rsp, %rdi
	movq	(%rax), %rdx
	movq	8(%rax), %rax
	rep movsl
	movq	%rdx, %rdi
	movq	%rax, %rsi
	call	_Z7forward5NET_T5IMG_T
	addq	$48, %rsp
	.cfi_def_cfa_offset 1168
	orl	$-1, %r9d
	orl	$-1, %r10d
	movq	%rax, %r12
.L49:
	movsd	(%r12,%rbx,8), %xmm0
	movl	%ebx, %edx
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC13(%rip), %rsi
	movl	%r9d, 12(%rsp)
	movl	%r10d, 8(%rsp)
	call	__printf_chk@PLT
	movl	8(%rsp), %r10d
	movsd	(%r12,%rbx,8), %xmm0
	movl	12(%rsp), %r9d
	cvtsi2sdl	%r10d, %xmm1
	comisd	%xmm1, %xmm0
	jbe	.L47
	cvttsd2sil	%xmm0, %r10d
	movl	%ebx, %r9d
.L47:
	incq	%rbx
	cmpq	$10, %rbx
	jne	.L49
	cmpl	%r9d, (%r14,%r15,4)
	jne	.L50
	incl	%ebp
.L50:
	incq	%r15
	cmpq	$64, %r15
	jne	.L51
	cvtsi2ssl	%ebp, %xmm0
	movl	$2, %edi
	leaq	.LC15(%rip), %rsi
	movb	$1, %al
	mulss	.LC14(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	1096(%rsp), %rax
	subq	%fs:40, %rax
	je	.L52
	call	__stack_chk_fail@PLT
.L52:
	addq	$1112, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.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
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC14:
	.long	1015021568
	.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>

typedef struct NET_T {
  int nb_layers;
  int* size0;//size of output
  int* size1;//size of input
  double** layers;
  double** biases;
} net_t;

typedef struct IMG_T{
  int l;
  int ll;
  double* pixels;
} img_t;

net_t load_coeffs(char* file_address){
  FILE* f = fopen(file_address, "r");
  //printf("Opened\n");
  
  net_t network;
  int current_layer;
  int size0, size1;

  char garbage;
  fscanf(f, "%c:", &garbage);
  fscanf(f, "%d", &(network.nb_layers));

  double** n = (double**) malloc(network.nb_layers*sizeof(double*));
  int* s0 = (int*) malloc(network.nb_layers*sizeof(int));
  int* s1 = (int*) malloc(network.nb_layers*sizeof(int));
  double** b = (double**) malloc(network.nb_layers*sizeof(double*));
  network.layers = n;
  network.biases = b;
  network.size0 = s0;
  network.size1 = s1;
  //printf("Entering loop, nb_layers:%d\n", network.nb_layers);
  int old_layer =-1;
  while(!feof(f)){
    fscanf(f, " %c", &garbage); //"L"
    fscanf(f, " %d", &current_layer);
    if(current_layer == old_layer)
      break;
    old_layer=current_layer;
    fscanf(f, " %c", &garbage); // ":"
    fscanf(f, " %d", &size0);
    s0[current_layer] = size0;
    fscanf(f, " %d", &size1);
    s1[current_layer] = size1;
    //printf("Current Layer %d, size0 = %d, size1 = %d\n", current_layer, size0, size1);
    double* tab = (double*) malloc(size0 * size1 * sizeof(double));
    network.layers[current_layer] = tab;
    for(int i = 0; i < size0*size1; i++){
      fscanf(f, "%lf", &(tab[i]));
      //printf("%lf",tab[i]);
    }

    fscanf(f, " %c", &garbage); //"L"
    fscanf(f, " %d", &current_layer);
    fscanf(f, " %c", &garbage); // ":"
    fscanf(f, " %d", &size0);
    //printf("Current Bias %d, size0 = %d\n", current_layer, size0);
    double* tab2 = (double*) malloc(size0 * sizeof(double));
    network.biases[current_layer] = tab2;
    for(int i = 0; i < size0; i++){
      fscanf(f, " %lf", &(tab2[i]));
    }

  }
  fclose(f);
  return network;
}


img_t* load_image(FILE* f){
  img_t* image = (img_t*)malloc(sizeof(img_t));
  image->l = 28;
  image->ll = 28;
  double* img = (double*) malloc(image->l*image->ll*sizeof(double));
  image->pixels = img;
  char garbage;
  fscanf(f, " %c", &garbage);
  for(int i=0; i<image->l*image->ll; i++){
    fscanf(f, " %lf", &(img[i]));
  }
  return image;
}




double relu(double in){
  if(in > 0)
    return in;
  return 0;
}

double* forward(net_t net, img_t img){
  double* in, *out;
  in = (double*)malloc(net.size1[0]*sizeof(double));
  for(int i = 0; i<net.size1[0]; i++){
    in[i]= img.pixels[i];
  //printf("in[%d]=%lf\n", i, in[i]);
  }
  //for(int i=0;i<28;i++)
  //  for(int j =0; j<28; j++)
  //    in[i*8+j] = img.pixels[j*8+i];
  
  for(int l = 0; l <net.nb_layers; l++){
    int size_o = net.size0[l];
    int size_i = net.size1[l];
    out = (double*) malloc(size_o*sizeof(double));
    for(int ligne = 0; ligne < size_o; ligne++){
      out[ligne] = 0;
      for(int col = 0; col < size_i; col++){
	//printf("net.layers[l][ligne+col*]=%lf\n",net.layers[l][ligne+col*size_o]);
	out[ligne]+=in[col]*net.layers[l][ligne*size_i+col];
      }
      out[ligne] = relu(out[ligne]+net.biases[l][ligne]);
    }
    free(in);
    in = out;
   
  }
  return in;
}


void print_image(img_t* im){
  for(int i = 0; i<28*28;i++){
    printf( "%lf ",im->pixels[i]);
  }
  printf("\n\n");
}


int main(){
  char address[256] = "test.txt";
  net_t test = load_coeffs(address);
  char garbage;
  int res[64];

  printf("Reseau ok\n");
  
  FILE* f = fopen("images3.txt", "r");
  img_t* images[64];

  for(int i=0; i<64; i++){
    images[i]=load_image(f);
    //print_image(images[i]);
  }
  printf("Images chargees\n");
  fscanf(f, " %c", &garbage);
  for(int i=0; i<64; i++){
    fscanf(f, "%d", &res[i]);
  }
  
  double* result ;
  int max =-1,i_max=-1;
  int found = 0;
  for(int k =0; k<64; k++){
    result = forward(test, *images[k]);
    max=-1;
    i_max=-1;
    for(int i =0; i < 10; i++){
      printf("proba %d: %lf\n", i, result[i]);
      if(result[i]>max){
	i_max=i;
	max=result[i];
      }
    }
    if(i_max == res[k]){
      found+=1;
    }
  }

  printf("Percentage = %lf\n", (float)found/64);
  // printf("Expected: %d\n", res[0]);
  free(result);
  
  
  return 0;
}

	.text
	.file	"classifier.hip"
	.globl	_Z11load_coeffsPc               # -- Begin function _Z11load_coeffsPc
	.type	_Z11load_coeffsPc,@function
_Z11load_coeffsPc:                      # @_Z11load_coeffsPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rax
	movq	%rdi, %rbx
	movl	$.L.str, %esi
	movq	%rax, %rdi
	callq	fopen
	movq	%rax, %r14
	leaq	3(%rsp), %rdx
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.2, %esi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	(%rbx), %r12
	leaq	(,%r12,8), %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %rbp
	shlq	$2, %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%r13, %rdi
	callq	malloc
	movq	%rbp, 24(%rbx)
	movq	%rax, 32(%rbx)
	movq	%r15, 32(%rsp)                  # 8-byte Spill
	movq	%r15, 8(%rbx)
	movq	%r12, 24(%rsp)                  # 8-byte Spill
	movq	%rbx, 16(%rsp)                  # 8-byte Spill
	movq	%r12, 16(%rbx)
	movq	%r14, %rdi
	callq	feof
	testl	%eax, %eax
	jne	.LBB0_10
# %bb.1:                                # %.lr.ph42.preheader
	movl	$-1, %r15d
	leaq	3(%rsp), %r13
	leaq	8(%rsp), %rbx
.LBB0_3:                                # %.lr.ph42
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_6 Depth 2
                                        #     Child Loop BB0_9 Depth 2
	movl	%r15d, %ebp
	movl	$.L.str.3, %esi
	movq	%r14, %rdi
	movq	%r13, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	8(%rsp), %r15d
	cmpl	%ebp, %r15d
	je	.LBB0_10
# %bb.4:                                #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.3, %esi
	movq	%r14, %rdi
	movq	%r13, %rbx
	movq	%r13, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	leaq	4(%rsp), %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	4(%rsp), %eax
	movslq	8(%rsp), %rcx
	movq	32(%rsp), %rdx                  # 8-byte Reload
	movl	%eax, (%rdx,%rcx,4)
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	leaq	12(%rsp), %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	12(%rsp), %rax
	movslq	8(%rsp), %r12
	movq	24(%rsp), %rcx                  # 8-byte Reload
	movl	%eax, (%rcx,%r12,4)
	movslq	4(%rsp), %r13
	imulq	%rax, %r13
	movq	%r13, %rdi
	shlq	$3, %rdi
	callq	malloc
	movq	%rax, %rbp
	movq	16(%rsp), %rax                  # 8-byte Reload
	movq	24(%rax), %rax
	movq	%rbp, (%rax,%r12,8)
	testl	%r13d, %r13d
	jle	.LBB0_7
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB0_3 Depth=1
	xorl	%r12d, %r12d
.LBB0_6:                                # %.lr.ph
                                        #   Parent Loop BB0_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	incq	%r12
	movslq	4(%rsp), %rax
	movslq	12(%rsp), %rcx
	imulq	%rax, %rcx
	addq	$8, %rbp
	cmpq	%rcx, %r12
	jl	.LBB0_6
.LBB0_7:                                # %._crit_edge
                                        #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.3, %esi
	movq	%r14, %rdi
	movq	%rbx, %r13
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.3, %esi
	movq	%r14, %rdi
	movq	%r13, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	leaq	4(%rsp), %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	4(%rsp), %r12
	leaq	(,%r12,8), %rdi
	callq	malloc
	movq	%rax, %rbp
	movq	16(%rsp), %rax                  # 8-byte Reload
	movq	32(%rax), %rax
	movslq	8(%rsp), %rcx
	movq	%rbp, (%rax,%rcx,8)
	testq	%r12, %r12
	jle	.LBB0_2
# %bb.8:                                # %.lr.ph38.preheader
                                        #   in Loop: Header=BB0_3 Depth=1
	xorl	%r12d, %r12d
.LBB0_9:                                # %.lr.ph38
                                        #   Parent Loop BB0_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$.L.str.6, %esi
	movq	%r14, %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	incq	%r12
	movslq	4(%rsp), %rax
	addq	$8, %rbp
	cmpq	%rax, %r12
	jl	.LBB0_9
.LBB0_2:                                # %.loopexit
                                        #   in Loop: Header=BB0_3 Depth=1
	movq	%r14, %rdi
	callq	feof
	testl	%eax, %eax
	je	.LBB0_3
.LBB0_10:                               # %._crit_edge43
	movq	%r14, %rdi
	callq	fclose
	movq	16(%rsp), %rax                  # 8-byte Reload
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z11load_coeffsPc, .Lfunc_end0-_Z11load_coeffsPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z10load_imageP8_IO_FILE        # -- Begin function _Z10load_imageP8_IO_FILE
	.type	_Z10load_imageP8_IO_FILE,@function
_Z10load_imageP8_IO_FILE:               # @_Z10load_imageP8_IO_FILE
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	$16, %edi
	callq	malloc
	movq	%rax, %r14
	movabsq	$120259084316, %rax             # imm = 0x1C0000001C
	movq	%rax, (%r14)
	movl	$6272, %edi                     # imm = 0x1880
	callq	malloc
	movq	%rax, %r15
	movq	%rax, 8(%r14)
	leaq	7(%rsp), %rdx
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	xorl	%r12d, %r12d
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	leaq	(%r15,%r12), %rdx
	movl	$.L.str.6, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$8, %r12
	cmpq	$6272, %r12                     # imm = 0x1880
	jne	.LBB1_1
# %bb.2:
	movq	%r14, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z10load_imageP8_IO_FILE, .Lfunc_end1-_Z10load_imageP8_IO_FILE
	.cfi_endproc
                                        # -- End function
	.globl	_Z4relud                        # -- Begin function _Z4relud
	.type	_Z4relud,@function
_Z4relud:                               # @_Z4relud
	.cfi_startproc
# %bb.0:
	xorpd	%xmm1, %xmm1
	maxsd	%xmm1, %xmm0
	retq
.Lfunc_end2:
	.size	_Z4relud, .Lfunc_end2-_Z4relud
	.cfi_endproc
                                        # -- End function
	.globl	_Z7forward5NET_T5IMG_T          # -- Begin function _Z7forward5NET_T5IMG_T
	.type	_Z7forward5NET_T5IMG_T,@function
_Z7forward5NET_T5IMG_T:                 # @_Z7forward5NET_T5IMG_T
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r14
	leaq	96(%rsp), %r15
	movq	16(%r15), %rax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movslq	(%rax), %r12
	leaq	(,%r12,8), %rdi
	callq	malloc
	movq	%rax, %rbx
	testq	%r12, %r12
	jle	.LBB3_2
# %bb.1:                                # %.lr.ph.preheader
	movl	%r12d, %edx
	shlq	$3, %rdx
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	memcpy@PLT
.LBB3_2:                                # %.preheader
	movl	(%r15), %eax
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	testl	%eax, %eax
	jle	.LBB3_3
# %bb.5:                                # %.lr.ph48
	movq	8(%r15), %rax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movq	24(%r15), %rbp
	movq	32(%r15), %rax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	xorl	%r15d, %r15d
.LBB3_6:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_8 Depth 2
                                        #       Child Loop BB3_13 Depth 3
	movq	16(%rsp), %rax                  # 8-byte Reload
	movslq	(%rax,%r15,4), %r12
	movq	32(%rsp), %rax                  # 8-byte Reload
	movl	(%rax,%r15,4), %r13d
	leaq	(,%r12,8), %rdi
	callq	malloc
	movq	%rax, %r14
	testq	%r12, %r12
	xorpd	%xmm2, %xmm2
	jle	.LBB3_11
# %bb.7:                                # %.lr.ph44
                                        #   in Loop: Header=BB3_6 Depth=1
	movl	%r12d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	movq	(%rcx,%r15,8), %rcx
	xorl	%edx, %edx
	xorl	%esi, %esi
.LBB3_8:                                #   Parent Loop BB3_6 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_13 Depth 3
	movq	$0, (%r14,%rsi,8)
	testl	%r13d, %r13d
	jle	.LBB3_9
# %bb.12:                               # %.lr.ph41
                                        #   in Loop: Header=BB3_8 Depth=2
	movl	%edx, %edi
	shlq	$3, %rdi
	addq	(%rbp,%r15,8), %rdi
	xorpd	%xmm0, %xmm0
	xorl	%r8d, %r8d
.LBB3_13:                               #   Parent Loop BB3_6 Depth=1
                                        #     Parent Loop BB3_8 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rbx,%r8,8), %xmm1             # xmm1 = mem[0],zero
	mulsd	(%rdi,%r8,8), %xmm1
	addsd	%xmm1, %xmm0
	movsd	%xmm0, (%r14,%rsi,8)
	incq	%r8
	cmpq	%r8, %r13
	jne	.LBB3_13
	jmp	.LBB3_10
.LBB3_9:                                #   in Loop: Header=BB3_8 Depth=2
	xorpd	%xmm0, %xmm0
.LBB3_10:                               # %._crit_edge
                                        #   in Loop: Header=BB3_8 Depth=2
	addsd	(%rcx,%rsi,8), %xmm0
	maxsd	%xmm2, %xmm0
	movsd	%xmm0, (%r14,%rsi,8)
	incq	%rsi
	addl	%r13d, %edx
	cmpq	%rax, %rsi
	jne	.LBB3_8
.LBB3_11:                               # %._crit_edge45
                                        #   in Loop: Header=BB3_6 Depth=1
	movq	%rbx, %rdi
	callq	free
	incq	%r15
	movq	%r14, %rbx
	cmpq	24(%rsp), %r15                  # 8-byte Folded Reload
	jne	.LBB3_6
	jmp	.LBB3_4
.LBB3_3:
	movq	%rbx, %r14
.LBB3_4:                                # %._crit_edge49
	movq	%r14, %rax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z7forward5NET_T5IMG_T, .Lfunc_end3-_Z7forward5NET_T5IMG_T
	.cfi_endproc
                                        # -- End function
	.globl	_Z11print_imageP5IMG_T          # -- Begin function _Z11print_imageP5IMG_T
	.type	_Z11print_imageP5IMG_T,@function
_Z11print_imageP5IMG_T:                 # @_Z11print_imageP5IMG_T
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.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 %r14, -16
	movq	%rdi, %rbx
	xorl	%r14d, %r14d
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	movq	8(%rbx), %rax
	movsd	(%rax,%r14,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	incq	%r14
	cmpq	$784, %r14                      # imm = 0x310
	jne	.LBB4_1
# %bb.2:
	movl	$.Lstr, %edi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end4:
	.size	_Z11print_imageP5IMG_T, .Lfunc_end4-_Z11print_imageP5IMG_T
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI5_0:
	.long	0x3c800000                      # float 0.015625
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$872, %rsp                      # imm = 0x368
	.cfi_def_cfa_offset 928
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	56(%rsp), %rdi
	movl	$.L__const.main.address, %esi
	callq	_Z11load_coeffsPc
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.L.str.10, %edi
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %rbx
	xorl	%r14d, %r14d
.LBB5_1:                                # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	callq	_Z10load_imageP8_IO_FILE
	movq	%rax, 352(%rsp,%r14,8)
	incq	%r14
	cmpq	$64, %r14
	jne	.LBB5_1
# %bb.2:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	leaq	47(%rsp), %rdx
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	xorl	%r14d, %r14d
.LBB5_3:                                # =>This Inner Loop Header: Depth=1
	leaq	(%rsp,%r14), %rdx
	addq	$96, %rdx
	movl	$.L.str.2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %r14
	cmpq	$256, %r14                      # imm = 0x100
	jne	.LBB5_3
# %bb.4:                                # %.preheader.preheader
	xorl	%r15d, %r15d
	xorl	%ebp, %ebp
.LBB5_5:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_6 Depth 2
	movq	352(%rsp,%r15,8), %rax
	movq	8(%rax), %rsi
	movq	88(%rsp), %rax
	movq	%rax, 32(%rsp)
	movups	56(%rsp), %xmm0
	movups	72(%rsp), %xmm1
	movups	%xmm1, 16(%rsp)
	movups	%xmm0, (%rsp)
	callq	_Z7forward5NET_T5IMG_T
	movq	%rax, %rbx
	movl	$-1, %r12d
	xorl	%r14d, %r14d
	movl	$-1, %r13d
.LBB5_6:                                #   Parent Loop BB5_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rbx,%r14,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, 48(%rsp)                 # 8-byte Spill
	movl	$.L.str.12, %edi
	movl	%r14d, %esi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r13d, %xmm0
	movsd	48(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	ucomisd	%xmm0, %xmm1
	cvttsd2si	%xmm1, %eax
	cmoval	%eax, %r13d
	cmoval	%r14d, %r12d
	incq	%r14
	cmpq	$10, %r14
	jne	.LBB5_6
# %bb.7:                                #   in Loop: Header=BB5_5 Depth=1
	xorl	%eax, %eax
	cmpl	96(%rsp,%r15,4), %r12d
	sete	%al
	addl	%eax, %ebp
	incq	%r15
	cmpq	$64, %r15
	jne	.LBB5_5
# %bb.8:
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebp, %xmm0
	mulss	.LCPI5_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.13, %edi
	movb	$1, %al
	callq	printf
	movq	%rbx, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$872, %rsp                      # imm = 0x368
	.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_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"r"
	.size	.L.str, 2

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%d"
	.size	.L.str.2, 3

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	" %c"
	.size	.L.str.3, 4

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	" %d"
	.size	.L.str.4, 4

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%lf"
	.size	.L.str.5, 4

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	" %lf"
	.size	.L.str.6, 5

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%lf "
	.size	.L.str.7, 5

	.type	.L__const.main.address,@object  # @__const.main.address
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
.L__const.main.address:
	.asciz	"test.txt\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
	.size	.L__const.main.address, 256

	.type	.L.str.10,@object               # @.str.10
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.10:
	.asciz	"images3.txt"
	.size	.L.str.10, 12

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"proba %d: %lf\n"
	.size	.L.str.12, 15

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Percentage = %lf\n"
	.size	.L.str.13, 18

	.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	"\n"
	.size	.Lstr, 2

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Reseau ok"
	.size	.Lstr.1, 10

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Images chargees"
	.size	.Lstr.2, 16

	.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
