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

//Number of elements of the inpu layers, that correspond to the number of pixels of a picture
#define PIXELS 3073
//Number of elements of the first hidden layer
#define HIDDEN_LAYER_1 2000
//Number of elements of the second hidden layer
#define HIDDEN_LAYER_2 450
//Number of elements of the output layer
#define OUTPUT_LAYER 10
//Learning rate of the algorithm
#define LEARNING_RATE 0.01
//Numbers of elements to use for training
#define ELEMENTS 1000

/* 
 * Function that given a vector and its size, print it
 * In: 
 * f: vector of doubles to be printed
 * N: size of the vector
 */
void print_vector(double *f, int N){
	//Move in all vector to print each value
	for (int i =0; i < N; ++i)
		printf("%f\n",f[i]);
}

/*
 * Function that given the value of the previous layer of a neural network, and its transition matrix
 * to the new layer, calculates the net value of the layer
 * In: 
 * input: vector that represents the previous layer of the layer to calculate
 * matrix: transition matrix with the weigths of the neural network
 * result: vector to store the results. It represents the layer to be calculated
 * input_size: size of the previous layer
 * hidden_size: size of the calculated layer
 *
 */
void get_layer(double *input, double *matrix, double *result,int input_size, int hidden_size){
	//Move thorugh every element of the layer
	for (int i = 0; i<hidden_size; ++i){
		//Init the neuron value in 0
		result[i] = 0.0;
		//Multiply each value of the previous neuron times its weigth and store it in result
		for (int j = 0; j < input_size; ++j){
			result[i] += input[j] * matrix[j*hidden_size+i];
		}
	}
}

/*
 * Function that apply the sigmoid function to every element of a vector
 * In:
 * double: vector to apply the signmoid function to every element
 * N: size of the vector
 */
void sigmoid(double *f, int N){
	//Move through all elements of the vector
	for (int i =0; i < N; ++i)
		//Apply the sigmoid function to every element
		//Sigmoid used: f(x) = 1 / (1 + e^(-x))
		f[i] = 1.0 / (1.0 + exp(-f[i]));
}

/*
 * Function that normalize the input, so all the values are equally important. Normalize is the process
 * to transform every element of a vector to its correspondent value beetwen 0 and 1
 * In:
 * c: vector with the numbers between 0 and 255, each one which corresponds to a pixel of the input image
 * f: vector so save the normalized vector
 * N: size of the vectors
 */
void process_input(unsigned char *c, double *f, int N){
	//Move through all elements of the vecotr
	for (int i =0; i < N; ++i){
		//Normalize x cosist of (x - Min)/ (Max-Min), in pixels Max is 255 and Min is 1
		f[i] = (c[i]-1)/254.0;
	}
		
}

/*
 * Function that returns the index corresponding to the maximum element of an array
 * In:
 * f: vector of values
 * N: size of vector
 * Out:
 * int corresponding to the index of the maximum value
 */
int max_index(double *f, int N){
	//The max is the first element
	int max_index = 0;
	for (int i = 1; i < N; ++ i){
		//If there is a new max, then substitute it
		if (f[i] > f[max_index]){
			max_index = i;
		}
	}
	//Return the index of the max element
	return max_index;
}

/*
 * Function that calculate the error of the neural network
 * In:
 * f: output vector of the neural network
 * output: expected value
 * N: size of the vector
 * Out:
 * double corresponding to the calculated error of the NN
 */
double error(double *f, int output, int N) {
	double *output_array = (double *) malloc(N * sizeof(double));
	//Init the expected answer in 0
	for (int i = 0; i < N; ++i)
		output_array[i] = 0.0;
	//Mark the expected answer 1
	output_array[output] = 1.0;

	//Init the error in 0
	double error = 0.0;
	//Calulate the total error, the rror is defined as
	//(1/2)*SUM(di - oi)^2 where di is expected value, oi is calculated value
	for (int i = 0; i < N; ++i)
		error += (output_array[i] - f[i]) * (output_array[i] - f[i]);
	return 0.5*error;
}

/*
 * Function that calculate the error of the output layers
 * In:
 * f: value of the output neurons
 * output: expected value
 * N: size of the vector
 * error_array: vector with the calculated error of every neuron
 *
 */
void error_output(double *f, int output, int N, double *error_array){
	double *output_array = (double *) malloc(N * sizeof(double));
	//Init the expected answer in 0
	for (int i = 0; i < N; ++i)
		output_array[i] = 0.0;
	//Mark the expected answer 1
	output_array[output] = 1.0;

	//Get the error for every neuron. The error in the output layer is defined as Si = (di - oi)*oi*(1-oi)
	for (int i = 0; i < N; ++i){
		error_array[i] = (output_array[i] - f[i])*f[i]*(1-f[i]);
	}
}

/* Function that calculates the error of the hidden layers
 * In: 
 * f: hidden layer calculated values
 * error_array: error vector, to save the error of every neuron in the hidden layer
 * next_layer_error: error vector of the next layer, neccessary to calculate the error of a hidden layer
 * layer_size: size of the hidden layer
 * next_size: size of the next layer
 * transition_matrix: transition matrix to propagate values from hidden to next layer 
 */
void error_hidden_layer(double *f, double* error_array, double *next_layer_error, int layer_size, int next_size, double *transition_matrix){

	//Calculate error of every neuron in a hidden layer
	//The error in a hidden layer is defined as Si = oi * (1 - oi) * SUM(Wij * Sj) where Sj is the error from next
	for (int i = 0; i < layer_size; ++i){
		//Inicial value of the sumatory
		double product = 0.0;
		for (int j = 0; j < next_size; ++j){
			//Add Wij * Sj to acumulator
			product += transition_matrix[i*next_size+j]*next_layer_error[j];
		}
		//Get the final product
		error_array[i] = f[i]*(1-f[i])*product;
	}

}

/*
 * Function that calculates the variation of weigths of a neural network
 * In:
 * error_vector: error vector of the layer
 * gradient: variance of the weights for every element
 * layer: value of the elements of the layer
 * N: rows of the transition matrix
 * M: columns ot the transition matrix
 *
 */
void calculate_error(double *error_vector, double* gradient, double *layer, int N, int M){
	//Iterate over the matrix
	for (int i =0; i<N; ++i){
		for (int j = 0; j<M; ++j){
			//The variance of the weigth is alpha * Sj * Oi
			gradient[i*M+j] = LEARNING_RATE * error_vector[j] * layer[i];
		}
	}

}

/*
 * Function that sums two matrix and store it directly in the first matrix
 * In:
 * transition: first matrix
 * gradient: second matrix
 * N: rows of the matrix
 * M: columns of the matrix
 */
void sum_matrix(double *transition, double *gradient, int N, int M){
	//Iterate over all the matrix 
	for (int i = 0; i < N; ++i){
		for (int j = 0; j < M; ++j){
			//Change the weight of every value of the transition matrix
			transition[i*M+j] = transition[i*M+j] + gradient[i*M+j];
		}
	}
}

/*
 * Function that reads a file, stores every vector of it, and then apply backpropagation
 * In:
 * file: name of the file with the data
 * buffer: vector where every pixel will be stored
 * transition_matrix_1: transition vector from input layer to hidden layer 1
 * transition_matrix_2: transition vector from hidden layer 1 to hidden layer 2
 * transition_matrix_3: transition vector from hidden layer 2 to output layer
 * elements: number of elements to use for training
 */
void read_file(char *file, unsigned char* buffer,double *transition_matrix_1,double *transition_matrix_2, double *transition_matrix_3, int elements){
	//Read the file that is in binary mode
	FILE *f;
	f = fopen(file, "rb");
	//Variable for the expected output
	unsigned char expected_output;
	int i = 0;
	//Init the total time to get the average of every classification
	float total_time = 0.0;

	//While there still elements on the file, and i is less than elements number cycloe
	//Read PIXELS elements, because every pixel is represented by a byte, is enough to tell the reader to read exactly PIXELS bytes
	while(1 == fread(buffer,PIXELS,1,f) && i < elements){

		//Start taking the time
		float tiempo1;
		cudaEvent_t inicio1, fin1;

		cudaEventCreate(&inicio1); // Se inicializan
   		cudaEventCreate(&fin1);
   		cudaEventRecord( inicio1, 0 );

   		//The first value of the vector is the expected time
		expected_output = buffer[0];
		//After the expected output is saved, it can be substituted by the bias
		buffer[0] = 1;
		//Init the layers of the network
		double *hidden_layer_1 = (double*)malloc((HIDDEN_LAYER_1+1)*sizeof(double));
		double *hidden_layer_2 = (double*)malloc((HIDDEN_LAYER_2+1)*sizeof(double));
		double *output_layer = (double*)malloc(OUTPUT_LAYER*sizeof(double));

		//Normalize the data
		double *input = (double*)malloc(PIXELS*sizeof(double));
		process_input(buffer,input,PIXELS);

		//Forward information from input layer to hidden layer 1
		get_layer(input,transition_matrix_1,hidden_layer_1,PIXELS,HIDDEN_LAYER_1);
		//Apply signmoid to hidden layer 1
		sigmoid(hidden_layer_1,HIDDEN_LAYER_1+1);
		//Assign the bias
		hidden_layer_1[HIDDEN_LAYER_1] = 1;

		//Forward information from hidden layer 1 to hidden layer 2
		get_layer(hidden_layer_1,transition_matrix_2,hidden_layer_2,HIDDEN_LAYER_1+1,HIDDEN_LAYER_2);
		//Apply signmoid to hidden layer 2
		sigmoid(hidden_layer_2,HIDDEN_LAYER_2+1);
		//Assign the bias
		hidden_layer_2[HIDDEN_LAYER_2] = 1;

		//Forward information from hidden layer 2 to output layer
		get_layer(hidden_layer_2,transition_matrix_3,output_layer,HIDDEN_LAYER_2+1,OUTPUT_LAYER);
		//Apply signmoid to output layer
		sigmoid(output_layer,OUTPUT_LAYER);

		//Get the error of the output
		double *errors_array = (double*)malloc(OUTPUT_LAYER* sizeof(double));
		error_output(output_layer,expected_output,OUTPUT_LAYER,errors_array);

		//Get the weight update for transision matrix 3
		double *transition_matrix_3_gradient = (double*)malloc((HIDDEN_LAYER_2+1)*OUTPUT_LAYER*sizeof(double));
		calculate_error(errors_array,transition_matrix_3_gradient,hidden_layer_2,HIDDEN_LAYER_2+1,OUTPUT_LAYER);

		//Get the weight update for transision matrix 2
		double *hidden_layer_array_2 = (double*)malloc((HIDDEN_LAYER_2+1)* sizeof(double));
		error_hidden_layer(hidden_layer_2,hidden_layer_array_2,errors_array,OUTPUT_LAYER,HIDDEN_LAYER_2+1,transition_matrix_3);
		double *transition_matrix_2_gradient = (double*)malloc((HIDDEN_LAYER_1+1)*HIDDEN_LAYER_2*sizeof(double));
		calculate_error(hidden_layer_array_2,transition_matrix_2_gradient,hidden_layer_1,HIDDEN_LAYER_1+1,HIDDEN_LAYER_2);

		//Get the weight update for transision matrix 1
		double *hidden_layer_array_1 = (double*)malloc((HIDDEN_LAYER_1+1)* sizeof(double));
		error_hidden_layer(hidden_layer_1,hidden_layer_array_1,hidden_layer_array_2,HIDDEN_LAYER_2,HIDDEN_LAYER_1+1,transition_matrix_2);
		double *transition_matrix_1_gradient = (double*)malloc(PIXELS*HIDDEN_LAYER_1*sizeof(double));
		calculate_error(hidden_layer_array_1,transition_matrix_1_gradient,input,PIXELS,HIDDEN_LAYER_1);

		//Update the value of the transitions matrix once all have been calculated
		sum_matrix(transition_matrix_1,transition_matrix_1_gradient,PIXELS,HIDDEN_LAYER_1);
		sum_matrix(transition_matrix_2,transition_matrix_2_gradient,HIDDEN_LAYER_1+1,HIDDEN_LAYER_2);
		sum_matrix(transition_matrix_3,transition_matrix_3_gradient,HIDDEN_LAYER_2+1,OUTPUT_LAYER);

		//Siguiente elemento 
		++i;

		//Free the information not required for the next iteration
		free(hidden_layer_1);
		free(hidden_layer_2);
		free(output_layer);
		free(input);
		free(errors_array);

		//Record the finish moment
		cudaEventRecord( fin1, 0); 
   		cudaEventSynchronize( fin1 );
   		cudaEventElapsedTime( &tiempo1, inicio1, fin1 );

   		//Add the time to the total
   		total_time += tiempo1;
		
	}

	//Take the average time
	total_time /= elements;
	printf ("Tiempo promedio por clasificacion: %f\n", total_time);
}

