#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 */
typedef scalar_t__ cmd;

/* Variables and functions */
int /*<<< orphan*/ CopyToScreen();
int /*<<< orphan*/ DisplayMenuItem(int, int, char *, int);
int /*<<< orphan*/ DoSounds();
int EnterCode(void *, char const *);
int /*<<< orphan*/ GetDstScreen();
int /*<<< orphan*/ GetMenuCmd(int *);
int /*<<< orphan*/ PlaySound(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ ShowControls();
scalar_t__ TestPassword(char const *);
int TextHeight();
int /*<<< orphan*/ VolumeDown();
int /*<<< orphan*/ VolumeUp();
int /*<<< orphan*/ WaitForRelease();
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, void *, int);
int EnterPassword(void *bkg, const char *password) {
  int cmd, prev = 0;
  int mission;
  int index = 0;
  if (TestPassword(password) > 0)
    index = 1;
  while (1) {
    memcpy(GetDstScreen(), bkg, 76800);
    GetMenuCmd(&cmd);
    if (cmd != prev)
      prev = cmd;
    else
      cmd = 0;
    if (cmd & 512) {
      VolumeUp();
    } else if (cmd & 1024) {
      VolumeDown();
    }
    if ((((cmd) & (16 | 32)) != 0)) {
      if (index == 1) {
        WaitForRelease();
        mission = EnterCode(bkg, password);
        if (mission)
          return mission;
      } else
        break;
    } else if (index > 0 && ((((cmd)&1) != 0) || (((cmd)&4) != 0))) {
      index--;
      PlaySound(6, 0, 255);
    } else if (index == 0 && ((((cmd)&2) != 0) || (((cmd)&8) != 0))) {
      index++;
      PlaySound(6, 0, 255);
    }
    DisplayMenuItem(125, 50, "Start campaign", index == 0);
    DisplayMenuItem(125, 50 + TextHeight(), "Enter code...", index == 1);
    ShowControls();
    CopyToScreen();
    DoSounds();
  }
  WaitForRelease();
  return 0;
}


