#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 EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ create_read_and_exec_thread(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
size_t optind;
int /*<<< orphan*/ read_and_exec_file(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int c;
  int threaded = 0;
  while ((c = getopt(argc, argv, "tp:")) != EOF) {
    switch (c) {
    case 't':
      threaded = 1;
      break;
    default:
      fprintf(stderr, "usage: %s [ -t ] payload_bin\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  if (threaded)
    create_read_and_exec_thread(argv[optind]);
  else
    read_and_exec_file(argv[optind]);
}


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)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%eax
je     11de <main+0x8e>
mov    -0x14(%rbp),%eax
sub    $0x74,%eax
jne    11af <main+0x5f>
jmp    11a3 <main+0x53>
movl   $0x1,-0x18(%rbp)
jmp    11d9 <main+0x89>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    116d <main+0x1d>
cmpl   $0x0,-0x18(%rbp)
je     1204 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x2ded(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <create_read_and_exec_thread@plt>
jmp    121b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    0x2dd1(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <read_and_exec_file@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe9d(%rip),%rdx
call   1060 <getopt@plt>
mov    0x2e79(%rip),%r15
cmp    (%r15),%eax
jne    1189 <main+0x39>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    (%rbx,%rax,8),%rdi
call   1040 <read_and_exec_file@plt>
jmp    11ba <main+0x6a>
lea    0xe70(%rip),%r14
cmp    $0x74,%eax
jne    11c7 <main+0x77>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
cmp    (%r15),%eax
jne    1190 <main+0x40>
mov    0x2e32(%rip),%rax
mov    (%rax),%rax
mov    (%rbx,%rax,8),%rdi
call   1030 <create_read_and_exec_thread@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"tp:\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"usage: %s [ -t ] payload_bin\0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i64 0
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
store i32 0, i32* %7
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %8
%15 = load i32, i32* %6
switch i32 %15, label %17 [
i32 116, label %16
]
16: ; preds = %14
store i32 1, i32* %7
br label %25
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
br label %8
26: ; preds = %8
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i8**, i8*** %5
%31 = load i64, i64* @optind
%32 = getelementptr inbounds i8*, i8** %30, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @create_read_and_exec_thread(i8* %33)
br label %41
35: ; preds = %26
%36 = load i8**, i8*** %5
%37 = load i64, i64* @optind
%38 = getelementptr inbounds i8*, i8** %36, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @read_and_exec_file(i8* %39)
br label %41
41: ; preds = %35, %29
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [4 x i8] c"tp:\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"usage: %s [ -t ] payload_bin\0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %24, label %10
6: ; preds = %10
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %19, label %10
10: ; preds = %2, %6
%11 = phi i32 [ %7, %6 ], [ %3, %2 ]
%12 = icmp eq i32 %11, 116
br i1 %12, label %6, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %6
%20 = load i64, i64* @optind
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = tail call i32 @create_read_and_exec_thread(i8* %22)
br label %29
24: ; preds = %2
%25 = load i64, i64* @optind
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i32 @read_and_exec_file(i8* %27)
br label %29
29: ; preds = %24, %19
ret i32 0
}