/*
 * Function that randomly initialize all values off the transiction matrix
 * In:
 * matrix: transition matrix of the neural network
 * N: rows of the matrix
 * M: columns of the matrix
 */
void init_layer(double *matrix, int N, int M){
	//Iterate over the matrix
	for (int i =0; i < N; ++ i){
		for (int j = 0; j < M; ++j){
			//Random number to see if its negative or positive
		    int sign = rand() % 2;
		    //Random number between 0 and 1
		    if (sign == 0)
		    	matrix[i*M+j] = (rand() % 1000000) / 1000000.0;
			else
				matrix[i*M+j] = - ((rand() % 1000000) / 1000000.0);
		}
	}
		
}

/*
 * Function that prints the value of the transition matrix
 * In:
 * matrix: transition matrix
 * N: rows of the matrix
 * M: columns of the matrix
 */
void print_layer(double *matrix, int N, int M){
	//Iterate over the matrix and print
	for (int i =0; i < N; ++ i){
		for (int j = 0; j < M; ++j)
			printf("%f ",matrix[i*M+j]);
		printf("\n");
	}		
}

int main(int argc, char *argv[]){

	//Init the random
	srand(time(NULL));

	//Review if the arguments
	if ( argc != 2 ) {
        /* We print argv[0] assuming it is the program name */
        printf( "Error se debe ejecutar: %s <N>\n", argv[0] );
        exit(0);
    }

    //Transform the argv to int
    int elements = atoi(argv[1]);

    printf("Se va a entrenar con %d elementos\n",elements);
	
	//Create the space for the transition matrix
	double *transition_matrix_1 = (double*)malloc(PIXELS*HIDDEN_LAYER_1*sizeof(double));
	double *transition_matrix_2 = (double*)malloc((HIDDEN_LAYER_1+1)*HIDDEN_LAYER_2*sizeof(double));
	double *transition_matrix_3 = (double*)malloc((HIDDEN_LAYER_2+1)*OUTPUT_LAYER*sizeof(double));

	//Initialize the values of the matrix
	init_layer(transition_matrix_1,PIXELS,HIDDEN_LAYER_1);
	init_layer(transition_matrix_2,HIDDEN_LAYER_1+1,HIDDEN_LAYER_2);
	init_layer(transition_matrix_3,HIDDEN_LAYER_2+1,OUTPUT_LAYER);

	//Start the time
	float tiempo1;
	cudaEvent_t inicio1, fin1;

	unsigned char *buffer = (unsigned char*)malloc(PIXELS*sizeof(unsigned char));

	//Start getting the time
	cudaEventCreate(&inicio1); // Se inicializan
   	cudaEventCreate(&fin1);
   	cudaEventRecord( inicio1, 0 );

   	//Start the training
	read_file("data_batch_1.bin",buffer,transition_matrix_1,transition_matrix_2,transition_matrix_3,elements);

	//Finish the time
	cudaEventRecord( fin1, 0); // Se toma el tiempo final.
   	cudaEventSynchronize( fin1 ); // Se sincroniza
   	cudaEventElapsedTime( &tiempo1, inicio1, fin1 );

   	//Print the time
   	printf("Tiempo total del programa: %f ms\n", tiempo1);

}


	.file	"tmpxft_00244cea_00000000-6_NeuralNetwork.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2043:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2043:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%f\n"
	.text
	.globl	_Z12print_vectorPdi
	.type	_Z12print_vectorPdi, @function
_Z12print_vectorPdi:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rdx
	.cfi_def_cfa_offset 48
.L3:
	cmpl	%ebx, %ebp
	jle	.L7
	movsd	(%r12,%rbx,8), %xmm0
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L3
.L7:
	popq	%rax
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12print_vectorPdi, .-_Z12print_vectorPdi
	.globl	_Z9get_layerPdS_S_ii
	.type	_Z9get_layerPdS_S_ii, @function
_Z9get_layerPdS_S_ii:
.LFB2028:
	.cfi_startproc
	endbr64
	movq	%rdi, %r9
	movslq	%r8d, %rdi
	movq	%rsi, %r10
	xorl	%eax, %eax
	salq	$3, %rdi
.L9:
	cmpl	%eax, %r8d
	jle	.L13
	leaq	(%r10,%rax,8), %r11
	xorl	%esi, %esi
	xorps	%xmm0, %xmm0
.L10:
	movsd	%xmm0, (%rdx,%rax,8)
	cmpl	%esi, %ecx
	jle	.L14
	movsd	(%r9,%rsi,8), %xmm1
	mulsd	(%r11), %xmm1
	incq	%rsi
	addq	%rdi, %r11
	addsd	%xmm1, %xmm0
	jmp	.L10
.L14:
	incq	%rax
	jmp	.L9
.L13:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9get_layerPdS_S_ii, .-_Z9get_layerPdS_S_ii
	.globl	_Z7sigmoidPdi
	.type	_Z7sigmoidPdi, @function
_Z7sigmoidPdi:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%esi, %r12d
	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
.L16:
	cmpl	%ebx, %r12d
	jle	.L19
	movsd	0(%rbp,%rbx,8), %xmm0
	xorps	.LC2(%rip), %xmm0
	call	exp@PLT
	movsd	.LC3(%rip), %xmm1
	addsd	%xmm1, %xmm0
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 0(%rbp,%rbx,8)
	incq	%rbx
	jmp	.L16
.L19:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z7sigmoidPdi, .-_Z7sigmoidPdi
	.globl	_Z13process_inputPhPdi
	.type	_Z13process_inputPhPdi, @function
_Z13process_inputPhPdi:
.LFB2030:
	.cfi_startproc
	endbr64
	movsd	.LC4(%rip), %xmm1
	xorl	%eax, %eax
.L21:
	cmpl	%eax, %edx
	jle	.L23
	movzbl	(%rdi,%rax), %ecx
	decl	%ecx
	cvtsi2sdl	%ecx, %xmm0
	divsd	%xmm1, %xmm0
	movsd	%xmm0, (%rsi,%rax,8)
	incq	%rax
	jmp	.L21
.L23:
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z13process_inputPhPdi, .-_Z13process_inputPhPdi
	.globl	_Z9max_indexPdi
	.type	_Z9max_indexPdi, @function
_Z9max_indexPdi:
.LFB2031:
	.cfi_startproc
	endbr64
	movl	$1, %eax
	xorl	%edx, %edx
.L25:
	cmpl	%eax, %esi
	jle	.L30
	movslq	%edx, %rcx
	movsd	(%rdi,%rax,8), %xmm0
	ucomisd	(%rdi,%rcx,8), %xmm0
	cmova	%eax, %edx
	incq	%rax
	jmp	.L25
.L30:
	movl	%edx, %eax
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z9max_indexPdi, .-_Z9max_indexPdi
	.globl	_Z5errorPdii
	.type	_Z5errorPdii, @function
_Z5errorPdii:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	movslq	%edx, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movslq	%esi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	salq	$3, %rdi
	call	malloc@PLT
	xorl	%edx, %edx
.L32:
	cmpl	%edx, %ebx
	jle	.L37
	movq	$0x000000000, (%rax,%rdx,8)
	incq	%rdx
	jmp	.L32
.L37:
	movq	.LC3(%rip), %rsi
	xorl	%ecx, %ecx
	xorps	%xmm0, %xmm0
	movq	%rsi, (%rax,%rbp,8)
.L34:
	cmpl	%ecx, %ebx
	jle	.L38
	movsd	(%rax,%rcx,8), %xmm1
	subsd	(%r12,%rcx,8), %xmm1
	incq	%rcx
	mulsd	%xmm1, %xmm1
	addsd	%xmm1, %xmm0
	jmp	.L34
.L38:
	mulsd	.LC5(%rip), %xmm0
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z5errorPdii, .-_Z5errorPdii
	.globl	_Z12error_outputPdiiS_
	.type	_Z12error_outputPdiiS_, @function
_Z12error_outputPdiiS_:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rcx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	movslq	%edx, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movslq	%esi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	salq	$3, %rdi
	pushq	%r8
	.cfi_def_cfa_offset 48
	call	malloc@PLT
	xorl	%edx, %edx
.L40:
	cmpl	%edx, %ebx
	jle	.L45
	movq	$0x000000000, (%rax,%rdx,8)
	incq	%rdx
	jmp	.L40
.L45:
	movsd	.LC3(%rip), %xmm2
	xorl	%edx, %edx
	movsd	%xmm2, (%rax,%rbp,8)
.L42:
	cmpl	%edx, %ebx
	jle	.L46
	movsd	(%r12,%rdx,8), %xmm1
	movsd	(%rax,%rdx,8), %xmm0
	movaps	%xmm2, %xmm3
	subsd	%xmm1, %xmm0
	subsd	%xmm1, %xmm3
	mulsd	%xmm1, %xmm0
	mulsd	%xmm3, %xmm0
	movsd	%xmm0, 0(%r13,%rdx,8)
	incq	%rdx
	jmp	.L42
.L46:
	popq	%rax
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z12error_outputPdiiS_, .-_Z12error_outputPdiiS_
	.globl	_Z18error_hidden_layerPdS_S_iiS_
	.type	_Z18error_hidden_layerPdS_S_iiS_, @function
_Z18error_hidden_layerPdS_S_iiS_:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	%rdx, %r10
	movl	%ecx, %r11d
	xorl	%edx, %edx
	movsd	.LC3(%rip), %xmm3
	xorl	%ecx, %ecx
	cmpl	%edx, %r11d
	jg	.L56
	ret
.L56:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
.L54:
	movslq	%ecx, %rax
	xorps	%xmm1, %xmm1
	leaq	(%r9,%rax,8), %rbx
	xorl	%eax, %eax
