#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 getchar();
int /*<<< orphan*/ newgame(int, int);
int /*<<< orphan*/ printf(char *);
void game_loop() {
  bool human = false;
  int depth;
start_game_loop:
  printf("\nStarting new game...");
move_first_menu:
  printf("\nWould you like to move first? (y/n) ");
  switch (getchar()) {
  case 'y':
    human = true;
    break;
  case 'n':
    human = false;
    break;
  default:
    goto move_first_menu;
  }
difficulty_menu:
  printf("\nChoose difficulty ([h]ard/[m]edium/[e]asy): ");
  switch (getchar()) {
  case 'h':
    depth = 9;
    break;
  case 'm':
    depth = 3;
    break;
  case 'e':
    depth = 1;
    break;
  default:
    goto difficulty_menu;
  }
  newgame(human, depth);
newgame_menu:
  printf("\nPlay again? (y/n) ");
  switch (getchar()) {
  case 'y':
    goto start_game_loop;
  case 'n':
    goto exit_game_loop;
  default:
    goto newgame_menu;
  }
exit_game_loop:
  printf("\nGoodbye!\n");
}


x86 assembly (clang, -O0):
<game_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
sub    $0x6e,%eax
je     118e <game_loop+0x5e>
jmp    1171 <game_loop+0x41>
mov    -0xc(%rbp),%eax
sub    $0x79,%eax
jne    119a <game_loop+0x6a>
jmp    1182 <game_loop+0x52>
movl   $0x1,-0x4(%rbp)
jmp    119f <game_loop+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    119f <game_loop+0x6f>
jmp    114b <game_loop+0x1b>
jmp    11a4 <game_loop+0x74>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
sub    $0x65,%eax
je     1204 <game_loop+0xd4>
jmp    11ca <game_loop+0x9a>
mov    -0x10(%rbp),%eax
sub    $0x68,%eax
je     11ec <game_loop+0xbc>
jmp    11db <game_loop+0xab>
mov    -0x10(%rbp),%eax
sub    $0x6d,%eax
je     11f8 <game_loop+0xc8>
jmp    1210 <game_loop+0xe0>
movl   $0x9,-0x8(%rbp)
jmp    1215 <game_loop+0xe5>
movl   $0x3,-0x8(%rbp)
jmp    1215 <game_loop+0xe5>
movl   $0x1,-0x8(%rbp)
jmp    1215 <game_loop+0xe5>
jmp    11a4 <game_loop+0x74>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <newgame@plt>
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0x6e,%eax
je     125c <game_loop+0x12c>
jmp    1246 <game_loop+0x116>
mov    -0x14(%rbp),%eax
sub    $0x79,%eax
jne    1261 <game_loop+0x131>
jmp    1257 <game_loop+0x127>
jmp    113f <game_loop+0xf>
jmp    1266 <game_loop+0x136>
jmp    1220 <game_loop+0xf0>
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<game_loop>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xeb1(%rip),%r14
lea    0xec0(%rip),%r12
lea    0xedf(%rip),%r15
lea    0xf06(%rip),%rbx
mov    %r14,%rdi
call   1040 <printf@plt>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x6e,%eax
je     1190 <game_loop+0x50>
cmp    $0x79,%eax
jne    1170 <game_loop+0x30>
mov    $0x1,%ebp
jmp    11a0 <game_loop+0x60>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x65,%eax
je     11d0 <game_loop+0x90>
cmp    $0x6d,%eax
je     11e0 <game_loop+0xa0>
cmp    $0x68,%eax
jne    11a0 <game_loop+0x60>
mov    $0x9,%esi
jmp    11e5 <game_loop+0xa5>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%esi
jmp    11e5 <game_loop+0xa5>
nopw   0x0(%rax,%rax,1)
mov    $0x3,%esi
mov    %ebp,%edi
call   1060 <newgame@plt>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x79,%eax
je     1164 <game_loop+0x24>
cmp    $0x6e,%eax
jne    11f0 <game_loop+0xb0>
lea    0xe6a(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"\0AStarting new game...\00"
@.str.1 = [38 x i8] c"\0AWould you like to move first? (y/n) \00"
@.str.2 = [46 x i8] c"\0AChoose difficulty ([h]ard/[m]edium/[e]asy): \00"
@.str.3 = [20 x i8] c"\0APlay again? (y/n) \00"
@.str.4 = [11 x i8] c"\0AGoodbye!\0A\00"
define void @game_loop() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %26, %0
%4 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %10, %3
%6 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (...) @getchar()
switch i32 %7, label %10 [
i32 121, label %8
i32 110, label %9
]
8: ; preds = %5
store i32 1, i32* %1
br label %11
9: ; preds = %5
store i32 0, i32* %1
br label %11
10: ; preds = %5
br label %5
11: ; preds = %9, %8
br label %12
12: ; preds = %18, %11
%13 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (...) @getchar()
switch i32 %14, label %18 [
i32 104, label %15
i32 109, label %16
i32 101, label %17
]
15: ; preds = %12
store i32 9, i32* %2
br label %19
16: ; preds = %12
store i32 3, i32* %2
br label %19
17: ; preds = %12
store i32 1, i32* %2
br label %19
18: ; preds = %12
br label %12
19: ; preds = %17, %16, %15
%20 = load i32, i32* %1
%21 = load i32, i32* %2
%22 = call i32 @newgame(i32 %20, i32 %21)
br label %23
23: ; preds = %28, %19
%24 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 (...) @getchar()
switch i32 %25, label %28 [
i32 121, label %26
i32 110, label %27
]
26: ; preds = %23
br label %3
27: ; preds = %23
br label %29
28: ; preds = %23
br label %23
29: ; preds = %27
%30 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"\0AStarting new game...\00"
@.str.1 = [38 x i8] c"\0AWould you like to move first? (y/n) \00"
@.str.2 = [46 x i8] c"\0AChoose difficulty ([h]ard/[m]edium/[e]asy): \00"
@.str.3 = [20 x i8] c"\0APlay again? (y/n) \00"
@str = [10 x i8] c"\0AGoodbye!\00"
define void @game_loop() {
br label %1
1: ; preds = %17, %0
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %3, %1
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (...) @getchar()
switch i32 %5, label %3 [
i32 121, label %6
i32 110, label %7
]
6: ; preds = %3
br label %7
7: ; preds = %3, %6
%8 = phi i32 [ 1, %6 ], [ 0, %3 ]
br label %9
9: ; preds = %9, %7
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 (...) @getchar()
switch i32 %11, label %9 [
i32 104, label %12
i32 109, label %13
i32 101, label %14
]
12: ; preds = %9
br label %14
13: ; preds = %9
br label %14
14: ; preds = %9, %13, %12
%15 = phi i32 [ 9, %12 ], [ 3, %13 ], [ 1, %9 ]
%16 = tail call i32 @newgame(i32 %8, i32 %15)
br label %17
17: ; preds = %17, %14
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i32 (...) @getchar()
switch i32 %19, label %17 [
i32 121, label %1
i32 110, label %20
]
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
ret void
}