// File: /workspace/github_cpp_makefile_star2_O2/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 0x2ed6b
movq %rdi, -0x58(%rbp)
leaq 0x2ca23(%rip), %rax     # 0x5b540
movq %rsi, %rdi
movq %rax, %rsi
callq 0x95a0
testq %rax, %rax
je 0x2ed7a
movq %rax, %r12
leaq 0x2a00e(%rip), %rsi     # 0x58b49
xorl %r15d, %r15d
leaq -0x2c(%rbp), %rbx
leaq -0x48(%rbp), %rcx
leaq -0x44(%rbp), %r8
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x9930
movslq (%rbx), %r13
leaq (,%r13,8), %r14
testq %r13, %r13
pushq $-0x1
popq %rbx
cmovsq %rbx, %r14
movq %r14, %rdi
callq 0x9050
movq %rax, -0x40(%rbp)
movq %r14, %rdi
movq %r13, %r14
callq 0x9050
movq %rax, -0x38(%rbp)
leaq -0x48(%rbp), %rax
movslq (%rax), %rax
leaq (,%rax,8), %rcx
testq %rax, %rax
cmovsq %rbx, %rcx
movq %rcx, -0x50(%rbp)
leaq -0x44(%rbp), %rax
movslq (%rax), %rax
leaq (,%rax,8), %r13
testq %rax, %rax
cmovsq %rbx, %r13
testl %r14d, %r14d
movl $0x0, %ebx
cmovgl %r14d, %ebx
cmpq %r15, %rbx
je 0x2ebee
movq -0x50(%rbp), %rdi
callq 0x9050
movq -0x40(%rbp), %rcx
movq %rax, (%rcx,%r15,8)
movq %r13, %rdi
callq 0x9050
movq -0x38(%rbp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0x2ebc3
leaq 0x2c448(%rip), %r13     # 0x5b03d
xorl %r15d, %r15d
movslq %r14d, %rax
cmpq %rax, %r15
jge 0x2ec67
xorl %ebx, %ebx
xorl %r14d, %r14d
movslq -0x48(%rbp), %rax
cmpq %rax, %r14
jge 0x2ec2f
movq -0x40(%rbp), %rax
movq (%rax,%r15,8), %rdx
addq %rbx, %rdx
movq %r12, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x9930
incq %r14
addq $0x8, %rbx
jmp 0x2ec05
xorl %ebx, %ebx
xorl %r14d, %r14d
movslq -0x44(%rbp), %rax
cmpq %rax, %r14
jge 0x2ec5e
movq -0x38(%rbp), %rax
movq (%rax,%r15,8), %rdx
addq %rbx, %rdx
movq %r12, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x9930
incq %r14
addq $0x8, %rbx
jmp 0x2ec34
incq %r15
movl -0x2c(%rbp), %r14d
jmp 0x2ebf8
movq -0x58(%rbp), %r14
movq 0x58(%r14), %rdi
xorl %r13d, %r13d
testq %rdi, %rdi
je 0x2ec97
leaq 0x2b7cd(%rip), %rsi     # 0x5a44b
callq 0x95a0
movq %rax, %r15
testq %rax, %rax
jne 0x2ec9a
leaq 0x29ec0(%rip), %rdi     # 0x58b52
jmp 0x2ed81
xorl %r15d, %r15d
cmpl 0x50(%r14), %r13d
jg 0x2ed0d
xorpd %xmm1, %xmm1
xorl %ebx, %ebx
movslq -0x2c(%rbp), %rax
cmpq %rax, %rbx
movsd %xmm1, -0x50(%rbp)
jge 0x2ecda
movq -0x40(%rbp), %rax
movq (%rax,%rbx,8), %rsi
movq -0x38(%rbp), %rax
movq (%rax,%rbx,8), %rdx
movq %r14, %rdi
callq 0x2eaae
movsd -0x50(%rbp), %xmm1
addsd %xmm0, %xmm1
incq %rbx
jmp 0x2eca6
incl %r13d
cmpq $0x0, 0x58(%r14)
je 0x2ed01
movq %r15, %rdi
leaq 0x29e74(%rip), %rsi     # 0x58b62
movl %r13d, %edx
movapd %xmm1, %xmm0
movb $0x1, %al
callq 0x96f0
movsd -0x50(%rbp), %xmm1
movsd 0x48(%r14), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2ec9a
cmpq $0x0, 0x58(%r14)
je 0x2ed1c
movq %r15, %rdi
callq 0x94c0
movq %r12, %rdi
callq 0x94c0
xorl %r15d, %r15d
movslq -0x2c(%rbp), %rax
cmpq %rax, %r15
jge 0x2ed59
movq -0x40(%rbp), %rax
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x2ed42
callq 0x9630
movq -0x38(%rbp), %rax
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x2ed54
callq 0x9630
incq %r15
jmp 0x2ed27
movq -0x40(%rbp), %rdi
callq 0x9630
movq -0x38(%rbp), %rdi
callq 0x9630
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x29daa(%rip), %rdi     # 0x58b2b
callq 0x9410
pushq $0x1
popq %rdi
callq 0x95d0