.L51:
	cmpl	%eax, %r8d
	jle	.L57
	movsd	(%rbx,%rax,8), %xmm0
	mulsd	(%r10,%rax,8), %xmm0
	incq	%rax
	addsd	%xmm0, %xmm1
	jmp	.L51
.L57:
	movsd	(%rdi,%rdx,8), %xmm2
	movaps	%xmm3, %xmm0
	addl	%r8d, %ecx
	subsd	%xmm2, %xmm0
	mulsd	%xmm2, %xmm0
	mulsd	%xmm1, %xmm0
	movsd	%xmm0, (%rsi,%rdx,8)
	incq	%rdx
	cmpl	%edx, %r11d
	jg	.L54
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z18error_hidden_layerPdS_S_iiS_, .-_Z18error_hidden_layerPdS_S_iiS_
	.globl	_Z15calculate_errorPdS_S_ii
	.type	_Z15calculate_errorPdS_S_ii, @function
_Z15calculate_errorPdS_S_ii:
.LFB2035:
	.cfi_startproc
	endbr64
	movsd	.LC6(%rip), %xmm1
	movq	%rdi, %r9
	movq	%rdx, %r10
	xorl	%edi, %edi
	xorl	%edx, %edx
.L59:
	cmpl	%edx, %ecx
	jle	.L58
	movslq	%edi, %rax
	leaq	(%rsi,%rax,8), %r11
	xorl	%eax, %eax
.L62:
	cmpl	%eax, %r8d
	jle	.L63
	movsd	(%r9,%rax,8), %xmm0
	mulsd	%xmm1, %xmm0
	mulsd	(%r10,%rdx,8), %xmm0
	movsd	%xmm0, (%r11,%rax,8)
	incq	%rax
	jmp	.L62
.L63:
	incq	%rdx
	addl	%r8d, %edi
	jmp	.L59
.L58:
	ret
	.cfi_endproc
.LFE2035:
	.size	_Z15calculate_errorPdS_S_ii, .-_Z15calculate_errorPdS_S_ii
	.globl	_Z10sum_matrixPdS_ii
	.type	_Z10sum_matrixPdS_ii, @function
_Z10sum_matrixPdS_ii:
.LFB2036:
	.cfi_startproc
	endbr64
	xorl	%r9d, %r9d
	xorl	%r10d, %r10d
.L65:
	cmpl	%edx, %r10d
	jge	.L64
	movslq	%r9d, %rax
	xorl	%r8d, %r8d
	salq	$3, %rax
.L68:
	cmpl	%ecx, %r8d
	jge	.L69
	movsd	(%rdi,%rax), %xmm0
	addsd	(%rsi,%rax), %xmm0
	incl	%r8d
	movsd	%xmm0, (%rdi,%rax)
	addq	$8, %rax
	jmp	.L68
.L69:
	incl	%r10d
	addl	%ecx, %r9d
	jmp	.L65
.L64:
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z10sum_matrixPdS_ii, .-_Z10sum_matrixPdS_ii
	.section	.rodata.str1.1
.LC8:
	.string	"rb"
.LC9:
	.string	"Tiempo promedio por clasificacion: %f\n"
	.text
	.globl	_Z9read_filePcPhPdS1_S1_i
	.type	_Z9read_filePcPhPdS1_S1_i, @function
