#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*/ fixDiskImage(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ readDiskImage(char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ writeDiskImage(char *);
int main(int argc, char **argv) {
  if (argc == 4) {
    int code = -1;
    if (sscanf(argv[3], "%d", &code) == 1) {
      if ((code >= 0) && (code <= 1)) {
        readDiskImage(argv[1]);
        fixDiskImage(code);
        writeDiskImage(argv[2]);
        printf("Myth patched.\n");
        return 0;
      }
    }
  }
  printf("Removes password protection from Magnetic Scrolls' Myth.\n");
  printf("Use: myth input.d64 output.d64 code\n");
  printf("If code is 0, the password protection is completely removed.\n");
  printf("If code is 1, any user name and password will be accepted.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    11f0 <main+0xa0>
movl   $0xffffffff,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11eb <main+0x9b>
cmpl   $0x0,-0x14(%rbp)
jl     11e6 <main+0x96>
cmpl   $0x1,-0x14(%rbp)
jg     11e6 <main+0x96>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <readDiskImage@plt>
mov    -0x14(%rbp),%edi
call   1050 <fixDiskImage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <writeDiskImage@plt>
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1227 <main+0xd7>
jmp    11eb <main+0x9b>
jmp    11f0 <main+0xa0>
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x4,%edi
jne    11aa <main+0x5a>
mov    %rsi,%rbx
movl   $0xffffffff,0xc(%rsp)
ff
mov    0x18(%rsi),%rdi
lea    0xe90(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11aa <main+0x5a>
cmpl   $0x2,0xc(%rsp)
jae    11aa <main+0x5a>
mov    0x8(%rbx),%rdi
call   1070 <readDiskImage@plt>
mov    0xc(%rsp),%edi
call   1050 <fixDiskImage@plt>
mov    0x10(%rbx),%rdi
call   1040 <writeDiskImage@plt>
lea    0xf30(%rip),%rdi
jmp    11d5 <main+0x85>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [15 x i8] c"Myth patched.\0A\00"
@.str.2 = [58 x i8] c"Removes password protection from Magnetic Scrolls' Myth.\0A\00"
@.str.3 = [37 x i8] c"Use: myth input.d64 output.d64 code\0A\00"
@.str.4 = [62 x i8] c"If code is 0, the password protection is completely removed.\0A\00"
@.str.5 = [60 x i8] c"If code is 1, any user name and password will be accepted.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 4
br i1 %8, label %9, label %35
9: ; preds = %2
store i32 -1, i32* %6
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 3
%12 = load i8*, i8** %11
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %34
15: ; preds = %9
%16 = load i32, i32* %6
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = load i32, i32* %6
%20 = icmp sle i32 %19, 1
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @readDiskImage(i8* %24)
%26 = load i32, i32* %6
%27 = call i32 @fixDiskImage(i32 %26)
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @writeDiskImage(i8* %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %40
33: ; preds = %18, %15
br label %34
34: ; preds = %33, %9
br label %35
35: ; preds = %34, %2
%36 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %40
40: ; preds = %35, %21
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [57 x i8] c"Removes password protection from Magnetic Scrolls' Myth.\00"
@str.6 = [36 x i8] c"Use: myth input.d64 output.d64 code\00"
@str.7 = [61 x i8] c"If code is 0, the password protection is completely removed.\00"
@str.8 = [59 x i8] c"If code is 1, any user name and password will be accepted.\00"
@str.9 = [14 x i8] c"Myth patched.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 4
br i1 %4, label %5, label %25
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%7 = getelementptr inbounds i8*, i8** %1, i64 3
%8 = load i8*, i8** %7
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = icmp eq i32 %9, 1
%11 = load i32, i32* %3
%12 = icmp ult i32 %11, 2
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %15, label %14
14: ; preds = %5
br label %25
15: ; preds = %5
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @readDiskImage(i8* %17)
%19 = load i32, i32* %3
%20 = call i32 @fixDiskImage(i32 %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @writeDiskImage(i8* %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
br label %30
25: ; preds = %14, %2
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.6, i64 0, i64 0))
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.7, i64 0, i64 0))
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.8, i64 0, i64 0))
br label %30
30: ; preds = %15, %25
ret i32 0
}