#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int check_all(char **);
scalar_t__ check_draw(char **);
scalar_t__ check_spot(char **, int);
int /*<<< orphan*/ draw_board(char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ init_board(char **);
int /*<<< orphan*/ move(char **, int, int);
int /*<<< orphan*/ print_controls();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ prompt();
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  char board[3][3];
  int choice, next_move, player_turn = 1, winner = 0;
  init_board(board);
  prompt();
  scanf(" %d", &choice);
  switch (choice) {
  case 1:
    draw_board(board);
    print_controls();
    break;
  case 2:
    printf("Okay bye bye!\n");
    exit(EXIT_SUCCESS);
    break;
  default:
    printf("you broke the game i leave now\n");
    exit(EXIT_FAILURE);
    break;
  }
  while (1) {
    switch (player_turn) {
    case 1:
      printf("Player 1 move: ");
      break;
    case 2:
      printf("Player 2 move: ");
      break;
    default:
      printf("uh no");
      break;
    }
    scanf(" %d", &next_move);
    if (check_spot(board, next_move)) {
      move(board, next_move, player_turn);
      winner = check_all(board);
      if (winner == 1) {
        printf("Player 1 Wins! Good job! buhbye now sleepy time...\n\n");
        exit(EXIT_SUCCESS);
      } else if (winner == 2) {
        printf("Player 2 Wins! Good job! buhbye now sleepy time...\n\n");
        exit(EXIT_SUCCESS);
      }
      if (check_draw(board)) {
        printf("Oh snap, a draw! Y'all must be great at tic-tac-toe "
               "waow!\nWell, buhbye\n\n");
        exit(EXIT_SUCCESS);
      }
      draw_board(board);
      print_controls();
      if (player_turn == 1) {
        player_turn = 2;
      } else if (player_turn == 2) {
        player_turn = 1;
      }
    } else {
      printf("Invalid move, try again!\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    -0x19(%rbp),%rdi
call   1060 <init_board@plt>
xor    %eax,%eax
call   1040 <prompt@plt>
lea    0xe15(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x1,%eax
je     1219 <main+0x69>
jmp    1208 <main+0x58>
mov    -0x30(%rbp),%eax
sub    $0x2,%eax
je     122e <main+0x7e>
jmp    1248 <main+0x98>
lea    -0x19(%rbp),%rdi
call   1030 <draw_board@plt>
mov    $0x0,%al
call   1090 <print_controls@plt>
jmp    1262 <main+0xb2>
lea    0xdcf(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xdc4(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    1267 <main+0xb7>
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x1,%eax
je     128c <main+0xdc>
jmp    127b <main+0xcb>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     129d <main+0xed>
jmp    12ae <main+0xfe>
lea    0xda0(%rip),%rdi
call   1050 <printf@plt>
jmp    12ba <main+0x10a>
lea    0xd9f(%rip),%rdi
call   1050 <printf@plt>
jmp    12ba <main+0x10a>
lea    0xd9e(%rip),%rdi
call   1050 <printf@plt>
lea    0xd3f(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   10a0 <scanf@plt>
lea    -0x19(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10b0 <check_spot@plt>
cmp    $0x0,%rax
je     13b6 <main+0x206>
lea    -0x19(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   10d0 <move@plt>
lea    -0x19(%rbp),%rdi
call   1070 <check_all@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    131f <main+0x16f>
lea    0xd4d(%rip),%rdi
call   1050 <printf@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
cmpl   $0x2,-0x2c(%rbp)
jne    1343 <main+0x193>
lea    0xd5e(%rip),%rdi
call   1050 <printf@plt>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    1348 <main+0x198>
lea    -0x19(%rbp),%rdi
call   1080 <check_draw@plt>
cmp    $0x0,%rax
je     1375 <main+0x1c5>
lea    0xd61(%rip),%rdi
call   1050 <printf@plt>
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x19(%rbp),%rdi
call   1030 <draw_board@plt>
mov    $0x0,%al
call   1090 <print_controls@plt>
cmpl   $0x1,-0x28(%rbp)
jne    139b <main+0x1eb>
movl   $0x2,-0x28(%rbp)
jmp    13b1 <main+0x201>
cmpl   $0x2,-0x28(%rbp)
jne    13ac <main+0x1fc>
movl   $0x1,-0x28(%rbp)
jmp    13b1 <main+0x201>
jmp    13c2 <main+0x212>
lea    0xd4f(%rip),%rdi
call   1050 <printf@plt>
jmp    1267 <main+0xb7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xf(%rsp),%rdi
call   1070 <init_board@plt>
xor    %eax,%eax
call   1050 <prompt@plt>
lea    0xe1a(%rip),%rdi
lea    0x8(%rsp),%rsi
call   10b0 <scanf@plt>
mov    0x8(%rsp),%eax
cmp    $0x2,%eax
je     12f1 <main+0x131>
cmp    $0x1,%eax
jne    12fa <main+0x13a>
lea    0xf(%rsp),%r14
mov    %r14,%rdi
call   1030 <draw_board@plt>
xor    %eax,%eax
call   10a0 <print_controls@plt>
mov    $0x1,%r12d
lea    0xdd9(%rip),%r15
lea    0x4(%rsp),%rbx
lea    0xe05(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x2,%r12d
lea    0xdd9(%rip),%rbp
lea    0xdc2(%rip),%rax
cmove  %rax,%rbp
cmp    $0x1,%r12d
lea    0xda3(%rip),%rax
cmove  %rax,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   10c0 <check_spot@plt>
test   %rax,%rax
jne    12a0 <main+0xe0>
mov    %r13,%rdi
call   1040 <puts@plt>
jmp    1270 <main+0xb0>
xchg   %ax,%ax
mov    0x4(%rsp),%esi
mov    %r14,%rdi
mov    %r12d,%edx
call   10e0 <move@plt>
mov    %r14,%rdi
call   1080 <check_all@plt>
cmp    $0x2,%eax
je     1314 <main+0x154>
cmp    $0x1,%eax
je     131d <main+0x15d>
mov    %r14,%rdi
call   1090 <check_draw@plt>
test   %rax,%rax
jne    1326 <main+0x166>
mov    %r14,%rdi
call   1030 <draw_board@plt>
xor    %eax,%eax
call   10a0 <print_controls@plt>
xor    %eax,%eax
cmp    $0x1,%r12d
sete   %al
add    $0x1,%eax
mov    %eax,%r12d
jmp    1240 <main+0x80>
lea    0xd32(%rip),%rdi
jmp    132d <main+0x16d>
lea    0xe00(%rip),%rdi
call   1040 <puts@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xd7e(%rip),%rdi
jmp    132d <main+0x16d>
lea    0xda9(%rip),%rdi
jmp    132d <main+0x16d>
lea    0xd24(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c" %d\00"
@.str.1 = [15 x i8] c"Okay bye bye!\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [32 x i8] c"you broke the game i leave now\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [16 x i8] c"Player 1 move: \00"
@.str.4 = [16 x i8] c"Player 2 move: \00"
@.str.5 = [6 x i8] c"uh no\00"
@.str.6 = [53 x i8] c"Player 1 Wins! Good job! buhbye now sleepy time...\0A\0A\00"
@.str.7 = [53 x i8] c"Player 2 Wins! Good job! buhbye now sleepy time...\0A\0A\00"
@.str.8 = [73 x i8] c"Oh snap, a draw! Y'all must be great at tic-tac-toe waow!\0AWell, buhbye\0A\0A\00"
@.str.9 = [26 x i8] c"Invalid move, try again!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x [3 x i8]]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
store i32 0, i32* %10
%11 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %6, i64 0, i64 0
%12 = bitcast [3 x i8]* %11 to i8**
%13 = call i32 @init_board(i8** %12)
%14 = call i32 (...) @prompt()
%15 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %7)
%16 = load i32, i32* %7
switch i32 %16, label %26 [
i32 1, label %17
i32 2, label %22
]
17: ; preds = %2
%18 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %6, i64 0, i64 0
%19 = bitcast [3 x i8]* %18 to i8**
%20 = call i32 @draw_board(i8** %19)
%21 = call i32 (...) @print_controls()
br label %30
22: ; preds = %2
%23 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_SUCCESS
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %2
%27 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %17
br label %31
31: ; preds = %30, %94
%32 = load i32, i32* %9
switch i32 %32, label %37 [
i32 1, label %33
i32 2, label %35
]
33: ; preds = %31
%34 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %39
35: ; preds = %31
%36 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %39
37: ; preds = %31
%38 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %39
39: ; preds = %37, %35, %33
%40 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %8)
%41 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %6, i64 0, i64 0
%42 = bitcast [3 x i8]* %41 to i8**
%43 = load i32, i32* %8
%44 = call i64 @check_spot(i8** %42, i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %92
46: ; preds = %39
%47 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %6, i64 0, i64 0
%48 = bitcast [3 x i8]* %47 to i8**
%49 = load i32, i32* %8
%50 = load i32, i32* %9
%51 = call i32 @move(i8** %48, i32 %49, i32 %50)
%52 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %6, i64 0, i64 0
%53 = bitcast [3 x i8]* %52 to i8**
%54 = call i32 @check_all(i8** %53)
store i32 %54, i32* %10
%55 = load i32, i32* %10
%56 = icmp eq i32 %55, 1
br i1 %56, label %57, label %61
57: ; preds = %46
%58 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0))
%59 = load i32, i32* @EXIT_SUCCESS
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %46
%62 = load i32, i32* %10
%63 = icmp eq i32 %62, 2
br i1 %63, label %64, label %68
64: ; preds = %61
%65 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0))
%66 = load i32, i32* @EXIT_SUCCESS
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %61
br label %69
69: ; preds = %68
%70 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %6, i64 0, i64 0
%71 = bitcast [3 x i8]* %70 to i8**
%72 = call i64 @check_draw(i8** %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %69
%75 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.8, i64 0, i64 0))
%76 = load i32, i32* @EXIT_SUCCESS
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %69
%79 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %6, i64 0, i64 0
%80 = bitcast [3 x i8]* %79 to i8**
%81 = call i32 @draw_board(i8** %80)
%82 = call i32 (...) @print_controls()
%83 = load i32, i32* %9
%84 = icmp eq i32 %83, 1
br i1 %84, label %85, label %86
85: ; preds = %78
store i32 2, i32* %9
br label %91
86: ; preds = %78
%87 = load i32, i32* %9
%88 = icmp eq i32 %87, 2
br i1 %88, label %89, label %90
89: ; preds = %86
store i32 1, i32* %9
br label %90
90: ; preds = %89, %86
br label %91
91: ; preds = %90, %85
br label %94
92: ; preds = %39
%93 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %94
94: ; preds = %92, %91
br label %31
}

LLVM IR (-O2):
@.str = [4 x i8] c" %d\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [16 x i8] c"Player 1 move: \00"
@.str.4 = [16 x i8] c"Player 2 move: \00"
@.str.5 = [6 x i8] c"uh no\00"
@str = [14 x i8] c"Okay bye bye!\00"
@str.10 = [25 x i8] c"Invalid move, try again!\00"
@str.11 = [72 x i8] c"Oh snap, a draw! Y'all must be great at tic-tac-toe waow!\0AWell, buhbye\0A\00"
@str.12 = [52 x i8] c"Player 2 Wins! Good job! buhbye now sleepy time...\0A\00"
@str.13 = [52 x i8] c"Player 1 Wins! Good job! buhbye now sleepy time...\0A\00"
@str.14 = [31 x i8] c"you broke the game i leave now\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x [3 x i8]]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %3, i64 0, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = bitcast [3 x [3 x i8]]* %3 to i8**
%10 = call i32 @init_board(i8** %9)
%11 = call i32 (...) @prompt()
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %4)
%13 = load i32, i32* %4
switch i32 %13, label %21 [
i32 1, label %14
i32 2, label %17
]
14: ; preds = %2
%15 = call i32 @draw_board(i8** %9)
%16 = call i32 (...) @print_controls()
br label %55
17: ; preds = %2
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_SUCCESS
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.14, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %55, %61
%26 = call i32 @printf(i8* dereferenceable(1) %60)
%27 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %5)
%28 = load i32, i32* %5
%29 = call i64 @check_spot(i8** %9, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %61, label %31
31: ; preds = %25
%32 = load i32, i32* %5
%33 = call i32 @move(i8** %9, i32 %32, i32 %56)
%34 = call i32 @check_all(i8** %9)
switch i32 %34, label %43 [
i32 1, label %35
i32 2, label %39
]
35: ; preds = %31
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.13, i64 0, i64 0))
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %31
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.12, i64 0, i64 0))
%41 = load i32, i32* @EXIT_SUCCESS
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %31
%44 = call i64 @check_draw(i8** %9)
%45 = icmp eq i64 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %43
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str.11, i64 0, i64 0))
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %43
%51 = call i32 @draw_board(i8** %9)
%52 = call i32 (...) @print_controls()
%53 = icmp eq i32 %56, 1
%54 = select i1 %53, i32 2, i32 1
br label %55
55: ; preds = %50, %14
%56 = phi i32 [ %54, %50 ], [ 1, %14 ]
%57 = icmp eq i32 %56, 2
%58 = select i1 %57, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%59 = icmp eq i32 %56, 1
%60 = select i1 %59, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %58
br label %25
61: ; preds = %25
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.10, i64 0, i64 0))
br label %25
}