#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*/ CopyToScreen();
int /*<<< orphan*/ DoSounds();
int /*<<< orphan*/ GetDstScreen();
int /*<<< orphan*/ GetMenuCmd(int *);
int /*<<< orphan*/ PasswordEntry(int, char *);
int /*<<< orphan*/ PlaySound(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ ShowControls();
int TestPassword(char *);
int /*<<< orphan*/ TextChar(char);
int /*<<< orphan*/ TextGoto(int, int);
int /*<<< orphan*/ TextString(char *);
int /*<<< orphan*/ TextStringAt(int, int, char *);
int /*<<< orphan*/ WaitForRelease();
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int EnterCode(void *bkg, const char *password) {
  int cmd, prev = 0;
  int mission = 0;
  int done = 0;
  char buffer[16 + 1];
  strcpy(buffer, password);
  while (!done) {
    memcpy(GetDstScreen(), bkg, 76800);
    GetMenuCmd(&cmd);
    if (cmd != prev)
      prev = cmd;
    else
      cmd = 0;
    if (!PasswordEntry(cmd, buffer)) {
      if (!buffer[0]) {
        mission = 0;
        done = 1;
      } else {
        mission = TestPassword(buffer);
        if (mission > 0)
          done = 1;
        else
          PlaySound(8, 0, 255);
      }
    }
    TextGoto(125, 50);
    TextChar('\020');
    TextString(buffer);
    TextChar('\021');
    TextStringAt(50, 5, "Enter code");
    ShowControls();
    CopyToScreen();
    DoSounds();
  }
  PlaySound(6, 0, 255);
  WaitForRelease();
  return mission;
}


x86 assembly (clang, -O0):
<EnterCode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1238 <EnterCode+0x48>
jmp    1341 <EnterCode+0x151>
mov    $0x0,%al
call   1080 <GetDstScreen@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
mov    $0x12c00,%edx
call   10e0 <memcpy@plt>
lea    -0x14(%rbp),%rdi
call   10a0 <GetMenuCmd@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     126f <EnterCode+0x7f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1276 <EnterCode+0x86>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1040 <PasswordEntry@plt>
cmp    $0x0,%eax
jne    12e5 <EnterCode+0xf5>
cmpb   $0x0,-0x40(%rbp)
jne    12a8 <EnterCode+0xb8>
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    12e0 <EnterCode+0xf0>
lea    -0x40(%rbp),%rdi
call   1110 <TestPassword@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    12ca <EnterCode+0xda>
movl   $0x1,-0x20(%rbp)
jmp    12db <EnterCode+0xeb>
mov    $0x8,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10b0 <PlaySound@plt>
jmp    12e0 <EnterCode+0xf0>
jmp    12e5 <EnterCode+0xf5>
mov    $0x7d,%edi
mov    $0x32,%esi
call   10c0 <TextGoto@plt>
mov    $0x10,%edi
call   1060 <TextChar@plt>
lea    -0x40(%rbp),%rdi
call   10d0 <TextString@plt>
mov    $0x11,%edi
call   1060 <TextChar@plt>
mov    $0x32,%edi
mov    $0x5,%esi
lea    0xcde(%rip),%rdx
call   1050 <TextStringAt@plt>
mov    $0x0,%al
call   1100 <ShowControls@plt>
mov    $0x0,%al
call   10f0 <CopyToScreen@plt>
mov    $0x0,%al
call   1090 <DoSounds@plt>
jmp    1222 <EnterCode+0x32>
mov    $0x6,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10b0 <PlaySound@plt>
mov    $0x0,%al
call   1070 <WaitForRelease@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EnterCode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xdeb(%rip),%r12
xor    %r13d,%r13d
xor    %ebp,%ebp
jmp    1290 <EnterCode+0xa0>
nopl   0x0(%rax)
mov    %eax,%ebp
mov    %rbx,%rsi
call   1040 <PasswordEntry@plt>
mov    $0x1,%r15b
test   %eax,%eax
je     12d0 <EnterCode+0xe0>
mov    $0x7d,%edi
mov    $0x32,%esi
call   10c0 <TextGoto@plt>
mov    $0x10,%edi
call   1060 <TextChar@plt>
mov    %rbx,%rdi
call   10d0 <TextString@plt>
mov    $0x11,%edi
call   1060 <TextChar@plt>
mov    $0x32,%edi
mov    $0x5,%esi
mov    %r12,%rdx
call   1050 <TextStringAt@plt>
xor    %eax,%eax
call   1100 <ShowControls@plt>
xor    %eax,%eax
call   10f0 <CopyToScreen@plt>
xor    %eax,%eax
call   1090 <DoSounds@plt>
test   %r15b,%r15b
je     130f <EnterCode+0x11f>
xor    %eax,%eax
call   1080 <GetDstScreen@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x12c00,%edx
call   10e0 <memcpy@plt>
lea    0xc(%rsp),%rdi
call   10a0 <GetMenuCmd@plt>
mov    0xc(%rsp),%edi
mov    %edi,%eax
cmp    %ebp,%edi
jne    1220 <EnterCode+0x30>
movl   $0x0,0xc(%rsp)
xor    %edi,%edi
mov    %ebp,%eax
jmp    1220 <EnterCode+0x30>
nop
cmpb   $0x0,0x10(%rsp)
je     12ee <EnterCode+0xfe>
mov    %rbx,%rdi
call   1110 <TestPassword@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    12f9 <EnterCode+0x109>
xor    %r15d,%r15d
jmp    1235 <EnterCode+0x45>
xor    %r13d,%r13d
xor    %r15d,%r15d
jmp    1235 <EnterCode+0x45>
mov    $0x8,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10b0 <PlaySound@plt>
jmp    1235 <EnterCode+0x45>
mov    $0x6,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10b0 <PlaySound@plt>
xor    %eax,%eax
call   1070 <WaitForRelease@plt>
mov    %r13d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Enter code\00"
define i32 @EnterCode(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [17 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = call i32 @strcpy(i8* %10, i8* %11)
br label %13
13: ; preds = %48, %2
%14 = load i32, i32* %8
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %58
17: ; preds = %13
%18 = call i32 (...) @GetDstScreen()
%19 = load i8*, i8** %3
%20 = call i32 @memcpy(i32 %18, i8* %19, i32 76800)
%21 = call i32 @GetMenuCmd(i32* %5)
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = load i32, i32* %5
store i32 %26, i32* %6
br label %28
27: ; preds = %17
store i32 0, i32* %5
br label %28
28: ; preds = %27, %25
%29 = load i32, i32* %5
%30 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%31 = call i32 @PasswordEntry(i32 %29, i8* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %48, label %33
33: ; preds = %28
%34 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %33
store i32 0, i32* %7
store i32 1, i32* %8
br label %47
38: ; preds = %33
%39 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%40 = call i32 @TestPassword(i8* %39)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 1, i32* %8
br label %46
44: ; preds = %38
%45 = call i32 @PlaySound(i32 8, i32 0, i32 255)
br label %46
46: ; preds = %44, %43
br label %47
47: ; preds = %46, %37
br label %48
48: ; preds = %47, %28
%49 = call i32 @TextGoto(i32 125, i32 50)
%50 = call i32 @TextChar(i8 signext 16)
%51 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%52 = call i32 @TextString(i8* %51)
%53 = call i32 @TextChar(i8 signext 17)
%54 = call i32 @TextStringAt(i32 50, i32 5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%55 = call i32 (...) @ShowControls()
%56 = call i32 (...) @CopyToScreen()
%57 = call i32 (...) @DoSounds()
br label %13
58: ; preds = %13
%59 = call i32 @PlaySound(i32 6, i32 0, i32 255)
%60 = call i32 (...) @WaitForRelease()
%61 = load i32, i32* %7
ret i32 %61
}

LLVM IR (-O2):
@.str = [11 x i8] c"Enter code\00"
define i32 @EnterCode(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [17 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%7 = call i32 @strcpy(i8* %6, i8* %1)
br label %8
8: ; preds = %2, %30
%9 = phi i32 [ 0, %2 ], [ %31, %30 ]
%10 = phi i32 [ 0, %2 ], [ %19, %30 ]
%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, %10
br i1 %15, label %16, label %17
16: ; preds = %8
store i32 0, i32* %3
br label %17
17: ; preds = %8, %16
%18 = phi i32 [ 0, %16 ], [ %14, %8 ]
%19 = phi i32 [ %10, %16 ], [ %14, %8 ]
%20 = call i32 @PasswordEntry(i32 %18, i8* %6)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = load i8, i8* %6
%24 = icmp eq i8 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = call i32 @TestPassword(i8* %6)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = call i32 @PlaySound(i32 8, i32 0, i32 255)
br label %30
30: ; preds = %25, %22, %28, %17
%31 = phi i32 [ %9, %17 ], [ %26, %28 ], [ 0, %22 ], [ %26, %25 ]
%32 = phi i1 [ true, %17 ], [ true, %28 ], [ false, %22 ], [ false, %25 ]
%33 = call i32 @TextGoto(i32 125, i32 50)
%34 = call i32 @TextChar(i8 signext 16)
%35 = call i32 @TextString(i8* %6)
%36 = call i32 @TextChar(i8 signext 17)
%37 = call i32 @TextStringAt(i32 50, i32 5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%38 = call i32 (...) @ShowControls()
%39 = call i32 (...) @CopyToScreen()
%40 = call i32 (...) @DoSounds()
br i1 %32, label %8, label %41
41: ; preds = %30
%42 = call i32 @PlaySound(i32 6, i32 0, i32 255)
%43 = call i32 (...) @WaitForRelease()
ret i32 %31
}