// File: /workspace/github_cpp_makefile_star2_O3/wrighteagle2d[P]wrighteaglebase/Debug/../src/Net.cpp
// Function: Net::TrainOnFile(char const*)
void Net::TrainOnFile(const char *fname) {
  if (mUnits == 0)
    return;
  FILE *fp;
  if ((fp = fopen(fname, "r")) == 0) {
    perror("BPN::TrainOnFile(char *fname)");
    exit(1);
  }
  int patterns;
  int input_size;
  int desire_size;
  real **input;
  real **desire;

  SCAN_PARAMS(patterns, input_size, desire_size)

  input = new real *[patterns];
  desire = new real *[patterns];
  for (int i = 0; i < patterns; ++i) {
    input[i] = new real[input_size];
    desire[i] = new real[desire_size];
  }

  SCAN_TRAIN(patterns, input_size, desire_size, input, desire)

  FILE *log_file = 0;
  if (mLogName != 0) {
    log_file = fopen(mLogName, "w");
    if (log_file == 0) {
      perror("fopen(mLogName)");
      exit(1);
    }
  }

  int epochs = 0;
  while (epochs <= mMaxEpochs) {
    ++epochs;
    real error = 0.0;
    for (int p = 0; p < patterns; ++p) {
      error += Train(input[p], desire[p]);
    }
    if (mLogName) {
      fprintf(log_file, "%d %f\n", epochs, error);
    }
    if (error < mDesiredError) {
      break;
    }
  }
  if (mLogName != 0) {
    fclose(log_file);
  }

  fclose(fp);
  for (int i = 0; i < patterns; ++i) {
    delete[] input[i];
    delete[] desire[i];
  }
  delete[] input;
  delete[] desire;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpq $0x0, 0x8(%rdi)
je 0x37507
movq %rdi, %r15
leaq 0x362d8(%rip), %rax     # 0x6d560
movq %rsi, %rdi
movq %rax, %rsi
callq 0x95a0
testq %rax, %rax
je 0x37516
movq %rax, %r12
leaq 0x338d7(%rip), %rsi     # 0x6ab7d
leaq -0x2c(%rbp), %rbx
leaq -0x40(%rbp), %rcx
leaq -0x3c(%rbp), %r8
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x9930
movslq (%rbx), %rbx
leaq (,%rbx,8), %r14
testq %rbx, %rbx
movq $-0x1, %r13
cmovsq %r13, %r14
movq %r14, %rdi
callq 0x9050
movq %rax, -0x48(%rbp)
movq %r14, %rdi
callq 0x9050
movq %rax, -0x58(%rbp)
testq %rbx, %rbx
jle 0x373ed
movq %rbx, %r14
movslq -0x40(%rbp), %rax
leaq (,%rax,8), %rdx
testq %rax, %rax
cmovsq %r13, %rdx
movq %rdx, -0x38(%rbp)
movslq -0x3c(%rbp), %rax
leaq (,%rax,8), %rdx
testq %rax, %rax
cmovsq %r13, %rdx
movq %rdx, -0x50(%rbp)
xorl %ebx, %ebx
movq -0x58(%rbp), %r13
movq -0x38(%rbp), %rdi
callq 0x9050
movq -0x48(%rbp), %rcx
movq %rax, (%rcx,%rbx,8)
movq -0x50(%rbp), %rdi
callq 0x9050
movq %rax, (%r13,%rbx,8)
incq %rbx
cmpq %rbx, %r14
jne 0x37330
testl %r14d, %r14d
jle 0x373ed
leaq 0x35cf6(%rip), %r13     # 0x6d05d
movq $0x0, -0x38(%rbp)
cmpl $0x0, -0x40(%rbp)
jle 0x373a4
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rbx
xorl %r14d, %r14d
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x9930
incq %r14
movslq -0x40(%rbp), %rax
addq $0x8, %rbx
cmpq %rax, %r14
jl 0x37384
cmpl $0x0, -0x3c(%rbp)
jle 0x373d9
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rbx
xorl %r14d, %r14d
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x9930
incq %r14
movslq -0x3c(%rbp), %rax
addq $0x8, %rbx
cmpq %rax, %r14
jl 0x373b9
movq -0x38(%rbp), %rdx
incq %rdx
movslq -0x2c(%rbp), %rax
movq %rdx, -0x38(%rbp)
cmpq %rax, %rdx
jl 0x3736f
movq 0x58(%r15), %rdi
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x37416
leaq 0x3506c(%rip), %rsi     # 0x6c46b
callq 0x95a0
movq %rax, -0x50(%rbp)
testq %rax, %rax
movq -0x48(%rbp), %r14
jne 0x37422
callq 0x9ed5
movq $0x0, -0x50(%rbp)
movq -0x48(%rbp), %r14
movq -0x58(%rbp), %r13
cmpl 0x50(%r15), %ebx
jg 0x374ab
movq %rbx, -0x48(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x37468
xorps %xmm1, %xmm1
xorl %ebx, %ebx
movsd %xmm1, -0x38(%rbp)
movq (%r14,%rbx,8), %rsi
movq (%r13,%rbx,8), %rdx
movq %r15, %rdi
callq 0x36efa
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
incq %rbx
movslq -0x2c(%rbp), %rax
cmpq %rax, %rbx
jl 0x3743b
jmp 0x3746c
xorpd %xmm1, %xmm1
movq -0x48(%rbp), %rbx
incl %ebx
cmpq $0x0, 0x58(%r15)
je 0x3749b
movq -0x50(%rbp), %rdi
leaq 0x33712(%rip), %rsi     # 0x6ab96
movl %ebx, %edx
movapd %xmm1, %xmm0
movb $0x1, %al
movsd %xmm1, -0x38(%rbp)
callq 0x96d0
movsd -0x38(%rbp), %xmm1
movsd 0x48(%r15), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x37426
cmpq $0x0, 0x58(%r15)
je 0x374bb
movq -0x50(%rbp), %rdi
callq 0x94b0
movq %r12, %rdi
callq 0x94b0
cmpl $0x0, -0x2c(%rbp)
movq -0x58(%rbp), %r15
jle 0x374f7
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
testq %rdi, %rdi
je 0x374dd
callq 0x9630
movq (%r15,%rbx,8), %rdi
testq %rdi, %rdi
je 0x374eb
callq 0x9630
incq %rbx
movslq -0x2c(%rbp), %rax
cmpq %rax, %rbx
jl 0x374cf
movq %r14, %rdi
callq 0x9630
movq %r15, %rdi
callq 0x9630
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x9eed
nop