/* 
 * CPU version of BackPropagation Neural Network written in CUDA. One can change the extension .cu to .c 
 * and compile the program with C compiler. 
 * 
 * This program is a rework of Source code for Neural Networks w/ JAVA (Tutorial 09) - Backpropagation 01
 * from http://zaneacademy.com
 * 
 * Author - Waylon Luo
 * Date - April 23, 2020 
 *
 */

#include <stdio.h>
#include <time.h>
#include <cuda_runtime.h>
#include <cassert>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>

#define LEARNING_RATE 0.80 
#define NUMB_OF_EPOCHS 100
#define TD_X 4 // training data in x- dimension
#define TD_Y 2 // training data in y- dimension
#define TD_Z 2 // training data in z- dimension   

double rand_double();
double TRAINING_DATA[TD_X][TD_Y][TD_Z] = {{{0,0},{0}},
					          	 {{0,1},{1}},
					          	 {{1,0},{1}},
					          	 {{1,1},{0}}}; 

#include "Neuron.cu"

int main(void){
 
 	double result[] = {0, 0, 0, 0}; 
 	// declare and initialize neurons 
	struct neuron neurons[5]; 
	setNeurons(neurons);

	// forward propagation before the training
	for(int i = 0; i < TD_X; i++) {   // TD_X - Traning Data Dimension X 
		forwardProp(TRAINING_DATA[i][0], neurons);
		result[i] = neurons[4].output; // get output
	}
	printResult(result); 

	// training 100 * 100 = 10,000 trainings 
	for(int x = 0; x < 100; x++){
		for(int i = 0; i < NUMB_OF_EPOCHS; i++) {   
			if(i%100 == 0) {
				printf("[epoch %d ]\n", i);
			}
			for(int j = 0; j < TD_X; j++) {  // TD_X - Traning Data Dimension X 
				forwardProp(TRAINING_DATA[j][0], neurons);
				backpropError(TRAINING_DATA[j][1][0], neurons);		
				if(i%100 == 0) printTrainingData(neurons); 
			}
		}
	}
	printf("[done training]\n");

	// forward propagation after the training
	for(int i = 0; i < TD_X; i++) {
		forwardProp(TRAINING_DATA[i][0], neurons);
		result[i] = neurons[4].output; // get output
	}
	printResult(result); 

	return(1);
}
	.file	"tmpxft_00292e6d_00000000-6_BackPropagation.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4899:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4899:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z23applyActivationFunctiond
	.type	_Z23applyActivationFunctiond, @function
_Z23applyActivationFunctiond:
.LFB4886:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorps	.LC0(%rip), %xmm0
	call	exp@PLT
	movsd	.LC1(%rip), %xmm1
	popq	%rdx
	.cfi_def_cfa_offset 8
	addsd	%xmm1, %xmm0
	divsd	%xmm0, %xmm1
	movaps	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE4886:
	.size	_Z23applyActivationFunctiond, .-_Z23applyActivationFunctiond
	.globl	_Z10derivatived
	.type	_Z10derivatived, @function
_Z10derivatived:
.LFB4887:
	.cfi_startproc
	endbr64
	movaps	%xmm0, %xmm1
	movsd	.LC1(%rip), %xmm0
	subsd	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE4887:
	.size	_Z10derivatived, .-_Z10derivatived
	.globl	_Z11forwardPropPdP6neuron
	.type	_Z11forwardPropPdP6neuron, @function
_Z11forwardPropPdP6neuron:
.LFB4888:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	384(%rsi), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rsi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 48
.L9:
	movl	40(%rbx), %eax
	cmpl	$1, %eax
	je	.L6
	cmpl	$2, %eax
	je	.L7
	testl	%eax, %eax
	jne	.L8
	movsd	0(%r13), %xmm0
	jmp	.L12
.L6:
	movsd	8(%rbx), %xmm0
	mulsd	24(%rbp), %xmm0
	movsd	16(%rbx), %xmm1
	addsd	(%rbx), %xmm0
	mulsd	72(%rbp), %xmm1
	jmp	.L13
.L7:
	movsd	16(%rbx), %xmm1
	mulsd	168(%rbp), %xmm1
	movsd	8(%rbx), %xmm0
	mulsd	120(%rbp), %xmm0
	addsd	(%rbx), %xmm0
.L13:
	addsd	%xmm1, %xmm0
	call	_Z23applyActivationFunctiond
.L12:
	movsd	%xmm0, 24(%rbx)
.L8:
	addq	$48, %rbx
	addq	$8, %r13
	cmpq	%r12, %rbx
	jne	.L9
	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
