// File: kobanium[P]Ray/src/feature/SimulationFeature.cpp
// Function: CheckCaptureAndAtariForSimulation(game_info_t*, int, int)
void
CheckCaptureAndAtariForSimulation( 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;
  const int other = GetOppositeColor(color);

  // 上を調べる
  // 1. 敵の石
  // 2. 呼吸点が1つ
  if (board[NORTH(pos)] == other) {
    const int libs = string[string_id[NORTH(pos)]].libs;
    if (libs == 1) {
      CompareSwapFeature(game->tactical_features, pos, CAPTURE, SIM_CAPTURE);
    } else if (libs == 2) {
      CompareSwapFeature(game->tactical_features, pos, ATARI, SIM_ATARI);
    }
  }

  //  左を調べる
  // 1. 敵の石
  // 2. 呼吸点が1つ
  if (board[WEST(pos)] == other) {
    const int libs = string[string_id[WEST(pos)]].libs;
    if (libs == 1) {
      CompareSwapFeature(game->tactical_features, pos, CAPTURE, SIM_CAPTURE);
    } else if (libs == 2) {
      CompareSwapFeature(game->tactical_features, pos, ATARI, SIM_ATARI);
    }
  }

  //  右を調べる
  // 1. 敵の石
  // 2. 呼吸点が1つ
  if (board[EAST(pos)] == other) {
    const int libs = string[string_id[EAST(pos)]].libs;
    if (libs == 1) {
      CompareSwapFeature(game->tactical_features, pos, CAPTURE, SIM_CAPTURE);
    } else if (libs == 2) {
      CompareSwapFeature(game->tactical_features, pos, ATARI, SIM_ATARI);
    }
  }

  //  下を調べる
  // 1. 敵の石
  // 2. 呼吸点が1つ
  if (board[SOUTH(pos)] == other) {
    const int libs = string[string_id[SOUTH(pos)]].libs;
    if (libs == 1) {
      CompareSwapFeature(game->tactical_features, pos, CAPTURE, SIM_CAPTURE);
    } else if (libs == 2) {
      CompareSwapFeature(game->tactical_features, pos, ATARI, SIM_ATARI);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
addq $0x43f8, %rax           # imm = 0x43F8
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x9620, %rax           # imm = 0x9620
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x95720, %rax          # imm = 0x95720
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %edi
callq 0x25810
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl -0x10(%rbp), %ecx
leaq 0x44877(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x2c(%rbp), %eax
jne 0xa3257
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movl -0x10(%rbp), %edx
leaq 0x44857(%rip), %rsi     # 0xe7a4c
subl (%rsi), %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x1, -0x30(%rbp)
jne 0xa3230
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x10(%rbp), %esi
xorl %edx, %edx
movl $0x4, %ecx
callq 0xa35f0
jmp 0xa3255
cmpl $0x2, -0x30(%rbp)
jne 0xa3253
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x10(%rbp), %esi
movl $0x2, %edx
movl $0x1, %ecx
callq 0xa35f0
jmp 0xa3255
jmp 0xa3257
movq -0x18(%rbp), %rax
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x2c(%rbp), %eax
jne 0xa32db
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movl -0x10(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0x1, -0x34(%rbp)
jne 0xa32b4
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x10(%rbp), %esi
xorl %edx, %edx
movl $0x4, %ecx
callq 0xa35f0
jmp 0xa32d9
cmpl $0x2, -0x34(%rbp)
jne 0xa32d7
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x10(%rbp), %esi
movl $0x2, %edx
movl $0x1, %ecx
callq 0xa35f0
jmp 0xa32d9
jmp 0xa32db
movq -0x18(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x2c(%rbp), %eax
jne 0xa335f
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movl -0x10(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x38(%rbp)
cmpl $0x1, -0x38(%rbp)
jne 0xa3338
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x10(%rbp), %esi
xorl %edx, %edx
movl $0x4, %ecx
callq 0xa35f0
jmp 0xa335d
cmpl $0x2, -0x38(%rbp)
jne 0xa335b
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x10(%rbp), %esi
movl $0x2, %edx
movl $0x1, %ecx
callq 0xa35f0
jmp 0xa335d
jmp 0xa335f
movq -0x18(%rbp), %rax
movl -0x10(%rbp), %ecx
leaq 0x446df(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x2c(%rbp), %eax
jne 0xa33ef
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movl -0x10(%rbp), %edx
leaq 0x446bf(%rip), %rsi     # 0xe7a4c
addl (%rsi), %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x1, -0x3c(%rbp)
jne 0xa33c8
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x10(%rbp), %esi
xorl %edx, %edx
movl $0x4, %ecx
callq 0xa35f0
jmp 0xa33ed
cmpl $0x2, -0x3c(%rbp)
jne 0xa33eb
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
movl -0x10(%rbp), %esi
movl $0x2, %edx
movl $0x1, %ecx
callq 0xa35f0
jmp 0xa33ed
jmp 0xa33ef
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)