#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*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ view_mode();
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Must pass file name as argument.\n");
    return -1;
  }
  if (file_load(argv[1])) {
    printf("can't open %s\n", argv[1]);
    return -1;
  }
  if (!strcmp(&argv[0][strlen(argv[0]) - 4], "view")) {
    extern int fileModified;
    if (fileModified) {
      printf("can't read %s\n", argv[1]);
      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    11ba <main+0x3a>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <file_load@plt>
cmp    $0x0,%rax
je     11f3 <main+0x73>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x18(%rbp),%rdi
sub    $0x4,%eax
cltq
add    %rax,%rdi
lea    0xe14(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1270 <main+0xf0>
mov    0x2db6(%rip),%rax
cmpl   $0x0,(%rax)
je     125d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <main+0x10c>
mov    $0x0,%al
call   1030 <console_init@plt>
mov    $0x0,%al
call   1070 <view_mode@plt>
jmp    127e <main+0xfe>
mov    $0x0,%al
call   1030 <console_init@plt>
mov    $0x0,%al
call   1040 <command_mode@plt>
mov    $0x0,%al
call   1090 <console_black@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11ac <main+0x1c>
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1212 <main+0x82>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10b0 <file_load@plt>
test   %rax,%rax
je     11d6 <main+0x46>
mov    0x8(%rbx),%rsi
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1212 <main+0x82>
mov    (%rbx),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe1d(%rip),%rsi
call   1090 <strcmp@plt>
test   %eax,%eax
je     121c <main+0x8c>
xor    %eax,%eax
call   1030 <console_init@plt>
xor    %eax,%eax
call   1050 <command_mode@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <console_black@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dc5(%rip),%rax
cmpl   $0x0,(%rax)
je     1235 <main+0xa5>
mov    0x8(%rbx),%rsi
lea    0xde1(%rip),%rdi
jmp    11c8 <main+0x38>
xor    %eax,%eax
call   1030 <console_init@plt>
xor    %eax,%eax
call   1080 <view_mode@plt>
jmp    1209 <main+0x79>

LLVM IR (-O0):
@.str = [34 x i8] c"Must pass file name as argument.\0A\00"
@.str.1 = [15 x i8] c"can't open %s\0A\00"
@.str.2 = [5 x i8] c"view\00"
@fileModified = external global i32
@.str.3 = [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**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %50
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @file_load(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %19)
store i32 -1, i32* %3
br label %50
21: ; preds = %10
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %24, i64 %30
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %45, label %34
34: ; preds = %21
%35 = load i32, i32* @fileModified
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %40)
store i32 -1, i32* %3
br label %50
42: ; preds = %34
%43 = call i32 (...) @console_init()
%44 = call i32 (...) @view_mode()
br label %48
45: ; preds = %21
%46 = call i32 (...) @console_init()
%47 = call i32 (...) @command_mode()
br label %48
48: ; preds = %45, %42
%49 = call i32 (...) @console_black()
store i32 0, i32* %3
br label %50
50: ; preds = %48, %37, %16, %8
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"can't open %s\0A\00"
@.str.2 = [5 x i8] c"view\00"
@fileModified = external global i32
@.str.3 = [15 x i8] c"can't read %s\0A\00"
@str = [33 x i8] c"Must pass file name as argument.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %36
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @file_load(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %36
14: ; preds = %6
%15 = load i8*, i8** %1
%16 = tail call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, -4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %14
%23 = load i32, i32* @fileModified
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %36
28: ; preds = %22
%29 = tail call i32 (...) @console_init()
%30 = tail call i32 (...) @view_mode()
br label %34
31: ; preds = %14
%32 = tail call i32 (...) @console_init()
%33 = tail call i32 (...) @command_mode()
br label %34
34: ; preds = %31, %28
%35 = tail call i32 (...) @console_black()
br label %36
36: ; preds = %34, %25, %11, %4
%37 = phi i32 [ -1, %4 ], [ -1, %11 ], [ 0, %34 ], [ -1, %25 ]
ret i32 %37
}