.LFE4888:
	.size	_Z11forwardPropPdP6neuron, .-_Z11forwardPropPdP6neuron
	.globl	_Z13backpropErrordP6neuron
	.type	_Z13backpropErrordP6neuron, @function
_Z13backpropErrordP6neuron:
.LFB4889:
	.cfi_startproc
	endbr64
	movsd	.LC1(%rip), %xmm1
	movsd	216(%rdi), %xmm2
	movsd	.LC2(%rip), %xmm4
	movsd	168(%rdi), %xmm7
	movaps	%xmm1, %xmm3
	subsd	%xmm2, %xmm0
	movsd	24(%rdi), %xmm8
	movsd	120(%rdi), %xmm6
	subsd	%xmm2, %xmm3
	mulsd	%xmm2, %xmm3
	movsd	192(%rdi), %xmm2
	mulsd	%xmm0, %xmm3
	movaps	%xmm3, %xmm0
	movsd	%xmm3, 224(%rdi)
	mulsd	%xmm4, %xmm0
	addsd	%xmm0, %xmm2
	movaps	%xmm0, %xmm5
	mulsd	%xmm7, %xmm0
	addsd	208(%rdi), %xmm0
	mulsd	%xmm6, %xmm5
	movsd	%xmm2, 192(%rdi)
	movaps	%xmm1, %xmm2
	subsd	%xmm6, %xmm1
	addsd	200(%rdi), %xmm5
	subsd	%xmm7, %xmm2
	movsd	%xmm0, 208(%rdi)
	mulsd	%xmm3, %xmm0
	mulsd	%xmm5, %xmm3
	movsd	%xmm5, 200(%rdi)
	mulsd	%xmm7, %xmm2
	movsd	72(%rdi), %xmm7
	mulsd	%xmm0, %xmm2
	movsd	144(%rdi), %xmm0
	movsd	%xmm2, 176(%rdi)
	mulsd	%xmm4, %xmm2
	addsd	%xmm2, %xmm0
	movsd	%xmm0, 144(%rdi)
	movaps	%xmm2, %xmm0
	mulsd	%xmm8, %xmm0
	addsd	152(%rdi), %xmm0
	mulsd	%xmm7, %xmm2
	addsd	160(%rdi), %xmm2
	movsd	%xmm0, 152(%rdi)
	movaps	%xmm1, %xmm0
	movsd	96(%rdi), %xmm1
	mulsd	%xmm6, %xmm0
	movsd	%xmm2, 160(%rdi)
	mulsd	%xmm3, %xmm0
	movsd	%xmm0, 128(%rdi)
	mulsd	%xmm4, %xmm0
	mulsd	%xmm0, %xmm8
	addsd	%xmm0, %xmm1
	mulsd	%xmm0, %xmm7
	addsd	104(%rdi), %xmm8
	addsd	112(%rdi), %xmm7
	movsd	%xmm1, 96(%rdi)
	movsd	%xmm8, 104(%rdi)
	movsd	%xmm7, 112(%rdi)
	ret
	.cfi_endproc
.LFE4889:
	.size	_Z13backpropErrordP6neuron, .-_Z13backpropErrordP6neuron
	.globl	_Z10setNeuronsP6neuron
	.type	_Z10setNeuronsP6neuron, @function
_Z10setNeuronsP6neuron:
.LFB4890:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	xorl	%edi, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	96(%rbp), %r12
	movq	%rbp, %rbx
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
.L17:
	call	rand@PLT
	movsd	.LC4(%rip), %xmm1
	addq	$48, %rbx
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC3(%rip), %xmm0
	subsd	%xmm0, %xmm1
	movsd	%xmm1, -48(%rbx)
	call	rand@PLT
	movsd	.LC4(%rip), %xmm1
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC3(%rip), %xmm0
	subsd	%xmm0, %xmm1
	movsd	%xmm1, -40(%rbx)
	call	rand@PLT
	movsd	.LC4(%rip), %xmm1
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC3(%rip), %xmm0
	xorl	%eax, %eax
	subsd	%xmm0, %xmm1
	movl	%eax, -8(%rbx)
	movsd	%xmm1, -32(%rbx)
	cmpq	%r12, %rbx
	jne	.L17
	leaq	192(%rbp), %r12
