#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 *);
scalar_t__ get_black_captured();
int get_last_move_color();
int get_last_move_count_stones();
int get_last_move_i();
int get_last_move_j();
int /*<<< orphan*/ get_last_move_stones(int **);
int get_move_number();
scalar_t__ get_white_captured();
int /*<<< orphan*/ pop_move();
int /*<<< orphan*/ set_black_captured(scalar_t__);
int /*<<< orphan*/ set_output_error();
int /*<<< orphan*/ set_vertex(int, int, int);
int /*<<< orphan*/ set_white_captured(scalar_t__);
void gtp_undo(int gtp_argc, char gtp_argv[][20]) {
  int move_number;
  int color;
  int i, j;
  int count_stones;
  int stones[21 * 21][2];
  int k;
  move_number = get_move_number();
  if (move_number <= 0) {
    set_output_error();
    add_output("cannot undo");
    return;
  }
  color = get_last_move_color();
  i = get_last_move_i();
  j = get_last_move_j();
  count_stones = get_last_move_count_stones();
  set_vertex(0, i, j);
  if (count_stones > 0) {
    get_last_move_stones(stones);
    for (k = 0; k < count_stones; k++) {
      set_vertex(color * -1, stones[k][0], stones[k][1]);
    }
    if (color == 1) {
      set_black_captured(get_black_captured() - count_stones);
    } else {
      set_white_captured(get_white_captured() - count_stones);
    }
  }
  pop_move();
  return;
}


