#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*/ COLOR_PAIR(int);
int /*<<< orphan*/ attroff(int /*<<< orphan*/);
int /*<<< orphan*/ attron(int /*<<< orphan*/);
int /*<<< orphan*/ endwin();
scalar_t__ get_board_score(int);
int getch();
int /*<<< orphan*/ init_board();
int /*<<< orphan*/ init_curses();
scalar_t__ is_move_possible(int);
int /*<<< orphan*/ make_computer_move();
int /*<<< orphan*/ make_player_move();
int /*<<< orphan*/ mvprintw(int, int, char *);
int /*<<< orphan*/ print_board();
int /*<<< orphan*/ print_game_title();
int /*<<< orphan*/ print_hud();
int /*<<< orphan*/ refresh();
int main() {
  int input;
  init_curses();
  init_board();
  print_game_title();
  print_board();
  print_hud();
  bool computer_move_possible = true;
  bool player_move_possible = true;
  while (computer_move_possible || player_move_possible) {
    print_board();
    print_hud();
    if (is_move_possible(1)) {
      make_player_move();
    } else {
      player_move_possible = false;
    }
    if (is_move_possible(2)) {
      make_computer_move();
    } else {
      computer_move_possible = false;
    }
  }
  if (get_board_score(2) > get_board_score(1)) {
    attron(COLOR_PAIR(4));
    mvprintw((3 + 1) + 8, ((8 + 2) * 4 + 2) + 1,
             "   GAME OVER: COMPUTER WON   ");
    attroff(COLOR_PAIR(4));
  } else if (get_board_score(2) < get_board_score(1)) {
    attron(COLOR_PAIR(3));
    mvprintw((3 + 1) + 8, ((8 + 2) * 4 + 2) + 1,
             "     GAME OVER: YOU WON      ");
    attroff(COLOR_PAIR(3));
  } else {
    attron(COLOR_PAIR(3));
    mvprintw((3 + 1) + 8, ((8 + 2) * 4 + 2) + 1,
             "    GAME OVER: IT'S A TIE    ");
    attroff(COLOR_PAIR(3));
  }
  attron(COLOR_PAIR(5));
  mvprintw((3 + 1) + 9, ((8 + 2) * 4 + 2) + 1, "   PRESS SPACE KEY TO EXIT   ");
  attroff(COLOR_PAIR(5));
  refresh();
  do {
    input = getch();
  } while (input != ' ');
  endwin();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <init_curses@plt>
mov    $0x0,%al
call   1060 <init_board@plt>
mov    $0x0,%al
call   10c0 <print_game_title@plt>
mov    $0x0,%al
call   1080 <print_board@plt>
mov    $0x0,%al
call   10b0 <print_hud@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x11(%rbp)
jne    1259 <main+0x59>
cmpl   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1269 <main+0x69>
jmp    12ca <main+0xca>
mov    $0x0,%al
call   1080 <print_board@plt>
mov    $0x0,%al
call   10b0 <print_hud@plt>
mov    $0x1,%edi
call   10f0 <is_move_possible@plt>
cmp    $0x0,%rax
je     1297 <main+0x97>
mov    $0x0,%al
call   1050 <make_player_move@plt>
jmp    129e <main+0x9e>
movl   $0x0,-0x10(%rbp)
mov    $0x2,%edi
call   10f0 <is_move_possible@plt>
cmp    $0x0,%rax
je     12be <main+0xbe>
mov    $0x0,%al
call   10d0 <make_computer_move@plt>
jmp    12c5 <main+0xc5>
movl   $0x0,-0xc(%rbp)
jmp    1240 <main+0x40>
mov    $0x2,%edi
call   1070 <get_board_score@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1,%edi
call   1070 <get_board_score@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jle    132f <main+0x12f>
mov    $0x4,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1090 <attron@plt>
mov    $0xc,%edi
mov    $0x2b,%esi
lea    0xcec(%rip),%rdx
call   1120 <mvprintw@plt>
mov    $0x4,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
jmp    13d1 <main+0x1d1>
mov    $0x2,%edi
call   1070 <get_board_score@plt>
mov    %rax,-0x28(%rbp)
mov    $0x1,%edi
call   1070 <get_board_score@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jge    1394 <main+0x194>
mov    $0x3,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1090 <attron@plt>
mov    $0xc,%edi
mov    $0x2b,%esi
lea    0xca5(%rip),%rdx
call   1120 <mvprintw@plt>
mov    $0x3,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
jmp    13cc <main+0x1cc>
mov    $0x3,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1090 <attron@plt>
mov    $0xc,%edi
mov    $0x2b,%esi
lea    0xc86(%rip),%rdx
call   1120 <mvprintw@plt>
mov    $0x3,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
jmp    13d1 <main+0x1d1>
mov    $0x5,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1090 <attron@plt>
mov    $0xd,%edi
mov    $0x2b,%esi
lea    0xc67(%rip),%rdx
call   1120 <mvprintw@plt>
mov    $0x5,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
mov    $0x0,%al
call   10e0 <refresh@plt>
mov    $0x0,%al
call   1100 <getch@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jne    1410 <main+0x210>
mov    $0x0,%al
call   1110 <endwin@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <init_curses@plt>
xor    %eax,%eax
call   1060 <init_board@plt>
xor    %eax,%eax
call   10c0 <print_game_title@plt>
xor    %eax,%eax
call   1080 <print_board@plt>
xor    %eax,%eax
call   10b0 <print_hud@plt>
mov    $0x1,%ebx
mov    $0x1,%r14d
jmp    1250 <main+0x50>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10d0 <make_computer_move@plt>
mov    %r14d,%eax
or     %ebp,%eax
mov    %ebp,%ebx
je     128f <main+0x8f>
xor    %eax,%eax
call   1080 <print_board@plt>
xor    %eax,%eax
call   10b0 <print_hud@plt>
mov    $0x1,%edi
call   10f0 <is_move_possible@plt>
mov    $0x0,%ebp
test   %rax,%rax
je     127b <main+0x7b>
xor    %eax,%eax
call   1050 <make_player_move@plt>
mov    %ebx,%ebp
mov    $0x2,%edi
call   10f0 <is_move_possible@plt>
test   %rax,%rax
jne    1240 <main+0x40>
xor    %r14d,%r14d
jmp    1247 <main+0x47>
mov    $0x2,%edi
call   1070 <get_board_score@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1070 <get_board_score@plt>
cmp    %rax,%rbx
jle    12ca <main+0xca>
mov    $0x4,%ebx
mov    $0x4,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1090 <attron@plt>
lea    0xd38(%rip),%rdx
jmp    130f <main+0x10f>
mov    $0x2,%edi
call   1070 <get_board_score@plt>
mov    %rax,%r14
mov    $0x1,%edi
call   1070 <get_board_score@plt>
mov    %rax,%r15
mov    $0x3,%ebx
mov    $0x3,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1090 <attron@plt>
cmp    %r15,%r14
lea    0xd1a(%rip),%rax
lea    0xd31(%rip),%rdx
cmovl  %rax,%rdx
mov    $0xc,%edi
mov    $0x2b,%esi
call   1120 <mvprintw@plt>
mov    %ebx,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
mov    $0x5,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1090 <attron@plt>
lea    0xd16(%rip),%rdx
mov    $0xd,%edi
mov    $0x2b,%esi
call   1120 <mvprintw@plt>
mov    $0x5,%edi
call   10a0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
xor    %eax,%eax
call   10e0 <refresh@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1100 <getch@plt>
cmp    $0x20,%eax
jne    1370 <main+0x170>
xor    %eax,%eax
call   1110 <endwin@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c" GAME OVER: COMPUTER WON \00"
@.str.1 = [30 x i8] c" GAME OVER: YOU WON \00"
@.str.2 = [30 x i8] c" GAME OVER: IT'S A TIE \00"
@.str.3 = [30 x i8] c" PRESS SPACE KEY TO EXIT \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @init_curses()
%6 = call i32 (...) @init_board()
%7 = call i32 (...) @print_game_title()
%8 = call i32 (...) @print_board()
%9 = call i32 (...) @print_hud()
store i32 1, i32* %3
store i32 1, i32* %4
br label %10
10: ; preds = %32, %0
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ true, %10 ], [ %15, %13 ]
br i1 %17, label %18, label %33
18: ; preds = %16
%19 = call i32 (...) @print_board()
%20 = call i32 (...) @print_hud()
%21 = call i64 @is_move_possible(i32 1)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (...) @make_player_move()
br label %26
25: ; preds = %18
store i32 0, i32* %4
br label %26
26: ; preds = %25, %23
%27 = call i64 @is_move_possible(i32 2)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (...) @make_computer_move()
br label %32
31: ; preds = %26
store i32 0, i32* %3
br label %32
32: ; preds = %31, %29
br label %10
33: ; preds = %16
%34 = call i64 @get_board_score(i32 2)
%35 = call i64 @get_board_score(i32 1)
%36 = icmp sgt i64 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %33
%38 = call i32 @COLOR_PAIR(i32 4)
%39 = call i32 @attron(i32 %38)
%40 = call i32 @mvprintw(i32 12, i32 43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @COLOR_PAIR(i32 4)
%42 = call i32 @attroff(i32 %41)
br label %60
43: ; preds = %33
%44 = call i64 @get_board_score(i32 2)
%45 = call i64 @get_board_score(i32 1)
%46 = icmp slt i64 %44, %45
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = call i32 @COLOR_PAIR(i32 3)
%49 = call i32 @attron(i32 %48)
%50 = call i32 @mvprintw(i32 12, i32 43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%51 = call i32 @COLOR_PAIR(i32 3)
%52 = call i32 @attroff(i32 %51)
br label %59
53: ; preds = %43
%54 = call i32 @COLOR_PAIR(i32 3)
%55 = call i32 @attron(i32 %54)
%56 = call i32 @mvprintw(i32 12, i32 43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 @COLOR_PAIR(i32 3)
%58 = call i32 @attroff(i32 %57)
br label %59
59: ; preds = %53, %47
br label %60
60: ; preds = %59, %37
%61 = call i32 @COLOR_PAIR(i32 5)
%62 = call i32 @attron(i32 %61)
%63 = call i32 @mvprintw(i32 13, i32 43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%64 = call i32 @COLOR_PAIR(i32 5)
%65 = call i32 @attroff(i32 %64)
%66 = call i32 (...) @refresh()
br label %67
67: ; preds = %69, %60
%68 = call i32 (...) @getch()
store i32 %68, i32* %2
br label %69
69: ; preds = %67
%70 = load i32, i32* %2
%71 = icmp ne i32 %70, 32
br i1 %71, label %67, label %72
72: ; preds = %69
%73 = call i32 (...) @endwin()
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c" GAME OVER: COMPUTER WON \00"
@.str.1 = [30 x i8] c" GAME OVER: YOU WON \00"
@.str.2 = [30 x i8] c" GAME OVER: IT'S A TIE \00"
@.str.3 = [30 x i8] c" PRESS SPACE KEY TO EXIT \00"
define i32 @main() {
%1 = tail call i32 (...) @init_curses()
%2 = tail call i32 (...) @init_board()
%3 = tail call i32 (...) @print_game_title()
%4 = tail call i32 (...) @print_board()
%5 = tail call i32 (...) @print_hud()
br label %6
6: ; preds = %0, %21
%7 = phi i32 [ 1, %0 ], [ %16, %21 ]
%8 = phi i32 [ 1, %0 ], [ %22, %21 ]
%9 = tail call i32 (...) @print_board()
%10 = tail call i32 (...) @print_hud()
%11 = tail call i64 @is_move_possible(i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %6
%14 = tail call i32 (...) @make_player_move()
br label %15
15: ; preds = %6, %13
%16 = phi i32 [ %7, %13 ], [ 0, %6 ]
%17 = tail call i64 @is_move_possible(i32 2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 (...) @make_computer_move()
br label %21
21: ; preds = %15, %19
%22 = phi i32 [ %8, %19 ], [ 0, %15 ]
%23 = icmp ne i32 %22, 0
%24 = icmp ne i32 %16, 0
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %6, label %26
26: ; preds = %21
%27 = tail call i64 @get_board_score(i32 2)
%28 = tail call i64 @get_board_score(i32 1)
%29 = icmp sgt i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = tail call i32 @COLOR_PAIR(i32 4)
%32 = tail call i32 @attron(i32 %31)
br label %40
33: ; preds = %26
%34 = tail call i64 @get_board_score(i32 2)
%35 = tail call i64 @get_board_score(i32 1)
%36 = icmp slt i64 %34, %35
%37 = tail call i32 @COLOR_PAIR(i32 3)
%38 = tail call i32 @attron(i32 %37)
%39 = select i1 %36, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0)
br label %40
40: ; preds = %33, %30
%41 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %30 ], [ %39, %33 ]
%42 = phi i32 [ 4, %30 ], [ 3, %33 ]
%43 = tail call i32 @mvprintw(i32 12, i32 43, i8* %41)
%44 = tail call i32 @COLOR_PAIR(i32 %42)
%45 = tail call i32 @attroff(i32 %44)
%46 = tail call i32 @COLOR_PAIR(i32 5)
%47 = tail call i32 @attron(i32 %46)
%48 = tail call i32 @mvprintw(i32 13, i32 43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%49 = tail call i32 @COLOR_PAIR(i32 5)
%50 = tail call i32 @attroff(i32 %49)
%51 = tail call i32 (...) @refresh()
br label %52
52: ; preds = %52, %40
%53 = tail call i32 (...) @getch()
%54 = icmp eq i32 %53, 32
br i1 %54, label %55, label %52
55: ; preds = %52
%56 = tail call i32 (...) @endwin()
ret i32 0
}