#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*/ command_mode();
int /*<<< orphan*/ console_black();
int /*<<< orphan*/ console_init();
scalar_t__ file_load(char *);
int /*<<< orphan*/ getchar();
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char *argv[]) {
  char *filename;
  if (argc < 2) {
    filename = malloc(200);
    filename[0] = 0;
    while (!filename[0]) {
      printf("Enter filename: ");
      scanf("%s", filename);
    }
    getchar();
  } else {
    filename = argv[1];
  }
  if (file_load(filename)) {
    printf("can't open %s\n", filename);
    return -1;
  }
  console_init();
  command_mode();
  console_black();
  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   $0x2,-0x8(%rbp)
jge    11fd <main+0x7d>
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ce <main+0x4e>
jmp    11f1 <main+0x71>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1090 <scanf@plt>
jmp    11b5 <main+0x35>
mov    $0x0,%al
call   1060 <getchar@plt>
jmp    1209 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <file_load@plt>
cmp    $0x0,%rax
je     123a <main+0xba>
mov    -0x18(%rbp),%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1256 <main+0xd6>
mov    $0x0,%al
call   1030 <console_init@plt>
mov    $0x0,%al
call   1040 <command_mode@plt>
mov    $0x0,%al
call   1080 <console_black@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x1,%edi
jg     11d3 <main+0x53>
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xe5f(%rip),%r14
lea    0xe69(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
cmpb   $0x0,(%rbx)
je     11b0 <main+0x30>
xor    %eax,%eax
call   1060 <getchar@plt>
jmp    11d7 <main+0x57>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   10a0 <file_load@plt>
test   %rax,%rax
je     11fc <main+0x7c>
lea    0xe29(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1213 <main+0x93>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <console_init@plt>
xor    %eax,%eax
call   1040 <command_mode@plt>
xor    %eax,%eax
call   1080 <console_black@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter filename: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [15 x i8] c"can't open %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %25
9: ; preds = %2
%10 = call i8* @malloc(i32 200)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 0, i8* %12
br label %13
13: ; preds = %19, %9
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%21 = load i8*, i8** %6
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %13
23: ; preds = %13
%24 = call i32 (...) @getchar()
br label %29
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
br label %29
29: ; preds = %25, %23
%30 = load i8*, i8** %6
%31 = call i64 @file_load(i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i8*, i8** %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %34)
store i32 -1, i32* %3
br label %40
36: ; preds = %29
%37 = call i32 (...) @console_init()
%38 = call i32 (...) @command_mode()
%39 = call i32 (...) @console_black()
store i32 0, i32* %3
br label %40
40: ; preds = %36, %33
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter filename: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [15 x i8] c"can't open %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = tail call dereferenceable_or_null(200) i8* @malloc(i32 200)
store i8 0, i8* %5
br label %6
6: ; preds = %4, %6
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = load i8, i8* %5
%10 = icmp eq i8 %9, 0
br i1 %10, label %6, label %11
11: ; preds = %6
%12 = tail call i32 (...) @getchar()
br label %16
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
br label %16
16: ; preds = %13, %11
%17 = phi i8* [ %5, %11 ], [ %15, %13 ]
%18 = tail call i64 @file_load(i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %26
22: ; preds = %16
%23 = tail call i32 (...) @console_init()
%24 = tail call i32 (...) @command_mode()
%25 = tail call i32 (...) @console_black()
br label %26
26: ; preds = %22, %20
%27 = phi i32 [ -1, %20 ], [ 0, %22 ]
ret i32 %27
}