// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
callq 0x4a61e
leaq 0x3c6c0(%rip), %rsi     # 0x5d402
xorl %edi, %edi
callq 0x6650
leaq 0x3ce4e(%rip), %rsi     # 0x5db9e
leaq 0xc(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x63e0
movw $0x20, 0x40(%rsp)
movl (%rbx), %eax
addl $-0xa, %eax
cmpl $-0x9, %eax
ja 0x20d81
leaq 0x3c666(%rip), %rdi     # 0x5d3e0
xorl %esi, %esi
jmp 0x20ee2
leaq 0x54b38(%rip), %rax     # 0x758c0
movl (%rax), %eax
leal 0x3(%rax), %esi
leaq 0x54b28(%rip), %rcx     # 0x758bc
movl (%rcx), %edx
leal 0x1(%rdx), %ecx
movl %ecx, %edi
imull %esi, %edi
movl %edi, 0x10(%rsp)
leal 0x9(%rax), %edi
imull %edx, %esi
leal (%rsi,%rax), %r8d
addl $0x9, %r8d
movl %r8d, 0x14(%rsp)
movl %eax, %r8d
addl $0xf, %r8d
addl %eax, %esi
addl $0xf, %esi
movl %esi, 0x18(%rsp)
movl %ecx, %esi
imull %edi, %esi
imull %edx, %edi
leal (%rdi,%rax), %r9d
addl $0x3, %r9d
movl %r9d, 0x1c(%rsp)
movl %esi, 0x20(%rsp)
leal (%rdi,%rax), %esi
addl $0xf, %esi
movl %esi, 0x24(%rsp)
imull %r8d, %edx
leal (%rdx,%rax), %esi
addl $0x3, %esi
movl %esi, 0x28(%rsp)
addl %edx, %eax
addl $0x9, %eax
movl %eax, 0x2c(%rsp)
imull %ecx, %r8d
movl %r8d, 0x30(%rsp)
movl 0xc(%rsp), %eax
testl %eax, %eax
jle 0x20ec2
leaq 0x3c5dd(%rip), %r13     # 0x5d3f8
leaq 0x54a92(%rip), %r12     # 0x758b4
leaq 0x3cea6(%rip), %rbx     # 0x5dccf
leaq 0x3b(%rsp), %r14
leaq 0x40(%rsp), %r15
xorl %ebp, %ebp
movq 0x55554(%rip), %rdi     # 0x76390
cltq
leaq (%rax,%rax,8), %rax
movslq (%r13,%rax,4), %rax
movl 0x10(%rsp,%rax,4), %esi
movl $0x1, %edx
callq 0x55134
movslq 0xc(%rsp), %rax
leaq (%rax,%rax,8), %rax
movslq (%r13,%rax,4), %rax
movl 0x10(%rsp,%rax,4), %eax
cltd
leaq 0x54a4d(%rip), %rcx     # 0x758bc
idivl (%rcx)
movslq %edx, %rcx
leaq 0x3c5a5(%rip), %rdx     # 0x5d420
movsbl -0x4(%rcx,%rdx), %ecx
movl (%r12), %r8d
subl %eax, %r8d
addl $0x5, %r8d
movl $0x5, %esi
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6690
movl $0x5, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x6260
incq %rbp
movslq 0xc(%rsp), %rax
addq $0x4, %r13
cmpq %rax, %rbp
jl 0x20e35
movsd 0x3c146(%rip), %xmm0    # 0x5d010
callq 0x53df3
movl 0xc(%rsp), %edi
callq 0x5631b
leaq 0x40(%rsp), %rdi
movl $0x1, %esi
callq 0x21c1a
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq