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

/* Variables and functions */
int /*<<< orphan*/ PTRACE_TRACEME;
int /*<<< orphan*/ SIGSTOP;
int /*<<< orphan*/ argv_join(char *, int, char **, char *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int /*<<< orphan*/ parent_loop(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ ptrace(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ raise(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: %s command [arguments ...]\n", argv[0]);
    exit(-1);
  }
  int pid = fork();
  if (pid == -1) {
    perror("fork()");
    exit(-1);
  }
  if (pid != 0) {
    parent_loop(pid);
  } else {
    ptrace(PTRACE_TRACEME, 0, NULL, NULL);
    raise(SIGSTOP);
    char buf[1024];
    argv_join(buf, sizeof(buf), &argv[1], " ");
    fprintf(stderr, "[+] pid=%i, running: %s\n", getpid(), buf);
    execvp(argv[1], &argv[1]);
    perror("execvp()");
  }
  exit(-1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11eb <main+0x4b>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1215 <main+0x75>
lea    0xe1d(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
je     122c <main+0x8c>
mov    -0x14(%rbp),%edi
call   1050 <parent_loop@plt>
jmp    12c5 <main+0x125>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1080 <ptrace@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
add    $0x8,%rdx
mov    $0x400,%esi
lea    0xdbe(%rip),%rcx
call   1070 <argv_join@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x424(%rbp),%edi
mov    %eax,%edx
lea    -0x420(%rbp),%rcx
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   10a0 <execvp@plt>
lea    0xd85(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jle    125d <main+0xbd>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
jne    124f <main+0xaf>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <ptrace@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
lea    0x8(%r14),%rbx
lea    0xe35(%rip),%rcx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <argv_join@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe0d(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%r14),%rdi
mov    %rbx,%rsi
call   10a0 <execvp@plt>
lea    0xe05(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
cmp    $0xffffffff,%eax
jne    1281 <main+0xe1>
lea    0xdc8(%rip),%rdi
jmp    1240 <main+0xa0>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd90(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    %eax,%edi
call   1050 <parent_loop@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Usage: %s command [arguments ...]\0A\00"
@.str.1 = [7 x i8] c"fork()\00"
@PTRACE_TRACEME = global i32 0
@SIGSTOP = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.3 = [25 x i8] c"[+] pid=%i, running: %s\0A\00"
@.str.4 = [9 x i8] c"execvp()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
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 %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = call i32 (...) @fork()
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %17
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %6
%29 = call i32 @parent_loop(i32 %28)
br label %50
30: ; preds = %24
%31 = load i32, i32* @PTRACE_TRACEME
%32 = call i32 @ptrace(i32 %31, i32 0, i32* null, i32* null)
%33 = load i32, i32* @SIGSTOP
%34 = call i32 @raise(i32 %33)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = call i32 @argv_join(i8* %35, i32 1024, i8** %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = call i32 (...) @getpid()
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %40, i8* %41)
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = call i32 @execvp(i8* %45, i8** %47)
%49 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %30, %27
%51 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Usage: %s command [arguments ...]\0A\00"
@.str.1 = [7 x i8] c"fork()\00"
@PTRACE_TRACEME = global i32 0
@SIGSTOP = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.3 = [25 x i8] c"[+] pid=%i, running: %s\0A\00"
@.str.4 = [9 x i8] c"execvp()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = tail call i32 (...) @fork()
switch i32 %11, label %15 [
i32 -1, label %12
i32 0, label %17
]
12: ; preds = %10
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %10
%16 = tail call i32 @parent_loop(i32 %11)
br label %31
17: ; preds = %10
%18 = load i32, i32* @PTRACE_TRACEME
%19 = tail call i32 @ptrace(i32 %18, i32 0, i32* null, i32* null)
%20 = load i32, i32* @SIGSTOP
%21 = tail call i32 @raise(i32 %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = call i32 @argv_join(i8* %22, i32 1024, i8** %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = call i32 (...) @getpid()
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %26, i8* %22)
%28 = load i8*, i8** %23
%29 = call i32 @execvp(i8* %28, i8** %23)
%30 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %17, %15
%32 = call i32 @exit(i32 -1)
unreachable
}