#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*/ display_message(int, int, int, int);
int /*<<< orphan*/ game_win();
int /*<<< orphan*/ log_score(int, int);
int play_level(int, long *, int, int);
int /*<<< orphan*/ printf(char *, int, int, char *);
int /*<<< orphan*/ wait_for_select();
void game(void) {
  int lives = 4;
  int score = 0;
  long int level_score;
  int level = 1;
  int result;
  do {
    result = play_level(level, &level_score, lives, score);
    switch (result) {
    case 5:
      score += level_score;
      level++;
      display_message(result, lives, level, score);
      break;
    case 6:
      score += level_score;
      level++;
      game_win();
      lives = 0;
      printf("\033[%d;%dH%s", 25, 1, "Done.");
      wait_for_select();
      break;
    case 8:
      return;
    default:
      lives--;
      display_message(result, lives, level, score);
      break;
    }
  } while (lives > 0);
  log_score(score, level);
}


x86 assembly (clang, -O0):
<game>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x4,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    -0x10(%rbp),%rsi
call   1080 <play_level@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x5,%eax
je     11c8 <game+0x68>
jmp    11a6 <game+0x46>
mov    -0x1c(%rbp),%eax
sub    $0x6,%eax
je     11f5 <game+0x95>
jmp    11b7 <game+0x57>
mov    -0x1c(%rbp),%eax
sub    $0x8,%eax
je     1243 <game+0xe3>
jmp    1248 <game+0xe8>
mov    -0x10(%rbp),%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
call   1050 <display_message@plt>
jmp    1262 <game+0x102>
mov    -0x10(%rbp),%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <game_win@plt>
movl   $0x0,-0x4(%rbp)
lea    0xddf(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
lea    0xdd9(%rip),%rcx
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <wait_for_select@plt>
jmp    1262 <game+0x102>
jmp    127c <game+0x11c>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
call   1050 <display_message@plt>
jmp    1267 <game+0x107>
cmpl   $0x0,-0x4(%rbp)
jg     117d <game+0x1d>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <log_score@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<game>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x4,%ebx
mov    $0x1,%r14d
xor    %ebp,%ebp
mov    %rsp,%r15
jmp    119c <game+0x3c>
nopl   0x0(%rax)
add    (%rsp),%ebp
add    $0x1,%r14d
mov    $0x5,%edi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1050 <display_message@plt>
test   %ebx,%ebx
je     11f3 <game+0x93>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1080 <play_level@plt>
cmp    $0x5,%eax
je     1180 <game+0x20>
cmp    $0x6,%eax
je     11c1 <game+0x61>
cmp    $0x8,%eax
je     11fd <game+0x9d>
add    $0xffffffff,%ebx
mov    %eax,%edi
jmp    118c <game+0x2c>
add    (%rsp),%ebp
add    $0x1,%r14d
xor    %eax,%eax
call   1060 <game_win@plt>
lea    0xe2a(%rip),%rdi
lea    0xe2e(%rip),%rcx
mov    $0x19,%esi
mov    $0x1,%edx
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <wait_for_select@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   1040 <log_score@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"\1B[%d;%dH%s\00"
@.str.1 = [6 x i8] c"Done.\00"
define void @game() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i32 4, i32* %1
store i32 0, i32* %2
store i32 1, i32* %4
br label %6
6: ; preds = %46, %0
%7 = load i32, i32* %4
%8 = load i32, i32* %1
%9 = load i32, i32* %2
%10 = call i32 @play_level(i32 %7, i64* %3, i32 %8, i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
switch i32 %11, label %37 [
i32 5, label %12
i32 6, label %25
i32 8, label %36
]
12: ; preds = %6
%13 = load i64, i64* %3
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = add nsw i64 %15, %13
%17 = trunc i64 %16 to i32
store i32 %17, i32* %2
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
%20 = load i32, i32* %5
%21 = load i32, i32* %1
%22 = load i32, i32* %4
%23 = load i32, i32* %2
%24 = call i32 @display_message(i32 %20, i32 %21, i32 %22, i32 %23)
br label %45
25: ; preds = %6
%26 = load i64, i64* %3
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %2
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
%33 = call i32 (...) @game_win()
store i32 0, i32* %1
%34 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 25, i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 (...) @wait_for_select()
br label %45
36: ; preds = %6
br label %53
37: ; preds = %6
%38 = load i32, i32* %1
%39 = add nsw i32 %38, -1
store i32 %39, i32* %1
%40 = load i32, i32* %5
%41 = load i32, i32* %1
%42 = load i32, i32* %4
%43 = load i32, i32* %2
%44 = call i32 @display_message(i32 %40, i32 %41, i32 %42, i32 %43)
br label %45
45: ; preds = %37, %25, %12
br label %46
46: ; preds = %45
%47 = load i32, i32* %1
%48 = icmp sgt i32 %47, 0
br i1 %48, label %6, label %49
49: ; preds = %46
%50 = load i32, i32* %2
%51 = load i32, i32* %4
%52 = call i32 @log_score(i32 %50, i32 %51)
br label %53
53: ; preds = %49, %36
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"\1B[%d;%dH%s\00"
@.str.1 = [6 x i8] c"Done.\00"
define void @game() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
br label %3
3: ; preds = %25, %0
%4 = phi i32 [ 0, %0 ], [ %26, %25 ]
%5 = phi i32 [ 1, %0 ], [ %27, %25 ]
%6 = phi i32 [ 4, %0 ], [ %28, %25 ]
%7 = call i32 @play_level(i32 %5, i64* %1, i32 %6, i32 %4)
switch i32 %7, label %22 [
i32 5, label %8
i32 6, label %14
i32 8, label %34
]
8: ; preds = %3
%9 = load i64, i64* %1
%10 = trunc i64 %9 to i32
%11 = add i32 %4, %10
%12 = add nsw i32 %5, 1
%13 = call i32 @display_message(i32 5, i32 %6, i32 %12, i32 %11)
br label %25
14: ; preds = %3
%15 = load i64, i64* %1
%16 = trunc i64 %15 to i32
%17 = add i32 %4, %16
%18 = add nsw i32 %5, 1
%19 = call i32 (...) @game_win()
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 25, i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 (...) @wait_for_select()
br label %30
22: ; preds = %3
%23 = add nsw i32 %6, -1
%24 = call i32 @display_message(i32 %7, i32 %23, i32 %5, i32 %4)
br label %25
25: ; preds = %8, %22
%26 = phi i32 [ %4, %22 ], [ %11, %8 ]
%27 = phi i32 [ %5, %22 ], [ %12, %8 ]
%28 = phi i32 [ %23, %22 ], [ %6, %8 ]
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %3
30: ; preds = %25, %14
%31 = phi i32 [ %18, %14 ], [ %27, %25 ]
%32 = phi i32 [ %17, %14 ], [ %26, %25 ]
%33 = call i32 @log_score(i32 %32, i32 %31)
br label %34
34: ; preds = %3, %30
ret void
}