#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*/ askForMenuNumber(int *, int);
int /*<<< orphan*/ checkForEndOfGame(int *, int *, char *, void (*)());
int drawing();
int /*<<< orphan*/ printGameboard(char *);
int /*<<< orphan*/ printTitle(char *);
int /*<<< orphan*/ printf(char *, int);
void multiplayer(void) {
  int startingPlayer = drawing();
  printTitle("INSTRUCTIONS");
  printf("   |   Let's flip a coin:                                            "
         "       |\n"
         "   |   PLAYER %d starts the game!                                    "
         "        |\n",
         startingPlayer);
  printGameboard("123456789");
  int field;
  char board[9] = "         ";
  for (int i = 0; 1; i++) {
    askForMenuNumber(&field, 9);
    if (board[field - 1] != ' ') {
      i--;
      continue;
    }
    board[field - 1] = i % 2 ? 'O' : 'X';
    printTitle("GAMEBOARD");
    checkForEndOfGame(&i, &field, board, multiplayer);
    int whoseTurnIsIt = (startingPlayer + i) % 2 + 1;
    printf("   |   PLAYER %d it's your turn now, make a move!                  "
           "          |\n",
           whoseTurnIsIt);
    printGameboard(board);
  }
}


x86 assembly (clang, -O0):
<multiplayer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1070 <drawing@plt>
mov    %eax,-0x4(%rbp)
lea    0xe87(%rip),%rdi
call   1040 <printTitle@plt>
mov    -0x4(%rbp),%esi
lea    0xe85(%rip),%rdi
call   1060 <printf@plt>
lea    0xf17(%rip),%rdi
call   1050 <printGameboard@plt>
mov    0xf6f(%rip),%rax
mov    %rax,-0x11(%rbp)
mov    0xf6d(%rip),%al
mov    %al,-0x9(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    11c3 <multiplayer+0x63>
jmp    127c <multiplayer+0x11c>
lea    -0x8(%rbp),%rdi
mov    $0x9,%esi
call   1080 <askForMenuNumber@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x11(%rbp,%rax,1),%eax
cmp    $0x20,%eax
je     11f5 <multiplayer+0x95>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    126e <multiplayer+0x10e>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x58,%eax
mov    $0x4f,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x11(%rbp,%rax,1)
lea    0xe90(%rip),%rdi
call   1040 <printTitle@plt>
lea    -0x11(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    0x2d9b(%rip),%rcx
call   1030 <checkForEndOfGame@plt>
mov    -0x4(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe5f(%rip),%rdi
call   1060 <printf@plt>
lea    -0x11(%rbp),%rdi
call   1050 <printGameboard@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b4 <multiplayer+0x54>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiplayer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <drawing@plt>
mov    %eax,%r14d
lea    0xe7e(%rip),%rdi
call   1040 <printTitle@plt>
lea    0xe7f(%rip),%rdi
mov    %r14d,%esi
call   1060 <printf@plt>
lea    0xf0e(%rip),%rdi
call   1050 <printGameboard@plt>
movabs $0x2020202020202020,%rax
20 20 20
mov    %rax,0x8(%rsp)
movb   $0x20,0x10(%rsp)
lea    0x4(%rsp),%rbx
lea    0x8(%rsp),%rbp
mov    %rsp,%r13
lea    0xef5(%rip),%r15
jmp    11dc <multiplayer+0x7c>
nopl   0x0(%rax)
add    $0xffffffff,%r12d
mov    %r12d,(%rsp)
add    $0x1,%r12d
mov    %r12d,(%rsp)
mov    %rbx,%rdi
mov    $0x9,%esi
call   1080 <askForMenuNumber@plt>
movslq 0x4(%rsp),%rax
cmpb   $0x20,-0x1(%rax,%rbp,1)
mov    (%rsp),%r12d
jne    11d0 <multiplayer+0x70>
xor    %ecx,%ecx
test   $0x1,%r12b
sete   %cl
lea    (%rcx,%rcx,8),%ecx
add    $0x4f,%ecx
mov    %cl,0x7(%rsp,%rax,1)
lea    0xe9e(%rip),%rdi
call   1040 <printTitle@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    0x2dac(%rip),%rcx
call   1030 <checkForEndOfGame@plt>
mov    (%rsp),%esi
add    %r14d,%esi
mov    %esi,%eax
shr    $0x1f,%eax
add    %esi,%eax
and    $0xfffffffe,%eax
sub    %eax,%esi
add    $0x1,%esi
mov    %r15,%rdi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1050 <printGameboard@plt>
mov    (%rsp),%r12d
add    $0x1,%r12d
jmp    11dc <multiplayer+0x7c>

LLVM IR (-O0):
@.str = [13 x i8] c"INSTRUCTIONS\00"
@.str.1 = [158 x i8] c" | Let's flip a coin: |\0A | PLAYER %d starts the game! |\0A\00"
@.str.2 = [10 x i8] c"123456789\00"
@__const.multiplayer.board = [9 x i8] c" "
@.str.3 = [10 x i8] c"GAMEBOARD\00"
@.str.4 = [80 x i8] c" | PLAYER %d it's your turn now, make a move! |\0A\00"
define void @multiplayer() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [9 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (...) @drawing()
store i32 %6, i32* %1
%7 = call i32 @printTitle(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %1
%9 = call i32 @printf(i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32 @printGameboard(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%11 = bitcast [9 x i8]* %3 to i8*
store i32 0, i32* %4
br label %12
12: ; preds = %48, %0
br i1 true, label %13, label %51
13: ; preds = %12
%14 = call i32 @askForMenuNumber(i32* %2, i32 9)
%15 = load i32, i32* %2
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 32
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
store i32 %24, i32* %4
br label %48
25: ; preds = %13
%26 = load i32, i32* %4
%27 = srem i32 %26, 2
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 79, i32 88
%31 = trunc i32 %30 to i8
%32 = load i32, i32* %2
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %34
store i8 %31, i8* %35
%36 = call i32 @printTitle(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%37 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%38 = call i32 @checkForEndOfGame(i32* %4, i32* %2, i8* %37, void (...)* bitcast (void ()* @multiplayer to void (...)*))
%39 = load i32, i32* %1
%40 = load i32, i32* %4
%41 = add nsw i32 %39, %40
%42 = srem i32 %41, 2
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
%44 = load i32, i32* %5
%45 = call i32 @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%47 = call i32 @printGameboard(i8* %46)
br label %48
48: ; preds = %25, %22
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
br label %12
51: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"INSTRUCTIONS\00"
@.str.1 = [158 x i8] c" | Let's flip a coin: |\0A | PLAYER %d starts the game! |\0A\00"
@.str.2 = [10 x i8] c"123456789\00"
@.str.3 = [10 x i8] c"GAMEBOARD\00"
@.str.4 = [80 x i8] c" | PLAYER %d it's your turn now, make a move! |\0A\00"
define void @multiplayer() {
%1 = alloca i32
%2 = alloca [9 x i8]
%3 = alloca i32
%4 = tail call i32 (...) @drawing()
%5 = tail call i32 @printTitle(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%7 = tail call i32 @printGameboard(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%8 = bitcast i32* %1 to i8*
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%10 = bitcast i32* %3 to i8*
br label %11
11: ; preds = %36, %0
%12 = phi i32 [ 0, %0 ], [ %38, %36 ]
store i32 %12, i32* %3
%13 = call i32 @askForMenuNumber(i32* %1, i32 9)
%14 = load i32, i32* %1
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 32
%20 = load i32, i32* %3
br i1 %19, label %23, label %21
21: ; preds = %11
%22 = add nsw i32 %20, -1
store i32 %22, i32* %3
br label %36
23: ; preds = %11
%24 = and i32 %20, 1
%25 = icmp eq i32 %24, 0
%26 = select i1 %25, i8 88, i8 79
store i8 %26, i8* %17
%27 = call i32 @printTitle(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @checkForEndOfGame(i32* %3, i32* %1, i8* %9, void (...)* bitcast (void ()* @multiplayer to void (...)*))
%29 = load i32, i32* %3
%30 = add nsw i32 %29, %4
%31 = srem i32 %30, 2
%32 = add nsw i32 %31, 1
%33 = call i32 @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = call i32 @printGameboard(i8* %9)
%35 = load i32, i32* %3
br label %36
36: ; preds = %23, %21
%37 = phi i32 [ %35, %23 ], [ %22, %21 ]
%38 = add nsw i32 %37, 1
br label %11
}