#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 gen_execve(int, char **);
int gen_nanosleep(int, char **);
int gen_open_openat(int);
int gen_read();
int /*<<< orphan*/ printf(char *, char const *);
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  if (argc < 2) {
    usage();
    return 1;
  }
  const char *syscall_name = argv[1];
  int r = 0;
  if (strcmp("--help", syscall_name) == 0 || strcmp("-h", syscall_name) == 0) {
    usage();
  } else if (strcmp("nanosleep", syscall_name) == 0) {
    r = gen_nanosleep(argc, argv);
  } else if (strcmp("openat", syscall_name) == 0) {
    r = gen_open_openat(false);
  } else if (strcmp("read", syscall_name) == 0) {
    r = gen_read();
  } else if (strcmp("execve", syscall_name) == 0) {
    r = gen_execve(argc, argv);
  } else {
    printf("%s is not supported yet\n", syscall_name);
    usage();
    r = 1;
  }
  return r;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a3 <main+0x33>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    12dc <main+0x16c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe3f(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11ea <main+0x7a>
mov    -0x18(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11f6 <main+0x86>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    12d6 <main+0x166>
mov    -0x18(%rbp),%rsi
lea    0xe09(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1224 <main+0xb4>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <gen_nanosleep@plt>
mov    %eax,-0x1c(%rbp)
jmp    12d1 <main+0x161>
mov    -0x18(%rbp),%rsi
lea    0xde5(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    124d <main+0xdd>
xor    %edi,%edi
call   1090 <gen_open_openat@plt>
mov    %eax,-0x1c(%rbp)
jmp    12cc <main+0x15c>
mov    -0x18(%rbp),%rsi
lea    0xdc3(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1276 <main+0x106>
mov    $0x0,%al
call   1040 <gen_read@plt>
mov    %eax,-0x1c(%rbp)
jmp    12c7 <main+0x157>
mov    -0x18(%rbp),%rsi
lea    0xd9f(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12a4 <main+0x134>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <gen_execve@plt>
mov    %eax,-0x1c(%rbp)
jmp    12c2 <main+0x152>
mov    -0x18(%rbp),%rsi
lea    0xd78(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0x1,-0x1c(%rbp)
jmp    12c7 <main+0x157>
jmp    12cc <main+0x15c>
jmp    12d1 <main+0x161>
jmp    12d6 <main+0x166>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x1,%edi
jg     118a <main+0x1a>
xor    %eax,%eax
call   1080 <usage@plt>
mov    $0x1,%ebx
jmp    1228 <main+0xb8>
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x8(%rsi),%rbx
lea    0xe66(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     121f <main+0xaf>
lea    0xe59(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     121f <main+0xaf>
lea    0xe48(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     122f <main+0xbf>
lea    0xe3e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     123d <main+0xcd>
lea    0xe31(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1248 <main+0xd8>
lea    0xe22(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1253 <main+0xe3>
lea    0xe15(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
jmp    1179 <main+0x9>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <usage@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <gen_nanosleep@plt>
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <gen_open_openat@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <gen_read@plt>
mov    %ebp,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <gen_execve@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [10 x i8] c"nanosleep\00"
@.str.3 = [7 x i8] c"openat\00"
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [7 x i8] c"execve\00"
@.str.6 = [25 x i8] c"%s is not supported yet\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%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 slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @usage()
store i32 1, i32* %3
br label %63
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %6
store i32 0, i32* %7
%16 = load i8*, i8** %6
%17 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19, %12
%24 = call i32 (...) @usage()
br label %61
25: ; preds = %19
%26 = load i8*, i8** %6
%27 = call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* %4
%31 = load i8**, i8*** %5
%32 = call i32 @gen_nanosleep(i32 %30, i8** %31)
store i32 %32, i32* %7
br label %60
33: ; preds = %25
%34 = load i8*, i8** %6
%35 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @gen_open_openat(i32 0)
store i32 %38, i32* %7
br label %59
39: ; preds = %33
%40 = load i8*, i8** %6
%41 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 (...) @gen_read()
store i32 %44, i32* %7
br label %58
45: ; preds = %39
%46 = load i8*, i8** %6
%47 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i32, i32* %4
%51 = load i8**, i8*** %5
%52 = call i32 @gen_execve(i32 %50, i8** %51)
store i32 %52, i32* %7
br label %57
53: ; preds = %45
%54 = load i8*, i8** %6
%55 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %54)
%56 = call i32 (...) @usage()
store i32 1, i32* %7
br label %57
57: ; preds = %53, %49
br label %58
58: ; preds = %57, %43
br label %59
59: ; preds = %58, %37
br label %60
60: ; preds = %59, %29
br label %61
61: ; preds = %60, %23
%62 = load i32, i32* %7
store i32 %62, i32* %3
br label %63
63: ; preds = %61, %10
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [10 x i8] c"nanosleep\00"
@.str.3 = [7 x i8] c"openat\00"
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [7 x i8] c"execve\00"
@.str.6 = [25 x i8] c"%s is not supported yet\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %39
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11, %6
%15 = tail call i32 (...) @usage()
br label %39
16: ; preds = %11
%17 = tail call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @gen_nanosleep(i32 %0, i8** %1)
br label %39
21: ; preds = %16
%22 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 @gen_open_openat(i32 0)
br label %39
26: ; preds = %21
%27 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i32 (...) @gen_read()
br label %39
31: ; preds = %26
%32 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 @gen_execve(i32 %0, i8** %1)
br label %39
36: ; preds = %31
%37 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %8)
%38 = tail call i32 (...) @usage()
br label %39
39: ; preds = %14, %24, %34, %36, %29, %19, %4
%40 = phi i32 [ 1, %4 ], [ 0, %14 ], [ %20, %19 ], [ %25, %24 ], [ %30, %29 ], [ %35, %34 ], [ 1, %36 ]
ret i32 %40
}