// File: /workspace/github_cpp_makefile_star2_O2/kobanium[P]Ray/src/learn/PatternAnalyzer.cpp
// Function: AnalyzePattern()
void
AnalyzePattern( void )
{
  std::unique_ptr<int[]> md2_count(new int[MD2_MAX]);
  std::unique_ptr<hash_table_t> md3_count(new hash_table_t);
  std::unique_ptr<hash_table_t> md4_count(new hash_table_t);
  std::unique_ptr<hash_table_t> md5_count(new hash_table_t);
  game_info_t *game = AllocateGame(), *init_game = AllocateGame();
  pattern_hash_t hash_pat;
  SGF_record_t kifu;
  unsigned int md2_transp[16];
  unsigned int md2;
  unsigned int min_md2;


  std::cerr << "Start" << std::endl;

  std::fill_n(md2_count.get(), MD2_MAX, 0);
  ClearAllHashData(md3_count);
  ClearAllHashData(md4_count);
  ClearAllHashData(md5_count);

  InitializeBoard(init_game);

  for (int i = ANALYZE_KIFU_START; i <= ANALYZE_KIFU_END; i++) {
    int color = S_BLACK;
    std::ostringstream oss;

    CopyGame(game, init_game);

    oss << ANALYZE_KIFU_PATH << PATH_SEPARATOR << i << ".sgf";


    ExtractKifu(oss.str().c_str(), &kifu);

    std::cerr << oss.str() << ", " << kifu.moves << std::endl;

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

      if (pos != PASS) {
        md2 = MD2(game->pat, pos);
        MD2Transpose16(md2, md2_transp);
        min_md2 = MD2_MAX;
        for (int k = 0; k < 16; k++) {
          if (min_md2 > md2_transp[k]) {
            min_md2 = md2_transp[k];
          }
        }
        md2_count[min_md2]++;

        PatternHash(&game->pat[pos], &hash_pat);
        Count(md3_count, hash_pat.list[MD_3], &game->pat[pos]);
        Count(md4_count, hash_pat.list[MD_4], &game->pat[pos]);
        Count(md5_count, hash_pat.list[MD_MAX + MD_5], &game->pat[pos]);
      }

      PutStone(game, pos, color);
      color = GetOppositeColor(color);
    }
  }

  OutputTargetPattern(md2_count, md3_count, md4_count, md5_count);

  FreeGame(game);
  FreeGame(init_game);

  std::cerr << "Finish" << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4988, %rsp           # imm = 0x4988