x86 assembly (clang, -O0):
<EnterPassword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   10d0 <TestPassword@plt>
cmp    $0x0,%rax
jle    1218 <EnterPassword+0x38>
movl   $0x1,-0x28(%rbp)
jmp    121d <EnterPassword+0x3d>
mov    $0x0,%al
call   1040 <GetDstScreen@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    $0x12c00,%edx
call   1080 <memcpy@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <GetMenuCmd@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     1254 <EnterPassword+0x74>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    125b <EnterPassword+0x7b>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x200,%eax
cmp    $0x0,%eax
je     1278 <EnterPassword+0x98>
mov    $0x0,%al
call   10b0 <VolumeUp@plt>
jmp    1295 <EnterPassword+0xb5>
mov    -0x1c(%rbp),%eax
and    $0x400,%eax
cmp    $0x0,%eax
je     1290 <EnterPassword+0xb0>
mov    $0x0,%al
call   1100 <VolumeDown@plt>
jmp    1295 <EnterPassword+0xb5>
mov    -0x1c(%rbp),%eax
and    $0x30,%eax
cmp    $0x0,%eax
je     12e9 <EnterPassword+0x109>
cmpl   $0x1,-0x28(%rbp)
jne    12df <EnterPassword+0xff>
mov    $0x0,%al
call   1030 <WaitForRelease@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10e0 <EnterCode@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12da <EnterPassword+0xfa>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13ef <EnterPassword+0x20f>
jmp    12e4 <EnterPassword+0x104>
jmp    13e1 <EnterPassword+0x201>
jmp    137c <EnterPassword+0x19c>
cmpl   $0x0,-0x28(%rbp)
jle    1330 <EnterPassword+0x150>
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1311 <EnterPassword+0x131>
mov    -0x1c(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1330 <EnterPassword+0x150>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    $0x6,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1070 <PlaySound@plt>
jmp    1377 <EnterPassword+0x197>
cmpl   $0x0,-0x28(%rbp)
jne    1372 <EnterPassword+0x192>
mov    -0x1c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    1358 <EnterPassword+0x178>
mov    -0x1c(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1372 <EnterPassword+0x192>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    $0x6,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1070 <PlaySound@plt>
jmp    1377 <EnterPassword+0x197>
jmp    137c <EnterPassword+0x19c>
cmpl   $0x0,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    $0x7d,%edi
mov    $0x32,%esi
lea    0xc67(%rip),%rdx
call   10f0 <DisplayMenuItem@plt>
mov    $0x0,%al
call   1090 <TextHeight@plt>
mov    %eax,%esi
add    $0x32,%esi
cmpl   $0x1,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    $0x7d,%edi
lea    0xc4d(%rip),%rdx
call   10f0 <DisplayMenuItem@plt>
mov    $0x0,%al
call   10c0 <ShowControls@plt>
mov    $0x0,%al
call   10a0 <CopyToScreen@plt>
mov    $0x0,%al
call   1050 <DoSounds@plt>
jmp    121d <EnterPassword+0x3d>
mov    $0x0,%al
call   1030 <WaitForRelease@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EnterPassword>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   10d0 <TestPassword@plt>
xor    %ebp,%ebp
test   %rax,%rax
setg   %bpl
xor    %r13d,%r13d
jmp    1271 <EnterPassword+0x91>
xor    %ebp,%ebp
mov    $0x1,%ecx
test   $0xa,%al
je     1229 <EnterPassword+0x49>
mov    %ecx,%ebx
mov    $0x6,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1070 <PlaySound@plt>
mov    %ebp,%ecx
mov    %ebx,%ebp
mov    $0x7d,%edi
mov    $0x32,%esi
lea    0xdc6(%rip),%rdx
call   10f0 <DisplayMenuItem@plt>
xor    %eax,%eax
call   1090 <TextHeight@plt>
lea    0x32(%rax),%esi
mov    $0x7d,%edi
lea    0xdba(%rip),%rdx
mov    %ebp,%ecx
call   10f0 <DisplayMenuItem@plt>
xor    %eax,%eax
call   10c0 <ShowControls@plt>
xor    %eax,%eax
call   10a0 <CopyToScreen@plt>
xor    %eax,%eax
call   1050 <DoSounds@plt>
xor    %eax,%eax
call   1040 <GetDstScreen@plt>
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x12c00,%edx
call   1080 <memcpy@plt>
lea    0x4(%rsp),%rdi
call   1060 <GetMenuCmd@plt>
mov    0x4(%rsp),%ebx
cmp    %r13d,%ebx
jne    12b0 <EnterPassword+0xd0>
movl   $0x0,0x4(%rsp)
jmp    12da <EnterPassword+0xfa>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   $0x200,%ebx
jne    12d0 <EnterPassword+0xf0>
test   $0x400,%ebx
je     12d7 <EnterPassword+0xf7>
xor    %eax,%eax
call   1100 <VolumeDown@plt>
jmp    12d7 <EnterPassword+0xf7>
nopl   0x0(%rax)
xor    %eax,%eax
call   10b0 <VolumeUp@plt>
mov    %ebx,%r13d
mov    0x4(%rsp),%eax
test   $0x30,%al
je     1310 <EnterPassword+0x130>
xor    %r12d,%r12d
xor    %eax,%eax
call   1030 <WaitForRelease@plt>
cmp    $0x1,%ebp
jne    132f <EnterPassword+0x14f>
mov    %r15,%rdi
mov    %r14,%rsi
call   10e0 <EnterCode@plt>
test   %eax,%eax
jne    132c <EnterPassword+0x14c>
mov    $0x1,%ebp
xor    %ecx,%ecx
jmp    1229 <EnterPassword+0x49>
nopl   0x0(%rax)
test   %ebp,%ebp
je     1207 <EnterPassword+0x27>
mov    $0x1,%ebp
xor    %ecx,%ecx
test   $0x5,%al
jne    1212 <EnterPassword+0x32>
jmp    1229 <EnterPassword+0x49>
mov    %eax,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Start campaign\00"
@.str.1 = [14 x i8] c"Enter code...\00"
define i32 @EnterPassword(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
store i32 0, i32* %9
%10 = load i8*, i8** %5
%11 = call i64 @TestPassword(i8* %10)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %9
br label %14
14: ; preds = %13, %2
br label %15
15: ; preds = %14, %90
%16 = call i32 (...) @GetDstScreen()
%17 = load i8*, i8** %4
%18 = call i32 @memcpy(i32 %16, i8* %17, i32 76800)
%19 = call i32 @GetMenuCmd(i32* %6)
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = load i32, i32* %6
store i32 %24, i32* %7
br label %26
25: ; preds = %15
store i32 0, i32* %6
br label %26
26: ; preds = %25, %23
%27 = load i32, i32* %6
%28 = and i32 %27, 512
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (...) @VolumeUp()
br label %39
32: ; preds = %26
%33 = load i32, i32* %6
%34 = and i32 %33, 1024
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 (...) @VolumeDown()
br label %38
38: ; preds = %36, %32
br label %39
39: ; preds = %38, %30
%40 = load i32, i32* %6
%41 = and i32 %40, 48
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %58
43: ; preds = %39
%44 = load i32, i32* %9
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %56
46: ; preds = %43
%47 = call i32 (...) @WaitForRelease()
%48 = load i8*, i8** %4
%49 = load i8*, i8** %5
%50 = call i32 @EnterCode(i8* %48, i8* %49)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = load i32, i32* %8
store i32 %54, i32* %3
br label %106
55: ; preds = %46
br label %57
56: ; preds = %43
br label %104
57: ; preds = %55
br label %90
58: ; preds = %39
%59 = load i32, i32* %9
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %73
61: ; preds = %58
%62 = load i32, i32* %6
%63 = and i32 %62, 1
%64 = icmp ne i32 %63, 0
br i1 %64, label %69, label %65
65: ; preds = %61
%66 = load i32, i32* %6
%67 = and i32 %66, 4
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %65, %61
%70 = load i32, i32* %9
%71 = add nsw i32 %70, -1
store i32 %71, i32* %9
%72 = call i32 @PlaySound(i32 6, i32 0, i32 255)
br label %89
73: ; preds = %65, %58
%74 = load i32, i32* %9
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %88
76: ; preds = %73
%77 = load i32, i32* %6
%78 = and i32 %77, 2
%79 = icmp ne i32 %78, 0
br i1 %79, label %84, label %80
80: ; preds = %76
%81 = load i32, i32* %6
%82 = and i32 %81, 8
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %80, %76
%85 = load i32, i32* %9
%86 = add nsw i32 %85, 1
store i32 %86, i32* %9
%87 = call i32 @PlaySound(i32 6, i32 0, i32 255)
br label %88
88: ; preds = %84, %80, %73
br label %89
89: ; preds = %88, %69
br label %90
90: ; preds = %89, %57
%91 = load i32, i32* %9
%92 = icmp eq i32 %91, 0
%93 = zext i1 %92 to i32
%94 = call i32 @DisplayMenuItem(i32 125, i32 50, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %93)
%95 = call i32 (...) @TextHeight()
%96 = add nsw i32 50, %95
%97 = load i32, i32* %9
%98 = icmp eq i32 %97, 1
%99 = zext i1 %98 to i32
%100 = call i32 @DisplayMenuItem(i32 125, i32 %96, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %99)
%101 = call i32 (...) @ShowControls()
%102 = call i32 (...) @CopyToScreen()
%103 = call i32 (...) @DoSounds()
br label %15
104: ; preds = %56
%105 = call i32 (...) @WaitForRelease()
store i32 0, i32* %3
br label %106
106: ; preds = %104, %53
%107 = load i32, i32* %3
ret i32 %107
}

LLVM IR (-O2):
@.str = [15 x i8] c"Start campaign\00"
@.str.1 = [14 x i8] c"Enter code...\00"
define i32 @EnterPassword(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 @TestPassword(i8* %1)
%6 = icmp sgt i64 %5, 0
%7 = zext i1 %6 to i32
br label %8
8: ; preds = %50, %2
%9 = phi i32 [ 0, %2 ], [ %28, %50 ]
%10 = phi i32 [ %7, %2 ], [ %52, %50 ]
%11 = call i32 (...) @GetDstScreen()
%12 = call i32 @memcpy(i32 %11, i8* %0, i32 76800)
%13 = call i32 @GetMenuCmd(i32* %3)
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, %9
br i1 %15, label %16, label %17
16: ; preds = %8
store i32 0, i32* %3
br label %27
17: ; preds = %8
%18 = and i32 %14, 512
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 (...) @VolumeUp()
br label %27
22: ; preds = %17
%23 = and i32 %14, 1024
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 (...) @VolumeDown()
br label %27
27: ; preds = %16, %22, %25, %20
%28 = phi i32 [ %14, %22 ], [ %14, %25 ], [ %14, %20 ], [ %9, %16 ]
%29 = load i32, i32* %3
%30 = and i32 %29, 48
%31 = icmp eq i32 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %27
%33 = icmp eq i32 %10, 1
%34 = call i32 (...) @WaitForRelease()
br i1 %33, label %35, label %60
35: ; preds = %32
%36 = call i32 @EnterCode(i8* %0, i8* %1)
%37 = icmp eq i32 %36, 0
br i1 %37, label %50, label %60
38: ; preds = %27
%39 = icmp eq i32 %10, 0
br i1 %39, label %43, label %40
40: ; preds = %38
%41 = and i32 %29, 5
%42 = icmp eq i32 %41, 0
br i1 %42, label %50, label %46
43: ; preds = %38
%44 = and i32 %29, 10
%45 = icmp eq i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %43, %40
%47 = phi i32 [ 1, %40 ], [ 0, %43 ]
%48 = phi i32 [ 0, %40 ], [ 1, %43 ]
%49 = call i32 @PlaySound(i32 6, i32 0, i32 255)
br label %50
50: ; preds = %46, %40, %43, %35
%51 = phi i32 [ 0, %35 ], [ 1, %43 ], [ 0, %40 ], [ %47, %46 ]
%52 = phi i32 [ 1, %35 ], [ 0, %43 ], [ 1, %40 ], [ %48, %46 ]
%53 = call i32 @DisplayMenuItem(i32 125, i32 50, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %51)
%54 = call i32 (...) @TextHeight()
%55 = add nsw i32 %54, 50
%56 = call i32 @DisplayMenuItem(i32 125, i32 %55, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%57 = call i32 (...) @ShowControls()
%58 = call i32 (...) @CopyToScreen()
%59 = call i32 (...) @DoSounds()
br label %8
60: ; preds = %35, %32
%61 = phi i32 [ 0, %32 ], [ %36, %35 ]
ret i32 %61
}