.L18:
	call	rand@PLT
	movsd	.LC4(%rip), %xmm1
	addq	$48, %rbx
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC3(%rip), %xmm0
	subsd	%xmm0, %xmm1
	movsd	%xmm1, -48(%rbx)
	call	rand@PLT
	movsd	.LC4(%rip), %xmm1
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC3(%rip), %xmm0
	subsd	%xmm0, %xmm1
	movsd	%xmm1, -40(%rbx)
	call	rand@PLT
	movsd	.LC4(%rip), %xmm1
	movl	$1, -8(%rbx)
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC3(%rip), %xmm0
	subsd	%xmm0, %xmm1
	movsd	%xmm1, -32(%rbx)
	cmpq	%r12, %rbx
	jne	.L18
	call	rand@PLT
	movsd	.LC4(%rip), %xmm1
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC3(%rip), %xmm0
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 192(%rbp)
	call	rand@PLT
	movsd	.LC4(%rip), %xmm1
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC3(%rip), %xmm0
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 200(%rbp)
	call	rand@PLT
	movsd	.LC4(%rip), %xmm0
	movl	$2, 232(%rbp)
	cvtsi2sdl	%eax, %xmm1
	divsd	.LC3(%rip), %xmm1
	subsd	%xmm1, %xmm0
	movsd	%xmm0, 208(%rbp)
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4890:
	.size	_Z10setNeuronsP6neuron, .-_Z10setNeuronsP6neuron
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC5:
	.string	"[(I: %.2f), (I: %.2f), "
.LC6:
	.string	"(H: %.2f, %.2f, %.2f, %.5f), "
.LC7:
	.string	"(O: %.2f, %.2f, %.2f, %.5f)]\n "
	.text
	.globl	_Z17printTrainingDataP6neuron
	.type	_Z17printTrainingDataP6neuron, @function