movl $0x4000000, %edi        # imm = 0x4000000
callq 0x6030
movq %rax, 0x20(%rsp)
movl $0x30000008, %edi       # imm = 0x30000008
callq 0x63e0
movq %rax, 0x18(%rsp)
movl $0x30000008, %edi       # imm = 0x30000008
callq 0x63e0
movq %rax, 0x10(%rsp)
movl $0x30000008, %edi       # imm = 0x30000008
callq 0x63e0
movq %rax, 0x8(%rsp)
callq 0x3b148
movq %rax, 0x30(%rsp)
callq 0x3b148
movq %rax, 0x38(%rsp)
movq 0x32f18(%rip), %rdi     # 0x60ff0
leaq 0x18cd8(%rip), %rsi     # 0x46db7
callq 0x63c0
movq %rax, %rdi
callq 0x6190
movq 0x20(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x4000000, %rcx        # imm = 0x4000000
je 0x2e106
andl $0x0, (%rax,%rcx)
addq $0x4, %rcx
jmp 0x2e0f3
leaq 0x18(%rsp), %rdi
callq 0x2e80f
leaq 0x10(%rsp), %rdi
callq 0x2e80f
leaq 0x8(%rsp), %rdi
callq 0x2e80f
movq 0x38(%rsp), %rdi
callq 0x3b173
movq 0x30(%rsp), %r12
addq $0x4748, %r12           # imm = 0x4748
pushq $0x1
popq %rax
leaq 0xe8(%rsp), %rbp
movl %eax, 0x2c(%rsp)
cmpl $0x7531, %eax           # imm = 0x7531
je 0x2e327
leaq 0x2e8(%rsp), %rdi
callq 0x6530
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3b5f2
leaq 0x2e8(%rsp), %rdi
leaq 0x18c51(%rip), %rsi     # 0x46dd0
callq 0x63c0
movq %rax, %rdi
leaq 0x374ba(%rip), %rsi     # 0x65648
callq 0x6350
movq %rax, %rdi
movl 0x2c(%rsp), %esi
callq 0x6700
movq %rax, %rdi
leaq 0x17df6(%rip), %rsi     # 0x45f9f
callq 0x63c0
movq %rbp, %rdi
leaq 0x2f0(%rsp), %rsi
callq 0x6640
movq 0xe8(%rsp), %rdi
leaq 0x8e8(%rsp), %rsi
callq 0x2ee83
movq %rbp, %rdi
callq 0x6838
movq %rbp, %rdi
leaq 0x2f0(%rsp), %rsi
callq 0x6640
movq 0x32dfe(%rip), %rdi     # 0x60ff0
movq %rbp, %rsi
callq 0x6350
movq %rax, %rdi
leaq 0x168a8(%rip), %rsi     # 0x44aac
callq 0x63c0
movl 0x8ec(%rsp), %esi
movq %rax, %rdi
callq 0x6700
movq %rax, %rdi
callq 0x6190
movq %rbp, %rdi
callq 0x6838
xorl %r14d, %r14d
pushq $0x1
popq %r15
cmpl 0x8ec(%rsp), %r14d
jge 0x2e30f
leaq 0x8e8(%rsp), %rdi
movl %r14d, %esi
callq 0x2ee30
movl %eax, %r13d
testl %eax, %eax
je 0x2e2f3
movq %r12, %rdi
movl %r13d, %esi
callq 0x37bd2
movl %eax, %edi
leaq 0xa0(%rsp), %rsi
callq 0x374d5
movl $0x1000000, %eax        # imm = 0x1000000
xorl %ecx, %ecx
cmpq $0x10, %rcx
je 0x2e290
movl 0xa0(%rsp,%rcx,4), %edx
cmpl %edx, %eax
cmovael %edx, %eax
incq %rcx
jmp 0x2e279
movl %eax, %eax
movq 0x20(%rsp), %rcx
incl (%rcx,%rax,4)
movslq %r13d, %rax
imulq $0x18, %rax, %rbx
addq %r12, %rbx
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
callq 0x39038
movq 0x88(%rsp), %rsi
leaq 0x18(%rsp), %rdi
movq %rbx, %rdx
callq 0x2e852
movq 0x90(%rsp), %rsi
leaq 0x10(%rsp), %rdi
movq %rbx, %rdx
callq 0x2e852
movq 0x98(%rsp), %rsi
leaq 0x8(%rsp), %rdi
movq %rbx, %rdx
callq 0x2e852
movq 0x30(%rsp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x3c2f8
xorl $0x3, %r15d
incl %r14d
jmp 0x2e22f
leaq 0x2e8(%rsp), %rdi
callq 0x60a0
movl 0x2c(%rsp), %eax
incl %eax
jmp 0x2e145
leaq 0x40(%rsp), %rdi
callq 0x1445b
leaq 0x37310(%rip), %rdx     # 0x65648
leaq 0x4e8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x25df4
leaq 0x18a8f(%rip), %rdx     # 0x46de0
leaq 0x6e8(%rsp), %rdi
leaq 0x4e8(%rsp), %rsi
callq 0x25e13
leaq 0x372db(%rip), %rdx     # 0x65648
leaq 0xe8(%rsp), %rdi
leaq 0x6e8(%rsp), %rsi
callq 0x25df4
leaq 0x18a67(%rip), %rdx     # 0x46df0
leaq 0x2e8(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x25e13
leaq 0x372a3(%rip), %rdx     # 0x65648
leaq 0x60(%rsp), %rdi
leaq 0x2e8(%rsp), %rsi
callq 0x25df4
leaq 0x2e8(%rsp), %rdi
callq 0x6838
leaq 0xe8(%rsp), %rdi
callq 0x6838
leaq 0x6e8(%rsp), %rdi
callq 0x6838
leaq 0x4e8(%rsp), %rdi
callq 0x6838
leaq 0x40(%rsp), %rdi
callq 0x6838
leaq 0x18a03(%rip), %rdx     # 0x46dff
leaq 0xe8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x25e32
leaq 0x2e8(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x6800
leaq 0xe8(%rsp), %rdi
callq 0x6838
leaq 0x189d3(%rip), %rdx     # 0x46e0d
leaq 0x6e8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x25e32
leaq 0xe8(%rsp), %rdi
leaq 0x6e8(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x6800
leaq 0x6e8(%rsp), %rdi
callq 0x6838
leaq 0x189a3(%rip), %rdx     # 0x46e1b
leaq 0x4e8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x25e32
leaq 0x6e8(%rsp), %rdi
leaq 0x4e8(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x6800
leaq 0x4e8(%rsp), %rdi
callq 0x6838
leaq 0x18973(%rip), %rdx     # 0x46e29
leaq 0x40(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x25e32
leaq 0x4e8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x6800
leaq 0x40(%rsp), %rdi
callq 0x6838
xorl %r14d, %r14d
leaq 0x2e8(%rsp), %r15
cmpq $0x1000000, %r14        # imm = 0x1000000
je 0x2e51c
movq 0x20(%rsp), %rax
cmpl $0xa, (%rax,%r14,4)
jl 0x2e517
movq %r15, %rdi
movl %r14d, %esi
callq 0x6700
movq %rax, %rdi
callq 0x6190
incq %r14
jmp 0x2e4ef
pushq $0x28
popq %rbx
leaq 0xe8(%rsp), %r14
cmpq $0x30000028, %rbx       # imm = 0x30000028
je 0x2e55d
movq 0x18(%rsp), %rax
cmpl $0x1, (%rax,%rbx)
jne 0x2e557
cmpl $0xa, -0x8(%rax,%rbx)
jl 0x2e557
movq -0x28(%rax,%rbx), %rsi
movq %r14, %rdi
callq 0x6260
movq %rax, %rdi
callq 0x6190
addq $0x30, %rbx
jmp 0x2e527
pushq $0x28
popq %rbx
leaq 0x6e8(%rsp), %r14
cmpq $0x30000028, %rbx       # imm = 0x30000028
je 0x2e59e
movq 0x10(%rsp), %rax
cmpl $0x1, (%rax,%rbx)
jne 0x2e598
cmpl $0xa, -0x8(%rax,%rbx)
jl 0x2e598
movq -0x28(%rax,%rbx), %rsi
movq %r14, %rdi
callq 0x6260
movq %rax, %rdi
callq 0x6190
addq $0x30, %rbx
jmp 0x2e568
pushq $0x28
popq %rbx
leaq 0x4e8(%rsp), %r14
cmpq $0x30000028, %rbx       # imm = 0x30000028
je 0x2e5df
movq 0x8(%rsp), %rax
cmpl $0x1, (%rax,%rbx)
jne 0x2e5d9
cmpl $0xa, -0x8(%rax,%rbx)
jl 0x2e5d9
movq -0x28(%rax,%rbx), %rsi
movq %r14, %rdi
callq 0x6260
movq %rax, %rdi
callq 0x6190
addq $0x30, %rbx
jmp 0x2e5a9
leaq 0x4e8(%rsp), %rdi
callq 0x65e0
leaq 0x6e8(%rsp), %rdi
callq 0x65e0
leaq 0xe8(%rsp), %rdi
callq 0x65e0
leaq 0x2e8(%rsp), %rdi
callq 0x65e0
leaq 0x60(%rsp), %rdi
callq 0x6838
movq 0x30(%rsp), %rdi
callq 0x3b163
movq 0x38(%rsp), %rdi
callq 0x3b163
movq 0x329b8(%rip), %rdi     # 0x60ff0
leaq 0x1877e(%rip), %rsi     # 0x46dbd
callq 0x63c0
movq %rax, %rdi
callq 0x6190
leaq 0x8(%rsp), %rdi
callq 0x2e988
leaq 0x10(%rsp), %rdi
callq 0x2e988
leaq 0x18(%rsp), %rdi
callq 0x2e988
leaq 0x20(%rsp), %rdi
callq 0x2e9a4
addq $0x4988, %rsp           # imm = 0x4988
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x6838
jmp 0x2e77d
movq %rax, %rbx
jmp 0x2e77d
movq %rax, %rbx
leaq 0x4e8(%rsp), %rdi
callq 0x6838
jmp 0x2e78a
movq %rax, %rbx
jmp 0x2e78a
movq %rax, %rbx
leaq 0x6e8(%rsp), %rdi
callq 0x6838
jmp 0x2e797
movq %rax, %rbx
jmp 0x2e797
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x6838
jmp 0x2e7a4
movq %rax, %rbx
jmp 0x2e7a4
movq %rax, %rbx
leaq 0x2e8(%rsp), %rdi
callq 0x6838
jmp 0x2e70c
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x6838
jmp 0x2e71e
movq %rax, %rbx
leaq 0x6e8(%rsp), %rdi
callq 0x6838
jmp 0x2e730
movq %rax, %rbx
leaq 0x4e8(%rsp), %rdi
callq 0x6838
jmp 0x2e742
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0x2e7a9
jmp 0x2e7b4
jmp 0x2e7b4
movq %rax, %rbx
jmp 0x2e7e9
movq %rax, %rbx
jmp 0x2e7f3
movq %rax, %rbx
jmp 0x2e7fd
jmp 0x2e7b4
jmp 0x2e76d
jmp 0x2e76d
jmp 0x2e76d
movq %rax, %rbx
leaq 0x4e8(%rsp), %rdi
callq 0x65e0
leaq 0x6e8(%rsp), %rdi
callq 0x65e0
leaq 0xe8(%rsp), %rdi
callq 0x65e0
leaq 0x2e8(%rsp), %rdi
callq 0x65e0
leaq 0x60(%rsp), %rdi
callq 0x6838
jmp 0x2e7df
jmp 0x2e7cf
jmp 0x2e7bb
movq %rax, %rbx
jmp 0x2e7df
jmp 0x2e7cf
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x6838
jmp 0x2e7d2
jmp 0x2e7cf
movq %rax, %rbx
leaq 0x2e8(%rsp), %rdi
callq 0x60a0
leaq 0x8(%rsp), %rdi
callq 0x2e988
leaq 0x10(%rsp), %rdi
callq 0x2e988
leaq 0x18(%rsp), %rdi
callq 0x2e988
leaq 0x20(%rsp), %rdi
callq 0x2e9a4
movq %rbx, %rdi
callq 0x6740