x86 assembly (clang, -O0):
<gtp_undo>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe00,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <get_move_number@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     121e <gtp_undo+0x3e>
mov    $0x0,%al
call   1080 <set_output_error@plt>
lea    0xdec(%rip),%rdi
call   10d0 <add_output@plt>
jmp    1302 <gtp_undo+0x122>
mov    $0x0,%al
call   10a0 <get_last_move_color@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <get_last_move_i@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1090 <get_last_move_j@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   10e0 <get_last_move_count_stones@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
xor    %edi,%edi
call   1070 <set_vertex@plt>
cmpl   $0x0,-0x24(%rbp)
jle    12fb <gtp_undo+0x11b>
lea    -0xdf0(%rbp),%rdi
call   10c0 <get_last_move_stones@plt>
movl   $0x0,-0xdf4(%rbp)
mov    -0xdf4(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12bb <gtp_undo+0xdb>
imul   $0xffffffff,-0x18(%rbp),%edi
movslq -0xdf4(%rbp),%rax
mov    -0xdf0(%rbp,%rax,8),%esi
movslq -0xdf4(%rbp),%rax
mov    -0xdec(%rbp,%rax,8),%edx
call   1070 <set_vertex@plt>
mov    -0xdf4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xdf4(%rbp)
jmp    1273 <gtp_undo+0x93>
cmpl   $0x1,-0x18(%rbp)
jne    12e0 <gtp_undo+0x100>
mov    $0x0,%al
call   1040 <get_black_captured@plt>
mov    %rax,%rdi
movslq -0x24(%rbp),%rax
sub    %rax,%rdi
call   1050 <set_black_captured@plt>
jmp    12f6 <gtp_undo+0x116>
mov    $0x0,%al
call   10f0 <get_white_captured@plt>
mov    %rax,%rdi
movslq -0x24(%rbp),%rax
sub    %rax,%rdi
call   10b0 <set_white_captured@plt>
jmp    12fb <gtp_undo+0x11b>
mov    $0x0,%al
call   1100 <pop_move@plt>
add    $0xe00,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtp_undo>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xdd0,%rsp
xor    %eax,%eax
call   1060 <get_move_number@plt>
test   %eax,%eax
jle    1284 <gtp_undo+0xa4>
xor    %eax,%eax
call   10a0 <get_last_move_color@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <get_last_move_i@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <get_last_move_j@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10e0 <get_last_move_count_stones@plt>
mov    %eax,%r15d
xor    %edi,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1070 <set_vertex@plt>
test   %r15d,%r15d
jle    12b9 <gtp_undo+0xd9>
mov    %rsp,%rdi
call   10c0 <get_last_move_stones@plt>
mov    %r14d,%ebp
neg    %ebp
mov    %r15d,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,8),%esi
mov    0x4(%rsp,%rbx,8),%edx
mov    %ebp,%edi
call   1070 <set_vertex@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1250 <gtp_undo+0x70>
xor    %eax,%eax
cmp    $0x1,%r14d
jne    12a6 <gtp_undo+0xc6>
call   1040 <get_black_captured@plt>
movslq %r15d,%rcx
sub    %rcx,%rax
mov    %rax,%rdi
call   1050 <set_black_captured@plt>
jmp    12b9 <gtp_undo+0xd9>
xor    %eax,%eax
call   1080 <set_output_error@plt>
lea    0xd6e(%rip),%rdi
add    $0xdd0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10d0 <add_output@plt>
call   10f0 <get_white_captured@plt>
movslq %r15d,%rcx
sub    %rcx,%rax
mov    %rax,%rdi
call   10b0 <set_white_captured@plt>
xor    %eax,%eax
call   1100 <pop_move@plt>
add    $0xdd0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"cannot undo\00"
define void @gtp_undo(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
store i32 %0, i32* %3
store [20 x i8]* %1, [20 x i8]** %4
%12 = call i32 (...) @get_move_number()
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (...) @set_output_error()
%17 = call i32 @add_output(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %71
18: ; preds = %2
%19 = call i32 (...) @get_last_move_color()
store i32 %19, i32* %6
%20 = call i32 (...) @get_last_move_i()
store i32 %20, i32* %7
%21 = call i32 (...) @get_last_move_j()
store i32 %21, i32* %8
%22 = call i32 (...) @get_last_move_count_stones()
store i32 %22, i32* %9
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = call i32 @set_vertex(i32 0, i32 %23, i32 %24)
%26 = load i32, i32* %9
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %69
28: ; preds = %18
%29 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %10, i64 0, i64 0
%30 = bitcast [2 x i32]* %29 to i32**
%31 = call i32 @get_last_move_stones(i32** %30)
store i32 0, i32* %11
br label %32
32: ; preds = %50, %28
%33 = load i32, i32* %11
%34 = load i32, i32* %9
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %53
36: ; preds = %32
%37 = load i32, i32* %6
%38 = mul nsw i32 %37, -1
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %10, i64 0, i64 %40
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %41, i64 0, i64 0
%43 = load i32, i32* %42
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %10, i64 0, i64 %45
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %46, i64 0, i64 1
%48 = load i32, i32* %47
%49 = call i32 @set_vertex(i32 %38, i32 %43, i32 %48)
br label %50
50: ; preds = %36
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %32
53: ; preds = %32
%54 = load i32, i32* %6
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %62
56: ; preds = %53
%57 = call i64 (...) @get_black_captured()
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = sub nsw i64 %57, %59
%61 = call i32 @set_black_captured(i64 %60)
br label %68
62: ; preds = %53
%63 = call i64 (...) @get_white_captured()
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = sub nsw i64 %63, %65
%67 = call i32 @set_white_captured(i64 %66)
br label %68
68: ; preds = %62, %56
br label %69
69: ; preds = %68, %18
%70 = call i32 (...) @pop_move()
br label %71
71: ; preds = %69, %15
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"cannot undo\00"
define void @gtp_undo(i32 %0, [20 x i8]* nocapture readnone %1) {
%3 = alloca [441 x [2 x i32]]
%4 = bitcast [441 x [2 x i32]]* %3 to i8*
%5 = tail call i32 (...) @get_move_number()
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 (...) @set_output_error()
%9 = tail call i32 @add_output(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %45
10: ; preds = %2
%11 = tail call i32 (...) @get_last_move_color()
%12 = tail call i32 (...) @get_last_move_i()
%13 = tail call i32 (...) @get_last_move_j()
%14 = tail call i32 (...) @get_last_move_count_stones()
%15 = tail call i32 @set_vertex(i32 0, i32 %12, i32 %13)
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %43
17: ; preds = %10
%18 = bitcast [441 x [2 x i32]]* %3 to i32**
%19 = call i32 @get_last_move_stones(i32** %18)
%20 = sub nsw i32 0, %11
%21 = zext i32 %14 to i64
br label %22
22: ; preds = %17, %22
%23 = phi i64 [ 0, %17 ], [ %29, %22 ]
%24 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %3, i64 0, i64 %23, i64 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds [441 x [2 x i32]], [441 x [2 x i32]]* %3, i64 0, i64 %23, i64 1
%27 = load i32, i32* %26
%28 = call i32 @set_vertex(i32 %20, i32 %25, i32 %27)
%29 = add nuw nsw i64 %23, 1
%30 = icmp eq i64 %29, %21
br i1 %30, label %31, label %22
31: ; preds = %22
%32 = icmp eq i32 %11, 1
br i1 %32, label %33, label %38
33: ; preds = %31
%34 = call i64 (...) @get_black_captured()
%35 = sext i32 %14 to i64
%36 = sub nsw i64 %34, %35
%37 = call i32 @set_black_captured(i64 %36)
br label %43
38: ; preds = %31
%39 = call i64 (...) @get_white_captured()
%40 = sext i32 %14 to i64
%41 = sub nsw i64 %39, %40
%42 = call i32 @set_white_captured(i64 %41)
br label %43
43: ; preds = %33, %38, %10
%44 = call i32 (...) @pop_move()
br label %45
45: ; preds = %43, %7
ret void
}