// File: kobanium[P]Ray/src/feature/Semeai.cpp
// Function: IsSelfAtari(game_info_t const*, int, int)
bool
IsSelfAtari( 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;
  const int other = GetOppositeColor(color);
  int already[4] = { 0 };
  int already_num = 0;
  int lib, count = 0, libs = 0;
  int lib_candidate[10];
  int i;
  int id;
  bool checked;

  // 上下左右が空点なら呼吸点の候補に入れる
  if (board[NORTH(pos)] == S_EMPTY) lib_candidate[libs++] = NORTH(pos);
  if (board[ WEST(pos)] == S_EMPTY) lib_candidate[libs++] =  WEST(pos);
  if (board[ EAST(pos)] == S_EMPTY) lib_candidate[libs++] =  EAST(pos);
  if (board[SOUTH(pos)] == S_EMPTY) lib_candidate[libs++] = SOUTH(pos);

  //  空点
  if (libs >= 2) return false;

  // 上を調べる
  if (board[NORTH(pos)] == color) {
    id = string_id[NORTH(pos)];
    if (string[id].libs > 2) return false;
    lib = string[id].lib[0];
    count = 0;
    while (lib != LIBERTY_END) {
      if (lib != pos) {
        checked = false;
        for (i = 0; i < libs; i++) {
          if (lib_candidate[i] == lib) {
            checked = true;
            break;
          }
        }
        if (!checked) {
          lib_candidate[libs + count] = lib;
          count++;
        }
      }
      lib = string[id].lib[lib];
    }
    libs += count;
    already[already_num++] = id;
    if (libs >= 2) return false;
  } else if (board[NORTH(pos)] == other &&
             string[string_id[NORTH(pos)]].libs == 1) {
    return false;
  }

  // 左を調べる
  if (board[WEST(pos)] == color) {
    id = string_id[WEST(pos)];
    if (already[0] != id) {
      if (string[id].libs > 2) return false;
      lib = string[id].lib[0];
      count = 0;
      while (lib != LIBERTY_END) {
        if (lib != pos) {
          checked = false;
          for (i = 0; i < libs; i++) {
            if (lib_candidate[i] == lib) {
              checked = true;
              break;
            }
          }
          if (!checked) {
            lib_candidate[libs + count] = lib;
            count++;
          }
        }
        lib = string[id].lib[lib];
      }
      libs += count;
      already[already_num++] = id;
      if (libs >= 2) return false;
    }
  } else if (board[WEST(pos)] == other &&
             string[string_id[WEST(pos)]].libs == 1) {
    return false;
  }

  // 右を調べる
  if (board[EAST(pos)] == color) {
    id = string_id[EAST(pos)];
    if (already[0] != id && already[1] != id) {
      if (string[id].libs > 2) return false;
      lib = string[id].lib[0];
      count = 0;
      while (lib != LIBERTY_END) {
        if (lib != pos) {
          checked = false;
          for (i = 0; i < libs; i++) {
            if (lib_candidate[i] == lib) {
              checked = true;
              break;
            }
          }
          if (!checked) {
            lib_candidate[libs + count] = lib;
            count++;
          }
        }
        lib = string[id].lib[lib];
      }
      libs += count;
      already[already_num++] = id;
      if (libs >= 2) return false;
    }
  } else if (board[EAST(pos)] == other &&
             string[string_id[EAST(pos)]].libs == 1) {
    return false;
  }


  // 下を調べる
  if (board[SOUTH(pos)] == color) {
    id = string_id[SOUTH(pos)];
    if (already[0] != id && already[1] != id && already[2] != id) {
      if (string[id].libs > 2) return false;
      lib = string[id].lib[0];
      count = 0;
      while (lib != LIBERTY_END) {
        if (lib != pos) {
          checked = false;
          for (i = 0; i < libs; i++) {
            if (lib_candidate[i] == lib) {
              checked = true;
              break;
            }
          }
          if (!checked) {
            lib_candidate[libs + count] = lib;
            count++;
          }
        }
        lib = string[id].lib[lib];
      }
      libs += count;
      already[already_num++] = id;
      if (libs >= 2) return false;
    }
  } else if (board[SOUTH(pos)] == other &&
             string[string_id[SOUTH(pos)]].libs == 1) {
    return false;
  }

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %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)
movl -0x14(%rbp), %edi
callq 0x25810
movl %eax, -0x34(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x72b0
movl $0x0, -0x54(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
leaq 0x3eb5f(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xa8f1b
movl -0x18(%rbp), %ecx
leaq 0x3eb47(%rip), %rax     # 0xe7a4c
subl (%rax), %ecx
movl -0x60(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x60(%rbp)
cltq
movl %ecx, -0x90(%rbp,%rax,4)
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xa8f4b
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movl -0x60(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x60(%rbp)
cltq
movl %ecx, -0x90(%rbp,%rax,4)
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xa8f7b
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movl -0x60(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x60(%rbp)
cltq
movl %ecx, -0x90(%rbp,%rax,4)
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
leaq 0x3eac3(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xa8fb7
movl -0x18(%rbp), %ecx
leaq 0x3eaab(%rip), %rax     # 0xe7a4c
addl (%rax), %ecx
movl -0x60(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x60(%rbp)
cltq
movl %ecx, -0x90(%rbp,%rax,4)
cmpl $0x2, -0x60(%rbp)
jl 0xa8fc6
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
leaq 0x3ea78(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
jne 0xa9126
movq -0x30(%rbp), %rax
movl -0x18(%rbp), %ecx
leaq 0x3ea58(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
jle 0xa9026
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x2b7, -0x58(%rbp)     # imm = 0x2B7
je 0xa90f5
movl -0x58(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0xa90cf
movb $0x0, -0x99(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x60(%rbp), %eax
jge 0xa90a9
movslq -0x94(%rbp), %rax
movl -0x90(%rbp,%rax,4), %eax
cmpl -0x58(%rbp), %eax
jne 0xa9096
movb $0x1, -0x99(%rbp)
jmp 0xa90a9
jmp 0xa9098
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0xa906f
testb $0x1, -0x99(%rbp)
jne 0xa90cd
movl -0x58(%rbp), %ecx
movl -0x60(%rbp), %eax
addl -0x5c(%rbp), %eax
cltq
movl %ecx, -0x90(%rbp,%rax,4)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xa90cf
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movslq -0x58(%rbp), %rcx
movswl 0x8(%rax,%rcx,2), %eax
movl %eax, -0x58(%rbp)
jmp 0xa9049
movl -0x5c(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x98(%rbp), %ecx
movl -0x54(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x54(%rbp)
cltq
movl %ecx, -0x50(%rbp,%rax,4)
cmpl $0x2, -0x60(%rbp)
jl 0xa9124
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
jmp 0xa9178
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
leaq 0x3e918(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x34(%rbp), %eax
jne 0xa9176
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x18(%rbp), %edx
leaq 0x3e8f8(%rip), %rsi     # 0xe7a4c
subl (%rsi), %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa9176
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
jmp 0xa9178
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
jne 0xa92dd
movq -0x30(%rbp), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x98(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x98(%rbp), %eax
je 0xa92db
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
jle 0xa91db
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x2b7, -0x58(%rbp)     # imm = 0x2B7
je 0xa92aa
movl -0x58(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0xa9284
movb $0x0, -0x99(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x60(%rbp), %eax
jge 0xa925e
movslq -0x94(%rbp), %rax
movl -0x90(%rbp,%rax,4), %eax
cmpl -0x58(%rbp), %eax
jne 0xa924b
movb $0x1, -0x99(%rbp)
jmp 0xa925e
jmp 0xa924d
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0xa9224
testb $0x1, -0x99(%rbp)
jne 0xa9282
movl -0x58(%rbp), %ecx
movl -0x60(%rbp), %eax
addl -0x5c(%rbp), %eax
cltq
movl %ecx, -0x90(%rbp,%rax,4)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xa9284
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movslq -0x58(%rbp), %rcx
movswl 0x8(%rax,%rcx,2), %eax
movl %eax, -0x58(%rbp)
jmp 0xa91fe
movl -0x5c(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x98(%rbp), %ecx
movl -0x54(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x54(%rbp)
cltq
movl %ecx, -0x50(%rbp,%rax,4)
cmpl $0x2, -0x60(%rbp)
jl 0xa92d9
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
jmp 0xa92db
jmp 0xa9323
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x34(%rbp), %eax
jne 0xa9321
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x18(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa9321
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
jmp 0xa9323
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
jne 0xa9497
movq -0x30(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x98(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x98(%rbp), %eax
je 0xa9495
movl -0x4c(%rbp), %eax
cmpl -0x98(%rbp), %eax
je 0xa9495
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
jle 0xa9395
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x2b7, -0x58(%rbp)     # imm = 0x2B7
je 0xa9464
movl -0x58(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0xa943e
movb $0x0, -0x99(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x60(%rbp), %eax
jge 0xa9418
movslq -0x94(%rbp), %rax
movl -0x90(%rbp,%rax,4), %eax
cmpl -0x58(%rbp), %eax
jne 0xa9405
movb $0x1, -0x99(%rbp)
jmp 0xa9418
jmp 0xa9407
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0xa93de
testb $0x1, -0x99(%rbp)
jne 0xa943c
movl -0x58(%rbp), %ecx
movl -0x60(%rbp), %eax
addl -0x5c(%rbp), %eax
cltq
movl %ecx, -0x90(%rbp,%rax,4)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xa943e
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movslq -0x58(%rbp), %rcx
movswl 0x8(%rax,%rcx,2), %eax
movl %eax, -0x58(%rbp)
jmp 0xa93b8
movl -0x5c(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x98(%rbp), %ecx
movl -0x54(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x54(%rbp)
cltq
movl %ecx, -0x50(%rbp,%rax,4)
cmpl $0x2, -0x60(%rbp)
jl 0xa9493
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
jmp 0xa9495
jmp 0xa94dd
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x34(%rbp), %eax
jne 0xa94db
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x18(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa94db
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
jmp 0xa94dd
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
leaq 0x3e561(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x14(%rbp), %eax
jne 0xa9669
movq -0x30(%rbp), %rax
movl -0x18(%rbp), %ecx
leaq 0x3e541(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x98(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x98(%rbp), %eax
je 0xa9667
movl -0x4c(%rbp), %eax
cmpl -0x98(%rbp), %eax
je 0xa9667
movl -0x48(%rbp), %eax
cmpl -0x98(%rbp), %eax
je 0xa9667
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
jle 0xa956a
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x2b7, -0x58(%rbp)     # imm = 0x2B7
je 0xa9639
movl -0x58(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0xa9613
movb $0x0, -0x99(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x60(%rbp), %eax
jge 0xa95ed
movslq -0x94(%rbp), %rax
movl -0x90(%rbp,%rax,4), %eax
cmpl -0x58(%rbp), %eax
jne 0xa95da
movb $0x1, -0x99(%rbp)
jmp 0xa95ed
jmp 0xa95dc
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0xa95b3
testb $0x1, -0x99(%rbp)
jne 0xa9611
movl -0x58(%rbp), %ecx
movl -0x60(%rbp), %eax
addl -0x5c(%rbp), %eax
cltq
movl %ecx, -0x90(%rbp,%rax,4)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xa9613
movq -0x28(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movslq -0x58(%rbp), %rcx
movswl 0x8(%rax,%rcx,2), %eax
movl %eax, -0x58(%rbp)
jmp 0xa958d
movl -0x5c(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x98(%rbp), %ecx
movl -0x54(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x54(%rbp)
cltq
movl %ecx, -0x50(%rbp,%rax,4)
cmpl $0x2, -0x60(%rbp)
jl 0xa9665
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
jmp 0xa9667
jmp 0xa96b8
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
leaq 0x3e3d5(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x34(%rbp), %eax
jne 0xa96b6
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x18(%rbp), %edx
leaq 0x3e3b5(%rip), %rsi     # 0xe7a4c
addl (%rsi), %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa96b6
movb $0x0, -0x1(%rbp)
jmp 0xa96bc
jmp 0xa96b8
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)