#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ backPropagation(double **, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ forwardPropagation(double **, int /*<<< orphan*/);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ testReadNeuralNetwork();
void testBackPropagation() {
  FILE *in;
  int n;
  testReadNeuralNetwork();
  in = fopen("X.txt", "r");
  fscanf(in, "%d", &n);
  double **X = (double **)malloc(n * sizeof(double *));
  for (int i = 0; i < n; i++) {
    X[i] = (double *)malloc(sizeof(double));
    fscanf(in, "%lf", &X[i][0]);
  }
  fclose(in);
  forwardPropagation(X, 0);
  in = fopen("Y.txt", "r");
  fscanf(in, "%d", &n);
  double **Y = (double **)malloc(n * sizeof(double *));
  for (int i = 0; i < n; i++) {
    Y[i] = (double *)malloc(sizeof(double));
    fscanf(in, "%lf", &Y[i][0]);
  }
  fclose(in);
  backPropagation(Y, 0);
}


x86 assembly (clang, -O0):
<testBackPropagation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1070 <testReadNeuralNetwork@plt>
lea    0xe7a(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe67(%rip),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1217 <testBackPropagation+0xa7>
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c6 <testBackPropagation+0x56>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1050 <forwardPropagation@plt>
lea    0xddd(%rip),%rdi
lea    0xdcd(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdbb(%rip),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12c3 <testBackPropagation+0x153>
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1272 <testBackPropagation+0x102>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1030 <backPropagation@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testBackPropagation>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <testReadNeuralNetwork@plt>
lea    0xe7a(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0xe6c(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    0x4(%rsp),%edi
shl    $0x3,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
cmpl   $0x0,0x4(%rsp)
jle    11fc <testBackPropagation+0x8c>
lea    0xe43(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     11d0 <testBackPropagation+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <forwardPropagation@plt>
lea    0xdfa(%rip),%rdi
lea    0xdea(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0xddd(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    0x4(%rsp),%edi
shl    $0x3,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
cmpl   $0x0,0x4(%rsp)
jle    128c <testBackPropagation+0x11c>
lea    0xdb4(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     1260 <testBackPropagation+0xf0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
xor    %esi,%esi
call   1030 <backPropagation@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"X.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [6 x i8] c"Y.txt\00"
define void @testBackPropagation() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca double**
%4 = alloca i32
%5 = alloca double**
%6 = alloca i32
%7 = call i32 (...) @testReadNeuralNetwork()
%8 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %1
%9 = load i32*, i32** %1
%10 = call i32 (i32*, i8*, ...) @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to double**
store double** %16, double*** %3
store i32 0, i32* %4
br label %17
17: ; preds = %36, %0
%18 = load i32, i32* %4
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %39
21: ; preds = %17
%22 = call i64 @malloc(i32 8)
%23 = inttoptr i64 %22 to double*
%24 = load double**, double*** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double*, double** %24, i64 %26
store double* %23, double** %27
%28 = load i32*, i32** %1
%29 = load double**, double*** %3
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double*, double** %29, i64 %31
%33 = load double*, double** %32
%34 = getelementptr inbounds double, double* %33, i64 0
%35 = call i32 (i32*, i8*, ...) @fscanf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %34)
br label %36
36: ; preds = %21
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %17
39: ; preds = %17
%40 = load i32*, i32** %1
%41 = call i32 @fclose(i32* %40)
%42 = load double**, double*** %3
%43 = call i32 @forwardPropagation(double** %42, i32 0)
%44 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %44, i32** %1
%45 = load i32*, i32** %1
%46 = call i32 (i32*, i8*, ...) @fscanf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%47 = load i32, i32* %2
%48 = sext i32 %47 to i64
%49 = mul i64 %48, 8
%50 = trunc i64 %49 to i32
%51 = call i64 @malloc(i32 %50)
%52 = inttoptr i64 %51 to double**
store double** %52, double*** %5
store i32 0, i32* %6
br label %53
53: ; preds = %72, %39
%54 = load i32, i32* %6
%55 = load i32, i32* %2
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %75
57: ; preds = %53
%58 = call i64 @malloc(i32 8)
%59 = inttoptr i64 %58 to double*
%60 = load double**, double*** %5
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double*, double** %60, i64 %62
store double* %59, double** %63
%64 = load i32*, i32** %1
%65 = load double**, double*** %5
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double*, double** %65, i64 %67
%69 = load double*, double** %68
%70 = getelementptr inbounds double, double* %69, i64 0
%71 = call i32 (i32*, i8*, ...) @fscanf(i32* %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %70)
br label %72
72: ; preds = %57
%73 = load i32, i32* %6
%74 = add nsw i32 %73, 1
store i32 %74, i32* %6
br label %53
75: ; preds = %53
%76 = load i32*, i32** %1
%77 = call i32 @fclose(i32* %76)
%78 = load double**, double*** %5
%79 = call i32 @backPropagation(double** %78, i32 0)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"X.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [6 x i8] c"Y.txt\00"
define void @testBackPropagation() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @testReadNeuralNetwork()
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = shl i32 %6, 3
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double**
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %23, %0
%13 = call i32 @fclose(i32* %4)
%14 = call i32 @forwardPropagation(double** %9, i32 0)
%15 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (i32*, i8*, ...) @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%17 = load i32, i32* %1
%18 = shl i32 %17, 3
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to double**
%21 = load i32, i32* %1
%22 = icmp sgt i32 %21, 0
br i1 %22, label %36, label %33
23: ; preds = %0, %23
%24 = phi i64 [ %29, %23 ], [ 0, %0 ]
%25 = call i64 @malloc(i32 8)
%26 = inttoptr i64 %25 to double*
%27 = getelementptr inbounds double*, double** %9, i64 %24
store double* %26, double** %27
%28 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %26)
%29 = add nuw nsw i64 %24, 1
%30 = load i32, i32* %1
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %23, label %12
33: ; preds = %36, %12
%34 = call i32 @fclose(i32* %15)
%35 = call i32 @backPropagation(double** %20, i32 0)
ret void
36: ; preds = %12, %36
%37 = phi i64 [ %42, %36 ], [ 0, %12 ]
%38 = call i64 @malloc(i32 8)
%39 = inttoptr i64 %38 to double*
%40 = getelementptr inbounds double*, double** %20, i64 %37
store double* %39, double** %40
%41 = call i32 (i32*, i8*, ...) @fscanf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %39)
%42 = add nuw nsw i64 %37, 1
%43 = load i32, i32* %1
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %42, %44
br i1 %45, label %36, label %33
}