#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ menu_add_employee();
int /*<<< orphan*/ menu_delete_employee();
int /*<<< orphan*/ menu_print_database();
int /*<<< orphan*/ read_employee_database(char *);
scalar_t__ read_line(int /*<<< orphan*/, char *, int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  if (argc != 1 && argc != 2) {
    fprintf(stderr, "Usage: %s [<database-file>]\n", argv[0]);
    exit(-1);
  }
  if (argc == 2)
    read_employee_database(argv[1]);
  for (;;) {
    int choice, result;
    char line[301];
    fprintf(stderr, "\nOptions:\n");
    fprintf(stderr, "%d: Add new employee to database\n", 0);
    fprintf(stderr, "%d: Delete employee from database\n", 1);
    fprintf(stderr, "%d: Print database to screen\n", 2);
    fprintf(stderr, "%d: Exit database program\n", 3);
    fprintf(stderr, "\nEnter option: ");
    if (read_line(stdin, line, 300) != 0)
      continue;
    result = sscanf(line, "%d", &choice);
    if (result != 1) {
      fprintf(stderr, "corrupted menu choice\n");
      continue;
    }
    switch (choice) {
    case 0:
      menu_add_employee();
      break;
    case 1:
      menu_delete_employee();
      break;
    case 2:
      menu_print_database();
      break;
    case 3:
      break;
    default:
      fprintf(stderr, "illegal choice %d\n", choice);
      break;
    }
    if (choice == 3)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11d5 <main+0x55>
cmpl   $0x2,-0x8(%rbp)
je     11d5 <main+0x55>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    11ec <main+0x6c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <read_employee_database@plt>
jmp    11f1 <main+0x71>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    -0x150(%rbp),%rsi
mov    $0x12c,%edx
call   1090 <read_line@plt>
cmp    $0x0,%rax
je     12b5 <main+0x135>
jmp    11f1 <main+0x71>
lea    -0x150(%rbp),%rdi
lea    0xe03(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1080 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     12f5 <main+0x175>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11f1 <main+0x71>
mov    -0x14(%rbp),%eax
mov    %rax,-0x158(%rbp)
sub    $0x3,%rax
ja     1349 <main+0x1c9>
mov    -0x158(%rbp),%rax
lea    0xce9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1040 <menu_add_employee@plt>
jmp    1363 <main+0x1e3>
mov    $0x0,%al
call   1060 <menu_delete_employee@plt>
jmp    1363 <main+0x1e3>
mov    $0x0,%al
call   1070 <menu_print_database@plt>
jmp    1363 <main+0x1e3>
jmp    1363 <main+0x1e3>
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x3,-0x14(%rbp)
jne    1372 <main+0x1f2>
jmp    1377 <main+0x1f7>
jmp    11f1 <main+0x71>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
lea    -0x3(%rdi),%eax
cmp    $0xfffffffd,%eax
jbe    1318 <main+0x198>
cmp    $0x2,%edi
jne    11ab <main+0x2b>
mov    0x8(%rsi),%rdi
call   1030 <read_employee_database@plt>
mov    0x2e26(%rip),%r15
lea    0xec4(%rip),%r13
lea    0xedb(%rip),%rbx
lea    0xeef(%rip),%rbp
mov    0x2e1a(%rip),%r12
lea    0x10(%rsp),%r14
jmp    11f0 <main+0x70>
mov    (%r15),%edi
lea    0xeea(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%edi
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
lea    0xe2d(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
lea    0xe3c(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
mov    %r13,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r12),%edi
mov    %r14,%rsi
mov    $0x12c,%edx
call   1090 <read_line@plt>
test   %rax,%rax
jne    11f0 <main+0x70>
mov    %r14,%rdi
lea    0xe47(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    11d5 <main+0x55>
mov    0xc(%rsp),%edx
cmp    $0x3,%rdx
ja     12c0 <main+0x140>
lea    0xd5d(%rip),%rcx
movslq (%rcx,%rdx,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
call   1040 <menu_add_employee@plt>
cmpl   $0x3,0xc(%rsp)
jne    11f0 <main+0x70>
jmp    1304 <main+0x184>
mov    (%r15),%edi
lea    0xe16(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmpl   $0x3,0xc(%rsp)
jne    11f0 <main+0x70>
jmp    1304 <main+0x184>
xor    %eax,%eax
call   1060 <menu_delete_employee@plt>
cmpl   $0x3,0xc(%rsp)
jne    11f0 <main+0x70>
jmp    1304 <main+0x184>
xor    %eax,%eax
call   1070 <menu_print_database@plt>
cmpl   $0x3,0xc(%rsp)
jne    11f0 <main+0x70>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xce5(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s [<database-file>]\0A\00"
@.str.1 = [11 x i8] c"\0AOptions:\0A\00"
@.str.2 = [34 x i8] c"%d: Add new employee to database\0A\00"
@.str.3 = [35 x i8] c"%d: Delete employee from database\0A\00"
@.str.4 = [30 x i8] c"%d: Print database to screen\0A\00"
@.str.5 = [27 x i8] c"%d: Exit database program\0A\00"
@.str.6 = [16 x i8] c"\0AEnter option: \00"
@stdin = global i32 0
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [23 x i8] c"corrupted menu choice\0A\00"
@.str.9 = [19 x i8] c"illegal choice %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [301 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %11, %2
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @read_employee_database(i8* %27)
br label %29
29: ; preds = %24, %21
br label %30
30: ; preds = %73, %53, %47, %29
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 0)
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 1)
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 2)
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 3)
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%43 = load i32, i32* @stdin
%44 = getelementptr inbounds [301 x i8], [301 x i8]* %8, i64 0, i64 0
%45 = call i64 @read_line(i32 %43, i8* %44, i32 300)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %30
br label %30
48: ; preds = %30
%49 = getelementptr inbounds [301 x i8], [301 x i8]* %8, i64 0, i64 0
%50 = call i32 @sscanf(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %6)
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = icmp ne i32 %51, 1
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %30
56: ; preds = %48
%57 = load i32, i32* %6
switch i32 %57, label %65 [
i32 0, label %58
i32 1, label %60
i32 2, label %62
i32 3, label %64
]
58: ; preds = %56
%59 = call i32 (...) @menu_add_employee()
br label %69
60: ; preds = %56
%61 = call i32 (...) @menu_delete_employee()
br label %69
62: ; preds = %56
%63 = call i32 (...) @menu_print_database()
br label %69
64: ; preds = %56
br label %69
65: ; preds = %56
%66 = load i32, i32* @stderr
%67 = load i32, i32* %6
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %65, %64, %62, %60, %58
%70 = load i32, i32* %6
%71 = icmp eq i32 %70, 3
br i1 %71, label %72, label %73
72: ; preds = %69
br label %74
73: ; preds = %69
br label %30
74: ; preds = %72
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s [<database-file>]\0A\00"
@.str.1 = [11 x i8] c"\0AOptions:\0A\00"
@.str.2 = [34 x i8] c"%d: Add new employee to database\0A\00"
@.str.3 = [35 x i8] c"%d: Delete employee from database\0A\00"
@.str.4 = [30 x i8] c"%d: Print database to screen\0A\00"
@.str.5 = [27 x i8] c"%d: Exit database program\0A\00"
@.str.6 = [16 x i8] c"\0AEnter option: \00"
@stdin = global i32 0
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [23 x i8] c"corrupted menu choice\0A\00"
@.str.9 = [19 x i8] c"illegal choice %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [301 x i8]
%5 = add i32 %0, -3
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = icmp eq i32 %0, 2
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @read_employee_database(i8* %16)
br label %18
18: ; preds = %14, %12
%19 = bitcast i32* %3 to i8*
%20 = getelementptr inbounds [301 x i8], [301 x i8]* %4, i64 0, i64 0
br label %21
21: ; preds = %57, %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 0)
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 1)
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 2)
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 3)
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = call i64 @read_line(i32 %34, i8* %20, i32 300)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %57
37: ; preds = %21
%38 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %3)
%39 = icmp eq i32 %38, 1
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %57
43: ; preds = %37
%44 = load i32, i32* %3
switch i32 %44, label %51 [
i32 0, label %45
i32 1, label %47
i32 2, label %49
i32 3, label %58
]
45: ; preds = %43
%46 = call i32 (...) @menu_add_employee()
br label %54
47: ; preds = %43
%48 = call i32 (...) @menu_delete_employee()
br label %54
49: ; preds = %43
%50 = call i32 (...) @menu_print_database()
br label %54
51: ; preds = %43
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %44)
br label %54
54: ; preds = %51, %49, %47, %45
%55 = load i32, i32* %3
%56 = icmp eq i32 %55, 3
br i1 %56, label %58, label %57
57: ; preds = %54, %21, %40
br label %21
58: ; preds = %43, %54
ret i32 0
}