#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ add_note();
int atoi(char *);
int /*<<< orphan*/ del_note();
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ get_flag();
int /*<<< orphan*/ print_menu();
int /*<<< orphan*/ print_note();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(void) {
  char buf[512];
  setvbuf(stdout, NULL, _IONBF, 0);
  for (;;) {
    print_menu();
    if (!fgets(buf, sizeof(buf), stdin))
      break;
    int num = atoi(buf);
    switch (num) {
    case 1:
      add_note();
      break;
    case 2:
      del_note();
      break;
    case 3:
      print_note();
      break;
    case 4:
      get_flag();
      break;
    case 5:
      printf("Bye!\n");
      return 0;
    default:
      printf("Invalid choice\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   10a0 <setvbuf@plt>
mov    $0x0,%al
call   1090 <print_menu@plt>
lea    -0x210(%rbp),%rdi
mov    0x2e14(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1070 <fgets@plt>
cmp    $0x0,%eax
jne    11ee <main+0x5e>
jmp    128b <main+0xfb>
lea    -0x210(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x214(%rbp)
mov    -0x214(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x220(%rbp)
sub    $0x4,%eax
ja     127a <main+0xea>
mov    -0x220(%rbp),%rax
lea    0xdd7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1080 <add_note@plt>
jmp    1286 <main+0xf6>
mov    $0x0,%al
call   1030 <del_note@plt>
jmp    1286 <main+0xf6>
mov    $0x0,%al
call   1060 <print_note@plt>
jmp    1286 <main+0xf6>
mov    $0x0,%al
call   1040 <get_flag@plt>
jmp    1286 <main+0xf6>
lea    0xdab(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1292 <main+0x102>
lea    0xd99(%rip),%rdi
call   1050 <printf@plt>
jmp    11bf <main+0x2f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10a0 <setvbuf@plt>
xor    %eax,%eax
call   1090 <print_menu@plt>
mov    0x2e21(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x200,%esi
call   1070 <fgets@plt>
test   %eax,%eax
je     1264 <main+0xd4>
mov    %rsp,%rbx
lea    0xe30(%rip),%r14
lea    0xe10(%rip),%r12
jmp    121b <main+0x8b>
mov    %r14,%rdi
call   1040 <puts@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <print_menu@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1070 <fgets@plt>
test   %eax,%eax
je     1264 <main+0xd4>
mov    %rbx,%rdi
call   10b0 <atoi@plt>
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     11f2 <main+0x62>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
xor    %eax,%eax
call   1080 <add_note@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   1030 <del_note@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   1060 <print_note@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   1050 <get_flag@plt>
jmp    1200 <main+0x70>
lea    0xdb5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@stdin = global i32 0
@.str = [6 x i8] c"Bye!\0A\00"
@.str.1 = [16 x i8] c"Invalid choice\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @stdout
%5 = load i32, i32* @_IONBF
%6 = call i32 @setvbuf(i32 %4, i32* null, i32 %5, i32 0)
br label %7
7: ; preds = %30, %0
%8 = call i32 (...) @print_menu()
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 512, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %7
br label %31
14: ; preds = %7
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
switch i32 %17, label %28 [
i32 1, label %18
i32 2, label %20
i32 3, label %22
i32 4, label %24
i32 5, label %26
]
18: ; preds = %14
%19 = call i32 (...) @add_note()
br label %30
20: ; preds = %14
%21 = call i32 (...) @del_note()
br label %30
22: ; preds = %14
%23 = call i32 (...) @print_note()
br label %30
24: ; preds = %14
%25 = call i32 (...) @get_flag()
br label %30
26: ; preds = %14
%27 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %32
28: ; preds = %14
%29 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %24, %22, %20, %18
br label %7
31: ; preds = %13
store i32 0, i32* %1
br label %32
32: ; preds = %31, %26
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@stdin = global i32 0
@str = [5 x i8] c"Bye!\00"
@str.2 = [15 x i8] c"Invalid choice\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdout
%4 = load i32, i32* @_IONBF
%5 = tail call i32 @setvbuf(i32 %3, i32* null, i32 %4, i32 0)
%6 = call i32 (...) @print_menu()
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %2, i32 512, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %29, label %10
10: ; preds = %0, %24
%11 = call i32 @atoi(i8* %2)
switch i32 %11, label %22 [
i32 1, label %12
i32 2, label %14
i32 3, label %16
i32 4, label %18
i32 5, label %20
]
12: ; preds = %10
%13 = call i32 (...) @add_note()
br label %24
14: ; preds = %10
%15 = call i32 (...) @del_note()
br label %24
16: ; preds = %10
%17 = call i32 (...) @print_note()
br label %24
18: ; preds = %10
%19 = call i32 (...) @get_flag()
br label %24
20: ; preds = %10
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %29
22: ; preds = %10
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.2, i64 0, i64 0))
br label %24
24: ; preds = %12, %14, %16, %18, %22
%25 = call i32 (...) @print_menu()
%26 = load i32, i32* @stdin
%27 = call i32 @fgets(i8* %2, i32 512, i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %10
29: ; preds = %24, %0, %20
ret i32 0
}