// File: kobanium[P]Ray/src/learn/MinorizationMaximization.cpp
// Function: MinorizationMaximization()
static void
MinorizationMaximization( void )
{
  train_thread_arg_t targ[TRAIN_THREAD_NUM];
  std::thread *handle[TRAIN_THREAD_NUM];

  for (int step = 0; step <= MM_UPDATE_MAX; step++) {
    std::chrono::system_clock::time_point start = std::chrono::system_clock::now();

    InitializeSigma();

    for (int i = 0; i < TRAIN_THREAD_NUM; i++) {
      targ[i].id = i;
      targ[i].step = step;
      handle[i] = new std::thread(LearningWorker, &targ[i]);
    }

    for (int i = 0; i < TRAIN_THREAD_NUM; i++) {
      handle[i]->join();
      delete handle[i];
    }

    if (first_flag) {
      SumWin(TRAIN_THREAD_NUM);
    }
    SumSigma(TRAIN_THREAD_NUM);

    UpdateParameters(step - 1);

    OutputLearningProgress(step - 1);
    
    std::chrono::system_clock::time_point end = std::chrono::system_clock::now();
    const double elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() * 0.001;

    OutputLearningLogFile(step, all_moves.load(), elapsed_time);

    if (step % MM_UPDATE_INTERVAL == 0 || step == MM_UPDATE_MAX) {
      OutputAllParameters(step);
      EvaluateMovePrediction(step);
    }

    first_flag = false;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x0, -0xa4(%rbp)
cmpl $0xf0, -0xa4(%rbp)
jg 0x72f02
callq 0x7090
movq %rax, -0xb0(%rbp)
callq 0x73010
movl $0x0, -0xb4(%rbp)
cmpl $0x8, -0xb4(%rbp)
jge 0x72cfc
movslq -0xb4(%rbp), %rax
movl %eax, %ecx
movl %ecx, -0x60(%rbp,%rax,8)
movl -0xa4(%rbp), %ecx
movslq -0xb4(%rbp), %rax
movl %ecx, -0x5c(%rbp,%rax,8)
movl $0x8, %edi
callq 0x7550
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xf8(%rbp)
movslq -0xb4(%rbp), %rax
leaq -0x60(%rbp,%rax,8), %rax
movq %rax, -0xc0(%rbp)
leaq 0x3f4(%rip), %rsi       # 0x73090
leaq -0xc0(%rbp), %rdx
callq 0x65fc0
jmp 0x72caa
movq -0xf8(%rbp), %rcx
movslq -0xb4(%rbp), %rax
movq %rcx, -0xa0(%rbp,%rax,8)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x72c40
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
movl $0x8, %esi
callq 0x7560
jmp 0x72f0b
movl $0x0, -0xd0(%rbp)
cmpl $0x8, -0xd0(%rbp)
jge 0x72d6f
movslq -0xd0(%rbp), %rax
movq -0xa0(%rbp,%rax,8), %rdi
callq 0x7940
movslq -0xd0(%rbp), %rax
movq -0xa0(%rbp,%rax,8), %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, %rax
je 0x72d5c
movq -0x100(%rbp), %rdi
callq 0x66080
movq -0x100(%rbp), %rdi
movl $0x8, %esi
callq 0x7560
jmp 0x72d5e
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x72d06
testb $0x1, 0x74c3a(%rip)     # 0xe79b0
je 0x72d82
movl $0x8, %edi
callq 0x73320
movl $0x8, %edi
callq 0x733c0
movl -0xa4(%rbp), %edi
decl %edi
callq 0x73460
movl -0xa4(%rbp), %edi
decl %edi
callq 0x73700
callq 0x7090
movq %rax, -0xd8(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x660e0
movq %rax, -0xf0(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x660b0
movq %rax, -0xe8(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x66130
cvtsi2sd %rax, %xmm0
movsd 0x3b110(%rip), %xmm1    # 0xadf08
mulsd %xmm1, %xmm0
movsd %xmm0, -0xe0(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0x114(%rbp)
leaq 0x77b85(%rip), %rax     # 0xea99c
movq %rax, -0x8(%rbp)
movl $0x5, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
movl -0xc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x25b00
movl %eax, -0x104(%rbp)
jmp 0x72e42
movl -0x104(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x118(%rbp)
decl %eax
subl $0x2, %eax
jb 0x72e78
jmp 0x72e5d
movl -0x118(%rbp), %eax
subl $0x5, %eax
je 0x72e86
jmp 0x72e6a
movq -0x110(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x72e9c
movq -0x110(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x72e9c
movq -0x110(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x72e9c
movq %rax, %rdi
callq 0x25ac0
movl -0x114(%rbp), %edi
movl -0x14(%rbp), %esi
movsd -0xe0(%rbp), %xmm0
callq 0x811c0
movl -0xa4(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x72ed1
cmpl $0xf0, -0xa4(%rbp)
jne 0x72ee7
movl -0xa4(%rbp), %edi
callq 0x743d0
movl -0xa4(%rbp), %edi
callq 0x74d20
movb $0x0, 0x74ac2(%rip)     # 0xe79b0
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x72c15
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0xc8(%rbp), %rdi
callq 0x79b0
nopw (%rax,%rax)