#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 */
scalar_t__ check_win_conditions(char);
int /*<<< orphan*/ computer_turn(int);
int /*<<< orphan*/ human_turn(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ set_default_values();
int /*<<< orphan*/ show_field();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int x, y;
  int game_state = 0;
  int ai_type;
  srand(time(NULL));
  set_default_values();
  do {
    printf("Choose ai type (1 or 2): \n");
    scanf("%d", &ai_type);
  } while (ai_type != 1 && ai_type != 2);
  while (!game_state) {
    human_turn(x, y);
    show_field();
    if (check_win_conditions('x')) {
      game_state = 1;
    }
    computer_turn(ai_type);
    show_field();
    if (check_win_conditions('o')) {
      game_state = 2;
    }
  }
  if (game_state == 1) {
    printf("Game ended human win\n");
  }
  if (game_state == 2) {
    printf("Game ended human loose\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    $0x0,%al
call   10b0 <set_default_values@plt>
lea    0xe3c(%rip),%rdi
call   1050 <printf@plt>
lea    0xe4b(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10a0 <scanf@plt>
xor    %eax,%eax
cmpl   $0x1,-0x14(%rbp)
mov    %al,-0x15(%rbp)
je     11f2 <main+0x62>
cmpl   $0x2,-0x14(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11bd <main+0x2d>
jmp    1202 <main+0x72>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1218 <main+0x88>
jmp    1274 <main+0xe4>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <human_turn@plt>
mov    $0x0,%al
call   1090 <show_field@plt>
mov    $0x78,%edi
call   1060 <check_win_conditions@plt>
cmp    $0x0,%rax
je     1245 <main+0xb5>
movl   $0x1,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <computer_turn@plt>
mov    $0x0,%al
call   1090 <show_field@plt>
mov    $0x6f,%edi
call   1060 <check_win_conditions@plt>
cmp    $0x0,%rax
je     126f <main+0xdf>
movl   $0x2,-0x10(%rbp)
jmp    1202 <main+0x72>
cmpl   $0x1,-0x10(%rbp)
jne    128a <main+0xfa>
lea    0xd99(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x2,-0x10(%rbp)
jne    12a0 <main+0x110>
lea    0xd99(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   10b0 <set_default_values@plt>
lea    0xe50(%rip),%r14
lea    0xe46(%rip),%r15
lea    0x4(%rsp),%rbx
nop
mov    %r14,%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xfffffffd,%eax
cmp    $0xfffffffe,%eax
jb     11c0 <main+0x30>
mov    $0x2,%ebx
xor    %ebp,%ebp
test   %ebp,%ebp
jne    1233 <main+0xa3>
nopw   0x0(%rax,%rax,1)
call   1030 <human_turn@plt>
xor    %eax,%eax
call   1090 <show_field@plt>
mov    $0x78,%edi
call   1060 <check_win_conditions@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    0x4(%rsp),%edi
call   1040 <computer_turn@plt>
xor    %eax,%eax
call   1090 <show_field@plt>
mov    $0x6f,%edi
call   1060 <check_win_conditions@plt>
test   %rax,%rax
cmovne %ebx,%ebp
test   %ebp,%ebp
je     11f0 <main+0x60>
cmp    $0x1,%ebp
je     1246 <main+0xb6>
cmp    $0x2,%ebp
jne    1252 <main+0xc2>
lea    0xdd9(%rip),%rdi
jmp    124d <main+0xbd>
lea    0xde7(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Choose ai type (1 or 2): \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"Game ended human win\0A\00"
@.str.3 = [24 x i8] c"Game ended human loose\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32 (...) @set_default_values()
br label %9
9: ; preds = %18, %0
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
br label %12
12: ; preds = %9
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 2
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ false, %12 ], [ %17, %15 ]
br i1 %19, label %9, label %20
20: ; preds = %18
br label %21
21: ; preds = %40, %20
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %41
25: ; preds = %21
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = call i32 @human_turn(i32 %26, i32 %27)
%29 = call i32 (...) @show_field()
%30 = call i64 @check_win_conditions(i8 signext 120)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 1, i32* %4
br label %33
33: ; preds = %32, %25
%34 = load i32, i32* %5
%35 = call i32 @computer_turn(i32 %34)
%36 = call i32 (...) @show_field()
%37 = call i64 @check_win_conditions(i8 signext 111)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 2, i32* %4
br label %40
40: ; preds = %39, %33
br label %21
41: ; preds = %21
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
%47 = load i32, i32* %4
%48 = icmp eq i32 %47, 2
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [26 x i8] c"Choose ai type (1 or 2): \00"
@str.4 = [23 x i8] c"Game ended human loose\00"
@str.5 = [21 x i8] c"Game ended human win\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (...) @set_default_values()
br label %6
6: ; preds = %6, %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = add i32 %9, -3
%11 = icmp ult i32 %10, -2
br i1 %11, label %6, label %12
12: ; preds = %6, %14
%13 = phi i32 [ %25, %14 ], [ 0, %6 ]
switch i32 %13, label %30 [
i32 0, label %14
i32 1, label %27
i32 2, label %26
]
14: ; preds = %12
%15 = call i32 @human_turn(i32 undef, i32 undef)
%16 = call i32 (...) @show_field()
%17 = call i64 @check_win_conditions(i8 signext 120)
%18 = icmp ne i64 %17, 0
%19 = zext i1 %18 to i32
%20 = load i32, i32* %1
%21 = call i32 @computer_turn(i32 %20)
%22 = call i32 (...) @show_field()
%23 = call i64 @check_win_conditions(i8 signext 111)
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i32 %19, i32 2
br label %12
26: ; preds = %12
br label %27
27: ; preds = %12, %26
%28 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0), %26 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0), %12 ]
%29 = call i32 @puts(i8* dereferenceable(1) %28)
br label %30
30: ; preds = %12, %27
ret i32 0
}