_Z17printTrainingDataP6neuron:
.LFB4891:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC5(%rip), %rsi
	leaq	.LC6(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rax
	.cfi_def_cfa_offset 32
	movsd	24(%rdi), %xmm0
	movb	$2, %al
	movsd	72(%rdi), %xmm1
	movl	$2, %edi
	call	__printf_chk@PLT
	movsd	104(%rbx), %xmm0
	movq	%rbp, %rsi
	movb	$4, %al
	movsd	120(%rbx), %xmm3
	movsd	96(%rbx), %xmm2
	movl	$2, %edi
	movsd	112(%rbx), %xmm1
	call	__printf_chk@PLT
	movsd	152(%rbx), %xmm0
	movq	%rbp, %rsi
	movsd	168(%rbx), %xmm3
	movsd	144(%rbx), %xmm2
	movsd	160(%rbx), %xmm1
	movl	$2, %edi
	movb	$4, %al
	call	__printf_chk@PLT
	movsd	200(%rbx), %xmm0
	movb	$4, %al
	movsd	216(%rbx), %xmm3
	movsd	192(%rbx), %xmm2
	movsd	208(%rbx), %xmm1
	movl	$2, %edi
	leaq	.LC7(%rip), %rsi
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE4891:
	.size	_Z17printTrainingDataP6neuron, .-_Z17printTrainingDataP6neuron
	.section	.rodata.str1.1
.LC8:
	.string	"    Input 1    |    Input 2    | Target Result |  Result    \n"
.LC9:
	.string	"-------------------------------------------------------------\n"
.LC10:
	.string	"    %.5f    |"
.LC11:
	.string	"    %.5f    |   %.5f   \n"
	.text
	.globl	_Z11printResultPd
	.type	_Z11printResultPd, @function
_Z11printResultPd:
.LFB4892:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC8(%rip), %rsi
	xorl	%eax, %eax
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	.LC10(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	leaq	TRAINING_DATA(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	movl	$2, %edi
	leaq	128(%rbp), %r13
	pushq	%rdx
	.cfi_def_cfa_offset 48
	call	__printf_chk@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L25:
	movsd	0(%rbp), %xmm0
	movq	%r12, %rsi
	movl	$2, %edi
	movb	$1, %al
	addq	$32, %rbp
	addq	$8, %rbx
	call	__printf_chk@PLT
	movsd	-24(%rbp), %xmm0
	movq	%r12, %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	movsd	-16(%rbp), %xmm0
	movsd	-8(%rbx), %xmm1
	movb	$2, %al
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	cmpq	%r13, %rbp
	jne	.L25
	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
.LFE4892:
	.size	_Z11printResultPd, .-_Z11printResultPd
	.section	.rodata.str1.1
.LC13:
	.string	"[epoch %d ]\n"
.LC14:
	.string	"[done training]\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4893:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$8, %ecx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$312, %rsp
	.cfi_def_cfa_offset 368
	movq	%fs:40, %rax
	movq	%rax, 296(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rdi
	leaq	24(%rsp), %r12
	leaq	296(%rsp), %rdx
	rep stosl
	leaq	56(%rsp), %rax
	movq	%rax, 8(%rsp)
.L29:
	movq	$0x000000000, (%rax)
	addq	$48, %rax
	movq	$0x000000000, -40(%rax)
	movq	$0x000000000, -32(%rax)
	movq	$0x000000000, -24(%rax)
	movq	$0x000000000, -16(%rax)
	cmpq	%rdx, %rax
	jne	.L29
	movq	8(%rsp), %rdi
	leaq	TRAINING_DATA(%rip), %rbx
	xorl	%ebp, %ebp
	movq	%rbx, %r13
	call	_Z10setNeuronsP6neuron
.L30:
	movq	8(%rsp), %rsi
	movq	%r13, %rdi
	addq	$32, %r13
	call	_Z11forwardPropPdP6neuron
	movsd	272(%rsp), %xmm0
	movsd	%xmm0, (%r12,%rbp,8)
	incq	%rbp
	cmpq	$4, %rbp
	jne	.L30
	movq	%r12, %rdi
	movl	$100, %r14d
	call	_Z11printResultPd
.L31:
	xorl	%edx, %edx
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%r13d, %r13d
	leaq	128(%rbx), %r15
.L34:
	movq	%rbx, %rbp
.L33:
	movq	8(%rsp), %rsi
	movq	%rbp, %rdi
	call	_Z11forwardPropPdP6neuron
	movsd	16(%rbp), %xmm0
	movq	8(%rsp), %rdi
	call	_Z13backpropErrordP6neuron
	testl	%r13d, %r13d
	jne	.L32
	movq	8(%rsp), %rdi
	call	_Z17printTrainingDataP6neuron
.L32:
	addq	$32, %rbp
	cmpq	%r15, %rbp
	jne	.L33
	incl	%r13d
	cmpl	$100, %r13d
	jne	.L34
	decl	%r14d
	jne	.L31
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	call	__printf_chk@PLT
.L36:
	movq	8(%rsp), %rsi
	movq	%rbx, %rdi
	addq	$32, %rbx
	call	_Z11forwardPropPdP6neuron
	movsd	272(%rsp), %xmm0
	movsd	%xmm0, (%r12,%rbp,8)
	incq	%rbp
	cmpq	$4, %rbp
	jne	.L36
	movq	%r12, %rdi
	call	_Z11printResultPd
	movq	296(%rsp), %rax
	subq	%fs:40, %rax
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	addq	$312, %rsp
	.cfi_def_cfa_offset 56
	movl	$1, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4893:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4922:
	.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
.LFE4922:
	.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
	.globl	TRAINING_DATA
	.data
	.align 32
	.type	TRAINING_DATA, @object
	.size	TRAINING_DATA, 128
TRAINING_DATA:
	.long	0
	.long	0
	.long	0
	.long	0
	.long	0
	.long	0
	.zero	8
	.long	0
	.long	0
	.long	0
	.long	1072693248
	.long	0
	.long	1072693248
	.zero	8
	.long	0
	.long	1072693248
	.long	0
	.long	0
	.long	0
	.long	1072693248
	.zero	8
	.long	0
	.long	1072693248
	.long	0
	.long	1072693248
	.long	0
	.long	0
	.zero	8
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1072693248
	.align 8
.LC2:
	.long	-1717986918
	.long	1072273817
	.align 8
.LC3:
	.long	-4194304
	.long	1105199103
	.align 8
.LC4:
	.long	0
	.long	1071644672
	.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:

/* 
 * CPU version of BackPropagation Neural Network written in CUDA. One can change the extension .cu to .c 
 * and compile the program with C compiler. 
 * 
 * This program is a rework of Source code for Neural Networks w/ JAVA (Tutorial 09) - Backpropagation 01
 * from http://zaneacademy.com
 * 
 * Author - Waylon Luo
 * Date - April 23, 2020 
 *
 */

#include <stdio.h>
#include <time.h>
#include <hip/hip_runtime.h>
#include <cassert>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>

#define LEARNING_RATE 0.80 
#define NUMB_OF_EPOCHS 100
#define TD_X 4 // training data in x- dimension
#define TD_Y 2 // training data in y- dimension
#define TD_Z 2 // training data in z- dimension   

double rand_double();
double TRAINING_DATA[TD_X][TD_Y][TD_Z] = {{{0,0},{0}},
					          	 {{0,1},{1}},
					          	 {{1,0},{1}},
					          	 {{1,1},{0}}}; 

#include "Neuron.cu"

int main(void){
 
 	double result[] = {0, 0, 0, 0}; 
 	// declare and initialize neurons 
	struct neuron neurons[5]; 
	setNeurons(neurons);

	// forward propagation before the training
	for(int i = 0; i < TD_X; i++) {   // TD_X - Traning Data Dimension X 
		forwardProp(TRAINING_DATA[i][0], neurons);
		result[i] = neurons[4].output; // get output
	}
	printResult(result); 

	// training 100 * 100 = 10,000 trainings 
	for(int x = 0; x < 100; x++){
		for(int i = 0; i < NUMB_OF_EPOCHS; i++) {   
			if(i%100 == 0) {
				printf("[epoch %d ]\n", i);
			}
			for(int j = 0; j < TD_X; j++) {  // TD_X - Traning Data Dimension X 
				forwardProp(TRAINING_DATA[j][0], neurons);
				backpropError(TRAINING_DATA[j][1][0], neurons);		
				if(i%100 == 0) printTrainingData(neurons); 
			}
		}
	}
	printf("[done training]\n");

	// forward propagation after the training
	for(int i = 0; i < TD_X; i++) {
		forwardProp(TRAINING_DATA[i][0], neurons);
		result[i] = neurons[4].output; // get output
	}
	printResult(result); 

	return(1);
}
	.text
	.file	"BackPropagation.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z23applyActivationFunctiond
.LCPI0_0:
	.quad	0x8000000000000000              # double -0
	.quad	0x8000000000000000              # double -0
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI0_1:
	.quad	0x3ff0000000000000              # double 1
	.text
	.globl	_Z23applyActivationFunctiond
	.type	_Z23applyActivationFunctiond,@function
_Z23applyActivationFunctiond:           # @_Z23applyActivationFunctiond
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorpd	.LCPI0_0(%rip), %xmm0
	callq	exp
	movsd	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	divsd	%xmm0, %xmm1
	movapd	%xmm1, %xmm0
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z23applyActivationFunctiond, .Lfunc_end0-_Z23applyActivationFunctiond
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z10derivatived
.LCPI1_0:
	.quad	0x3ff0000000000000              # double 1
	.text
	.globl	_Z10derivatived
	.type	_Z10derivatived,@function
_Z10derivatived:                        # @_Z10derivatived
	.cfi_startproc
# %bb.0:
	movsd	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	mulsd	%xmm1, %xmm0
	retq
.Lfunc_end1:
	.size	_Z10derivatived, .Lfunc_end1-_Z10derivatived
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z11forwardPropPdP6neuron
.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	_Z11forwardPropPdP6neuron
	.type	_Z11forwardPropPdP6neuron,@function
_Z11forwardPropPdP6neuron:              # @_Z11forwardPropPdP6neuron
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	xorl	%r15d, %r15d
	movq	%rsi, %r12
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	movl	40(%r12), %eax
	cmpl	$2, %eax
	je	.LBB2_6
# %bb.2:                                #   in Loop: Header=BB2_1 Depth=1
	cmpl	$1, %eax
	je	.LBB2_5
# %bb.3:                                #   in Loop: Header=BB2_1 Depth=1
	testl	%eax, %eax
	jne	.LBB2_9
# %bb.4:                                #   in Loop: Header=BB2_1 Depth=1
	movsd	(%r14,%r15,8), %xmm1            # xmm1 = mem[0],zero
	jmp	.LBB2_8
.LBB2_5:                                #   in Loop: Header=BB2_1 Depth=1
	movsd	8(%r12), %xmm1                  # xmm1 = mem[0],zero
	movsd	16(%r12), %xmm0                 # xmm0 = mem[0],zero
	mulsd	24(%rbx), %xmm1
	addsd	(%r12), %xmm1
	mulsd	72(%rbx), %xmm0
	jmp	.LBB2_7
.LBB2_6:                                #   in Loop: Header=BB2_1 Depth=1
	movsd	8(%r12), %xmm1                  # xmm1 = mem[0],zero
	movsd	16(%r12), %xmm0                 # xmm0 = mem[0],zero
	mulsd	120(%rbx), %xmm1
	addsd	(%r12), %xmm1
	mulsd	168(%rbx), %xmm0
.LBB2_7:                                # %.sink.split
                                        #   in Loop: Header=BB2_1 Depth=1
	addsd	%xmm1, %xmm0
	xorpd	.LCPI2_0(%rip), %xmm0
	callq	exp
	movsd	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	divsd	%xmm0, %xmm1
.LBB2_8:                                # %.sink.split
                                        #   in Loop: Header=BB2_1 Depth=1
	movsd	%xmm1, 24(%r12)
.LBB2_9:                                #   in Loop: Header=BB2_1 Depth=1
	incq	%r15
	addq	$48, %r12
	cmpq	$8, %r15
	jne	.LBB2_1
# %bb.10:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z11forwardPropPdP6neuron, .Lfunc_end2-_Z11forwardPropPdP6neuron
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z13backpropErrordP6neuron
.LCPI3_0:
	.quad	0x3ff0000000000000              # double 1
.LCPI3_1:
	.quad	0x3fe999999999999a              # double 0.80000000000000004
	.text
	.globl	_Z13backpropErrordP6neuron
	.type	_Z13backpropErrordP6neuron,@function
_Z13backpropErrordP6neuron:             # @_Z13backpropErrordP6neuron
	.cfi_startproc
# %bb.0:
	movsd	216(%rdi), %xmm3                # xmm3 = mem[0],zero
	subsd	%xmm3, %xmm0
	movsd	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero
	movapd	%xmm1, %xmm2
	subsd	%xmm3, %xmm2
	mulsd	%xmm3, %xmm2
	mulsd	%xmm0, %xmm2
	movsd	%xmm2, 224(%rdi)
	movsd	.LCPI3_1(%rip), %xmm0           # xmm0 = mem[0],zero
	movapd	%xmm2, %xmm5
	mulsd	%xmm0, %xmm5
	movsd	192(%rdi), %xmm3                # xmm3 = mem[0],zero
	addsd	%xmm5, %xmm3
	movsd	%xmm3, 192(%rdi)
	movsd	120(%rdi), %xmm4                # xmm4 = mem[0],zero
	movapd	%xmm5, %xmm3
	mulsd	%xmm4, %xmm3
	addsd	200(%rdi), %xmm3
	movsd	%xmm3, 200(%rdi)
	movsd	168(%rdi), %xmm6                # xmm6 = mem[0],zero
	mulsd	%xmm6, %xmm5
	addsd	208(%rdi), %xmm5
	movsd	%xmm5, 208(%rdi)
	mulsd	%xmm2, %xmm5
	movapd	%xmm1, %xmm7
	subsd	%xmm6, %xmm7
	mulsd	%xmm6, %xmm7
	mulsd	%xmm5, %xmm7
	movsd	%xmm7, 176(%rdi)
	mulsd	%xmm0, %xmm7
	movsd	144(%rdi), %xmm5                # xmm5 = mem[0],zero
	addsd	%xmm7, %xmm5
	movsd	%xmm5, 144(%rdi)
	movsd	24(%rdi), %xmm5                 # xmm5 = mem[0],zero
	movsd	72(%rdi), %xmm6                 # xmm6 = mem[0],zero
	movapd	%xmm7, %xmm8
	mulsd	%xmm5, %xmm8
	addsd	152(%rdi), %xmm8
	movsd	%xmm8, 152(%rdi)
	mulsd	%xmm6, %xmm7
	addsd	160(%rdi), %xmm7
	movsd	%xmm7, 160(%rdi)
	mulsd	%xmm2, %xmm3
	subsd	%xmm4, %xmm1
	mulsd	%xmm4, %xmm1
	mulsd	%xmm3, %xmm1
	movsd	%xmm1, 128(%rdi)
	mulsd	%xmm0, %xmm1
	movsd	96(%rdi), %xmm0                 # xmm0 = mem[0],zero
	addsd	%xmm1, %xmm0
	movsd	%xmm0, 96(%rdi)
	mulsd	%xmm1, %xmm5
	addsd	104(%rdi), %xmm5
	movsd	%xmm5, 104(%rdi)
	mulsd	%xmm6, %xmm1
	addsd	112(%rdi), %xmm1
	movsd	%xmm1, 112(%rdi)
	retq
.Lfunc_end3:
	.size	_Z13backpropErrordP6neuron, .Lfunc_end3-_Z13backpropErrordP6neuron
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z10setNeuronsP6neuron
.LCPI4_0:
	.quad	0x41dfffffffc00000              # double 2147483647
.LCPI4_1:
	.quad	0x3fe0000000000000              # double 0.5
	.text
	.globl	_Z10setNeuronsP6neuron
	.type	_Z10setNeuronsP6neuron,@function
_Z10setNeuronsP6neuron:                 # @_Z10setNeuronsP6neuron
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.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 %rbp, -16
	movq	%rdi, %rbx
	xorl	%r14d, %r14d
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movb	$1, %bpl
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	leaq	(%r14,%r14,2), %r14
	shlq	$4, %r14
	movsd	%xmm1, (%rbx,%r14)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 8(%rbx,%r14)
	callq	rand
	movsd	.LCPI4_0(%rip), %xmm3           # xmm3 = mem[0],zero
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm3, %xmm0
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 16(%rbx,%r14)
	movl	$0, 40(%rbx,%r14)
	movl	$1, %r14d
	testb	$1, %bpl
	movl	$0, %ebp
	jne	.LBB4_1
# %bb.2:                                # %.preheader.preheader
	xorl	%r14d, %r14d
.LBB4_3:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	.LCPI4_0(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm1, %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 96(%rbx,%r14)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 104(%rbx,%r14)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 112(%rbx,%r14)
	movl	$1, 136(%rbx,%r14)
	addq	$48, %r14
	cmpq	$96, %r14
	jne	.LBB4_3
# %bb.4:
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	.LCPI4_0(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm1, %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 192(%rbx)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 200(%rbx)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 208(%rbx)
	movl	$2, 232(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z10setNeuronsP6neuron, .Lfunc_end4-_Z10setNeuronsP6neuron
	.cfi_endproc
                                        # -- End function
	.globl	_Z17printTrainingDataP6neuron   # -- Begin function _Z17printTrainingDataP6neuron
	.type	_Z17printTrainingDataP6neuron,@function
_Z17printTrainingDataP6neuron:          # @_Z17printTrainingDataP6neuron
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movsd	24(%rdi), %xmm0                 # xmm0 = mem[0],zero
	movsd	72(%rdi), %xmm1                 # xmm1 = mem[0],zero
	movl	$.L.str, %edi
	movb	$2, %al
	callq	printf
	movsd	96(%rbx), %xmm2                 # xmm2 = mem[0],zero
	movsd	104(%rbx), %xmm0                # xmm0 = mem[0],zero
	movsd	112(%rbx), %xmm1                # xmm1 = mem[0],zero
	movsd	120(%rbx), %xmm3                # xmm3 = mem[0],zero
	movl	$.L.str.1, %edi
	movb	$4, %al
	callq	printf
	movsd	144(%rbx), %xmm2                # xmm2 = mem[0],zero
	movsd	152(%rbx), %xmm0                # xmm0 = mem[0],zero
	movsd	160(%rbx), %xmm1                # xmm1 = mem[0],zero
	movsd	168(%rbx), %xmm3                # xmm3 = mem[0],zero
	movl	$.L.str.1, %edi
	movb	$4, %al
	callq	printf
	movsd	192(%rbx), %xmm2                # xmm2 = mem[0],zero
	movsd	200(%rbx), %xmm0                # xmm0 = mem[0],zero
	movsd	208(%rbx), %xmm1                # xmm1 = mem[0],zero
	movsd	216(%rbx), %xmm3                # xmm3 = mem[0],zero
	movl	$.L.str.2, %edi
	movb	$4, %al
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.Lfunc_end5:
	.size	_Z17printTrainingDataP6neuron, .Lfunc_end5-_Z17printTrainingDataP6neuron
	.cfi_endproc
                                        # -- End function
	.globl	_Z11printResultPd               # -- Begin function _Z11printResultPd
	.type	_Z11printResultPd,@function
_Z11printResultPd:                      # @_Z11printResultPd
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	xorl	%r14d, %r14d
.LBB6_1:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movsd	TRAINING_DATA(,%r14,4), %xmm0   # xmm0 = mem[0],zero
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movsd	TRAINING_DATA+8(,%r14,4), %xmm0 # xmm0 = mem[0],zero
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movsd	TRAINING_DATA+16(,%r14,4), %xmm0 # xmm0 = mem[0],zero
	movsd	(%rbx,%r14), %xmm1              # xmm1 = mem[0],zero
	movl	$.L.str.6, %edi
	movb	$2, %al
	callq	printf
	addq	$8, %r14
	cmpq	$32, %r14
	jne	.LBB6_1
# %bb.2:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z11printResultPd, .Lfunc_end6-_Z11printResultPd
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$272, %rsp                      # imm = 0x110
	.cfi_def_cfa_offset 320
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorps	%xmm0, %xmm0
	movaps	%xmm0, 16(%rsp)
	movaps	%xmm0, (%rsp)
	xorl	%eax, %eax
.LBB7_1:                                # =>This Inner Loop Header: Depth=1
	movaps	%xmm0, 48(%rsp,%rax)
	movaps	%xmm0, 32(%rsp,%rax)
	movq	$0, 64(%rsp,%rax)
	addq	$48, %rax
	cmpq	$240, %rax
	jne	.LBB7_1
# %bb.2:
	leaq	32(%rsp), %rbx
	movq	%rbx, %rdi
	callq	_Z10setNeuronsP6neuron
	movl	$TRAINING_DATA, %r14d
	xorl	%r15d, %r15d
.LBB7_3:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	_Z11forwardPropPdP6neuron
	movsd	248(%rsp), %xmm0                # xmm0 = mem[0],zero
	movsd	%xmm0, (%rsp,%r15,8)
	incq	%r15
	addq	$32, %r14
	cmpq	$4, %r15
	jne	.LBB7_3
# %bb.4:
	movq	%rsp, %rdi
	callq	_Z11printResultPd
	leaq	32(%rsp), %rbx
	xorl	%ebp, %ebp
.LBB7_5:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_6 Depth 2
                                        #       Child Loop BB7_8 Depth 3
	xorl	%r15d, %r15d
.LBB7_6:                                #   Parent Loop BB7_5 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB7_8 Depth 3
	testl	%r15d, %r15d
	jne	.LBB7_7
# %bb.16:                               #   in Loop: Header=BB7_6 Depth=2
	movl	$.L.str.7, %edi
	xorl	%esi, %esi
	xorl	%eax, %eax
	callq	printf
.LBB7_7:                                # %.preheader41
                                        #   in Loop: Header=BB7_6 Depth=2
	xorl	%r12d, %r12d
.LBB7_8:                                #   Parent Loop BB7_5 Depth=1
                                        #     Parent Loop BB7_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	leaq	TRAINING_DATA(%r12), %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	_Z11forwardPropPdP6neuron
	movsd	16(%r14), %xmm0                 # xmm0 = mem[0],zero
	movq	%rbx, %rdi
	callq	_Z13backpropErrordP6neuron
	testl	%r15d, %r15d
	jne	.LBB7_10
# %bb.9:                                #   in Loop: Header=BB7_8 Depth=3
	movq	%rbx, %rdi
	callq	_Z17printTrainingDataP6neuron
.LBB7_10:                               #   in Loop: Header=BB7_8 Depth=3
	addq	$32, %r12
	cmpq	$128, %r12
	jne	.LBB7_8
# %bb.11:                               #   in Loop: Header=BB7_6 Depth=2
	incl	%r15d
	cmpl	$100, %r15d
	jne	.LBB7_6
# %bb.12:                               #   in Loop: Header=BB7_5 Depth=1
	incl	%ebp
	cmpl	$100, %ebp
	jne	.LBB7_5
# %bb.13:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$TRAINING_DATA, %ebx
	xorl	%r15d, %r15d
	leaq	32(%rsp), %r14
.LBB7_14:                               # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_Z11forwardPropPdP6neuron
	movsd	248(%rsp), %xmm0                # xmm0 = mem[0],zero
	movsd	%xmm0, (%rsp,%r15,8)
	incq	%r15
	addq	$32, %rbx
	cmpq	$4, %r15
	jne	.LBB7_14
# %bb.15:
	movq	%rsp, %rdi
	callq	_Z11printResultPd
	movl	$1, %eax
	addq	$272, %rsp                      # imm = 0x110
	.cfi_def_cfa_offset 48
	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_end7:
	.size	main, .Lfunc_end7-main
	.cfi_endproc
                                        # -- End function
	.type	TRAINING_DATA,@object           # @TRAINING_DATA
	.data
	.globl	TRAINING_DATA
	.p2align	4, 0x0
TRAINING_DATA:
	.zero	32
	.quad	0x0000000000000000              # double 0
	.quad	0x3ff0000000000000              # double 1
	.quad	0x3ff0000000000000              # double 1
	.quad	0x0000000000000000              # double 0
	.quad	0x3ff0000000000000              # double 1
	.quad	0x0000000000000000              # double 0
	.quad	0x3ff0000000000000              # double 1
	.quad	0x0000000000000000              # double 0
	.quad	0x3ff0000000000000              # double 1
	.quad	0x3ff0000000000000              # double 1
	.zero	16
	.size	TRAINING_DATA, 128

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"[(I: %.2f), (I: %.2f), "
	.size	.L.str, 24

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"(H: %.2f, %.2f, %.2f, %.5f), "
	.size	.L.str.1, 30

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"(O: %.2f, %.2f, %.2f, %.5f)]\n "
	.size	.L.str.2, 31

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"    %.5f    |"
	.size	.L.str.5, 14

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"    %.5f    |   %.5f   \n"
	.size	.L.str.6, 25

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"[epoch %d ]\n"
	.size	.L.str.7, 13

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"    Input 1    |    Input 2    | Target Result |  Result    "
	.size	.Lstr, 61

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"-------------------------------------------------------------"
	.size	.Lstr.1, 62

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"[done training]"
	.size	.Lstr.2, 16

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym TRAINING_DATA
	.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
