#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 /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ view_mode();
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;
  }
  if (!strcmp(&argv[0][strlen(argv[0]) - 4], "view")) {
    extern int fileModified;
    if (fileModified) {
      printf("can't read %s\n", filename);
      return -1;
    }
    console_init();
    view_mode();
  } else {
    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    122d <main+0x7d>
mov    $0xc8,%edi
call   10a0 <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    11fe <main+0x4e>
jmp    1221 <main+0x71>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdfa(%rip),%rdi
call   10c0 <scanf@plt>
jmp    11e5 <main+0x35>
mov    $0x0,%al
call   1090 <getchar@plt>
jmp    1239 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10d0 <file_load@plt>
cmp    $0x0,%rax
je     126a <main+0xba>
mov    -0x18(%rbp),%rsi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ff <main+0x14f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
sub    $0x4,%eax
cltq
add    %rax,%rdi
lea    0xd8f(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12e3 <main+0x133>
mov    0x2d3f(%rip),%rax
cmpl   $0x0,(%rax)
je     12d0 <main+0x120>
mov    -0x18(%rbp),%rsi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ff <main+0x14f>
mov    $0x0,%al
call   1030 <console_init@plt>
mov    $0x0,%al
call   1070 <view_mode@plt>
jmp    12f1 <main+0x141>
mov    $0x0,%al
call   1030 <console_init@plt>
mov    $0x0,%al
call   1040 <command_mode@plt>
mov    $0x0,%al
call   10b0 <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   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jg     1203 <main+0x53>
mov    $0xc8,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xe29(%rip),%r15
lea    0xe33(%rip),%r12
xchg   %ax,%ax
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   10c0 <scanf@plt>
cmpb   $0x0,(%rbx)
je     11e0 <main+0x30>
xor    %eax,%eax
call   1090 <getchar@plt>
jmp    1207 <main+0x57>
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
call   10d0 <file_load@plt>
test   %rax,%rax
je     122c <main+0x7c>
lea    0xdf9(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1268 <main+0xb8>
mov    (%r14),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xddb(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1276 <main+0xc6>
xor    %eax,%eax
call   1030 <console_init@plt>
xor    %eax,%eax
call   1040 <command_mode@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <console_black@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d6b(%rip),%rax
cmpl   $0x0,(%rax)
je     128b <main+0xdb>
lea    0xd9f(%rip),%rdi
jmp    121b <main+0x6b>
xor    %eax,%eax
call   1030 <console_init@plt>
xor    %eax,%eax
call   1070 <view_mode@plt>
jmp    125f <main+0xaf>

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"
@.str.3 = [5 x i8] c"view\00"
@fileModified = external global i32
@.str.4 = [15 x i8] c"can't read %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 %63
36: ; preds = %29
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @strlen(i8* %42)
%44 = sub nsw i32 %43, 4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %39, i64 %45
%47 = call i32 @strcmp(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp ne i32 %47, 0
br i1 %48, label %58, label %49
49: ; preds = %36
%50 = load i32, i32* @fileModified
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i8*, i8** %6
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %53)
store i32 -1, i32* %3
br label %63
55: ; preds = %49
%56 = call i32 (...) @console_init()
%57 = call i32 (...) @view_mode()
br label %61
58: ; preds = %36
%59 = call i32 (...) @console_init()
%60 = call i32 (...) @command_mode()
br label %61
61: ; preds = %58, %55
%62 = call i32 (...) @console_black()
store i32 0, i32* %3
br label %63
63: ; preds = %61, %52, %33
%64 = load i32, i32* %3
ret i32 %64
}

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"
@.str.3 = [5 x i8] c"view\00"
@fileModified = external global i32
@.str.4 = [15 x i8] c"can't read %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 %43
22: ; preds = %16
%23 = load i8*, i8** %1
%24 = tail call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, -4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = tail call i32 @strcmp(i8* dereferenceable(1) %27, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %22
%31 = load i32, i32* @fileModified
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %17)
br label %43
35: ; preds = %30
%36 = tail call i32 (...) @console_init()
%37 = tail call i32 (...) @view_mode()
br label %41
38: ; preds = %22
%39 = tail call i32 (...) @console_init()
%40 = tail call i32 (...) @command_mode()
br label %41
41: ; preds = %38, %35
%42 = tail call i32 (...) @console_black()
br label %43
43: ; preds = %41, %33, %20
%44 = phi i32 [ -1, %20 ], [ 0, %41 ], [ -1, %33 ]
ret i32 %44
}