_Z9read_filePcPhPdS1_S1_i:
.LFB2037:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%r9d, %r13d
	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
	leaq	.LC8(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdx, 48(%rsp)
	movq	%rcx, 32(%rsp)
	movq	%r8, 40(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	xorps	%xmm0, %xmm0
	movq	%rax, 80(%rsp)
.L72:
	movq	80(%rsp), %r8
	orq	$-1, %rsi
	movl	$1, %ecx
	movq	%rbp, %rdi
	movl	$3073, %edx
	movss	%xmm0, 8(%rsp)
	call	__fread_chk@PLT
	cmpl	%r13d, %r15d
	movss	8(%rsp), %xmm0
	jge	.L71
	decq	%rax
	jne	.L71
	leaq	104(%rsp), %rdi
	movss	%xmm0, 92(%rsp)
	incl	%r15d
	call	cudaEventCreate@PLT
	leaq	112(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	104(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movb	0(%rbp), %r12b
	movb	$1, 0(%rbp)
	movl	$16008, %edi
	call	malloc@PLT
	movl	$3608, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$80, %edi
	movq	%rax, %r14
	call	malloc@PLT
	movl	$24584, %edi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movl	$3073, %edx
	movq	%rbp, %rdi
	movl	$2000, %r8d
	movq	%rax, %rsi
	movq	%rax, 16(%rsp)
	call	_Z13process_inputPhPdi
	movq	48(%rsp), %rsi
	movq	16(%rsp), %rdi
	movq	%rbx, %rdx
	movl	$3073, %ecx
	call	_Z9get_layerPdS_S_ii
	movl	$2001, %esi
	movq	%rbx, %rdi
	call	_Z7sigmoidPdi
	movq	32(%rsp), %rsi
	movq	%r14, %rdx
	movq	%rbx, %rdi
	movq	.LC3(%rip), %rax
	movl	$450, %r8d
	movl	$2001, %ecx
	movq	%rax, 16000(%rbx)
	call	_Z9get_layerPdS_S_ii
	movl	$451, %esi
	movq	%r14, %rdi
	call	_Z7sigmoidPdi
	movq	.LC3(%rip), %rax
	movq	8(%rsp), %rdx
	movl	$10, %r8d
	movq	40(%rsp), %rsi
	movl	$451, %ecx
	movq	%r14, %rdi
	movq	%rax, 3600(%r14)
	call	_Z9get_layerPdS_S_ii
	movq	8(%rsp), %rdi
	movl	$10, %esi
	call	_Z7sigmoidPdi
	movl	$80, %edi
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movzbl	%r12b, %esi
	movl	$10, %edx
	movq	%rax, %rcx
	movq	%rax, 24(%rsp)
	call	_Z12error_outputPdiiS_
	movl	$36080, %edi
	call	malloc@PLT
	movq	24(%rsp), %rdi
	movl	$451, %ecx
	movq	%r14, %rdx
	movl	$10, %r8d
	movq	%rax, %rsi
	movq	%rax, 56(%rsp)
	call	_Z15calculate_errorPdS_S_ii
	movl	$3608, %edi
	call	malloc@PLT
	movq	40(%rsp), %r9
	movq	24(%rsp), %rdx
	movq	%r14, %rdi
	movl	$451, %r8d
	movl	$10, %ecx
	movq	%rax, %rsi
	movq	%rax, %r12
	call	_Z18error_hidden_layerPdS_S_iiS_
	movl	$7203600, %edi
	call	malloc@PLT
	movl	$2001, %ecx
	movq	%rbx, %rdx
	movq	%r12, %rdi
	movl	$450, %r8d
	movq	%rax, %rsi
	movq	%rax, 64(%rsp)
	call	_Z15calculate_errorPdS_S_ii
	movl	$16008, %edi
	call	malloc@PLT
	movq	32(%rsp), %r9
	movq	%r12, %rdx
	movq	%rbx, %rdi
	movl	$2001, %r8d
	movl	$450, %ecx
	movq	%rax, %rsi
	movq	%rax, 72(%rsp)
	call	_Z18error_hidden_layerPdS_S_iiS_
	movl	$49168000, %edi
	call	malloc@PLT
	movq	16(%rsp), %rdx
	movq	72(%rsp), %rdi
	movl	$2000, %r8d
	movq	%rax, %rsi
	movl	$3073, %ecx
	call	_Z15calculate_errorPdS_S_ii
	movq	48(%rsp), %rdi
	movl	$2000, %ecx
	movl	$3073, %edx
	call	_Z10sum_matrixPdS_ii
	movq	64(%rsp), %rsi
	movq	32(%rsp), %rdi
	movl	$450, %ecx
	movl	$2001, %edx
	call	_Z10sum_matrixPdS_ii
	movq	56(%rsp), %rsi
	movq	40(%rsp), %rdi
	movl	$10, %ecx
	movl	$451, %edx
	call	_Z10sum_matrixPdS_ii
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	112(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	112(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	112(%rsp), %rdx
	movq	104(%rsp), %rsi
	leaq	100(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movss	92(%rsp), %xmm0
	addss	100(%rsp), %xmm0
	jmp	.L72
.L71:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L73
	call	__stack_chk_fail@PLT
.L73:
	cvtsi2ssl	%r13d, %xmm1
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC9(%rip), %rsi
	movb	$1, %al
	popq	%rbx
	.cfi_def_cfa_offset 48
	movl	$2, %edi
	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
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2037:
	.size	_Z9read_filePcPhPdS1_S1_i, .-_Z9read_filePcPhPdS1_S1_i
	.globl	_Z10init_layerPdii
	.type	_Z10init_layerPdii, @function
_Z10init_layerPdii:
.LFB2038:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%esi, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L83:
	cmpl	%r15d, %r14d
	jge	.L82
	movslq	%r13d, %rax
	xorl	%ebx, %ebx
	leaq	(%r12,%rax,8), %rax
	movq	%rax, 8(%rsp)
.L88:
	cmpl	%ebx, %ebp
	jle	.L90
	call	rand@PLT
	testb	$1, %al
	jne	.L84
	call	rand@PLT
	movl	$1000000, %ecx
	cltd
	idivl	%ecx
	cvtsi2sdl	%edx, %xmm0
	divsd	.LC10(%rip), %xmm0
	jmp	.L85
.L84:
	call	rand@PLT
	movl	$1000000, %ecx
	cltd
	idivl	%ecx
	cvtsi2sdl	%edx, %xmm0
	divsd	.LC10(%rip), %xmm0
	xorps	.LC2(%rip), %xmm0
.L85:
	movq	8(%rsp), %rax
	movsd	%xmm0, (%rax,%rbx,8)
	incq	%rbx
	jmp	.L88
.L90:
	incl	%r14d
	addl	%ebp, %r13d
	jmp	.L83
.L82:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2038:
	.size	_Z10init_layerPdii, .-_Z10init_layerPdii
	.section	.rodata.str1.1
.LC11:
	.string	"%f "
.LC12:
	.string	"\n"
	.text
	.globl	_Z11print_layerPdii
	.type	_Z11print_layerPdii, @function
_Z11print_layerPdii:
.LFB2039:
	.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
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L92:
	cmpl	%r14d, %r13d
	jge	.L91
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,8), %rcx
.L95:
	cmpl	%r15d, %ebx
	jle	.L97
	movsd	(%rcx,%r15,8), %xmm0
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movq	%rcx, 8(%rsp)
	incq	%r15
	call	__printf_chk@PLT
	movq	8(%rsp), %rcx
	jmp	.L95
.L97:
	leaq	.LC12(%rip), %rsi
	xorl	%eax, %eax
	incl	%r13d
	addl	%ebx, %r12d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L92
.L91:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2039:
	.size	_Z11print_layerPdii, .-_Z11print_layerPdii
	.section	.rodata.str1.1
.LC13:
	.string	"Error se debe ejecutar: %s <N>\n"
.LC14:
	.string	"Se va a entrenar con %d elementos\n"
.LC15:
	.string	"data_batch_1.bin"
.LC16:
	.string	"Tiempo total del programa: %f ms\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edi, %ebp
	xorl	%edi, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rsi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	cmpl	$2, %ebp
	je	.L99
	movq	(%rbx), %rdx
	movl	$2, %edi
	leaq	.LC13(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	exit@PLT
.L99:
	movq	8(%rbx), %rdi
	call	atoi@PLT
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	movl	%eax, %edx
	movl	%eax, 12(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$49168000, %edi
	call	malloc@PLT
	movl	$7203600, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$36080, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$2000, %edx
	movl	$3073, %esi
	movq	%rbx, %rdi
	movq	%rax, %r12
	call	_Z10init_layerPdii
	movl	$450, %edx
	movl	$2001, %esi
	movq	%rbp, %rdi
	call	_Z10init_layerPdii
	movl	$10, %edx
	movl	$451, %esi
	movq	%r12, %rdi
	call	_Z10init_layerPdii
	movl	$3073, %edi
	call	malloc@PLT
	leaq	24(%rsp), %rdi
	movq	%rax, %r13
	call	cudaEventCreate@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	12(%rsp), %r9d
	movq	%r12, %r8
	movq	%rbp, %rcx
	movq	%rbx, %rdx
	movq	%r13, %rsi
	leaq	.LC15(%rip), %rdi
	call	_Z9read_filePcPhPdS1_S1_i
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rdx
	leaq	20(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	20(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L100
	call	__stack_chk_fail@PLT
.L100:
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2066:
	.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
.LFE2066:
	.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.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	0
	.long	1072693248
	.align 8
.LC4:
	.long	0
	.long	1081065472
	.align 8
.LC5:
	.long	0
	.long	1071644672
	.align 8
.LC6:
	.long	1202590843
	.long	1065646817
	.align 8
.LC10:
	.long	0
	.long	1093567616
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

//Number of elements of the inpu layers, that correspond to the number of pixels of a picture
#define PIXELS 3073
//Number of elements of the first hidden layer
#define HIDDEN_LAYER_1 2000
//Number of elements of the second hidden layer
#define HIDDEN_LAYER_2 450
//Number of elements of the output layer
#define OUTPUT_LAYER 10
//Learning rate of the algorithm
#define LEARNING_RATE 0.01
//Numbers of elements to use for training
#define ELEMENTS 1000

/* 
 * Function that given a vector and its size, print it
 * In: 
 * f: vector of doubles to be printed
 * N: size of the vector
 */
void print_vector(double *f, int N){
	//Move in all vector to print each value
	for (int i =0; i < N; ++i)
		printf("%f\n",f[i]);
}

/*
 * Function that given the value of the previous layer of a neural network, and its transition matrix
 * to the new layer, calculates the net value of the layer
 * In: 
 * input: vector that represents the previous layer of the layer to calculate
 * matrix: transition matrix with the weigths of the neural network
 * result: vector to store the results. It represents the layer to be calculated
 * input_size: size of the previous layer
 * hidden_size: size of the calculated layer
 *
 */
void get_layer(double *input, double *matrix, double *result,int input_size, int hidden_size){
	//Move thorugh every element of the layer
	for (int i = 0; i<hidden_size; ++i){
		//Init the neuron value in 0
		result[i] = 0.0;
		//Multiply each value of the previous neuron times its weigth and store it in result
		for (int j = 0; j < input_size; ++j){
			result[i] += input[j] * matrix[j*hidden_size+i];
		}
	}
}

/*
 * Function that apply the sigmoid function to every element of a vector
 * In:
 * double: vector to apply the signmoid function to every element
 * N: size of the vector
 */
void sigmoid(double *f, int N){
	//Move through all elements of the vector
	for (int i =0; i < N; ++i)
		//Apply the sigmoid function to every element
		//Sigmoid used: f(x) = 1 / (1 + e^(-x))
		f[i] = 1.0 / (1.0 + exp(-f[i]));
}

/*
 * Function that normalize the input, so all the values are equally important. Normalize is the process
 * to transform every element of a vector to its correspondent value beetwen 0 and 1
 * In:
 * c: vector with the numbers between 0 and 255, each one which corresponds to a pixel of the input image
 * f: vector so save the normalized vector
 * N: size of the vectors
 */
void process_input(unsigned char *c, double *f, int N){
	//Move through all elements of the vecotr
	for (int i =0; i < N; ++i){
		//Normalize x cosist of (x - Min)/ (Max-Min), in pixels Max is 255 and Min is 1
		f[i] = (c[i]-1)/254.0;
	}
		
}

/*
 * Function that returns the index corresponding to the maximum element of an array
 * In:
 * f: vector of values
 * N: size of vector
 * Out:
 * int corresponding to the index of the maximum value
 */
int max_index(double *f, int N){
	//The max is the first element
	int max_index = 0;
	for (int i = 1; i < N; ++ i){
		//If there is a new max, then substitute it
		if (f[i] > f[max_index]){
			max_index = i;
		}
	}
	//Return the index of the max element
	return max_index;
}

/*
 * Function that calculate the error of the neural network
 * In:
 * f: output vector of the neural network
 * output: expected value
 * N: size of the vector
 * Out:
 * double corresponding to the calculated error of the NN
 */
double error(double *f, int output, int N) {
	double *output_array = (double *) malloc(N * sizeof(double));
	//Init the expected answer in 0
	for (int i = 0; i < N; ++i)
		output_array[i] = 0.0;
	//Mark the expected answer 1
	output_array[output] = 1.0;

	//Init the error in 0
	double error = 0.0;
	//Calulate the total error, the rror is defined as
	//(1/2)*SUM(di - oi)^2 where di is expected value, oi is calculated value
	for (int i = 0; i < N; ++i)
		error += (output_array[i] - f[i]) * (output_array[i] - f[i]);
	return 0.5*error;
}

/*
 * Function that calculate the error of the output layers
 * In:
 * f: value of the output neurons
 * output: expected value
 * N: size of the vector
 * error_array: vector with the calculated error of every neuron
 *
 */
void error_output(double *f, int output, int N, double *error_array){
	double *output_array = (double *) malloc(N * sizeof(double));
	//Init the expected answer in 0
	for (int i = 0; i < N; ++i)
		output_array[i] = 0.0;
	//Mark the expected answer 1
	output_array[output] = 1.0;

	//Get the error for every neuron. The error in the output layer is defined as Si = (di - oi)*oi*(1-oi)
	for (int i = 0; i < N; ++i){
		error_array[i] = (output_array[i] - f[i])*f[i]*(1-f[i]);
	}
}

/* Function that calculates the error of the hidden layers
 * In: 
 * f: hidden layer calculated values
 * error_array: error vector, to save the error of every neuron in the hidden layer
 * next_layer_error: error vector of the next layer, neccessary to calculate the error of a hidden layer
 * layer_size: size of the hidden layer
 * next_size: size of the next layer
 * transition_matrix: transition matrix to propagate values from hidden to next layer 
 */
void error_hidden_layer(double *f, double* error_array, double *next_layer_error, int layer_size, int next_size, double *transition_matrix){

	//Calculate error of every neuron in a hidden layer
	//The error in a hidden layer is defined as Si = oi * (1 - oi) * SUM(Wij * Sj) where Sj is the error from next
	for (int i = 0; i < layer_size; ++i){
		//Inicial value of the sumatory
		double product = 0.0;
		for (int j = 0; j < next_size; ++j){
			//Add Wij * Sj to acumulator
			product += transition_matrix[i*next_size+j]*next_layer_error[j];
		}
		//Get the final product
		error_array[i] = f[i]*(1-f[i])*product;
	}

}

/*
 * Function that calculates the variation of weigths of a neural network
 * In:
 * error_vector: error vector of the layer
 * gradient: variance of the weights for every element
 * layer: value of the elements of the layer
 * N: rows of the transition matrix
 * M: columns ot the transition matrix
 *
 */
void calculate_error(double *error_vector, double* gradient, double *layer, int N, int M){
	//Iterate over the matrix
	for (int i =0; i<N; ++i){
		for (int j = 0; j<M; ++j){
			//The variance of the weigth is alpha * Sj * Oi
			gradient[i*M+j] = LEARNING_RATE * error_vector[j] * layer[i];
		}
	}

}

/*
 * Function that sums two matrix and store it directly in the first matrix
 * In:
 * transition: first matrix
 * gradient: second matrix
 * N: rows of the matrix
 * M: columns of the matrix
 */
void sum_matrix(double *transition, double *gradient, int N, int M){
	//Iterate over all the matrix 
	for (int i = 0; i < N; ++i){
		for (int j = 0; j < M; ++j){
			//Change the weight of every value of the transition matrix
			transition[i*M+j] = transition[i*M+j] + gradient[i*M+j];
		}
	}
}

/*
 * Function that reads a file, stores every vector of it, and then apply backpropagation
 * In:
 * file: name of the file with the data
 * buffer: vector where every pixel will be stored
 * transition_matrix_1: transition vector from input layer to hidden layer 1
 * transition_matrix_2: transition vector from hidden layer 1 to hidden layer 2
 * transition_matrix_3: transition vector from hidden layer 2 to output layer
 * elements: number of elements to use for training
 */
void read_file(char *file, unsigned char* buffer,double *transition_matrix_1,double *transition_matrix_2, double *transition_matrix_3, int elements){
	//Read the file that is in binary mode
	FILE *f;
	f = fopen(file, "rb");
	//Variable for the expected output
	unsigned char expected_output;
	int i = 0;
	//Init the total time to get the average of every classification
	float total_time = 0.0;

	//While there still elements on the file, and i is less than elements number cycloe
	//Read PIXELS elements, because every pixel is represented by a byte, is enough to tell the reader to read exactly PIXELS bytes
	while(1 == fread(buffer,PIXELS,1,f) && i < elements){

		//Start taking the time
		float tiempo1;
		hipEvent_t inicio1, fin1;

		hipEventCreate(&inicio1); // Se inicializan
   		hipEventCreate(&fin1);
   		hipEventRecord( inicio1, 0 );

   		//The first value of the vector is the expected time
		expected_output = buffer[0];
		//After the expected output is saved, it can be substituted by the bias
		buffer[0] = 1;
		//Init the layers of the network
		double *hidden_layer_1 = (double*)malloc((HIDDEN_LAYER_1+1)*sizeof(double));
		double *hidden_layer_2 = (double*)malloc((HIDDEN_LAYER_2+1)*sizeof(double));
		double *output_layer = (double*)malloc(OUTPUT_LAYER*sizeof(double));

		//Normalize the data
		double *input = (double*)malloc(PIXELS*sizeof(double));
		process_input(buffer,input,PIXELS);

		//Forward information from input layer to hidden layer 1
		get_layer(input,transition_matrix_1,hidden_layer_1,PIXELS,HIDDEN_LAYER_1);
		//Apply signmoid to hidden layer 1
		sigmoid(hidden_layer_1,HIDDEN_LAYER_1+1);
		//Assign the bias
		hidden_layer_1[HIDDEN_LAYER_1] = 1;

		//Forward information from hidden layer 1 to hidden layer 2
		get_layer(hidden_layer_1,transition_matrix_2,hidden_layer_2,HIDDEN_LAYER_1+1,HIDDEN_LAYER_2);
		//Apply signmoid to hidden layer 2
		sigmoid(hidden_layer_2,HIDDEN_LAYER_2+1);
		//Assign the bias
		hidden_layer_2[HIDDEN_LAYER_2] = 1;

		//Forward information from hidden layer 2 to output layer
		get_layer(hidden_layer_2,transition_matrix_3,output_layer,HIDDEN_LAYER_2+1,OUTPUT_LAYER);
		//Apply signmoid to output layer
		sigmoid(output_layer,OUTPUT_LAYER);

		//Get the error of the output
		double *errors_array = (double*)malloc(OUTPUT_LAYER* sizeof(double));
		error_output(output_layer,expected_output,OUTPUT_LAYER,errors_array);

		//Get the weight update for transision matrix 3
		double *transition_matrix_3_gradient = (double*)malloc((HIDDEN_LAYER_2+1)*OUTPUT_LAYER*sizeof(double));
		calculate_error(errors_array,transition_matrix_3_gradient,hidden_layer_2,HIDDEN_LAYER_2+1,OUTPUT_LAYER);

		//Get the weight update for transision matrix 2
		double *hidden_layer_array_2 = (double*)malloc((HIDDEN_LAYER_2+1)* sizeof(double));
		error_hidden_layer(hidden_layer_2,hidden_layer_array_2,errors_array,OUTPUT_LAYER,HIDDEN_LAYER_2+1,transition_matrix_3);
		double *transition_matrix_2_gradient = (double*)malloc((HIDDEN_LAYER_1+1)*HIDDEN_LAYER_2*sizeof(double));
		calculate_error(hidden_layer_array_2,transition_matrix_2_gradient,hidden_layer_1,HIDDEN_LAYER_1+1,HIDDEN_LAYER_2);

		//Get the weight update for transision matrix 1
		double *hidden_layer_array_1 = (double*)malloc((HIDDEN_LAYER_1+1)* sizeof(double));
		error_hidden_layer(hidden_layer_1,hidden_layer_array_1,hidden_layer_array_2,HIDDEN_LAYER_2,HIDDEN_LAYER_1+1,transition_matrix_2);
		double *transition_matrix_1_gradient = (double*)malloc(PIXELS*HIDDEN_LAYER_1*sizeof(double));
		calculate_error(hidden_layer_array_1,transition_matrix_1_gradient,input,PIXELS,HIDDEN_LAYER_1);

		//Update the value of the transitions matrix once all have been calculated
		sum_matrix(transition_matrix_1,transition_matrix_1_gradient,PIXELS,HIDDEN_LAYER_1);
		sum_matrix(transition_matrix_2,transition_matrix_2_gradient,HIDDEN_LAYER_1+1,HIDDEN_LAYER_2);
		sum_matrix(transition_matrix_3,transition_matrix_3_gradient,HIDDEN_LAYER_2+1,OUTPUT_LAYER);

		//Siguiente elemento 
		++i;

		//Free the information not required for the next iteration
		free(hidden_layer_1);
		free(hidden_layer_2);
		free(output_layer);
		free(input);
		free(errors_array);

		//Record the finish moment
		hipEventRecord( fin1, 0); 
   		hipEventSynchronize( fin1 );
   		hipEventElapsedTime( &tiempo1, inicio1, fin1 );

   		//Add the time to the total
   		total_time += tiempo1;
		
	}

	//Take the average time
	total_time /= elements;
	printf ("Tiempo promedio por clasificacion: %f\n", total_time);
}

/*
 * Function that randomly initialize all values off the transiction matrix
 * In:
 * matrix: transition matrix of the neural network
 * N: rows of the matrix
 * M: columns of the matrix
 */
void init_layer(double *matrix, int N, int M){
	//Iterate over the matrix
	for (int i =0; i < N; ++ i){
		for (int j = 0; j < M; ++j){
			//Random number to see if its negative or positive
		    int sign = rand() % 2;
		    //Random number between 0 and 1
		    if (sign == 0)
		    	matrix[i*M+j] = (rand() % 1000000) / 1000000.0;
			else
				matrix[i*M+j] = - ((rand() % 1000000) / 1000000.0);
		}
	}
		
}

/*
 * Function that prints the value of the transition matrix
 * In:
 * matrix: transition matrix
 * N: rows of the matrix
 * M: columns of the matrix
 */
void print_layer(double *matrix, int N, int M){
	//Iterate over the matrix and print
	for (int i =0; i < N; ++ i){
		for (int j = 0; j < M; ++j)
			printf("%f ",matrix[i*M+j]);
		printf("\n");
	}		
}

int main(int argc, char *argv[]){

	//Init the random
	srand(time(NULL));

	//Review if the arguments
	if ( argc != 2 ) {
        /* We print argv[0] assuming it is the program name */
        printf( "Error se debe ejecutar: %s <N>\n", argv[0] );
        exit(0);
    }

    //Transform the argv to int
    int elements = atoi(argv[1]);

    printf("Se va a entrenar con %d elementos\n",elements);
	
	//Create the space for the transition matrix
	double *transition_matrix_1 = (double*)malloc(PIXELS*HIDDEN_LAYER_1*sizeof(double));
	double *transition_matrix_2 = (double*)malloc((HIDDEN_LAYER_1+1)*HIDDEN_LAYER_2*sizeof(double));
	double *transition_matrix_3 = (double*)malloc((HIDDEN_LAYER_2+1)*OUTPUT_LAYER*sizeof(double));

	//Initialize the values of the matrix
	init_layer(transition_matrix_1,PIXELS,HIDDEN_LAYER_1);
	init_layer(transition_matrix_2,HIDDEN_LAYER_1+1,HIDDEN_LAYER_2);
	init_layer(transition_matrix_3,HIDDEN_LAYER_2+1,OUTPUT_LAYER);

	//Start the time
	float tiempo1;
	hipEvent_t inicio1, fin1;

	unsigned char *buffer = (unsigned char*)malloc(PIXELS*sizeof(unsigned char));

	//Start getting the time
	hipEventCreate(&inicio1); // Se inicializan
   	hipEventCreate(&fin1);
   	hipEventRecord( inicio1, 0 );

   	//Start the training
	read_file("data_batch_1.bin",buffer,transition_matrix_1,transition_matrix_2,transition_matrix_3,elements);

	//Finish the time
	hipEventRecord( fin1, 0); // Se toma el tiempo final.
   	hipEventSynchronize( fin1 ); // Se sincroniza
   	hipEventElapsedTime( &tiempo1, inicio1, fin1 );

   	//Print the time
   	printf("Tiempo total del programa: %f ms\n", tiempo1);

}


	.text
	.file	"NeuralNetwork.hip"
	.globl	_Z12print_vectorPdi             # -- Begin function _Z12print_vectorPdi
	.type	_Z12print_vectorPdi,@function
_Z12print_vectorPdi:                    # @_Z12print_vectorPdi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB0_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%rbx,%r15,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB0_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB0_4:                                # %._crit_edge
	retq
.Lfunc_end0:
	.size	_Z12print_vectorPdi, .Lfunc_end0-_Z12print_vectorPdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z9get_layerPdS_S_ii            # -- Begin function _Z9get_layerPdS_S_ii
	.type	_Z9get_layerPdS_S_ii,@function
_Z9get_layerPdS_S_ii:                   # @_Z9get_layerPdS_S_ii
	.cfi_startproc
# %bb.0:
	testl	%r8d, %r8d
	jle	.LBB1_7
# %bb.1:                                # %.lr.ph20
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%r8d, %eax
	movl	%ecx, %r8d
	leaq	(,%rax,8), %r9
	xorl	%r10d, %r10d
.LBB1_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	movq	$0, (%rdx,%r10,8)
	testl	%ecx, %ecx
	jle	.LBB1_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	xorpd	%xmm0, %xmm0
	movq	%rsi, %r11
	xorl	%ebx, %ebx
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rdi,%rbx,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%r11), %xmm1
	addsd	%xmm1, %xmm0
	movsd	%xmm0, (%rdx,%r10,8)
	incq	%rbx
	addq	%r9, %r11
	cmpq	%rbx, %r8
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	incq	%r10
	addq	$8, %rsi
	cmpq	%rax, %r10
	jne	.LBB1_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB1_7:                                # %._crit_edge21
	retq
.Lfunc_end1:
	.size	_Z9get_layerPdS_S_ii, .Lfunc_end1-_Z9get_layerPdS_S_ii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z7sigmoidPdi
.LCPI2_0:
	.quad	0x8000000000000000              # double -0
	.quad	0x8000000000000000              # double -0
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI2_1:
	.quad	0x3ff0000000000000              # double 1
	.text
	.globl	_Z7sigmoidPdi
	.type	_Z7sigmoidPdi,@function
_Z7sigmoidPdi:                          # @_Z7sigmoidPdi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB2_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%rbx,%r15,8), %xmm0            # xmm0 = mem[0],zero
	xorpd	.LCPI2_0(%rip), %xmm0
	callq	exp
	movsd	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	divsd	%xmm0, %xmm1
	movsd	%xmm1, (%rbx,%r15,8)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB2_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB2_4:                                # %._crit_edge
	retq
.Lfunc_end2:
	.size	_Z7sigmoidPdi, .Lfunc_end2-_Z7sigmoidPdi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z13process_inputPhPdi
.LCPI3_0:
	.quad	0x406fc00000000000              # double 254
	.text
	.globl	_Z13process_inputPhPdi
	.type	_Z13process_inputPhPdi,@function
_Z13process_inputPhPdi:                 # @_Z13process_inputPhPdi
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB3_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%edx, %eax
	xorl	%ecx, %ecx
	movsd	.LCPI3_0(%rip), %xmm0           # xmm0 = mem[0],zero
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movzbl	(%rdi,%rcx), %edx
	decl	%edx
	xorps	%xmm1, %xmm1
	cvtsi2sd	%edx, %xmm1
	divsd	%xmm0, %xmm1
	movsd	%xmm1, (%rsi,%rcx,8)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB3_2
.LBB3_3:                                # %._crit_edge
	retq
.Lfunc_end3:
	.size	_Z13process_inputPhPdi, .Lfunc_end3-_Z13process_inputPhPdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z9max_indexPdi                 # -- Begin function _Z9max_indexPdi
	.type	_Z9max_indexPdi,@function
_Z9max_indexPdi:                        # @_Z9max_indexPdi
	.cfi_startproc
# %bb.0:
	xorl	%eax, %eax
	cmpl	$2, %esi
	jl	.LBB4_5
# %bb.1:                                # %.lr.ph.preheader
	movl	%esi, %ecx
	xorl	%esi, %esi
	movl	$1, %edx
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%rdi,%rdx,8), %xmm0            # xmm0 = mem[0],zero
	movslq	%esi, %rax
	ucomisd	(%rdi,%rax,8), %xmm0
	movl	%edx, %eax
	ja	.LBB4_4
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB4_2 Depth=1
	movl	%esi, %eax
.LBB4_4:                                # %.lr.ph
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%rdx
	movl	%eax, %esi
	cmpq	%rdx, %rcx
	jne	.LBB4_2
.LBB4_5:                                # %._crit_edge
	retq
.Lfunc_end4:
	.size	_Z9max_indexPdi, .Lfunc_end4-_Z9max_indexPdi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z5errorPdii
.LCPI5_0:
	.quad	0x3fe0000000000000              # double 0.5
	.text
	.globl	_Z5errorPdii
	.type	_Z5errorPdii,@function
_Z5errorPdii:                           # @_Z5errorPdii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %r15d
	movl	%esi, %ebp
	movq	%rdi, %rbx
	movslq	%edx, %r12
	leaq	(,%r12,8), %rdi
	callq	malloc
	testl	%r12d, %r12d
	jle	.LBB5_1
# %bb.4:                                # %.lr.ph27.preheader
	movq	%rax, %r14
	movl	%r15d, %r15d
	leaq	(,%r15,8), %rdx
	xorl	%r12d, %r12d
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movslq	%ebp, %rax
	movabsq	$4607182418800017408, %rcx      # imm = 0x3FF0000000000000
	movq	%rcx, (%r14,%rax,8)
	xorpd	%xmm0, %xmm0
.LBB5_5:                                # %.lr.ph27
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%r14,%r12,8), %xmm1            # xmm1 = mem[0],zero
	subsd	(%rbx,%r12,8), %xmm1
	mulsd	%xmm1, %xmm1
	addsd	%xmm1, %xmm0
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB5_5
# %bb.2:                                # %._crit_edge28.loopexit
	mulsd	.LCPI5_0(%rip), %xmm0
	jmp	.LBB5_3
.LBB5_1:
	xorpd	%xmm0, %xmm0
.LBB5_3:                                # %._crit_edge28
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z5errorPdii, .Lfunc_end5-_Z5errorPdii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z12error_outputPdiiS_
.LCPI6_0:
	.quad	0x3ff0000000000000              # double 1
	.text
	.globl	_Z12error_outputPdiiS_
	.type	_Z12error_outputPdiiS_,@function
_Z12error_outputPdiiS_:                 # @_Z12error_outputPdiiS_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, %rbx
	movl	%edx, %r12d
	movl	%esi, %ebp
	movq	%rdi, %r14
	movslq	%edx, %r13
	leaq	(,%r13,8), %rdi
	callq	malloc
	testl	%r13d, %r13d
	jle	.LBB6_3
# %bb.1:                                # %.lr.ph25.preheader
	movq	%rax, %r15
	movl	%r12d, %r12d
	leaq	(,%r12,8), %rdx
	xorl	%r13d, %r13d
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movslq	%ebp, %rax
	movabsq	$4607182418800017408, %rcx      # imm = 0x3FF0000000000000
	movq	%rcx, (%r15,%rax,8)
	movsd	.LCPI6_0(%rip), %xmm0           # xmm0 = mem[0],zero
.LBB6_2:                                # %.lr.ph25
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%r15,%r13,8), %xmm1            # xmm1 = mem[0],zero
	movsd	(%r14,%r13,8), %xmm2            # xmm2 = mem[0],zero
	subsd	%xmm2, %xmm1
	mulsd	%xmm2, %xmm1
	movapd	%xmm0, %xmm3
	subsd	%xmm2, %xmm3
	mulsd	%xmm1, %xmm3
	movsd	%xmm3, (%rbx,%r13,8)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB6_2
.LBB6_3:                                # %._crit_edge26
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z12error_outputPdiiS_, .Lfunc_end6-_Z12error_outputPdiiS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z18error_hidden_layerPdS_S_iiS_
.LCPI7_0:
	.quad	0x3ff0000000000000              # double 1
	.text
	.globl	_Z18error_hidden_layerPdS_S_iiS_
	.type	_Z18error_hidden_layerPdS_S_iiS_,@function
_Z18error_hidden_layerPdS_S_iiS_:       # @_Z18error_hidden_layerPdS_S_iiS_
	.cfi_startproc
# %bb.0:
	testl	%ecx, %ecx
	jle	.LBB7_6
# %bb.1:                                # %.preheader.lr.ph
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%ecx, %eax
	movl	%r8d, %ecx
	xorl	%r10d, %r10d
	movsd	.LCPI7_0(%rip), %xmm0           # xmm0 = mem[0],zero
	xorl	%r11d, %r11d
.LBB7_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_8 Depth 2
	testl	%r8d, %r8d
	jle	.LBB7_3
# %bb.7:                                # %.lr.ph
                                        #   in Loop: Header=BB7_2 Depth=1
	movl	%r10d, %ebx
	leaq	(%r9,%rbx,8), %rbx
	xorpd	%xmm1, %xmm1
	xorl	%r14d, %r14d
.LBB7_8:                                #   Parent Loop BB7_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rbx,%r14,8), %xmm2            # xmm2 = mem[0],zero
	mulsd	(%rdx,%r14,8), %xmm2
	addsd	%xmm2, %xmm1
	incq	%r14
	cmpq	%r14, %rcx
	jne	.LBB7_8
	jmp	.LBB7_4
.LBB7_3:                                #   in Loop: Header=BB7_2 Depth=1
	xorpd	%xmm1, %xmm1
.LBB7_4:                                # %._crit_edge
                                        #   in Loop: Header=BB7_2 Depth=1
	movsd	(%rdi,%r11,8), %xmm2            # xmm2 = mem[0],zero
	movapd	%xmm0, %xmm3
	subsd	%xmm2, %xmm3
	mulsd	%xmm2, %xmm3
	mulsd	%xmm1, %xmm3
	movsd	%xmm3, (%rsi,%r11,8)
	incq	%r11
	addl	%r8d, %r10d
	cmpq	%rax, %r11
	jne	.LBB7_2
# %bb.5:
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
.LBB7_6:                                # %._crit_edge25
	retq
.Lfunc_end7:
	.size	_Z18error_hidden_layerPdS_S_iiS_, .Lfunc_end7-_Z18error_hidden_layerPdS_S_iiS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z15calculate_errorPdS_S_ii
.LCPI8_0:
	.quad	0x3f847ae147ae147b              # double 0.01
	.text
	.globl	_Z15calculate_errorPdS_S_ii
	.type	_Z15calculate_errorPdS_S_ii,@function
_Z15calculate_errorPdS_S_ii:            # @_Z15calculate_errorPdS_S_ii
	.cfi_startproc
# %bb.0:
	testl	%ecx, %ecx
	jle	.LBB8_7
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%ecx, %eax
	movl	%r8d, %ecx
	xorl	%r9d, %r9d
	movsd	.LCPI8_0(%rip), %xmm0           # xmm0 = mem[0],zero
	xorl	%r10d, %r10d
.LBB8_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB8_4 Depth 2
	testl	%r8d, %r8d
	jle	.LBB8_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB8_2 Depth=1
	movl	%r9d, %r11d
	leaq	(%rsi,%r11,8), %r11
	xorl	%ebx, %ebx
.LBB8_4:                                #   Parent Loop BB8_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rdi,%rbx,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	%xmm0, %xmm1
	mulsd	(%rdx,%r10,8), %xmm1
	movsd	%xmm1, (%r11,%rbx,8)
	incq	%rbx
	cmpq	%rbx, %rcx
	jne	.LBB8_4
.LBB8_5:                                # %._crit_edge
                                        #   in Loop: Header=BB8_2 Depth=1
	incq	%r10
	addl	%r8d, %r9d
	cmpq	%rax, %r10
	jne	.LBB8_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB8_7:                                # %._crit_edge17
	retq
.Lfunc_end8:
	.size	_Z15calculate_errorPdS_S_ii, .Lfunc_end8-_Z15calculate_errorPdS_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z10sum_matrixPdS_ii            # -- Begin function _Z10sum_matrixPdS_ii
	.type	_Z10sum_matrixPdS_ii,@function
_Z10sum_matrixPdS_ii:                   # @_Z10sum_matrixPdS_ii
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB9_7
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edx, %eax
	movl	%ecx, %edx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
.LBB9_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB9_4 Depth 2
	testl	%ecx, %ecx
	jle	.LBB9_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB9_2 Depth=1
	movl	%r8d, %r11d
	leaq	(%rsi,%r11,8), %r10
	leaq	(%rdi,%r11,8), %r11
	xorl	%ebx, %ebx
.LBB9_4:                                #   Parent Loop BB9_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r11,%rbx,8), %xmm0            # xmm0 = mem[0],zero
	addsd	(%r10,%rbx,8), %xmm0
	movsd	%xmm0, (%r11,%rbx,8)
	incq	%rbx
	cmpq	%rbx, %rdx
	jne	.LBB9_4
.LBB9_5:                                # %._crit_edge
                                        #   in Loop: Header=BB9_2 Depth=1
	incq	%r9
	addl	%ecx, %r8d
	cmpq	%rax, %r9
	jne	.LBB9_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB9_7:                                # %._crit_edge21
	retq
.Lfunc_end9:
	.size	_Z10sum_matrixPdS_ii, .Lfunc_end9-_Z10sum_matrixPdS_ii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z9read_filePcPhPdS1_S1_i
.LCPI10_0:
	.quad	0x406fc00000000000              # double 254
.LCPI10_2:
	.quad	0x3ff0000000000000              # double 1
.LCPI10_3:
	.quad	0x3f847ae147ae147b              # double 0.01
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI10_1:
	.quad	0x8000000000000000              # double -0
	.quad	0x8000000000000000              # double -0
	.text
	.globl	_Z9read_filePcPhPdS1_S1_i
	.type	_Z9read_filePcPhPdS1_S1_i,@function
_Z9read_filePcPhPdS1_S1_i:              # @_Z9read_filePcPhPdS1_S1_i
	.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	$104, %rsp
	.cfi_def_cfa_offset 160
	.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	%r9d, %ebx
	movq	%r8, %r12
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	movq	%rdx, %r14
	movq	%rsi, %r15
	movl	$.L.str.1, %esi
	callq	fopen
	movl	$3073, %esi                     # imm = 0xC01
	movl	$1, %edx
	movq	%r15, %rdi
	movq	%rax, 88(%rsp)                  # 8-byte Spill
	movq	%rax, %rcx
	callq	fread
	xorps	%xmm0, %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cmpq	$1, %rax
	jne	.LBB10_57
# %bb.1:
	testl	%ebx, %ebx
	jle	.LBB10_57
# %bb.2:                                # %.lr.ph.preheader
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	xorl	%eax, %eax
	movl	%ebx, 40(%rsp)                  # 4-byte Spill
	movq	%r12, 80(%rsp)                  # 8-byte Spill
	movq	%r14, 72(%rsp)                  # 8-byte Spill
	movq	%r15, 64(%rsp)                  # 8-byte Spill
.LBB10_3:                               # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB10_4 Depth 2
                                        #     Child Loop BB10_6 Depth 2
                                        #       Child Loop BB10_7 Depth 3
                                        #     Child Loop BB10_10 Depth 2
                                        #     Child Loop BB10_12 Depth 2
                                        #       Child Loop BB10_13 Depth 3
                                        #     Child Loop BB10_16 Depth 2
                                        #     Child Loop BB10_18 Depth 2
                                        #       Child Loop BB10_19 Depth 3
                                        #     Child Loop BB10_22 Depth 2
                                        #     Child Loop BB10_24 Depth 2
                                        #       Child Loop BB10_25 Depth 3
                                        #     Child Loop BB10_28 Depth 2
                                        #       Child Loop BB10_29 Depth 3
                                        #     Child Loop BB10_32 Depth 2
                                        #       Child Loop BB10_33 Depth 3
                                        #     Child Loop BB10_36 Depth 2
                                        #       Child Loop BB10_37 Depth 3
                                        #     Child Loop BB10_40 Depth 2
                                        #       Child Loop BB10_41 Depth 3
                                        #     Child Loop BB10_44 Depth 2
                                        #       Child Loop BB10_45 Depth 3
                                        #     Child Loop BB10_48 Depth 2
                                        #       Child Loop BB10_49 Depth 3
                                        #     Child Loop BB10_52 Depth 2
                                        #       Child Loop BB10_53 Depth 3
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	leaq	56(%rsp), %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movzbl	(%r15), %r13d
	movb	$1, (%r15)
	movl	$16008, %edi                    # imm = 0x3E88
	callq	malloc
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movl	$3608, %edi                     # imm = 0xE18
	callq	malloc
	movq	%rax, %rbp
	movl	$80, %edi
	callq	malloc
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movl	$24584, %edi                    # imm = 0x6008
	callq	malloc
	xorl	%edx, %edx
	movsd	.LCPI10_0(%rip), %xmm1          # xmm1 = mem[0],zero
.LBB10_4:                               # %.lr.ph.i
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movzbl	(%r15,%rdx), %ecx
	decl	%ecx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ecx, %xmm0
	divsd	%xmm1, %xmm0
	movsd	%xmm0, (%rax,%rdx,8)
	incq	%rdx
	cmpq	$3073, %rdx                     # imm = 0xC01
	jne	.LBB10_4
# %bb.5:                                # %_Z13process_inputPhPdi.exit.preheader
                                        #   in Loop: Header=BB10_3 Depth=1
	movq	%r14, %r8
	xorl	%ecx, %ecx
	movq	8(%rsp), %rdi                   # 8-byte Reload
.LBB10_6:                               # %_Z13process_inputPhPdi.exit
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_7 Depth 3
	xorpd	%xmm0, %xmm0
	movq	%r8, %rdx
	xorl	%esi, %esi
.LBB10_7:                               #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rax,%rsi,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%rdx), %xmm1
	addsd	%xmm1, %xmm0
	incq	%rsi
	addq	$16000, %rdx                    # imm = 0x3E80
	cmpq	$3073, %rsi                     # imm = 0xC01
	jne	.LBB10_7
# %bb.8:                                # %._crit_edge.i
                                        #   in Loop: Header=BB10_6 Depth=2
	movsd	%xmm0, (%rdi,%rcx,8)
	incq	%rcx
	addq	$8, %r8
	cmpq	$2000, %rcx                     # imm = 0x7D0
	jne	.LBB10_6
# %bb.9:                                # %.lr.ph.i63.preheader
                                        #   in Loop: Header=BB10_3 Depth=1
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
.LBB10_10:                              # %.lr.ph.i63
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rdi,%rbx,8), %xmm0            # xmm0 = mem[0],zero
	xorpd	.LCPI10_1(%rip), %xmm0
	callq	exp
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movsd	.LCPI10_2(%rip), %xmm1          # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	divsd	%xmm0, %xmm1
	movsd	%xmm1, (%rdi,%rbx,8)
	incq	%rbx
	cmpq	$2001, %rbx                     # imm = 0x7D1
	jne	.LBB10_10
# %bb.11:                               # %_Z7sigmoidPdi.exit
                                        #   in Loop: Header=BB10_3 Depth=1
	movabsq	$4607182418800017408, %rax      # imm = 0x3FF0000000000000
	movq	%rax, 16000(%rdi)
	movq	16(%rsp), %rax                  # 8-byte Reload
	xorl	%ecx, %ecx
.LBB10_12:                              #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_13 Depth 3
	xorpd	%xmm0, %xmm0
	movq	%rax, %rdx
	xorl	%esi, %esi
.LBB10_13:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_12 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rdi,%rsi,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%rdx), %xmm1
	addsd	%xmm1, %xmm0
	incq	%rsi
	addq	$3600, %rdx                     # imm = 0xE10
	cmpq	$2001, %rsi                     # imm = 0x7D1
	jne	.LBB10_13
# %bb.14:                               # %._crit_edge.i75
                                        #   in Loop: Header=BB10_12 Depth=2
	movsd	%xmm0, (%rbp,%rcx,8)
	incq	%rcx
	addq	$8, %rax
	cmpq	$450, %rcx                      # imm = 0x1C2
	jne	.LBB10_12
# %bb.15:                               # %.lr.ph.i79.preheader
                                        #   in Loop: Header=BB10_3 Depth=1
	xorl	%ebx, %ebx
.LBB10_16:                              # %.lr.ph.i79
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rbp,%rbx,8), %xmm0            # xmm0 = mem[0],zero
	xorpd	.LCPI10_1(%rip), %xmm0
	callq	exp
	movsd	.LCPI10_2(%rip), %xmm1          # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	divsd	%xmm0, %xmm1
	movsd	%xmm1, (%rbp,%rbx,8)
	incq	%rbx
	cmpq	$451, %rbx                      # imm = 0x1C3
	jne	.LBB10_16
# %bb.17:                               # %_Z7sigmoidPdi.exit84
                                        #   in Loop: Header=BB10_3 Depth=1
	movabsq	$4607182418800017408, %rax      # imm = 0x3FF0000000000000
	movq	%rax, 3600(%rbp)
	movq	%r12, %rax
	xorl	%ecx, %ecx
	movq	24(%rsp), %rdi                  # 8-byte Reload
.LBB10_18:                              #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_19 Depth 3
	xorpd	%xmm0, %xmm0
	movq	%rax, %rdx
	xorl	%esi, %esi
.LBB10_19:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_18 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rbp,%rsi,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%rdx), %xmm1
	addsd	%xmm1, %xmm0
	incq	%rsi
	addq	$80, %rdx
	cmpq	$451, %rsi                      # imm = 0x1C3
	jne	.LBB10_19
# %bb.20:                               # %._crit_edge.i92
                                        #   in Loop: Header=BB10_18 Depth=2
	movsd	%xmm0, (%rdi,%rcx,8)
	incq	%rcx
	addq	$8, %rax
	cmpq	$10, %rcx
	jne	.LBB10_18
# %bb.21:                               # %.lr.ph.i96.preheader
                                        #   in Loop: Header=BB10_3 Depth=1
	xorl	%ebx, %ebx
.LBB10_22:                              # %.lr.ph.i96
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rdi,%rbx,8), %xmm0            # xmm0 = mem[0],zero
	xorpd	.LCPI10_1(%rip), %xmm0
	callq	exp
	movq	24(%rsp), %rdi                  # 8-byte Reload
	movsd	.LCPI10_2(%rip), %xmm1          # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	divsd	%xmm0, %xmm1
	movsd	%xmm1, (%rdi,%rbx,8)
	incq	%rbx
	cmpq	$10, %rbx
	jne	.LBB10_22
# %bb.23:                               # %_Z7sigmoidPdi.exit101
                                        #   in Loop: Header=BB10_3 Depth=1
	movq	%rdi, %rbx
	movl	$80, %edi
	callq	malloc
	movq	%rax, %r15
	movq	%rbx, %rdi
	movl	%r13d, %esi
	movl	$10, %edx
	movq	%rax, %rcx
	callq	_Z12error_outputPdiiS_
	movl	$36080, %edi                    # imm = 0x8CF0
	callq	malloc
	movq	%rax, %r13
	xorl	%ecx, %ecx
	movsd	.LCPI10_3(%rip), %xmm2          # xmm2 = mem[0],zero
.LBB10_24:                              # %.preheader.i
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_25 Depth 3
	movsd	(%rbp,%rcx,8), %xmm0            # xmm0 = mem[0],zero
	xorl	%edx, %edx
.LBB10_25:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_24 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%r15,%rdx,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	%xmm2, %xmm1
	mulsd	%xmm0, %xmm1
	movsd	%xmm1, (%rax,%rdx,8)
	incq	%rdx
	cmpq	$10, %rdx
	jne	.LBB10_25
# %bb.26:                               # %._crit_edge.i108
                                        #   in Loop: Header=BB10_24 Depth=2
	incq	%rcx
	addq	$80, %rax
	cmpq	$451, %rcx                      # imm = 0x1C3
	jne	.LBB10_24
# %bb.27:                               # %_Z15calculate_errorPdS_S_ii.exit
                                        #   in Loop: Header=BB10_3 Depth=1
	movl	$3608, %edi                     # imm = 0xE18
	callq	malloc
	movq	%rax, %r14
	movq	%r12, %rax
	xorl	%ecx, %ecx
	movsd	.LCPI10_2(%rip), %xmm3          # xmm3 = mem[0],zero
.LBB10_28:                              # %.preheader.i109
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_29 Depth 3
	xorpd	%xmm0, %xmm0
	xorl	%edx, %edx
.LBB10_29:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_28 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rax,%rdx,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%r15,%rdx,8), %xmm1
	addsd	%xmm1, %xmm0
	incq	%rdx
	cmpq	$451, %rdx                      # imm = 0x1C3
	jne	.LBB10_29
