// File: /workspace/github_cpp_makefile_star2_O3/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 0x4a986
leaq 0x3c89a(%rip), %rsi     # 0x5d402
xorl %edi, %edi
callq 0x6640
leaq 0x3d028(%rip), %rsi     # 0x5db9e
leaq 0xc(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x63d0
movw $0x20, 0x40(%rsp)
movl (%rbx), %eax
leal -0xa(%rax), %ecx
cmpl $-0x9, %ecx
ja 0x20ba7
leaq 0x3c840(%rip), %rdi     # 0x5d3e0
xorl %esi, %esi
jmp 0x20d03
leaq 0x55d12(%rip), %rcx     # 0x768c0
movl (%rcx), %ecx
leal 0x3(%rcx), %edi
leaq 0x55d02(%rip), %rdx     # 0x768bc
movl (%rdx), %esi
leal 0x1(%rsi), %edx
movl %edx, %r8d
imull %edi, %r8d
movl %r8d, 0x10(%rsp)
leal 0x9(%rcx), %r8d
imull %esi, %edi
leal (%rdi,%rcx), %r9d
addl $0x9, %r9d
movl %r9d, 0x14(%rsp)
movl %ecx, %r9d
addl $0xf, %r9d
addl %ecx, %edi
addl $0xf, %edi
movl %edi, 0x18(%rsp)
movl %edx, %edi
imull %r8d, %edi
imull %esi, %r8d
leal (%r8,%rcx), %r10d
addl $0x3, %r10d
movl %r10d, 0x1c(%rsp)
movl %edi, 0x20(%rsp)
leal (%r8,%rcx), %edi
addl $0xf, %edi
movl %edi, 0x24(%rsp)
imull %r9d, %esi
leal (%rsi,%rcx), %edi
addl $0x3, %edi
movl %edi, 0x28(%rsp)
addl %esi, %ecx
addl $0x9, %ecx
movl %ecx, 0x2c(%rsp)
imull %edx, %r9d
movl %r9d, 0x30(%rsp)
leaq 0x3c7bc(%rip), %r13     # 0x5d3f8
leaq 0x55c71(%rip), %r12     # 0x768b4
leaq 0x3d085(%rip), %rbx     # 0x5dccf
leaq 0x3b(%rsp), %r14
leaq 0x40(%rsp), %r15
xorl %ebp, %ebp
movq 0x56733(%rip), %rdi     # 0x77390
cltq
leaq (%rax,%rax,8), %rax
movslq (%r13,%rax,4), %rax
movl 0x10(%rsp,%rax,4), %esi
movl $0x1, %edx
callq 0x55ae8
movslq 0xc(%rsp), %rax
leaq (%rax,%rax,8), %rax
movslq (%r13,%rax,4), %rax
movl 0x10(%rsp,%rax,4), %eax
cltd
leaq 0x55c2c(%rip), %rcx     # 0x768bc
idivl (%rcx)
movslq %edx, %rcx
leaq 0x3c784(%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 0x6680
movl $0x5, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x6250
incq %rbp
movslq 0xc(%rsp), %rax
addq $0x4, %r13
cmpq %rax, %rbp
jl 0x20c56
movsd 0x3c325(%rip), %xmm0    # 0x5d010
callq 0x54351
movl 0xc(%rsp), %edi
callq 0x56cd3
leaq 0x40(%rsp), %rdi
movl $0x1, %esi
callq 0x21a05
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq