#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 */
scalar_t__ ERR;
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ clear();
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ has_colors();
int /*<<< orphan*/ initscr();
scalar_t__ keypad(int /*<<< orphan*/, int);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ printUsage(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ runMainMenu();
int /*<<< orphan*/ start_color();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdscr;
int main(int argc, char *argv[]) {
  int arg;
  while ((arg = getopt(argc, argv, "hv")) != -1) {
    switch (arg) {
    case 'h':
      printUsage(argv[0]);
      return 0;
    case 'v':
      printf("%s\n", "v0.1");
      return 0;
    default:
      fprintf(stderr, "Invalid option.\n");
      printUsage(argv[0]);
      return 1;
    }
  }
  initscr();
  if (!has_colors()) {
    endwin();
    fprintf(stderr, "ERROR: Your terminal does not support color.\n");
    return 1;
  }
  if (keypad(stdscr, true) == ERR) {
    endwin();
    fprintf(stderr, "ERROR: Cannot translate keys.\n");
    return 1;
  }
  start_color();
  cbreak();
  noecho();
  runMainMenu();
  clear();
  refresh();
  endwin();
  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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdfc(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     129e <main+0xbe>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x68,%eax
je     123a <main+0x5a>
jmp    1229 <main+0x49>
mov    -0x18(%rbp),%eax
sub    $0x76,%eax
je     1252 <main+0x72>
jmp    1271 <main+0x91>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <printUsage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1360 <main+0x180>
lea    0xdaa(%rip),%rdi
lea    0xda7(%rip),%rsi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1360 <main+0x180>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <printUsage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1360 <main+0x180>
mov    $0x0,%al
call   1080 <initscr@plt>
mov    $0x0,%al
call   1040 <has_colors@plt>
cmp    $0x0,%eax
jne    12dd <main+0xfd>
mov    $0x0,%al
call   10d0 <endwin@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1360 <main+0x180>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1070 <keypad@plt>
mov    0x2cf1(%rip),%rcx
cmp    (%rcx),%rax
jne    1328 <main+0x148>
mov    $0x0,%al
call   10d0 <endwin@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xd34(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1360 <main+0x180>
mov    $0x0,%al
call   1090 <start_color@plt>
mov    $0x0,%al
call   1050 <cbreak@plt>
mov    $0x0,%al
call   10f0 <noecho@plt>
mov    $0x0,%al
call   1030 <runMainMenu@plt>
mov    $0x0,%al
call   1100 <clear@plt>
mov    $0x0,%al
call   10b0 <refresh@plt>
mov    $0x0,%al
call   10d0 <endwin@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
lea    0xe15(%rip),%rdx
call   10e0 <getopt@plt>
cmp    $0xffffffff,%eax
je     1212 <main+0x32>
cmp    $0x76,%eax
je     126d <main+0x8d>
cmp    $0x68,%eax
jne    1284 <main+0xa4>
mov    (%rbx),%rdi
call   10c0 <printUsage@plt>
xor    %ebx,%ebx
jmp    12fe <main+0x11e>
xor    %eax,%eax
call   1080 <initscr@plt>
xor    %eax,%eax
call   1040 <has_colors@plt>
test   %eax,%eax
je     12a8 <main+0xc8>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%ebx
mov    $0x1,%esi
call   1070 <keypad@plt>
mov    0x2da1(%rip),%rcx
cmp    (%rcx),%rax
jne    12cb <main+0xeb>
xor    %eax,%eax
call   10d0 <endwin@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    12fe <main+0x11e>
lea    0xd8f(%rip),%rdi
lea    0xd8c(%rip),%rsi
call   1060 <printf@plt>
xor    %ebx,%ebx
jmp    12fe <main+0x11e>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
call   10a0 <fprintf@plt>
mov    (%rbx),%rdi
call   10c0 <printUsage@plt>
mov    $0x1,%ebx
jmp    12fe <main+0x11e>
xor    %eax,%eax
call   10d0 <endwin@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%ebx
jmp    12fe <main+0x11e>
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <start_color@plt>
xor    %eax,%eax
call   1050 <cbreak@plt>
xor    %eax,%eax
call   10f0 <noecho@plt>
xor    %eax,%eax
call   1030 <runMainMenu@plt>
xor    %eax,%eax
call   1100 <clear@plt>
xor    %eax,%eax
call   10b0 <refresh@plt>
xor    %eax,%eax
call   10d0 <endwin@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"hv\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"v0.1\00"
@stderr = global i32 0
@.str.3 = [17 x i8] c"Invalid option.\0A\00"
@.str.4 = [46 x i8] c"ERROR: Your terminal does not support color.\0A\00"
@stdscr = global i32 0
@ERR = global i64 0
@.str.5 = [31 x i8] c"ERROR: Cannot translate keys.\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
br label %7
7: ; preds = %2
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @getopt(i32 %8, i8** %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %6
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %28
12: ; preds = %7
%13 = load i32, i32* %6
switch i32 %13, label %21 [
i32 104, label %14
i32 118, label %19
]
14: ; preds = %12
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @printUsage(i8* %17)
store i32 0, i32* %3
br label %53
19: ; preds = %12
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %53
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @printUsage(i8* %26)
store i32 1, i32* %3
br label %53
28: ; preds = %7
%29 = call i32 (...) @initscr()
%30 = call i32 (...) @has_colors()
%31 = icmp ne i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = call i32 (...) @endwin()
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %53
36: ; preds = %28
%37 = load i32, i32* @stdscr
%38 = call i64 @keypad(i32 %37, i32 1)
%39 = load i64, i64* @ERR
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = call i32 (...) @endwin()
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %53
45: ; preds = %36
%46 = call i32 (...) @start_color()
%47 = call i32 (...) @cbreak()
%48 = call i32 (...) @noecho()
%49 = call i32 (...) @runMainMenu()
%50 = call i32 (...) @clear()
%51 = call i32 (...) @refresh()
%52 = call i32 (...) @endwin()
store i32 0, i32* %3
br label %53
53: ; preds = %45, %41, %32, %21, %19, %14
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"hv\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"v0.1\00"
@stderr = global i32 0
@.str.3 = [17 x i8] c"Invalid option.\0A\00"
@.str.4 = [46 x i8] c"ERROR: Your terminal does not support color.\0A\00"
@stdscr = global i32 0
@ERR = global i64 0
@.str.5 = [31 x i8] c"ERROR: Cannot translate keys.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %3, label %9 [
i32 -1, label %14
i32 104, label %4
i32 118, label %7
]
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printUsage(i8* %5)
br label %39
7: ; preds = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %39
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%12 = load i8*, i8** %1
%13 = tail call i32 @printUsage(i8* %12)
br label %39
14: ; preds = %2
%15 = tail call i32 (...) @initscr()
%16 = tail call i32 (...) @has_colors()
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = tail call i32 (...) @endwin()
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
br label %39
22: ; preds = %14
%23 = load i32, i32* @stdscr
%24 = tail call i64 @keypad(i32 %23, i32 1)
%25 = load i64, i64* @ERR
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = tail call i32 (...) @endwin()
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %39
31: ; preds = %22
%32 = tail call i32 (...) @start_color()
%33 = tail call i32 (...) @cbreak()
%34 = tail call i32 (...) @noecho()
%35 = tail call i32 (...) @runMainMenu()
%36 = tail call i32 (...) @clear()
%37 = tail call i32 (...) @refresh()
%38 = tail call i32 (...) @endwin()
br label %39
39: ; preds = %31, %27, %18, %9, %7, %4
%40 = phi i32 [ 1, %9 ], [ 0, %7 ], [ 0, %4 ], [ 1, %27 ], [ 0, %31 ], [ 1, %18 ]
ret i32 %40
}