# %bb.30:                               # %._crit_edge.i116
                                        #   in Loop: Header=BB10_28 Depth=2
	movsd	(%rbp,%rcx,8), %xmm1            # xmm1 = mem[0],zero
	movapd	%xmm3, %xmm2
	subsd	%xmm1, %xmm2
	mulsd	%xmm1, %xmm2
	mulsd	%xmm2, %xmm0
	movsd	%xmm0, (%r14,%rcx,8)
	incq	%rcx
	addq	$3608, %rax                     # imm = 0xE18
	cmpq	$10, %rcx
	jne	.LBB10_28
# %bb.31:                               # %_Z18error_hidden_layerPdS_S_iiS_.exit
                                        #   in Loop: Header=BB10_3 Depth=1
	movl	$7203600, %edi                  # imm = 0x6DEB10
	callq	malloc
	movq	%rax, %r12
	xorl	%ecx, %ecx
	movsd	.LCPI10_3(%rip), %xmm2          # xmm2 = mem[0],zero
	movq	8(%rsp), %rsi                   # 8-byte Reload
.LBB10_32:                              # %.preheader.i117
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_33 Depth 3
	movsd	(%rsi,%rcx,8), %xmm0            # xmm0 = mem[0],zero
	xorl	%edx, %edx
.LBB10_33:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_32 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%r14,%rdx,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	%xmm2, %xmm1
	mulsd	%xmm0, %xmm1
	movsd	%xmm1, (%rax,%rdx,8)
	incq	%rdx
	cmpq	$450, %rdx                      # imm = 0x1C2
	jne	.LBB10_33
