#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ add_cont(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ exp_cb(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ imp_cb(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ rem_cont(int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ see_con_det(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *cb = fopen("contactbook.bin", "ab+");
  if (cb == NULL)
    cb = fopen("contactbook.bin", "wb+");
  if (cb == NULL) {
    puts("Error, file (contactbook.bin) could not be found.");
    exit(3);
  };
  int menu_pick = 0;
  while (1) {
    printf("Pick options: \n"
           "------------------\n"
           "1. Add contact\n"
           "2. Remove contact\n"
           "3. Export contact book\n"
           "4. Import contact book\n"
           "5. See contact details\n"
           "6. Exit program.\n"
           "Input: ");
    scanf("%d", &menu_pick);
    if (menu_pick == 0) {
      fclose(cb);
      exit(2);
    }
    switch (menu_pick) {
    case 1:
      add_cont(cb);
      break;
    case 2:
      rem_cont(cb);
      break;
    case 3:
      exp_cb(cb);
      break;
    case 4:
      imp_cb(cb);
      break;
    case 5:
      see_con_det(cb);
      break;
    case 0:
      fclose(cb);
      exit(1);
      break;
    default:
      fclose(cb);
      exit(0);
      break;
    }
  }
  fclose(cb);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe4b(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ff <main+0x4f>
lea    0xe29(%rip),%rdi
lea    0xe36(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1220 <main+0x70>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1090 <scanf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1260 <main+0xb0>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
mov    -0x1c(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x5,%rax
ja     12de <main+0x12e>
mov    -0x28(%rbp),%rax
lea    0xd84(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
call   1080 <add_cont@plt>
jmp    12ee <main+0x13e>
mov    -0x18(%rbp),%rdi
call   1060 <rem_cont@plt>
jmp    12ee <main+0x13e>
mov    -0x18(%rbp),%rdi
call   10b0 <exp_cb@plt>
jmp    12ee <main+0x13e>
mov    -0x18(%rbp),%rdi
call   10a0 <imp_cb@plt>
jmp    12ee <main+0x13e>
mov    -0x18(%rbp),%rdi
call   1070 <see_con_det@plt>
jmp    12ee <main+0x13e>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    1227 <main+0x77>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe54(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1209 <main+0x59>
lea    0xe39(%rip),%rdi
lea    0xe46(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1209 <main+0x59>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
movl   $0x0,0xc(%rsp)
lea    0xe4a(%rip),%r14
lea    0xee4(%rip),%r15
lea    0xc(%rsp),%r12
lea    0xdd5(%rip),%rbx
jmp    1240 <main+0x90>
mov    %r13,%rdi
call   1070 <see_con_det@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x5,%rax
ja     12a0 <main+0xf0>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r13,%rdi
call   1080 <add_cont@plt>
jmp    1240 <main+0x90>
mov    %r13,%rdi
call   1060 <rem_cont@plt>
jmp    1240 <main+0x90>
mov    %r13,%rdi
call   10b0 <exp_cb@plt>
jmp    1240 <main+0x90>
mov    %r13,%rdi
call   10a0 <imp_cb@plt>
jmp    1240 <main+0x90>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"contactbook.bin\00"
@.str.1 = [4 x i8] c"ab+\00"
@.str.2 = [4 x i8] c"wb+\00"
@.str.3 = [50 x i8] c"Error, file (contactbook.bin) could not be found.\00"
@.str.4 = [161 x i8] c"Pick options: \0A------------------\0A1. Add contact\0A2. Remove contact\0A3. Export contact book\0A4. Import contact book\0A5. See contact details\0A6. Exit program.\0AInput: \00"
@.str.5 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %6
br label %13
13: ; preds = %11, %2
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @puts(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @exit(i32 3)
unreachable
19: ; preds = %13
store i32 0, i32* %7
br label %20
20: ; preds = %19, %54
%21 = call i32 @printf(i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %7)
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %20
%30 = load i32, i32* %7
switch i32 %30, label %50 [
i32 1, label %31
i32 2, label %34
i32 3, label %37
i32 4, label %40
i32 5, label %43
i32 0, label %46
]
31: ; preds = %29
%32 = load i32*, i32** %6
%33 = call i32 @add_cont(i32* %32)
br label %54
34: ; preds = %29
%35 = load i32*, i32** %6
%36 = call i32 @rem_cont(i32* %35)
br label %54
37: ; preds = %29
%38 = load i32*, i32** %6
%39 = call i32 @exp_cb(i32* %38)
br label %54
40: ; preds = %29
%41 = load i32*, i32** %6
%42 = call i32 @imp_cb(i32* %41)
br label %54
43: ; preds = %29
%44 = load i32*, i32** %6
%45 = call i32 @see_con_det(i32* %44)
br label %54
46: ; preds = %29
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %29
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %43, %40, %37, %34, %31
br label %20
}

LLVM IR (-O2):
@.str = [16 x i8] c"contactbook.bin\00"
@.str.1 = [4 x i8] c"ab+\00"
@.str.2 = [4 x i8] c"wb+\00"
@.str.3 = [50 x i8] c"Error, file (contactbook.bin) could not be found.\00"
@.str.4 = [161 x i8] c"Pick options: \0A------------------\0A1. Add contact\0A2. Remove contact\0A3. Export contact book\0A4. Import contact book\0A5. See contact details\0A6. Exit program.\0AInput: \00"
@.str.5 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @exit(i32 3)
unreachable
12: ; preds = %2, %6
%13 = phi i32* [ %7, %6 ], [ %4, %2 ]
%14 = bitcast i32* %3 to i8*
store i32 0, i32* %3
br label %15
15: ; preds = %32, %12
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([161 x i8], [161 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
switch i32 %18, label %33 [
i32 0, label %19
i32 1, label %22
i32 2, label %24
i32 3, label %26
i32 4, label %28
i32 5, label %30
]
19: ; preds = %15
%20 = call i32 @fclose(i32* %13)
%21 = call i32 @exit(i32 2)
unreachable
22: ; preds = %15
%23 = call i32 @add_cont(i32* %13)
br label %32
24: ; preds = %15
%25 = call i32 @rem_cont(i32* %13)
br label %32
26: ; preds = %15
%27 = call i32 @exp_cb(i32* %13)
br label %32
28: ; preds = %15
%29 = call i32 @imp_cb(i32* %13)
br label %32
30: ; preds = %15
%31 = call i32 @see_con_det(i32* %13)
br label %32
32: ; preds = %30, %28, %26, %24, %22
br label %15
33: ; preds = %15
%34 = call i32 @fclose(i32* %13)
%35 = call i32 @exit(i32 0)
unreachable
}