#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*/ addEmployee(int /*<<< orphan*/ *);
int atoi(char *);
int /*<<< orphan*/ calculateAvarageSalaryByGender(int /*<<< orphan*/ *);
int /*<<< orphan*/ compactData(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ exportTextFile(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ removeEmployee(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc == 3) {
    int option = atoi(argv[2]);
    FILE *f;
    f = fopen(argv[1], "ab+");
    fclose(f);
    switch (option) {
    case 1:
      if ((f = fopen(argv[1], "ab+")) == NULL) {
        printf("Error opening/creating the file");
      } else {
        addEmployee(f);
        fclose(f);
      }
      break;
    case 2:
      if ((f = fopen(argv[1], "rb+")) == NULL) {
        printf("Error opening/creating the file");
      } else {
        removeEmployee(f);
        fclose(f);
      }
      break;
    case 3:
      if ((f = fopen(argv[1], "rb")) == NULL) {
        printf("Error opening/creating the file");
      } else {
        calculateAvarageSalaryByGender(f);
        fclose(f);
      }
      break;
    case 4:
      if ((f = fopen(argv[1], "rb")) == NULL) {
        printf("Error opening/creating the file");
      } else {
        exportTextFile(f);
        fclose(f);
      }
      break;
    case 5:
      if ((f = fopen(argv[1], "rb")) == NULL) {
        printf("Error opening/creating the file");
      } else {
        compactData(f, argv[1]);
        fclose(f);
      }
      break;
    }
  } else {
    printf("Need to provide two arguments, the first one is the binary file "
           "and second is the option. \n");
    printf("1 - Add employee \n");
    printf("2 - Remove employee \n");
    printf("3 - Calculate avarage salary by gender \n");
    printf("4 - Export data to a text file \n");
    printf("5 - Compact data \n");
  }
  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)
cmpl   $0x3,-0x8(%rbp)
jne    1389 <main+0x1f9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe45(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     1384 <main+0x1f4>
mov    -0x28(%rbp),%rax
lea    0xdff(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdfb(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    123d <main+0xad>
lea    0xde5(%rip),%rdi
call   1050 <printf@plt>
jmp    124f <main+0xbf>
mov    -0x20(%rbp),%rdi
call   1070 <addEmployee@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1384 <main+0x1f4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd5(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1287 <main+0xf7>
lea    0xd9b(%rip),%rdi
call   1050 <printf@plt>
jmp    1299 <main+0x109>
mov    -0x20(%rbp),%rdi
call   10a0 <removeEmployee@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1384 <main+0x1f4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd8f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12d1 <main+0x141>
lea    0xd51(%rip),%rdi
call   1050 <printf@plt>
jmp    12e3 <main+0x153>
mov    -0x20(%rbp),%rdi
call   1060 <calculateAvarageSalaryByGender@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1384 <main+0x1f4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd45(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    131b <main+0x18b>
lea    0xd07(%rip),%rdi
call   1050 <printf@plt>
jmp    132d <main+0x19d>
mov    -0x20(%rbp),%rdi
call   10b0 <exportTextFile@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1384 <main+0x1f4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcfb(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1365 <main+0x1d5>
lea    0xcbd(%rip),%rdi
call   1050 <printf@plt>
jmp    137f <main+0x1ef>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <compactData@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1384 <main+0x1f4>
jmp    13d1 <main+0x241>
lea    0xcaf(%rip),%rdi
call   1050 <printf@plt>
lea    0xcff(%rip),%rdi
call   1050 <printf@plt>
lea    0xd06(%rip),%rdi
call   1050 <printf@plt>
lea    0xd10(%rip),%rdi
call   1050 <printf@plt>
lea    0xd2d(%rip),%rdi
call   1050 <printf@plt>
lea    0xd42(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1214 <main+0x74>
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
mov    0x8(%r14),%rdi
lea    0xe52(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rdi
call   1050 <fclose@plt>
add    $0xffffffff,%ebx
cmp    $0x4,%ebx
ja     1301 <main+0x161>
lea    0xe1e(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    0x8(%r14),%rdi
lea    0xe1e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12f5 <main+0x155>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <addEmployee@plt>
jmp    12eb <main+0x14b>
lea    0xe24(%rip),%rdi
call   1040 <puts@plt>
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
jmp    1301 <main+0x161>
mov    0x8(%r14),%rdi
lea    0xdcc(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12f5 <main+0x155>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <removeEmployee@plt>
jmp    12eb <main+0x14b>
mov    0x8(%r14),%rdi
lea    0xdae(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12f5 <main+0x155>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <calculateAvarageSalaryByGender@plt>
jmp    12eb <main+0x14b>
mov    0x8(%r14),%rdi
lea    0xd8c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12f5 <main+0x155>
mov    %rax,%rbx
mov    %rax,%rdi
call   10c0 <exportTextFile@plt>
jmp    12eb <main+0x14b>
mov    0x8(%r14),%rdi
lea    0xd6a(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12f5 <main+0x155>
mov    %rax,%rbx
mov    0x8(%r14),%rsi
mov    %rax,%rdi
call   1030 <compactData@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1301 <main+0x161>
lea    0xd1c(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"ab+\00"
@.str.1 = [32 x i8] c"Error opening/creating the file\00"
@.str.2 = [4 x i8] c"rb+\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [92 x i8] c"Need to provide two arguments, the first one is the binary file and second is the option. \0A\00"
@.str.5 = [19 x i8] c"1 - Add employee \0A\00"
@.str.6 = [22 x i8] c"2 - Remove employee \0A\00"
@.str.7 = [41 x i8] c"3 - Calculate avarage salary by gender \0A\00"
@.str.8 = [33 x i8] c"4 - Export data to a text file \0A\00"
@.str.9 = [19 x i8] c"5 - Compact data \0A\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 = load i32, i32* %4
%9 = icmp eq i32 %8, 3
br i1 %9, label %10, label %96
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %6
switch i32 %21, label %95 [
i32 1, label %22
i32 2, label %36
i32 3, label %50
i32 4, label %64
i32 5, label %78
]
22: ; preds = %10
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %26, i32** %7
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %35
30: ; preds = %22
%31 = load i32*, i32** %7
%32 = call i32 @addEmployee(i32* %31)
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %30, %28
br label %95
36: ; preds = %10
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32* %40, i32** %7
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %49
44: ; preds = %36
%45 = load i32*, i32** %7
%46 = call i32 @removeEmployee(i32* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
br label %49
49: ; preds = %44, %42
br label %95
50: ; preds = %10
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %54, i32** %7
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %58
56: ; preds = %50
%57 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %63
58: ; preds = %50
%59 = load i32*, i32** %7
%60 = call i32 @calculateAvarageSalaryByGender(i32* %59)
%61 = load i32*, i32** %7
%62 = call i32 @fclose(i32* %61)
br label %63
63: ; preds = %58, %56
br label %95
64: ; preds = %10
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %68, i32** %7
%69 = icmp eq i32* %68, null
br i1 %69, label %70, label %72
70: ; preds = %64
%71 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %77
72: ; preds = %64
%73 = load i32*, i32** %7
%74 = call i32 @exportTextFile(i32* %73)
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
br label %77
77: ; preds = %72, %70
br label %95
78: ; preds = %10
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32* @fopen(i8* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %82, i32** %7
%83 = icmp eq i32* %82, null
br i1 %83, label %84, label %86
84: ; preds = %78
%85 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %94
86: ; preds = %78
%87 = load i32*, i32** %7
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 1
%90 = load i8*, i8** %89
%91 = call i32 @compactData(i32* %87, i8* %90)
%92 = load i32*, i32** %7
%93 = call i32 @fclose(i32* %92)
br label %94
94: ; preds = %86, %84
br label %95
95: ; preds = %10, %94, %77, %63, %49, %35
br label %103
96: ; preds = %2
%97 = call i32 @printf(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.4, i64 0, i64 0))
%98 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%99 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%100 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
%101 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%102 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %103
103: ; preds = %96, %95
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"ab+\00"
@.str.1 = [32 x i8] c"Error opening/creating the file\00"
@.str.2 = [4 x i8] c"rb+\00"
@.str.3 = [3 x i8] c"rb\00"
@str = [91 x i8] c"Need to provide two arguments, the first one is the binary file and second is the option. \00"
@str.10 = [18 x i8] c"1 - Add employee \00"
@str.11 = [21 x i8] c"2 - Remove employee \00"
@str.12 = [40 x i8] c"3 - Calculate avarage salary by gender \00"
@str.13 = [32 x i8] c"4 - Export data to a text file \00"
@str.14 = [18 x i8] c"5 - Compact data \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %58
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @fclose(i32* %10)
switch i32 %7, label %65 [
i32 1, label %12
i32 2, label %21
i32 3, label %30
i32 4, label %39
i32 5, label %48
]
12: ; preds = %4
%13 = load i8*, i8** %8
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %65
18: ; preds = %12
%19 = tail call i32 @addEmployee(i32* %14)
%20 = tail call i32 @fclose(i32* %14)
br label %65
21: ; preds = %4
%22 = load i8*, i8** %8
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %65
27: ; preds = %21
%28 = tail call i32 @removeEmployee(i32* %23)
%29 = tail call i32 @fclose(i32* %23)
br label %65
30: ; preds = %4
%31 = load i8*, i8** %8
%32 = tail call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %65
36: ; preds = %30
%37 = tail call i32 @calculateAvarageSalaryByGender(i32* %32)
%38 = tail call i32 @fclose(i32* %32)
br label %65
39: ; preds = %4
%40 = load i8*, i8** %8
%41 = tail call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %65
45: ; preds = %39
%46 = tail call i32 @exportTextFile(i32* %41)
%47 = tail call i32 @fclose(i32* %41)
br label %65
48: ; preds = %4
%49 = load i8*, i8** %8
%50 = tail call i32* @fopen(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %65
54: ; preds = %48
%55 = load i8*, i8** %8
%56 = tail call i32 @compactData(i32* %50, i8* %55)
%57 = tail call i32 @fclose(i32* %50)
br label %65
58: ; preds = %2
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @str, i64 0, i64 0))
%60 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.10, i64 0, i64 0))
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%62 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.12, i64 0, i64 0))
%63 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.13, i64 0, i64 0))
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.14, i64 0, i64 0))
br label %65
65: ; preds = %4, %18, %16, %27, %25, %36, %34, %45, %43, %54, %52, %58
ret i32 0
}