# %bb.34:                               # %._crit_edge.i125
                                        #   in Loop: Header=BB10_32 Depth=2
	incq	%rcx
	addq	$3600, %rax                     # imm = 0xE10
	cmpq	$2001, %rcx                     # imm = 0x7D1
	jne	.LBB10_32
# %bb.35:                               # %_Z15calculate_errorPdS_S_ii.exit128
                                        #   in Loop: Header=BB10_3 Depth=1
	movl	$16008, %edi                    # imm = 0x3E88
	callq	malloc
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movq	%rax, %rbx
	movq	16(%rsp), %rax                  # 8-byte Reload
	xorl	%ecx, %ecx
	movsd	.LCPI10_2(%rip), %xmm3          # xmm3 = mem[0],zero
.LBB10_36:                              # %.preheader.i129
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_37 Depth 3
	xorpd	%xmm0, %xmm0
	xorl	%edx, %edx
.LBB10_37:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_36 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rax,%rdx,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%r14,%rdx,8), %xmm1
	addsd	%xmm1, %xmm0
	incq	%rdx
	cmpq	$2001, %rdx                     # imm = 0x7D1
	jne	.LBB10_37
# %bb.38:                               # %._crit_edge.i138
                                        #   in Loop: Header=BB10_36 Depth=2
	movsd	(%rsi,%rcx,8), %xmm1            # xmm1 = mem[0],zero
	movapd	%xmm3, %xmm2
	subsd	%xmm1, %xmm2
	mulsd	%xmm1, %xmm2
	mulsd	%xmm2, %xmm0
	movsd	%xmm0, (%rbx,%rcx,8)
	incq	%rcx
	addq	$16008, %rax                    # imm = 0x3E88
	cmpq	$450, %rcx                      # imm = 0x1C2
	jne	.LBB10_36
