// File: /workspace/github_cpp_makefile_star2_O1/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 %esi, %ebp
movq %rdi, %rbx
movl %esi, (%rdi)
movl %edx, 0x4(%rdi)
movl %ecx, 0x8(%rdi)
movslq %edx, %r12
leaq (,%r12,8), %r14
testl %r12d, %r12d
movq $-0x1, %r15
cmovsq %r15, %r14
movq %r14, %rdi
callq 0x2030
movq %rax, 0x28(%rbx)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x20(%rbx)
imull %ebp, %r12d
movslq %r12d, %rax
leaq (,%rax,8), %rdi
testl %eax, %eax
cmovsq %r15, %rdi
callq 0x2030
movq %rax, 0x18(%rbx)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x10(%rbx)
movl 0x4(%rbx), %r12d
testl %r12d, %r12d
jle 0x3d42
xorl %r14d, %r14d
movslq (%rbx), %rax
movslq %r14d, %rcx
imulq %rax, %rcx
shlq $0x3, %rcx
addq 0x18(%rbx), %rcx
movq 0x10(%rbx), %rax
movq %rcx, (%rax,%r14,8)
cmpl $0x0, (%rbx)
jle 0x3d36
xorl %r12d, %r12d
callq 0x2080
movsd 0x1562(%rip), %xmm1     # 0x5268
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movsd 0x12ef(%rip), %xmm1     # 0x5008
addsd %xmm1, %xmm0
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r12,8)
incq %r12
movslq (%rbx), %rax
cmpq %rax, %r12
jl 0x3cf9
incq %r14
movslq 0x4(%rbx), %r12
cmpq %r12, %r14
jl 0x3cd7
movslq 0x8(%rbx), %r13
leaq (,%r13,8), %r14
testq %r13, %r13
cmovsq %r15, %r14
movq %r14, %rdi
callq 0x2030
movq %rax, 0x48(%rbx)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x40(%rbx)
imull %r13d, %r12d
movslq %r12d, %rax
leaq (,%rax,8), %rdi
testl %eax, %eax
cmovsq %r15, %rdi
callq 0x2030
movq %rax, 0x38(%rbx)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x30(%rbx)
cmpl $0x0, 0x8(%rbx)
jle 0x3e0e
xorl %r14d, %r14d
movslq 0x4(%rbx), %rax
movslq %r14d, %rcx
imulq %rax, %rcx
shlq $0x3, %rcx
addq 0x38(%rbx), %rcx
movq 0x30(%rbx), %rax
movq %rcx, (%rax,%r14,8)
cmpl $0x0, 0x4(%rbx)
jle 0x3e02
xorl %r15d, %r15d
callq 0x2080
movsd 0x1497(%rip), %xmm1     # 0x5268
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movsd 0x1224(%rip), %xmm1     # 0x5008
addsd %xmm1, %xmm0
movq 0x30(%rbx), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movslq 0x4(%rbx), %rax
cmpq %rax, %r15
jl 0x3dc4
incq %r14
movslq 0x8(%rbx), %rax
cmpq %rax, %r14
jl 0x3da0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop