#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 RAND_MAX;
scalar_t__ check_for_lose(int);
int /*<<< orphan*/ compy_turn();
int /*<<< orphan*/ player_turn();
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ show_board();
void play(void) {
  int winner = 0;
  if (rand() < RAND_MAX / 2) {
    printf("\nYou go first.\n");
    player_turn();
  } else
    printf("\nI'll go first.\n");
  do {
    compy_turn();
    if (check_for_lose(0)) {
      winner = 1;
      printf("\nI win!\n");
    } else {
      player_turn();
      if (check_for_lose(1)) {
        winner = 1;
        printf("\nYou win!\n");
      }
    }
  } while (!winner);
  show_board();
}


x86 assembly (clang, -O0):
<play>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
cmp    %ecx,%eax
jge    11af <play+0x4f>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <player_turn@plt>
jmp    11bb <play+0x5b>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
jmp    11c0 <play+0x60>
mov    $0x0,%al
call   1040 <compy_turn@plt>
xor    %edi,%edi
call   1060 <check_for_lose@plt>
cmp    $0x0,%rax
je     11f0 <play+0x90>
movl   $0x1,-0x4(%rbp)
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
jmp    1223 <play+0xc3>
mov    $0x0,%al
call   1050 <player_turn@plt>
mov    $0x1,%edi
call   1060 <check_for_lose@plt>
cmp    $0x0,%rax
je     121e <play+0xbe>
movl   $0x1,-0x4(%rbp)
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
jmp    1223 <play+0xc3>
jmp    1228 <play+0xc8>
cmpl   $0x0,-0x4(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c0 <play+0x60>
mov    $0x0,%al
call   1070 <show_board@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<play>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <rand@plt>
mov    0x2e76(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
jge    1196 <play+0x36>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <player_turn@plt>
jmp    11a2 <play+0x42>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
lea    0xe71(%rip),%rbx
lea    0xe60(%rip),%r14
xor    %eax,%eax
call   1040 <compy_turn@plt>
xor    %edi,%edi
call   1060 <check_for_lose@plt>
test   %rax,%rax
jne    11dc <play+0x7c>
xor    %eax,%eax
call   1050 <player_turn@plt>
mov    $0x1,%edi
call   1060 <check_for_lose@plt>
test   %rax,%rax
je     11b0 <play+0x50>
mov    %r14,%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <show_board@plt>

LLVM IR (-O0):
@RAND_MAX = global i32 0
@.str = [16 x i8] c"\0AYou go first.\0A\00"
@.str.1 = [17 x i8] c"\0AI'll go first.\0A\00"
@.str.2 = [9 x i8] c"\0AI win!\0A\00"
@.str.3 = [11 x i8] c"\0AYou win!\0A\00"
define void @play() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (...) @rand()
%3 = load i32, i32* @RAND_MAX
%4 = sdiv i32 %3, 2
%5 = icmp slt i32 %2, %4
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @player_turn()
br label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
br label %12
12: ; preds = %26, %11
%13 = call i32 (...) @compy_turn()
%14 = call i64 @check_for_lose(i32 0)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
store i32 1, i32* %1
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %25
18: ; preds = %12
%19 = call i32 (...) @player_turn()
%20 = call i64 @check_for_lose(i32 1)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
store i32 1, i32* %1
%23 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
br label %25
25: ; preds = %24, %16
br label %26
26: ; preds = %25
%27 = load i32, i32* %1
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %12, label %30
30: ; preds = %26
%31 = call i32 (...) @show_board()
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
@str = [16 x i8] c"\0AI'll go first.\00"
@str.4 = [10 x i8] c"\0AYou win!\00"
@str.5 = [8 x i8] c"\0AI win!\00"
@str.6 = [15 x i8] c"\0AYou go first.\00"
define void @play() {
%1 = tail call i32 (...) @rand()
%2 = load i32, i32* @RAND_MAX
%3 = sdiv i32 %2, 2
%4 = icmp slt i32 %1, %3
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.6, i64 0, i64 0))
%7 = tail call i32 (...) @player_turn()
br label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
br label %11
11: ; preds = %10, %15
%12 = tail call i32 (...) @compy_turn()
%13 = tail call i64 @check_for_lose(i32 0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = tail call i32 (...) @player_turn()
%17 = tail call i64 @check_for_lose(i32 1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %11, label %19
19: ; preds = %15, %11
%20 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.5, i64 0, i64 0), %11 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0), %15 ]
%21 = tail call i32 @puts(i8* dereferenceable(1) %20)
%22 = tail call i32 (...) @show_board()
ret void
}