# %bb.39:                               # %_Z18error_hidden_layerPdS_S_iiS_.exit141
                                        #   in Loop: Header=BB10_3 Depth=1
	movl	$49168000, %edi                 # imm = 0x2EE3E80
	callq	malloc
	movq	%rax, %rcx
	xorl	%edx, %edx
	movq	72(%rsp), %r14                  # 8-byte Reload
	movsd	.LCPI10_3(%rip), %xmm2          # xmm2 = mem[0],zero
	movl	$16000, %edi                    # imm = 0x3E80
	movq	48(%rsp), %r8                   # 8-byte Reload
.LBB10_40:                              # %.preheader.i142
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_41 Depth 3
	movsd	(%r8,%rdx,8), %xmm0             # xmm0 = mem[0],zero
	xorl	%esi, %esi
.LBB10_41:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_40 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rbx,%rsi,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	%xmm2, %xmm1
	mulsd	%xmm0, %xmm1
	movsd	%xmm1, (%rcx,%rsi,8)
	incq	%rsi
	cmpq	$2000, %rsi                     # imm = 0x7D0
	jne	.LBB10_41
# %bb.42:                               # %._crit_edge.i150
                                        #   in Loop: Header=BB10_40 Depth=2
	incq	%rdx
	addq	$16000, %rcx                    # imm = 0x3E80
	cmpq	$3073, %rdx                     # imm = 0xC01
	jne	.LBB10_40
