// File: kobanium[P]Ray/src/learn/MinorizationMaximization.cpp
// Function: ReplayMatch(game_info_t*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
static void
ReplayMatch( game_info_t *game, const std::string filename, const int id )
{
  pattern_t *pat = game->pat;
  int color = S_BLACK;
  SGF_record_t kifu;
  unsigned char *tactical_features = game->tactical_features;

  ExtractKifu(filename.c_str(), &kifu);

  for (int i = 0; i < kifu.moves; i++) {
    const int pos = GetKifuMove(&kifu, i);

    if (first_flag) {
      if (pos != PASS) {
        // 戦術的特徴
        IncrementTacticalFeatureCount(capture[id], tactical_features, pos, CAPTURE);
        IncrementTacticalFeatureCount(save_extension[id], tactical_features, pos, SAVE_EXTENSION);
        IncrementTacticalFeatureCount(atari[id], tactical_features, pos, ATARI);
        IncrementTacticalFeatureCount(extension[id], tactical_features, pos, EXTENSION);
        IncrementTacticalFeatureCount(dame[id], tactical_features, pos, DAME);
        IncrementTacticalFeatureCount(throw_in[id], tactical_features, pos, THROW_IN);
        

        if (game->moves > 1 &&
            game->record[game->moves - 1].pos != PASS) {
          const int distance = DIS(game->record[game->moves - 1].pos, pos);

          if (distance == 2) {
            previous_distance[id][0].w++;
          } else if (distance == 3) {
            previous_distance[id][1].w++;
          } else if (distance == 4) {
            previous_distance[id][2].w++;
          }
        }

        const int pat_md2 = md2_index[MD2(pat, pos)];
        const int pat_3x3 = pat3_index[Pat3(pat, pos)];
        if (md2_target[pat_md2]) {
          md2[id][pat_md2].w++;
        } else {
          pat3[id][pat_3x3].w++;
        }
      }
      
      all_moves++;
    }
    PutStone(game, pos, color);

    color = GetOppositeColor(color);
    
    SamplingFeatures(game, color, id);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4100, %rsp           # imm = 0x4100
movq %rsi, -0x4100(%rbp)
movq %rdi, %rax
movq -0x4100(%rbp), %rdi
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
addq $0x4748, %rax           # imm = 0x4748
movq %rax, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movq -0x8(%rbp), %rax
addq $0x97372, %rax          # imm = 0x97372
movq %rax, -0x40d0(%rbp)
callq 0x71d0
movq %rax, %rdi
leaq -0x40c8(%rbp), %rsi
callq 0x818f0
movl $0x0, -0x40d4(%rbp)
movl -0x40d4(%rbp), %eax
cmpl -0x40c4(%rbp), %eax
jge 0x75bcc
movl -0x40d4(%rbp), %esi
leaq -0x40c8(%rbp), %rdi
callq 0x81830
movl %eax, -0x40d8(%rbp)
testb $0x1, 0x72174(%rip)     # 0xe79b0
je 0x75b8c
cmpl $0x0, -0x40d8(%rbp)
je 0x75b7e
movslq -0x14(%rbp), %rsi
leaq 0x74ace(%rip), %rdi     # 0xea328
callq 0x792c0
movq %rax, %rdi
movq -0x40d0(%rbp), %rsi
movl -0x40d8(%rbp), %edx
xorl %ecx, %ecx
callq 0x75be0
movslq -0x14(%rbp), %rsi
leaq 0x74abf(%rip), %rdi     # 0xea340
callq 0x792c0
movq %rax, %rdi
movq -0x40d0(%rbp), %rsi
movl -0x40d8(%rbp), %edx
movl $0x1, %ecx
callq 0x75be0
movslq -0x14(%rbp), %rsi
leaq 0x74aad(%rip), %rdi     # 0xea358
callq 0x792c0
movq %rax, %rdi
movq -0x40d0(%rbp), %rsi
movl -0x40d8(%rbp), %edx
movl $0x2, %ecx
callq 0x75be0
movslq -0x14(%rbp), %rsi
leaq 0x74a9b(%rip), %rdi     # 0xea370
callq 0x792c0
movq %rax, %rdi
movq -0x40d0(%rbp), %rsi
movl -0x40d8(%rbp), %edx
movl $0x3, %ecx
callq 0x75be0
movslq -0x14(%rbp), %rsi
leaq 0x74a89(%rip), %rdi     # 0xea388
callq 0x792c0
movq %rax, %rdi
movq -0x40d0(%rbp), %rsi
movl -0x40d8(%rbp), %edx
movl $0x4, %ecx
callq 0x75be0
movslq -0x14(%rbp), %rsi
leaq 0x74a77(%rip), %rdi     # 0xea3a0
callq 0x792c0
movq %rax, %rdi
movq -0x40d0(%rbp), %rsi
movl -0x40d8(%rbp), %edx
movl $0x5, %ecx
callq 0x75be0
movq -0x8(%rbp), %rax
cmpl $0x1, 0x43b0(%rax)
jle 0x75aad
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x43b0(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
je 0x75aad
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x43b0(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rcx
leaq 0x1ab0945c(%rip), %rax  # 0x1ab7ee00
movl (%rax,%rcx,4), %eax
movslq -0x40d8(%rbp), %rdx
leaq 0x1ab0944b(%rip), %rcx  # 0x1ab7ee00
subl (%rcx,%rdx,4), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movslq %eax, %rcx
leaq 0x1ab5c8f7(%rip), %rax  # 0x1abd22c0
imulq $0x4c, %rcx, %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movq -0x8(%rbp), %rdx
movl 0x43b0(%rdx), %edx
subl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movslq 0x4(%rcx), %rdx
leaq 0x1ab0a13a(%rip), %rcx  # 0x1ab7fb30
movl (%rcx,%rdx,4), %ecx
movslq -0x40d8(%rbp), %rsi
leaq 0x1ab0a129(%rip), %rdx  # 0x1ab7fb30
subl (%rdx,%rsi,4), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40dc(%rbp)
cmpl $0x2, -0x40dc(%rbp)
jne 0x75a4b
movslq -0x14(%rbp), %rsi
leaq 0x748af(%rip), %rdi     # 0xea2e0
callq 0x792c0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x792e0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x75aab
cmpl $0x3, -0x40dc(%rbp)
jne 0x75a7a
movslq -0x14(%rbp), %rsi
leaq 0x74881(%rip), %rdi     # 0xea2e0
callq 0x792c0
movq %rax, %rdi
movl $0x1, %esi
callq 0x792e0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x75aa9
cmpl $0x4, -0x40dc(%rbp)
jne 0x75aa7
movslq -0x14(%rbp), %rsi
leaq 0x74852(%rip), %rdi     # 0xea2e0
callq 0x792c0
movq %rax, %rdi
movl $0x2, %esi
callq 0x792e0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x75aa9
jmp 0x75aab
jmp 0x75aad
movq -0x20(%rbp), %rdi
movl -0x40d8(%rbp), %esi
callq 0x93d60
movl %eax, %eax
movl %eax, %esi
leaq 0x74801(%rip), %rdi     # 0xea2c8
callq 0x63590
movl (%rax), %eax
movl %eax, -0x40e0(%rbp)
movq -0x20(%rbp), %rdi
movl -0x40d8(%rbp), %esi
callq 0x93d30
movl %eax, %eax
movl %eax, %esi
leaq 0x747c2(%rip), %rdi     # 0xea2b0
callq 0x63590
movl (%rax), %eax
movl %eax, -0x40e4(%rbp)
movslq -0x40e0(%rbp), %rsi
leaq 0x748c7(%rip), %rdi     # 0xea3d0
callq 0x67360
movq %rax, -0x40f8(%rbp)
movq %rdx, -0x40f0(%rbp)
leaq -0x40f8(%rbp), %rdi
callq 0x673c0
testb $0x1, %al
jne 0x75b2e
jmp 0x75b56
movslq -0x14(%rbp), %rsi
leaq 0x747d7(%rip), %rdi     # 0xea310
callq 0x792c0
movq %rax, %rdi
movslq -0x40e0(%rbp), %rsi
callq 0x792e0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x75b7c
movslq -0x14(%rbp), %rsi
leaq 0x74797(%rip), %rdi     # 0xea2f8
callq 0x792c0
movq %rax, %rdi
movslq -0x40e4(%rbp), %rsi
callq 0x792e0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x75b7e
leaq 0x74e17(%rip), %rdi     # 0xea99c
xorl %esi, %esi
callq 0x6c350
movq -0x8(%rbp), %rdi
movl -0x40d8(%rbp), %esi
movl -0x24(%rbp), %edx
callq 0x9dbc0
movl -0x24(%rbp), %edi
callq 0x25810
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x75c40
movl -0x40d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40d4(%rbp)
jmp 0x7580b
addq $0x4100, %rsp           # imm = 0x4100
popq %rbp
retq
nopw %cs:(%rax,%rax)