#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 /*<<< orphan*/);
int /*<<< orphan*/ fopentest();
int /*<<< orphan*/ getcwd1();
int /*<<< orphan*/ lseek_test();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ testExecve(char **);
int /*<<< orphan*/ testchdir();
int /*<<< orphan*/ testfork();
int /*<<< orphan*/ testmalloc();
int /*<<< orphan*/ testpipe();
int main(int argc, char *argv[], char *envp[]) {
  while (1) {
    printf("Enter 1 for open() and close() API test \n 2 for malloc() and "
           "free() API test \n 3 for pipe() api test \n 4 for chdir() API test "
           "\n 5 for cwd() API test \n 6 for execve() API test \n 7 for fork() "
           "API test \n 8 for exit  \n 9 for lseek \n");
    int c;
    scanf("%d", &c);
    switch (c) {
    case 1:
      fopentest();
      break;
    case 2:
      testmalloc();
      break;
    case 3:
      testpipe();
      break;
    case 4:
      testchdir();
      break;
    case 5:
      getcwd1();
      break;
    case 6:
      testExecve(envp);
      break;
    case 7:
      testfork();
      break;
    case 8:
      exit(0);
    case 9:
      lseek_test();
      break;
    default:
      printf("Please enter valid option \n");
      break;
    }
  }
  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)
mov    %rdx,-0x18(%rbp)
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
lea    0xf2c(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   10c0 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x8,%eax
ja     1278 <main+0xc8>
mov    -0x28(%rbp),%rax
lea    0xdfa(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1030 <fopentest@plt>
jmp    1284 <main+0xd4>
mov    $0x0,%al
call   1070 <testmalloc@plt>
jmp    1284 <main+0xd4>
mov    $0x0,%al
call   1080 <testpipe@plt>
jmp    1284 <main+0xd4>
mov    $0x0,%al
call   1060 <testchdir@plt>
jmp    1284 <main+0xd4>
mov    $0x0,%al
call   10b0 <getcwd1@plt>
jmp    1284 <main+0xd4>
mov    -0x18(%rbp),%rdi
call   10a0 <testExecve@plt>
jmp    1284 <main+0xd4>
mov    $0x0,%al
call   1090 <testfork@plt>
jmp    1284 <main+0xd4>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   1040 <lseek_test@plt>
jmp    1284 <main+0xd4>
lea    0xe8d(%rip),%rdi
call   1050 <printf@plt>
jmp    11ca <main+0x1a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
lea    0xe62(%rip),%r15
lea    0xe58(%rip),%r12
lea    0x4(%rsp),%rbx
lea    0xf33(%rip),%r13
lea    0xe21(%rip),%rbp
jmp    11f0 <main+0x40>
xor    %eax,%eax
call   1050 <lseek_test@plt>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   10c0 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x8,%eax
ja     1222 <main+0x72>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
xor    %eax,%eax
call   1030 <fopentest@plt>
jmp    11f0 <main+0x40>
mov    %r13,%rdi
call   1040 <puts@plt>
jmp    11f0 <main+0x40>
xor    %eax,%eax
call   1070 <testmalloc@plt>
jmp    11f0 <main+0x40>
xor    %eax,%eax
call   1080 <testpipe@plt>
jmp    11f0 <main+0x40>
xor    %eax,%eax
call   1060 <testchdir@plt>
jmp    11f0 <main+0x40>
xor    %eax,%eax
call   10b0 <getcwd1@plt>
jmp    11f0 <main+0x40>
mov    %r14,%rdi
call   10a0 <testExecve@plt>
jmp    11f0 <main+0x40>
xor    %eax,%eax
call   1090 <testfork@plt>
jmp    11f0 <main+0x40>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [229 x i8] c"Enter 1 for open() and close() API test \0A 2 for malloc() and free() API test \0A 3 for pipe() api test \0A 4 for chdir() API test \0A 5 for cwd() API test \0A 6 for execve() API test \0A 7 for fork() API test \0A 8 for exit \0A 9 for lseek \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"Please enter valid option \0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
br label %9
9: ; preds = %3, %34
%10 = call i32 @printf(i8* getelementptr inbounds ([229 x i8], [229 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%12 = load i32, i32* %8
switch i32 %12, label %32 [
i32 1, label %13
i32 2, label %15
i32 3, label %17
i32 4, label %19
i32 5, label %21
i32 6, label %23
i32 7, label %26
i32 8, label %28
i32 9, label %30
]
13: ; preds = %9
%14 = call i32 (...) @fopentest()
br label %34
15: ; preds = %9
%16 = call i32 (...) @testmalloc()
br label %34
17: ; preds = %9
%18 = call i32 (...) @testpipe()
br label %34
19: ; preds = %9
%20 = call i32 (...) @testchdir()
br label %34
21: ; preds = %9
%22 = call i32 (...) @getcwd1()
br label %34
23: ; preds = %9
%24 = load i8**, i8*** %7
%25 = call i32 @testExecve(i8** %24)
br label %34
26: ; preds = %9
%27 = call i32 (...) @testfork()
br label %34
28: ; preds = %9
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %9
%31 = call i32 (...) @lseek_test()
br label %34
32: ; preds = %9
%33 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %30, %26, %23, %21, %19, %17, %15, %13
br label %9
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [228 x i8] c"Enter 1 for open() and close() API test \0A 2 for malloc() and free() API test \0A 3 for pipe() api test \0A 4 for chdir() API test \0A 5 for cwd() API test \0A 6 for execve() API test \0A 7 for fork() API test \0A 8 for exit \0A 9 for lseek \00"
@str.3 = [27 x i8] c"Please enter valid option \00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
br label %6
6: ; preds = %3, %30
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([228 x i8], [228 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%9 = load i32, i32* %4
switch i32 %9, label %28 [
i32 1, label %10
i32 2, label %12
i32 3, label %14
i32 4, label %16
i32 5, label %18
i32 6, label %20
i32 7, label %22
i32 8, label %24
i32 9, label %26
]
10: ; preds = %6
%11 = call i32 (...) @fopentest()
br label %30
12: ; preds = %6
%13 = call i32 (...) @testmalloc()
br label %30
14: ; preds = %6
%15 = call i32 (...) @testpipe()
br label %30
16: ; preds = %6
%17 = call i32 (...) @testchdir()
br label %30
18: ; preds = %6
%19 = call i32 (...) @getcwd1()
br label %30
20: ; preds = %6
%21 = call i32 @testExecve(i8** %2)
br label %30
22: ; preds = %6
%23 = call i32 (...) @testfork()
br label %30
24: ; preds = %6
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %6
%27 = call i32 (...) @lseek_test()
br label %30
28: ; preds = %6
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %26, %22, %20, %18, %16, %14, %12, %10
br label %6
}