// File: /workspace/github_cpp_makefile_star2_O1/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 0x383df
movq %rdi, -0x58(%rbp)
leaq 0x37411(%rip), %rax     # 0x6f590
movq %rsi, %rdi
movq %rax, %rsi
callq 0x95a0
testq %rax, %rax
je 0x383ee
leaq 0x349f3(%rip), %rsi     # 0x6cb8d
leaq -0x2c(%rbp), %rbx
leaq -0x40(%rbp), %rcx
leaq -0x3c(%rbp), %r8
movq %rax, -0x50(%rbp)
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, -0x38(%rbp)
movq %r14, %rdi
callq 0x9050
movq %rax, %r12
testq %rbx, %rbx
jle 0x38242
movq %rbx, %r14
movslq -0x40(%rbp), %rax
leaq (,%rax,8), %r15
testq %rax, %rax
cmovsq %r13, %r15
movslq -0x3c(%rbp), %rax
movq $-0x1, %rdx
leaq (,%rax,8), %r13
testq %rax, %rax
cmovsq %rdx, %r13
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x9050
movq -0x38(%rbp), %rcx
movq %rax, (%rcx,%rbx,8)
movq %r13, %rdi
callq 0x9050
movq %rax, (%r12,%rbx,8)
incq %rbx
cmpq %rbx, %r14
jne 0x3821e
cmpl $0x0, -0x2c(%rbp)
jle 0x382d1
xorl %r15d, %r15d
movq %r12, -0x60(%rbp)
movq -0x50(%rbp), %r13
cmpl $0x0, -0x40(%rbp)
movq -0x38(%rbp), %r12
jle 0x3828e
xorl %ebx, %ebx
xorl %r14d, %r14d
movq (%r12,%r15,8), %rdx
addq %rbx, %rdx
movq %r13, %rdi
leaq 0x36e16(%rip), %rsi     # 0x6f08d
xorl %eax, %eax
callq 0x9930
incq %r14
movslq -0x40(%rbp), %rax
addq $0x8, %rbx
cmpq %rax, %r14
jl 0x38266
cmpl $0x0, -0x3c(%rbp)
movq -0x60(%rbp), %r12
jle 0x382c5
xorl %ebx, %ebx
xorl %r14d, %r14d
movq (%r12,%r15,8), %rdx
addq %rbx, %rdx
movq %r13, %rdi
leaq 0x36ddf(%rip), %rsi     # 0x6f08d
xorl %eax, %eax
callq 0x9930
incq %r14
movslq -0x3c(%rbp), %rax
addq $0x8, %rbx
cmpq %rax, %r14
jl 0x3829d
incq %r15
movslq -0x2c(%rbp), %rax
cmpq %rax, %r15
jl 0x38257
movq -0x58(%rbp), %r15
movq 0x58(%r15), %rdi
xorl %r13d, %r13d
testq %rdi, %rdi
je 0x382ff
leaq 0x361b3(%rip), %rsi     # 0x6e49b
callq 0x95a0
movq %rax, -0x48(%rbp)
testq %rax, %rax
movq -0x38(%rbp), %r14
jne 0x3830b
callq 0x9f01
movq $0x0, -0x48(%rbp)
movq -0x38(%rbp), %r14
cmpl 0x50(%r15), %r13d
jg 0x38385
cmpl $0x0, -0x2c(%rbp)
jle 0x38348
xorps %xmm1, %xmm1
xorl %ebx, %ebx
movsd %xmm1, -0x38(%rbp)
movq (%r14,%rbx,8), %rsi
movq (%r12,%rbx,8), %rdx
movq %r15, %rdi
callq 0x37df4
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
incq %rbx
movslq -0x2c(%rbp), %rax
cmpq %rax, %rbx
jl 0x3831c
jmp 0x3834c
xorpd %xmm1, %xmm1
incl %r13d
cmpq $0x0, 0x58(%r15)
je 0x38379
movq -0x48(%rbp), %rdi
leaq 0x34845(%rip), %rsi     # 0x6cba6
movl %r13d, %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 0x3830b
cmpq $0x0, 0x58(%r15)
je 0x38395
movq -0x48(%rbp), %rdi
callq 0x94b0
movq -0x50(%rbp), %rdi
callq 0x94b0
cmpl $0x0, -0x2c(%rbp)
jle 0x383cf
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
testq %rdi, %rdi
je 0x383b5
callq 0x9630
movq (%r12,%r15,8), %rdi
testq %rdi, %rdi
je 0x383c3
callq 0x9630
incq %r15
movslq -0x2c(%rbp), %rax
cmpq %rax, %r15
jl 0x383a7
movq %r14, %rdi
callq 0x9630
movq %r12, %rdi
callq 0x9630
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x9f19
nop