#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*/ add_item(int);
int /*<<< orphan*/ area_menu(int *, int *);
int /*<<< orphan*/ destroy_game();
int encounter(int);
char *eq_name(int);
int /*<<< orphan*/ explore_areamap(int, int);
int /*<<< orphan*/ gen_areamap(int *, int *);
int get_area_map(int, int);
int get_random(int /*<<< orphan*/, int);
int /*<<< orphan*/ print_message(char *);
int spawn_item_by_price(int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ world_menu();
void run_game() {
  char buf[40];
  int x, y;
  int flags;
  int result = 1;
  int index;
  int theme;
  while (1) {
    gen_areamap(&x, &y);
    theme = get_random(0, 5);
    while (1) {
      area_menu(&x, &y);
      flags = get_area_map(x, y);
      if (flags & (1 << 1)) {
        result = encounter(theme);
        if (!result) {
          destroy_game();
          return;
        }
      }
      if (flags & (1 << 2)) {
        index = spawn_item_by_price(50, 500);
        add_item(index);
        sprintf(buf, "Obtained %s!", eq_name(index));
        print_message(buf);
      }
      if (flags & (1 << 3))
        break;
      explore_areamap(x, y);
    }
    world_menu();
  }
}


x86 assembly (clang, -O0):
<run_game>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x1,-0x40(%rbp)
lea    -0x34(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <gen_areamap@plt>
xor    %edi,%edi
mov    $0x5,%esi
call   1040 <get_random@plt>
mov    %eax,-0x48(%rbp)
lea    -0x34(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <area_menu@plt>
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
call   10e0 <get_area_map@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     124c <run_game+0x7c>
mov    -0x48(%rbp),%edi
call   1070 <encounter@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    1247 <run_game+0x77>
mov    $0x0,%al
call   1080 <destroy_game@plt>
add    $0x50,%rsp
pop    %rbp
ret
jmp    124c <run_game+0x7c>
mov    -0x3c(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     12a1 <run_game+0xd1>
mov    $0x32,%edi
mov    $0x1f4,%esi
call   10c0 <spawn_item_by_price@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <add_item@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%edi
call   10b0 <eq_name@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xd6d(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1050 <print_message@plt>
mov    -0x3c(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     12b5 <run_game+0xe5>
jmp    12c5 <run_game+0xf5>
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
call   10f0 <explore_areamap@plt>
jmp    11fb <run_game+0x2b>
mov    $0x0,%al
call   1090 <world_menu@plt>
jmp    11df <run_game+0xf>

x86 assembly (clang, -O2):
<run_game>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r13
lea    0x10(%rsp),%r12
jmp    11f7 <run_game+0x27>
nop
xor    %eax,%eax
call   1090 <world_menu@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <gen_areamap@plt>
xor    %edi,%edi
mov    $0x5,%esi
call   1040 <get_random@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r13,%rsi
call   10a0 <area_menu@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   10e0 <get_area_map@plt>
mov    %eax,%ebx
test   $0x2,%bl
je     123a <run_game+0x6a>
mov    %ebp,%edi
call   1070 <encounter@plt>
test   %eax,%eax
je     1295 <run_game+0xc5>
test   $0x4,%bl
je     127a <run_game+0xaa>
mov    $0x32,%edi
mov    $0x1f4,%esi
call   10c0 <spawn_item_by_price@plt>
mov    %eax,%r15d
mov    %eax,%edi
call   1060 <add_item@plt>
mov    %r15d,%edi
call   10b0 <eq_name@plt>
mov    %r12,%rdi
lea    0xd96(%rip),%rsi
mov    %rax,%rdx
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1050 <print_message@plt>
test   $0x8,%bl
jne    11f0 <run_game+0x20>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   10f0 <explore_areamap@plt>
jmp    1210 <run_game+0x40>
xor    %eax,%eax
call   1080 <destroy_game@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Obtained %s!\00"
define void @run_game() {
%1 = alloca [40 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 1, i32* %5
br label %8
8: ; preds = %0, %50
%9 = call i32 @gen_areamap(i32* %2, i32* %3)
%10 = call i32 @get_random(i32 0, i32 5)
store i32 %10, i32* %7
br label %11
11: ; preds = %8, %46
%12 = call i32 @area_menu(i32* %2, i32* %3)
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = call i32 @get_area_map(i32 %13, i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = and i32 %16, 2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %11
%20 = load i32, i32* %7
%21 = call i32 @encounter(i32 %20)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = call i32 (...) @destroy_game()
ret void
26: ; preds = %19
br label %27
27: ; preds = %26, %11
%28 = load i32, i32* %4
%29 = and i32 %28, 4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = call i32 @spawn_item_by_price(i32 50, i32 500)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = call i32 @add_item(i32 %33)
%35 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%36 = load i32, i32* %6
%37 = call i8* @eq_name(i32 %36)
%38 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%40 = call i32 @print_message(i8* %39)
br label %41
41: ; preds = %31, %27
%42 = load i32, i32* %4
%43 = and i32 %42, 8
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41
br label %50
46: ; preds = %41
%47 = load i32, i32* %2
%48 = load i32, i32* %3
%49 = call i32 @explore_areamap(i32 %47, i32 %48)
br label %11
50: ; preds = %45
%51 = call i32 (...) @world_menu()
br label %8
}

LLVM IR (-O2):
@.str = [13 x i8] c"Obtained %s!\00"
define void @run_game() {
%1 = alloca [40 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %38, %0
%8 = call i32 @gen_areamap(i32* %2, i32* %3)
%9 = call i32 @get_random(i32 0, i32 5)
br label %10
10: ; preds = %34, %7
%11 = call i32 @area_menu(i32* %2, i32* %3)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 @get_area_map(i32 %12, i32 %13)
%15 = and i32 %14, 2
%16 = icmp eq i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %10
%18 = call i32 @encounter(i32 %9)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (...) @destroy_game()
ret void
22: ; preds = %17, %10
%23 = and i32 %14, 4
%24 = icmp eq i32 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %22
%26 = call i32 @spawn_item_by_price(i32 50, i32 500)
%27 = call i32 @add_item(i32 %26)
%28 = call i8* @eq_name(i32 %26)
%29 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @print_message(i8* %4)
br label %31
31: ; preds = %25, %22
%32 = and i32 %14, 8
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* %2
%36 = load i32, i32* %3
%37 = call i32 @explore_areamap(i32 %35, i32 %36)
br label %10
38: ; preds = %31
%39 = call i32 (...) @world_menu()
br label %7
}