#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 display_standard_menu(char *, char *, int, int, int);
int screen_load_game_menu(int game_state, int menu_type, int *menu_state) {
  int option = 0;
  if (menu_type == 0) {
    option = display_standard_menu(
        "Load Game Menu",
        "1. Back\n2. Load Save 1\n3. Load Save 2\n4. Load Save 3", menu_type, 4,
        1);
  } else if (menu_type == 1) {
    option = display_standard_menu(
        "Load Game Menu",
        "A. Back\nB. Load Save 1\nC. Load Save 2\nD. Load Save 3", menu_type, 4,
        1);
  }
  if (option == 1) {
    game_state = 3;
  } else if (option == 2) {
    *menu_state = 1;
  } else if (option == 3) {
    *menu_state = 2;
  } else if (option == 4) {
    *menu_state = 3;
  }
  return game_state;
}


x86 assembly (clang, -O0):
<screen_load_game_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    115c <screen_load_game_menu+0x4c>
mov    -0x8(%rbp),%edx
lea    0xec3(%rip),%rdi
lea    0xecb(%rip),%rsi
mov    $0x4,%ecx
mov    $0x1,%r8d
call   1030 <display_standard_menu@plt>
mov    %eax,-0x14(%rbp)
jmp    118f <screen_load_game_menu+0x7f>
cmpl   $0x1,-0x8(%rbp)
jne    118a <screen_load_game_menu+0x7a>
mov    -0x8(%rbp),%edx
lea    0xe90(%rip),%rdi
lea    0xecd(%rip),%rsi
mov    $0x4,%ecx
mov    $0x1,%r8d
call   1030 <display_standard_menu@plt>
mov    %eax,-0x14(%rbp)
jmp    118f <screen_load_game_menu+0x7f>
cmpl   $0x1,-0x14(%rbp)
jne    11a5 <screen_load_game_menu+0x95>
movl   $0x3,-0x4(%rbp)
jmp    11fa <screen_load_game_menu+0xea>
cmpl   $0x2,-0x14(%rbp)
jne    11be <screen_load_game_menu+0xae>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    11f5 <screen_load_game_menu+0xe5>
cmpl   $0x3,-0x14(%rbp)
jne    11d7 <screen_load_game_menu+0xc7>
mov    -0x10(%rbp),%rax
movl   $0x2,(%rax)
jmp    11f0 <screen_load_game_menu+0xe0>
cmpl   $0x4,-0x14(%rbp)
jne    11eb <screen_load_game_menu+0xdb>
mov    -0x10(%rbp),%rax
movl   $0x3,(%rax)
jmp    11f0 <screen_load_game_menu+0xe0>
jmp    11f5 <screen_load_game_menu+0xe5>
jmp    11fa <screen_load_game_menu+0xea>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<screen_load_game_menu>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %edi,%ebx
cmp    $0x1,%esi
je     1134 <screen_load_game_menu+0x24>
test   %esi,%esi
jne    118d <screen_load_game_menu+0x7d>
lea    0xee7(%rip),%rdi
lea    0xeef(%rip),%rsi
xor    %edx,%edx
jmp    1147 <screen_load_game_menu+0x37>
lea    0xed5(%rip),%rdi
lea    0xf12(%rip),%rsi
mov    $0x1,%edx
mov    $0x4,%ecx
mov    $0x1,%r8d
call   1030 <display_standard_menu@plt>
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     118d <screen_load_game_menu+0x7d>
mov    $0x3,%ecx
lea    0xe95(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
movl   $0x1,(%r14)
jmp    118d <screen_load_game_menu+0x7d>
movl   $0x2,(%r14)
jmp    118d <screen_load_game_menu+0x7d>
movl   $0x3,(%r14)
mov    %ebx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Load Game Menu\00"
@.str.1 = [53 x i8] c"1. Back\0A2. Load Save 1\0A3. Load Save 2\0A4. Load Save 3\00"
@.str.2 = [53 x i8] c"A. Back\0AB. Load Save 1\0AC. Load Save 2\0AD. Load Save 3\00"
define i32 @screen_load_game_menu(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* %5
%12 = call i32 @display_standard_menu(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 4, i32 1)
store i32 %12, i32* %7
br label %20
13: ; preds = %3
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %5
%18 = call i32 @display_standard_menu(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 4, i32 1)
store i32 %18, i32* %7
br label %19
19: ; preds = %16, %13
br label %20
20: ; preds = %19, %10
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 3, i32* %4
br label %42
24: ; preds = %20
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i32*, i32** %6
store i32 1, i32* %28
br label %41
29: ; preds = %24
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 3
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load i32*, i32** %6
store i32 2, i32* %33
br label %40
34: ; preds = %29
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 4
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = load i32*, i32** %6
store i32 3, i32* %38
br label %39
39: ; preds = %37, %34
br label %40
40: ; preds = %39, %32
br label %41
41: ; preds = %40, %27
br label %42
42: ; preds = %41, %23
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@.str = [15 x i8] c"Load Game Menu\00"
@.str.1 = [53 x i8] c"1. Back\0A2. Load Save 1\0A3. Load Save 2\0A4. Load Save 3\00"
@.str.2 = [53 x i8] c"A. Back\0AB. Load Save 1\0AC. Load Save 2\0AD. Load Save 3\00"
define i32 @screen_load_game_menu(i32 %0, i32 %1, i32* nocapture writeonly %2) {
switch i32 %1, label %13 [
i32 0, label %4
i32 1, label %6
]
4: ; preds = %3
%5 = tail call i32 @display_standard_menu(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 4, i32 1)
br label %8
6: ; preds = %3
%7 = tail call i32 @display_standard_menu(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 4, i32 1)
br label %8
8: ; preds = %6, %4
%9 = phi i32 [ %5, %4 ], [ %7, %6 ]
switch i32 %9, label %13 [
i32 1, label %14
i32 2, label %10
i32 3, label %11
i32 4, label %12
]
10: ; preds = %8
store i32 1, i32* %2
br label %14
11: ; preds = %8
store i32 2, i32* %2
br label %14
12: ; preds = %8
store i32 3, i32* %2
br label %14
13: ; preds = %3, %8
br label %14
14: ; preds = %8, %13, %10, %12, %11
%15 = phi i32 [ %0, %10 ], [ %0, %11 ], [ %0, %12 ], [ 3, %8 ], [ %0, %13 ]
ret i32 %15
}