// File: kobanium[P]Ray/src/feature/Ladder.cpp
// Function: CheckLadderExtension(game_info_t const*, int, int)
bool
CheckLadderExtension( const game_info_t *game, const int color, const int pos )
{
  const char *board = game->board;
  const string_t *string = game->string;
  const int *string_id = game->string_id;

  if (board[pos] != color){
    return false;
  }

  const int id = string_id[pos];
  const int ladder = string[id].lib[0];

  if (string[id].libs == 1 &&
      IsLegal(game, ladder, color)) {
    std::unique_ptr<search_game_info_t> search_game(new search_game_info_t(game));
    search_game_info_t *ladder_game = search_game.get();
    PutStoneForSearch(ladder_game, ladder, color);
    if (IsLadderCaptured(0, ladder_game, ladder, GetOppositeColor(color)) == DEAD) {
      return true;
    } 
  }

  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x43f8, %rax           # imm = 0x43F8
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x9620, %rax           # imm = 0x9620
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq $0x95720, %rax          # imm = 0x95720
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
je 0xaaed9
movb $0x0, -0x1(%rbp)
jmp 0xab027
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xab023
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x9d0b0
testb $0x1, %al
jne 0xaaf34
jmp 0xab023
movl $0x69ae40, %edi         # imm = 0x69AE40
callq 0x7550
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rsi
callq 0x98300
jmp 0xaaf53
movq -0x68(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0xaa250
movq -0x70(%rbp), %rdi
callq 0xaa280
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x98700
jmp 0xaaf82
movq -0x58(%rbp), %rax
movq %rax, -0x80(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x14(%rbp), %edi
callq 0x25810
movl %eax, -0x74(%rbp)
jmp 0xaaf9d
movl -0x74(%rbp), %ecx
movl -0x78(%rbp), %edx
movq -0x80(%rbp), %rsi
xorl %edi, %edi
callq 0xaaae0
movb %al, -0x81(%rbp)
jmp 0xaafb6
movb -0x81(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xab006
movb $0x1, -0x1(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0xab00d
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl $0x69ae40, %esi         # imm = 0x69AE40
callq 0x7560
jmp 0xab035
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xaa2b0
jmp 0xab035
movl $0x0, -0x5c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xaa2b0
movl -0x5c(%rbp), %eax
testl %eax, %eax
je 0xab021
jmp 0xab01f
jmp 0xab027
jmp 0xab023
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x79b0
nop