#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ add_output(char *);
int /*<<< orphan*/ create_next_move();
int get_captured_now(int **);
int get_nr_of_liberties(int);
int get_size_of_worm(int);
int get_worm_nr(int, int);
int /*<<< orphan*/ i_to_x(int, char *);
int /*<<< orphan*/ is_color_valid(char *, int *);
int /*<<< orphan*/ j_to_y(int, char *);
int /*<<< orphan*/ push_move();
int remove_stones(int);
int /*<<< orphan*/ scan_board_1();
int /*<<< orphan*/ search_tree(int, int *, int *);
int /*<<< orphan*/ set_move_captured_stones(int **);
int /*<<< orphan*/ set_move_ko(int, int);
int /*<<< orphan*/ set_move_pass(int);
int /*<<< orphan*/ set_move_vertex(int, int, int);
int /*<<< orphan*/ set_output_error();
int /*<<< orphan*/ set_vertex(int, int, int);
int /*<<< orphan*/ strcat(char *, char *);
void gtp_genmove(int gtp_argc, char gtp_argv[][20]) {
  int k;
  int color;
  int i, j;
  int nr_of_removed_stones;
  int captured_now[21 * 21][2];
  int group_nr;
  int nr_of_liberties;
  int group_size;
  char x[2];
  char y[3];
  char vertex[4] = "\0";
  for (k = 0; k < 21 * 21; k++) {
    captured_now[k][0] = -1;
    captured_now[k][1] = -1;
  }
  if (!is_color_valid(gtp_argv[0], &color)) {
    set_output_error();
    add_output("invalid color");
    return;
  }
  i = -1;
  j = -1;
  search_tree(color, &i, &j);
  if (i == -1 && j == -1) {
    create_next_move();
    set_move_pass(color);
    push_move();
    add_output("pass");
    return;
  }
  set_vertex(color, i, j);
  scan_board_1();
  nr_of_removed_stones = remove_stones(color * -1);
  if (nr_of_removed_stones > 0) {
    scan_board_1();
  }
  nr_of_removed_stones = get_captured_now(captured_now);
  create_next_move();
  set_move_vertex(color, i, j);
  set_move_captured_stones(captured_now);
  group_nr = get_worm_nr(i, j);
  nr_of_liberties = get_nr_of_liberties(group_nr);
  group_size = get_size_of_worm(group_nr);
  if (nr_of_removed_stones == 1 && group_size == 1 && nr_of_liberties == 1) {
    set_move_ko(captured_now[0][0], captured_now[0][1]);
  }
  push_move();
  i_to_x(i, x);
  j_to_y(j, y);
  strcat(vertex, x);
  strcat(vertex, y);
  add_output(vertex);
  return;
}


