// File: /workspace/github_cpp_makefile_star2_O3/ghulette[P]neural-net-openmp/neuralnet.cpp
// Function: NeuralNet::NeuralNet(int, int, int)
NeuralNet::NeuralNet(int n_inputs, int n_hidden, int n_outputs) {
  num_inputs = n_inputs;
  num_hidden = n_hidden;
  num_outputs = n_outputs;
  
  hidden_values = new double[num_hidden];
  hidden_weight_deltas = new double[num_hidden];
  hidden_weights_buffer = new double[num_hidden * num_inputs];
  hidden_weights = new double*[num_hidden];
  
  #pragma omp parallel for
  for(int i=0; i < num_hidden; i++) {
    hidden_weights[i] = hidden_weights_buffer + (i * num_inputs);
    for(int j=0; j < num_inputs; j++) {
      hidden_weights[i][j] = rand_weight();
    }
  }
  
  output_values = new double[num_outputs];
  output_weight_deltas = new double[num_outputs];
  output_weights_buffer = new double[num_outputs * num_hidden];
  output_weights = new double*[num_outputs];
  
  #pragma omp parallel for
  for(int i=0; i < num_outputs; i++) {
    output_weights[i] = output_weights_buffer + (i * num_hidden);
    for(int j=0; j < num_hidden; j++) {
      output_weights[i][j] = rand_weight();
    }
  }
  
#ifdef _OPENMP
#pragma omp parallel 
    {
#pragma omp single
    std::cout << "Using OpenMP with " << omp_get_num_threads() 
              << " threads" << std::endl;
    }
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %rbx
movl %esi, (%rdi)
movl %edx, 0x4(%rdi)
movl %ecx, 0x8(%rdi)
movl %edx, %r12d
shlq $0x3, %r12
testl %edx, %edx
movq $-0x1, %r13
cmovsq %r13, %r12
movq %r12, %rdi
callq 0x2030
movq %rax, 0x28(%rbx)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x20(%rbx)
movl %r14d, %eax
imull %r15d, %eax
leaq (,%rax,8), %rdi
testl %eax, %eax
cmovsq %r13, %rdi
callq 0x2030
movq %rax, 0x18(%rbx)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x10(%rbx)
testl %r14d, %r14d
jle 0x3d50
xorl %r12d, %r12d
movl %r12d, %eax
imull %r15d, %eax
cltq
shlq $0x3, %rax
addq 0x18(%rbx), %rax
movq 0x10(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
testl %r15d, %r15d
jle 0x3d42
xorl %r14d, %r14d
callq 0x2080
movsd 0x155a(%rip), %xmm1     # 0x5268
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movsd 0x12e7(%rip), %xmm1     # 0x5008
addsd %xmm1, %xmm0
movq 0x10(%rbx), %rax
movq (%rax,%r12,8), %rax
movsd %xmm0, (%rax,%r14,8)
incq %r14
movslq (%rbx), %r15
cmpq %r15, %r14
jl 0x3d01
movl 0x4(%rbx), %r14d
incq %r12
movslq %r14d, %rax
cmpq %rax, %r12
jl 0x3ce0
movl 0x8(%rbx), %ebp
movslq %ebp, %r12
leaq (,%r12,8), %r15
testl %r12d, %r12d
cmovsq %r13, %r15
movq %r15, %rdi
callq 0x2030
movq %rax, 0x48(%rbx)
movq %r15, %rdi
callq 0x2030
movq %rax, 0x40(%rbx)
movl %r12d, %eax
imull %r14d, %eax
cltq
leaq (,%rax,8), %rdi
testl %eax, %eax
cmovsq %r13, %rdi
callq 0x2030
movq %rax, 0x38(%rbx)
movq %r15, %rdi
callq 0x2030
movq %rax, 0x30(%rbx)
testl %r12d, %r12d
jle 0x3e1b
xorl %r15d, %r15d
movl %r15d, %eax
imull %r14d, %eax
cltq
shlq $0x3, %rax
addq 0x38(%rbx), %rax
movq 0x30(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testl %r14d, %r14d
jle 0x3e10
xorl %r12d, %r12d
callq 0x2080
movsd 0x148c(%rip), %xmm1     # 0x5268
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movsd 0x1219(%rip), %xmm1     # 0x5008
addsd %xmm1, %xmm0
movq 0x30(%rbx), %rax
movq (%rax,%r15,8), %rax
movsd %xmm0, (%rax,%r12,8)
incq %r12
movslq 0x4(%rbx), %r14
cmpq %r14, %r12
jl 0x3dcf
movl 0x8(%rbx), %ebp
incq %r15
movslq %ebp, %rax
cmpq %rax, %r15
jl 0x3dae
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq