// File: 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
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, 0x8(%rax)
jne 0x60e37
jmp 0x611c3
movq -0x10(%rbp), %rdi
leaq 0x647de(%rip), %rsi     # 0xc5620
callq 0xa710
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x60e67
leaq 0x61c6b(%rip), %rdi     # 0xc2ac3
callq 0xa4c0
movl $0x1, %edi
callq 0xa740
movq -0x18(%rbp), %rdi
leaq 0x61c6f(%rip), %rsi     # 0xc2ae1
leaq -0x1c(%rbp), %rdx
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
movb $0x0, %al
callq 0xab10
cmpl $0x1, %eax
jge 0x60e8c
jmp 0x60e8c
movslq -0x1c(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xa050
movq %rax, -0x30(%rbp)
movslq -0x1c(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xa050
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x60f60
movslq -0x20(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xa050
movq %rax, %rdx
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq -0x24(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xa050
movq %rax, %rdx
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x60ee5
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x6101b
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x60fbf
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movslq -0x44(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x64178(%rip), %rsi     # 0xc511c
movb $0x0, %al
callq 0xab10
cmpl $0x1, %eax
jge 0x60fb2
jmp 0x60fb2
jmp 0x60fb4
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x60f7a
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x6100b
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movslq -0x48(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x6412c(%rip), %rsi     # 0xc511c
movb $0x0, %al
callq 0xab10
cmpl $0x1, %eax
jge 0x60ffe
jmp 0x60ffe
jmp 0x61000
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x60fc6
jmp 0x6100d
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x60f67
movq -0x70(%rbp), %rax
movq $0x0, -0x50(%rbp)
cmpq $0x0, 0x58(%rax)
je 0x61065
movq -0x70(%rbp), %rax
movq 0x58(%rax), %rdi
leaq 0x6357e(%rip), %rsi     # 0xc45bb
callq 0xa710
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x61063
leaq 0x61a96(%rip), %rdi     # 0xc2aea
callq 0xa4c0
movl $0x1, %edi
callq 0xa740
jmp 0x61065
movl $0x0, -0x54(%rbp)
movq -0x70(%rbp), %rcx
movl -0x54(%rbp), %eax
cmpl 0x50(%rcx), %eax
jg 0x61112
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x610d2
movq -0x70(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x38(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
callq 0x60d90
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x61094
movq -0x70(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x610f7
movq -0x50(%rbp), %rdi
movl -0x54(%rbp), %edx
movsd -0x60(%rbp), %xmm0
leaq 0x61a0a(%rip), %rsi     # 0xc2afa
movb $0x1, %al
callq 0xa890
movq -0x70(%rbp), %rax
movsd -0x60(%rbp), %xmm1
movsd 0x48(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6110d
jmp 0x61112
jmp 0x6106c
movq -0x70(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x61126
movq -0x50(%rbp), %rdi
callq 0xa5b0
movq -0x18(%rbp), %rdi
callq 0xa5b0
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x61189
movq -0x30(%rbp), %rax
movslq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0x6115d
movq -0x78(%rbp), %rdi
callq 0xa7b0
movq -0x38(%rbp), %rax
movslq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x6117c
movq -0x80(%rbp), %rdi
callq 0xa7b0
jmp 0x6117e
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x61136
movq -0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, %rax
je 0x611a6
movq -0x88(%rbp), %rdi
callq 0xa7b0
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x611c3
movq -0x90(%rbp), %rdi
callq 0xa7b0
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)