#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__ INT_MIN;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ cbreak();
scalar_t__ database_menu(char *);
int database_number();
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ get_database(int, char *);
int /*<<< orphan*/ initscr();
int main_menu();
int /*<<< orphan*/ new_database_form();
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sort_database();
int /*<<< orphan*/ start_color();
int main() {
  signal(SIGINT, SIG_IGN);
  int choice, n;
  char database[128];
  initscr();
  start_color();
  cbreak();
  noecho();
  while (1) {
    n = database_number();
    choice = main_menu();
    if (choice == -1)
      continue;
    if (choice == n + 2) {
      endwin();
      return 0;
    } else if (choice == n + 1)
      new_database_form();
    else if (choice == n + 3)
      sort_database();
    else {
      get_database(choice, database);
      if (database_menu(database) == INT_MIN) {
        endwin();
        return 0;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
mov    $0x0,%al
call   1060 <initscr@plt>
mov    $0x0,%al
call   1070 <start_color@plt>
mov    $0x0,%al
call   1040 <cbreak@plt>
mov    $0x0,%al
call   10d0 <noecho@plt>
mov    $0x0,%al
call   10c0 <database_number@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   10a0 <main_menu@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1228 <main+0x68>
jmp    1205 <main+0x45>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jne    124c <main+0x8c>
mov    $0x0,%al
call   10b0 <endwin@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d8 <main+0x118>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1269 <main+0xa9>
mov    $0x0,%al
call   1050 <new_database_form@plt>
jmp    12ce <main+0x10e>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x3,%ecx
cmp    %ecx,%eax
jne    1286 <main+0xc6>
mov    $0x0,%al
call   10e0 <sort_database@plt>
jmp    12c9 <main+0x109>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1030 <get_database@plt>
lea    -0x90(%rbp),%rdi
call   1090 <database_menu@plt>
mov    0x2d38(%rip),%rcx
cmp    (%rcx),%rax
jne    12c4 <main+0x104>
mov    $0x0,%al
call   10b0 <endwin@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d8 <main+0x118>
jmp    12c9 <main+0x109>
jmp    12ce <main+0x10e>
jmp    12d3 <main+0x113>
jmp    1205 <main+0x45>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
xor    %eax,%eax
call   1060 <initscr@plt>
xor    %eax,%eax
call   1070 <start_color@plt>
xor    %eax,%eax
call   1040 <cbreak@plt>
xor    %eax,%eax
call   10d0 <noecho@plt>
mov    %rsp,%r14
mov    0x2dd7(%rip),%r15
jmp    1217 <main+0x57>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <new_database_form@plt>
xor    %eax,%eax
call   10c0 <database_number@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10a0 <main_menu@plt>
cmp    $0xffffffff,%eax
je     1217 <main+0x57>
lea    0x2(%rbx),%ecx
cmp    %ecx,%eax
je     1261 <main+0xa1>
lea    0x1(%rbx),%ecx
cmp    %ecx,%eax
je     1210 <main+0x50>
add    $0x3,%ebx
cmp    %ebx,%eax
jne    124a <main+0x8a>
xor    %eax,%eax
call   10e0 <sort_database@plt>
jmp    1217 <main+0x57>
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <get_database@plt>
mov    %r14,%rdi
call   1090 <database_menu@plt>
cmp    (%r15),%rax
jne    1217 <main+0x57>
xor    %eax,%eax
call   10b0 <endwin@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@INT_MIN = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @SIGINT
%6 = load i32, i32* @SIG_IGN
%7 = call i32 @signal(i32 %5, i32 %6)
%8 = call i32 (...) @initscr()
%9 = call i32 (...) @start_color()
%10 = call i32 (...) @cbreak()
%11 = call i32 (...) @noecho()
br label %12
12: ; preds = %0, %17, %52
%13 = call i32 (...) @database_number()
store i32 %13, i32* %3
%14 = call i32 (...) @main_menu()
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %12
br label %12
18: ; preds = %12
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 2
%22 = icmp eq i32 %19, %21
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (...) @endwin()
store i32 0, i32* %1
br label %53
25: ; preds = %18
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 (...) @new_database_form()
br label %51
32: ; preds = %25
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 3
%36 = icmp eq i32 %33, %35
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (...) @sort_database()
br label %50
39: ; preds = %32
%40 = load i32, i32* %2
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%42 = call i32 @get_database(i32 %40, i8* %41)
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%44 = call i64 @database_menu(i8* %43)
%45 = load i64, i64* @INT_MIN
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = call i32 (...) @endwin()
store i32 0, i32* %1
br label %53
49: ; preds = %39
br label %50
50: ; preds = %49, %37
br label %51
51: ; preds = %50, %30
br label %52
52: ; preds = %51
br label %12
53: ; preds = %47, %23
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@INT_MIN = global i64 0
define i32 @main() {
%1 = alloca [128 x i8]
%2 = load i32, i32* @SIGINT
%3 = load i32, i32* @SIG_IGN
%4 = tail call i32 @signal(i32 %2, i32 %3)
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%6 = tail call i32 (...) @initscr()
%7 = tail call i32 (...) @start_color()
%8 = tail call i32 (...) @cbreak()
%9 = tail call i32 (...) @noecho()
br label %10
10: ; preds = %27, %0
%11 = call i32 (...) @database_number()
%12 = call i32 (...) @main_menu()
%13 = icmp eq i32 %12, -1
br i1 %13, label %27, label %14
14: ; preds = %10
%15 = add nsw i32 %11, 2
%16 = icmp eq i32 %12, %15
br i1 %16, label %33, label %17
17: ; preds = %14
%18 = add nsw i32 %11, 1
%19 = icmp eq i32 %12, %18
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (...) @new_database_form()
br label %27
22: ; preds = %17
%23 = add nsw i32 %11, 3
%24 = icmp eq i32 %12, %23
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 (...) @sort_database()
br label %27
27: ; preds = %25, %28, %20, %10
br label %10
28: ; preds = %22
%29 = call i32 @get_database(i32 %12, i8* %5)
%30 = call i64 @database_menu(i8* %5)
%31 = load i64, i64* @INT_MIN
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %27
33: ; preds = %28, %14
%34 = call i32 (...) @endwin()
ret i32 0
}