# %bb.43:                               # %.preheader.i154.preheader
                                        #   in Loop: Header=BB10_3 Depth=1
	movq	%r14, %rcx
	xorl	%edx, %edx
	movl	40(%rsp), %ebx                  # 4-byte Reload
.LBB10_44:                              # %.preheader.i154
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_45 Depth 3
	xorl	%esi, %esi
.LBB10_45:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_44 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rcx,%rsi,8), %xmm0            # xmm0 = mem[0],zero
	addsd	(%rax,%rsi,8), %xmm0
	movsd	%xmm0, (%rcx,%rsi,8)
	incq	%rsi
	cmpq	$2000, %rsi                     # imm = 0x7D0
	jne	.LBB10_45
# %bb.46:                               # %._crit_edge.i160
                                        #   in Loop: Header=BB10_44 Depth=2
	incq	%rdx
	addq	%rdi, %rax
	addq	%rdi, %rcx
	cmpq	$3073, %rdx                     # imm = 0xC01
	jne	.LBB10_44
# %bb.47:                               # %.preheader.i163.preheader
                                        #   in Loop: Header=BB10_3 Depth=1
	movq	16(%rsp), %rax                  # 8-byte Reload
	xorl	%ecx, %ecx
	movl	$3600, %esi                     # imm = 0xE10
	movq	8(%rsp), %rdi                   # 8-byte Reload
.LBB10_48:                              # %.preheader.i163
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_49 Depth 3
	xorl	%edx, %edx
.LBB10_49:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_48 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rax,%rdx,8), %xmm0            # xmm0 = mem[0],zero
	addsd	(%r12,%rdx,8), %xmm0
	movsd	%xmm0, (%rax,%rdx,8)
	incq	%rdx
	cmpq	$450, %rdx                      # imm = 0x1C2
	jne	.LBB10_49
# %bb.50:                               # %._crit_edge.i169
                                        #   in Loop: Header=BB10_48 Depth=2
	incq	%rcx
	addq	%rsi, %r12
	addq	%rsi, %rax
	cmpq	$2001, %rcx                     # imm = 0x7D1
	jne	.LBB10_48
# %bb.51:                               # %.preheader.i173.preheader
                                        #   in Loop: Header=BB10_3 Depth=1
	movq	80(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rax
	xorl	%ecx, %ecx
.LBB10_52:                              # %.preheader.i173
                                        #   Parent Loop BB10_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB10_53 Depth 3
	xorl	%edx, %edx
.LBB10_53:                              #   Parent Loop BB10_3 Depth=1
                                        #     Parent Loop BB10_52 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rax,%rdx,8), %xmm0            # xmm0 = mem[0],zero
	addsd	(%r13,%rdx,8), %xmm0
	movsd	%xmm0, (%rax,%rdx,8)
	incq	%rdx
	cmpq	$10, %rdx
	jne	.LBB10_53
# %bb.54:                               # %._crit_edge.i179
                                        #   in Loop: Header=BB10_52 Depth=2
	incq	%rcx
	addq	$80, %r13
	addq	$80, %rax
	cmpq	$451, %rcx                      # imm = 0x1C3
	jne	.LBB10_52
# %bb.55:                               # %_Z10sum_matrixPdS_ii.exit182
                                        #   in Loop: Header=BB10_3 Depth=1
	callq	free
	movq	%rbp, %rdi
	callq	free
	movq	24(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	48(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	movq	56(%rsp), %rsi
	movq	32(%rsp), %rdx
	leaq	44(%rsp), %rdi
	callq	hipEventElapsedTime
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addss	44(%rsp), %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	movl	$3073, %esi                     # imm = 0xC01
	movl	$1, %edx
	movq	64(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rdi
	movq	88(%rsp), %rcx                  # 8-byte Reload
	callq	fread
	cmpq	$1, %rax
	movq	96(%rsp), %rax                  # 8-byte Reload
	jne	.LBB10_57
# %bb.56:                               # %_Z10sum_matrixPdS_ii.exit182
                                        #   in Loop: Header=BB10_3 Depth=1
	incl	%eax
	cmpl	%ebx, %eax
	jl	.LBB10_3
.LBB10_57:                              # %._crit_edge
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebx, %xmm0
	movss	4(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	divss	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	addq	$104, %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_end10:
	.size	_Z9read_filePcPhPdS1_S1_i, .Lfunc_end10-_Z9read_filePcPhPdS1_S1_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	3, 0x0                          # -- Begin function _Z10init_layerPdii
.LCPI11_0:
	.quad	0xc12e848000000000              # double -1.0E+6
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z10init_layerPdii
	.type	_Z10init_layerPdii,@function
_Z10init_layerPdii:                     # @_Z10init_layerPdii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, 8(%rsp)                   # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB11_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%edx, %r12d
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
	movl	%edx, 4(%rsp)                   # 4-byte Spill
.LBB11_2:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB11_4 Depth 2
	testl	%edx, %edx
	jle	.LBB11_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB11_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,8), %r14
	xorl	%r15d, %r15d
.LBB11_4:                               #   Parent Loop BB11_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorl	%ebx, %ebx
	testb	$1, %al
	sete	%bl
	callq	rand
	cltq
	imulq	$1125899907, %rax, %rcx         # imm = 0x431BDE83
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$50, %rcx
	addl	%edx, %ecx
	imull	$1000000, %ecx, %ecx            # imm = 0xF4240
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI11_0(,%rbx,8), %xmm0
	movsd	%xmm0, (%r14,%r15,8)
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB11_4
.LBB11_5:                               # %._crit_edge
                                        #   in Loop: Header=BB11_2 Depth=1
	incq	%rbp
	movl	4(%rsp), %edx                   # 4-byte Reload
	addl	%edx, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB11_2
.LBB11_6:                               # %._crit_edge18
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end11:
	.size	_Z10init_layerPdii, .Lfunc_end11-_Z10init_layerPdii
	.cfi_endproc
                                        # -- End function
	.globl	_Z11print_layerPdii             # -- Begin function _Z11print_layerPdii
	.type	_Z11print_layerPdii,@function
_Z11print_layerPdii:                    # @_Z11print_layerPdii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, 8(%rsp)                   # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB12_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %ebx
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%edx, %r12d
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB12_2:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB12_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB12_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB12_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,8), %r14
	xorl	%r15d, %r15d
.LBB12_4:                               #   Parent Loop BB12_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r14,%r15,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB12_4
.LBB12_5:                               # %._crit_edge
                                        #   in Loop: Header=BB12_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%rbp
	addl	%ebx, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB12_2
.LBB12_6:                               # %._crit_edge13
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end12:
	.size	_Z11print_layerPdii, .Lfunc_end12-_Z11print_layerPdii
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	cmpl	$2, %ebp
	jne	.LBB13_2
# %bb.1:
	movq	8(%rbx), %rdi
	callq	atoi
	movl	%eax, (%rsp)                    # 4-byte Spill
	movl	$.L.str.6, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$49168000, %edi                 # imm = 0x2EE3E80
	callq	malloc
	movq	%rax, %r14
	movl	$7203600, %edi                  # imm = 0x6DEB10
	callq	malloc
	movq	%rax, %r15
	movl	$36080, %edi                    # imm = 0x8CF0
	callq	malloc
	movq	%rax, %r12
	movq	%r14, %rdi
	movl	$3073, %esi                     # imm = 0xC01
	movl	$2000, %edx                     # imm = 0x7D0
	callq	_Z10init_layerPdii
	movq	%r15, %rdi
	movl	$2001, %esi                     # imm = 0x7D1
	movl	$450, %edx                      # imm = 0x1C2
	callq	_Z10init_layerPdii
	movq	%r12, %rdi
	movl	$451, %esi                      # imm = 0x1C3
	movl	$10, %edx
	callq	_Z10init_layerPdii
	movl	$3073, %edi                     # imm = 0xC01
	callq	malloc
	movq	%rax, %rbx
	leaq	16(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	$.L.str.7, %edi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	movq	%r15, %rcx
	movq	%r12, %r8
	movl	(%rsp), %r9d                    # 4-byte Reload
	callq	_Z9read_filePcPhPdS1_S1_i
	movq	(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbp), %rdi
	callq	hipEventSynchronize
	movq	(%r13), %rsi
	movq	(%rbp), %rdx
	leaq	4(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB13_2:
	.cfi_def_cfa_offset 80
	movq	(%rbx), %rsi
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%edi, %edi
	callq	exit
.Lfunc_end13:
	.size	main, .Lfunc_end13-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%f\n"
	.size	.L.str, 4

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"rb"
	.size	.L.str.1, 3

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Tiempo promedio por clasificacion: %f\n"
	.size	.L.str.2, 39

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Error se debe ejecutar: %s <N>\n"
	.size	.L.str.5, 32

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Se va a entrenar con %d elementos\n"
	.size	.L.str.6, 35

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"data_batch_1.bin"
	.size	.L.str.7, 17

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Tiempo total del programa: %f ms\n"
	.size	.L.str.8, 34

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