x86 assembly (clang, -O0):
<gtp_genmove>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xe05(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x1b9,-0x14(%rbp)
jge    12b5 <gtp_genmove+0x65>
movslq -0x14(%rbp),%rax
movl   $0xffffffff,-0xdf0(%rbp,%rax,8)
ff ff ff ff
movslq -0x14(%rbp),%rax
movl   $0xffffffff,-0xdec(%rbp,%rax,8)
ff ff ff ff
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    127c <gtp_genmove+0x2c>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <is_color_valid@plt>
cmp    $0x0,%eax
jne    12e3 <gtp_genmove+0x93>
mov    $0x0,%al
call   10e0 <set_output_error@plt>
lea    0xd27(%rip),%rdi
call   1170 <add_output@plt>
jmp    145d <gtp_genmove+0x20d>
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1150 <search_tree@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    133c <gtp_genmove+0xec>
cmpl   $0xffffffff,-0x20(%rbp)
jne    133c <gtp_genmove+0xec>
mov    $0x0,%al
call   1060 <create_next_move@plt>
mov    -0x18(%rbp),%edi
call   10b0 <set_move_pass@plt>
mov    $0x0,%al
call   10f0 <push_move@plt>
lea    0xcdc(%rip),%rdi
call   1170 <add_output@plt>
jmp    145d <gtp_genmove+0x20d>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10c0 <set_vertex@plt>
mov    $0x0,%al
call   1080 <scan_board_1@plt>
imul   $0xffffffff,-0x18(%rbp),%edi
call   1050 <remove_stones@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    136e <gtp_genmove+0x11e>
mov    $0x0,%al
call   1080 <scan_board_1@plt>
lea    -0xdf0(%rbp),%rdi
call   1110 <get_captured_now@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <create_next_move@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1120 <set_move_vertex@plt>
lea    -0xdf0(%rbp),%rdi
call   1130 <set_move_captured_stones@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <get_worm_nr@plt>
mov    %eax,-0xdf4(%rbp)
mov    -0xdf4(%rbp),%edi
call   1090 <get_nr_of_liberties@plt>
mov    %eax,-0xdf8(%rbp)
mov    -0xdf4(%rbp),%edi
call   10d0 <get_size_of_worm@plt>
mov    %eax,-0xdfc(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    1406 <gtp_genmove+0x1b6>
cmpl   $0x1,-0xdfc(%rbp)
jne    1406 <gtp_genmove+0x1b6>
cmpl   $0x1,-0xdf8(%rbp)
jne    1406 <gtp_genmove+0x1b6>
mov    -0xdf0(%rbp),%edi
mov    -0xdec(%rbp),%esi
call   1140 <set_move_ko@plt>
mov    $0x0,%al
call   10f0 <push_move@plt>
mov    -0x1c(%rbp),%edi
lea    -0xdfe(%rbp),%rsi
call   1070 <i_to_x@plt>
mov    -0x20(%rbp),%edi
lea    -0xe01(%rbp),%rsi
call   1100 <j_to_y@plt>
lea    -0xe05(%rbp),%rdi
lea    -0xdfe(%rbp),%rsi
call   1160 <strcat@plt>
lea    -0xe05(%rbp),%rdi
lea    -0xe01(%rbp),%rsi
call   1160 <strcat@plt>
lea    -0xe05(%rbp),%rdi
call   1170 <add_output@plt>
add    $0xe10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtp_genmove>:
push   %rbp
push   %r14
push   %rbx
sub    $0xdf0,%rsp
mov    %rsi,%rbx
movl   $0x0,0x14(%rsp)
lea    0x20(%rsp),%rdi
mov    $0xdc8,%edx
mov    $0xff,%esi
call   10a0 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <is_color_valid@plt>
test   %eax,%eax
je     12e3 <gtp_genmove+0x93>
movl   $0xffffffff,0xc(%rsp)
ff
movl   $0xffffffff,0x8(%rsp)
ff
mov    0x10(%rsp),%edi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1150 <search_tree@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
cmp    $0xffffffff,%esi
jne    12f6 <gtp_genmove+0xa6>
cmp    $0xffffffff,%edx
jne    12f6 <gtp_genmove+0xa6>
xor    %eax,%eax
call   1060 <create_next_move@plt>
mov    0x10(%rsp),%edi
call   10b0 <set_move_pass@plt>
xor    %eax,%eax
call   10f0 <push_move@plt>
lea    0xd30(%rip),%rdi
jmp    13d1 <gtp_genmove+0x181>
xor    %eax,%eax
call   10e0 <set_output_error@plt>
lea    0xd0f(%rip),%rdi
jmp    13d1 <gtp_genmove+0x181>
mov    0x10(%rsp),%edi
call   10c0 <set_vertex@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <scan_board_1@plt>
sub    0x10(%rsp),%ebx
mov    %ebx,%edi
call   1050 <remove_stones@plt>
test   %eax,%eax
jle    131e <gtp_genmove+0xce>
xor    %eax,%eax
call   1080 <scan_board_1@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1110 <get_captured_now@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1060 <create_next_move@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
call   1120 <set_move_vertex@plt>
mov    %rbp,%rdi
call   1130 <set_move_captured_stones@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   1030 <get_worm_nr@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1090 <get_nr_of_liberties@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   10d0 <get_size_of_worm@plt>
cmp    $0x1,%r14d
jne    138a <gtp_genmove+0x13a>
cmp    $0x1,%eax
jne    138a <gtp_genmove+0x13a>
cmp    $0x1,%ebp
jne    138a <gtp_genmove+0x13a>
mov    0x20(%rsp),%edi
mov    0x24(%rsp),%esi
call   1140 <set_move_ko@plt>
xor    %eax,%eax
call   10f0 <push_move@plt>
mov    0xc(%rsp),%edi
lea    0x1b(%rsp),%r14
mov    %r14,%rsi
call   1070 <i_to_x@plt>
mov    0x8(%rsp),%edi
lea    0x1d(%rsp),%rbp
mov    %rbp,%rsi
call   1100 <j_to_y@plt>
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1160 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1160 <strcat@plt>
mov    %rbx,%rdi
call   1170 <add_output@plt>
add    $0xdf0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"invalid color\00"
@.str.1 = [5 x i8] c"pass\00"
define void @gtp_genmove(i32 %0, [20 x i8]* %1) {
%3 = alloca i32
%4 = alloca [20 x i8]*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [441 x [2 x i32]]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [2 x i8]
%15 = alloca [3 x i8]
%16 = alloca [4 x i8]
store i32 %0, i32* %3
store [20 x i8]* %1, [20 x i8]** %4
%17 = bitcast [4 x i8]* %16 to i8*
store i32 0, i32* %5
br label %18
18: ; preds = %30, %2
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 441
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %10, i64 0, i64 %23
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %24, i64 0, i64 0
store i32 -1, i32* %25
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %10, i64 0, i64 %27
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %28, i64 0, i64 1
store i32 -1, i32* %29
br label %30
30: ; preds = %21
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %18
33: ; preds = %18
%34 = load [20 x i8]*, [20 x i8]** %4
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %34, i64 0
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %35, i64 0, i64 0
%37 = call i32 @is_color_valid(i8* %36, i32* %6)
%38 = icmp ne i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %33
%40 = call i32 (...) @set_output_error()
%41 = call i32 @add_output(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %120
42: ; preds = %33
store i32 -1, i32* %7
store i32 -1, i32* %8
%43 = load i32, i32* %6
%44 = call i32 @search_tree(i32 %43, i32* %7, i32* %8)
%45 = load i32, i32* %7
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %56
47: ; preds = %42
%48 = load i32, i32* %8
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = call i32 (...) @create_next_move()
%52 = load i32, i32* %6
%53 = call i32 @set_move_pass(i32 %52)
%54 = call i32 (...) @push_move()
%55 = call i32 @add_output(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %120
56: ; preds = %47, %42
%57 = load i32, i32* %6
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = call i32 @set_vertex(i32 %57, i32 %58, i32 %59)
%61 = call i32 (...) @scan_board_1()
%62 = load i32, i32* %6
%63 = mul nsw i32 %62, -1
%64 = call i32 @remove_stones(i32 %63)
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = icmp sgt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %56
%68 = call i32 (...) @scan_board_1()
br label %69
69: ; preds = %67, %56
%70 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %10, i64 0, i64 0
%71 = bitcast [2 x i32]* %70 to i32**
%72 = call i32 @get_captured_now(i32** %71)
store i32 %72, i32* %9
%73 = call i32 (...) @create_next_move()
%74 = load i32, i32* %6
%75 = load i32, i32* %7
%76 = load i32, i32* %8
%77 = call i32 @set_move_vertex(i32 %74, i32 %75, i32 %76)
%78 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %10, i64 0, i64 0
%79 = bitcast [2 x i32]* %78 to i32**
%80 = call i32 @set_move_captured_stones(i32** %79)
%81 = load i32, i32* %7
%82 = load i32, i32* %8
%83 = call i32 @get_worm_nr(i32 %81, i32 %82)
store i32 %83, i32* %11
%84 = load i32, i32* %11
%85 = call i32 @get_nr_of_liberties(i32 %84)
store i32 %85, i32* %12
%86 = load i32, i32* %11
%87 = call i32 @get_size_of_worm(i32 %86)
store i32 %87, i32* %13
%88 = load i32, i32* %9
%89 = icmp eq i32 %88, 1
br i1 %89, label %90, label %104
90: ; preds = %69
%91 = load i32, i32* %13
%92 = icmp eq i32 %91, 1
br i1 %92, label %93, label %104
93: ; preds = %90
%94 = load i32, i32* %12
%95 = icmp eq i32 %94, 1
br i1 %95, label %96, label %104
96: ; preds = %93
%97 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %10, i64 0, i64 0
%98 = getelementptr inbounds [2 x i32], [2 x i32]* %97, i64 0, i64 0
%99 = load i32, i32* %98
%100 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %10, i64 0, i64 0
%101 = getelementptr inbounds [2 x i32], [2 x i32]* %100, i64 0, i64 1
%102 = load i32, i32* %101
%103 = call i32 @set_move_ko(i32 %99, i32 %102)
br label %104
104: ; preds = %96, %93, %90, %69
%105 = call i32 (...) @push_move()
%106 = load i32, i32* %7
%107 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 0
%108 = call i32 @i_to_x(i32 %106, i8* %107)
%109 = load i32, i32* %8
%110 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%111 = call i32 @j_to_y(i32 %109, i8* %110)
%112 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%113 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 0
%114 = call i32 @strcat(i8* %112, i8* %113)
%115 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%116 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%117 = call i32 @strcat(i8* %115, i8* %116)
%118 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%119 = call i32 @add_output(i8* %118)
br label %120
120: ; preds = %104, %50, %39
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"invalid color\00"
@.str.1 = [5 x i8] c"pass\00"
define void @gtp_genmove(i32 %0, [20 x i8]* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [441 x [2 x i32]]
%7 = bitcast [441 x [2 x i32]]* %6 to i8*
%8 = alloca [2 x i8]
%9 = alloca [3 x i8]
%10 = alloca i32
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%16 = bitcast i32* %10 to i8*
store i32 0, i32* %10
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%18 = call i32 @is_color_valid(i8* %17, i32* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 (...) @set_output_error()
%22 = call i32 @add_output(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %81
23: ; preds = %2
store i32 -1, i32* %4
store i32 -1, i32* %5
%24 = load i32, i32* %3
%25 = call i32 @search_tree(i32 %24, i32* %4, i32* %5)
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, -1
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, -1
%30 = select i1 %27, i1 %29, i1 false
br i1 %30, label %31, label %37
31: ; preds = %23
%32 = call i32 (...) @create_next_move()
%33 = load i32, i32* %3
%34 = call i32 @set_move_pass(i32 %33)
%35 = call i32 (...) @push_move()
%36 = call i32 @add_output(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %81
37: ; preds = %23
%38 = load i32, i32* %3
%39 = call i32 @set_vertex(i32 %38, i32 %26, i32 %28)
%40 = call i32 (...) @scan_board_1()
%41 = load i32, i32* %3
%42 = sub nsw i32 0, %41
%43 = call i32 @remove_stones(i32 %42)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = call i32 (...) @scan_board_1()
br label %47
47: ; preds = %45, %37
%48 = bitcast [441 x [2 x i32]]* %6 to i32**
%49 = call i32 @get_captured_now(i32** %48)
%50 = call i32 (...) @create_next_move()
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = load i32, i32* %5
%54 = call i32 @set_move_vertex(i32 %51, i32 %52, i32 %53)
%55 = call i32 @set_move_captured_stones(i32** %48)
%56 = load i32, i32* %4
%57 = load i32, i32* %5
%58 = call i32 @get_worm_nr(i32 %56, i32 %57)
%59 = call i32 @get_nr_of_liberties(i32 %58)
%60 = call i32 @get_size_of_worm(i32 %58)
%61 = icmp eq i32 %49, 1
%62 = icmp eq i32 %60, 1
%63 = select i1 %61, i1 %62, i1 false
%64 = icmp eq i32 %59, 1
%65 = select i1 %63, i1 %64, i1 false
br i1 %65, label %66, label %72
66: ; preds = %47
%67 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %6, i64 0, i64 0, i64 0
%68 = load i32, i32* %67
%69 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %6, i64 0, i64 0, i64 1
%70 = load i32, i32* %69
%71 = call i32 @set_move_ko(i32 %68, i32 %70)
br label %72
72: ; preds = %66, %47
%73 = call i32 (...) @push_move()
%74 = load i32, i32* %4
%75 = call i32 @i_to_x(i32 %74, i8* %14)
%76 = load i32, i32* %5
%77 = call i32 @j_to_y(i32 %76, i8* %15)
%78 = call i32 @strcat(i8* %16, i8* %14)
%79 = call i32 @strcat(i8* %16, i8* %15)
%80 = call i32 @add_output(i8* %16)
br label %81
81: ; preds = %72, %31, %20
ret void
}