// File: kobanium[P]Ray/src/gtp/Gtp.cpp
// Function: GTP_fixed_handicap()
static void
GTP_fixed_handicap( void )
{
  char *command;
  int num;
  char buf[1024];
  char pos[5];
  int handicap[9];
  const int place_index[8][9] = {
    {2, 6},
    {0, 2, 6},
    {0, 2, 6, 8},
    {0, 2, 4, 6, 8},
    {0, 2, 3, 5, 6, 8},
    {0, 2, 3, 4, 5, 6, 8},
    {0, 1, 2, 3, 5, 6, 7, 8},
    {0, 1, 2, 3, 4, 5, 6, 7, 8},
  };

  StopPondering();
  
  command = STRTOK(NULL, DELIM, &next_token);
  
#if defined (_WIN32)
  sscanf_s(command, "%d", &num);
  sprintf_s(buf, 1024, " ");
#else
  sscanf(command, "%d", &num);
  snprintf(buf, 1024, " ");
#endif

  if (num < 2 || 9 < num) {
    GTP_response(blank, false);
    return ;
  }

  handicap[0] = POS(board_start +  3, board_start +  3);
  handicap[1] = POS(board_start +  9, board_start +  3);
  handicap[2] = POS(board_start + 15, board_start +  3);
  handicap[3] = POS(board_start +  3, board_start +  9);
  handicap[4] = POS(board_start +  9, board_start +  9);
  handicap[5] = POS(board_start + 15, board_start +  9);
  handicap[6] = POS(board_start +  3, board_start + 15);
  handicap[7] = POS(board_start +  9, board_start + 15);
  handicap[8] = POS(board_start + 15, board_start + 15);

  for (int i = 0; i < num; i++) {
    PutStone(game, handicap[place_index[num - 2][i]], S_BLACK);
#if defined (_WIN32)
    sprintf_s(pos, 5, "%c%d ", GOGUI_X(handicap[place_index[num - 2][i]]), GOGUI_Y(handicap[place_index[num - 2][i]]));
    strcat_s(buf, 1024, pos);
#else
    snprintf(pos, 5, "%c%d ", GOGUI_X(handicap[place_index[num - 2][i]]), GOGUI_Y(handicap[place_index[num - 2][i]]));
    strncat(buf, pos, 5);
#endif
  }
  
  SetKomi(0.5);
  SetHandicapNum(num);
  GTP_response(buf, true);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x570, %rsp            # imm = 0x570
leaq -0x560(%rbp), %rdi
leaq 0x862b7(%rip), %rsi     # 0xacc00
movl $0x120, %edx            # imm = 0x120
callq 0x7430
callq 0x892c0
xorl %eax, %eax
movl %eax, %edi
leaq 0x8623d(%rip), %rsi     # 0xacba0
callq 0x7850
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x8606d(%rip), %rsi     # 0xac9e4
leaq -0xc(%rbp), %rdx
movb $0x0, %al
callq 0x7520
leaq -0x410(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
leaq 0x85ab1(%rip), %rdx     # 0xac446
movb $0x0, %al
callq 0x78a0
cmpl $0x2, -0xc(%rbp)
jl 0x269ac
movl $0x9, %eax
cmpl -0xc(%rbp), %eax
jge 0x269bf
leaq 0x8620f(%rip), %rdi     # 0xacbc2
xorl %esi, %esi
callq 0x27f30
jmp 0x26c8b
leaq 0xc108a(%rip), %rax     # 0xe7a50
movl (%rax), %eax
addl $0x3, %eax
leaq 0xc107e(%rip), %rcx     # 0xe7a50
movl (%rcx), %ecx
addl $0x3, %ecx
leaq 0xc106e(%rip), %rdx     # 0xe7a4c
imull (%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x440(%rbp)
leaq 0xc1060(%rip), %rax     # 0xe7a50
movl (%rax), %eax
addl $0x9, %eax
leaq 0xc1054(%rip), %rcx     # 0xe7a50
movl (%rcx), %ecx
addl $0x3, %ecx
leaq 0xc1044(%rip), %rdx     # 0xe7a4c
imull (%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x43c(%rbp)
leaq 0xc1036(%rip), %rax     # 0xe7a50
movl (%rax), %eax
addl $0xf, %eax
leaq 0xc102a(%rip), %rcx     # 0xe7a50
movl (%rcx), %ecx
addl $0x3, %ecx
leaq 0xc101a(%rip), %rdx     # 0xe7a4c
imull (%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x438(%rbp)
leaq 0xc100c(%rip), %rax     # 0xe7a50
movl (%rax), %eax
addl $0x3, %eax
leaq 0xc1000(%rip), %rcx     # 0xe7a50
movl (%rcx), %ecx
addl $0x9, %ecx
leaq 0xc0ff0(%rip), %rdx     # 0xe7a4c
imull (%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x434(%rbp)
leaq 0xc0fe2(%rip), %rax     # 0xe7a50
movl (%rax), %eax
addl $0x9, %eax
leaq 0xc0fd6(%rip), %rcx     # 0xe7a50
movl (%rcx), %ecx
addl $0x9, %ecx
leaq 0xc0fc6(%rip), %rdx     # 0xe7a4c
imull (%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x430(%rbp)
leaq 0xc0fb8(%rip), %rax     # 0xe7a50
movl (%rax), %eax
addl $0xf, %eax
leaq 0xc0fac(%rip), %rcx     # 0xe7a50
movl (%rcx), %ecx
addl $0x9, %ecx
leaq 0xc0f9c(%rip), %rdx     # 0xe7a4c
imull (%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x42c(%rbp)
leaq 0xc0f8e(%rip), %rax     # 0xe7a50
movl (%rax), %eax
addl $0x3, %eax
leaq 0xc0f82(%rip), %rcx     # 0xe7a50
movl (%rcx), %ecx
addl $0xf, %ecx
leaq 0xc0f72(%rip), %rdx     # 0xe7a4c
imull (%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x428(%rbp)
leaq 0xc0f64(%rip), %rax     # 0xe7a50
movl (%rax), %eax
addl $0x9, %eax
leaq 0xc0f58(%rip), %rcx     # 0xe7a50
movl (%rcx), %ecx
addl $0xf, %ecx
leaq 0xc0f48(%rip), %rdx     # 0xe7a4c
imull (%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x424(%rbp)
leaq 0xc0f3a(%rip), %rax     # 0xe7a50
movl (%rax), %eax
addl $0xf, %eax
leaq 0xc0f2e(%rip), %rcx     # 0xe7a50
movl (%rcx), %ecx
addl $0xf, %ecx
leaq 0xc0f1e(%rip), %rdx     # 0xe7a4c
imull (%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x420(%rbp)
movl $0x0, -0x564(%rbp)
movl -0x564(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x26c65
movq 0xc19c7(%rip), %rdi     # 0xe8520
movl -0xc(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rcx
leaq -0x560(%rbp), %rax
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq -0x564(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
movl -0x440(%rbp,%rax,4), %esi
movl $0x1, %edx
callq 0x9dbc0
leaq -0x415(%rbp), %rdi
movl -0xc(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rcx
leaq -0x560(%rbp), %rax
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq -0x564(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
movl -0x440(%rbp,%rax,4), %eax
leaq 0xc0e89(%rip), %rcx     # 0xe7a4c
cltd
idivl (%rcx)
movl %edx, %eax
subl $0x5, %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x86008(%rip), %rax     # 0xacbe0
movsbl (%rax,%rcx), %ecx
leaq 0xc0e61(%rip), %rax     # 0xe7a44
movl (%rax), %r8d
addl $0x1, %r8d
movl -0xc(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rdx
leaq -0x560(%rbp), %rax
imulq $0x24, %rdx, %rdx
addq %rdx, %rax
movslq -0x564(%rbp), %rdx
movslq (%rax,%rdx,4), %rax
movl -0x440(%rbp,%rax,4), %eax
leaq 0xc0e32(%rip), %rsi     # 0xe7a4c
cltd
idivl (%rsi)
subl $0x5, %eax
addl $0x1, %eax
subl %eax, %r8d
movl $0x5, %esi
leaq 0x85ee5(%rip), %rdx     # 0xacb17
movb $0x0, %al
callq 0x78a0
leaq -0x410(%rbp), %rdi
leaq -0x415(%rbp), %rsi
movl $0x5, %edx
callq 0x7360
movl -0x564(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x564(%rbp)
jmp 0x26b43
movsd 0x853a3(%rip), %xmm0    # 0xac010
callq 0x9bc10
movl -0xc(%rbp), %edi
callq 0x9fde0
leaq -0x410(%rbp), %rdi
movl $0x1, %esi
callq 0x27f30
addq $0x570, %rsp            # imm = 0x570
popq %rbp
retq
nopw %cs:(%rax,%rax)