#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 EXIT_FAILURE;
int /*<<< orphan*/ PTRACE_TRACEME;
int /*<<< orphan*/ execv(char *const, char *const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *const);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int target(char *const *args) {
  printf("target started. will run '%s'\n", args[0]);
  if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
    perror("ptrace");
    return EXIT_FAILURE;
  }
  execv(args[0], args);
  perror("target exec");
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<target>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1040 <ptrace@plt>
cmp    $0x0,%rax
jge    119a <target+0x5a>
lea    0xe9b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <target+0x82>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execv@plt>
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<target>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rsi
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
test   %rax,%rax
jns    1175 <target+0x35>
lea    0xeac(%rip),%rdi
jmp    1187 <target+0x47>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1060 <execv@plt>
lea    0xe9f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"target started. will run '%s'\0A\00"
@PTRACE_TRACEME = global i32 0
@.str.1 = [7 x i8] c"ptrace\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"target exec\00"
define i32 @target(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
store i8** %0, i8*** %3
%4 = load i8**, i8*** %3
%5 = getelementptr inbounds i8*, i8** %4, i64 0
%6 = load i8*, i8** %5
%7 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @PTRACE_TRACEME
%9 = call i64 @ptrace(i32 %8, i32 0, i32 0, i32 0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %2
br label %22
14: ; preds = %1
%15 = load i8**, i8*** %3
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %3
%19 = call i32 @execv(i8* %17, i8** %18)
%20 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %2
br label %22
22: ; preds = %14, %11
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [31 x i8] c"target started. will run '%s'\0A\00"
@PTRACE_TRACEME = global i32 0
@.str.1 = [7 x i8] c"ptrace\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"target exec\00"
define i32 @target(i8** %0) {
%2 = load i8*, i8** %0
%3 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = load i32, i32* @PTRACE_TRACEME
%5 = tail call i64 @ptrace(i32 %4, i32 0, i32 0, i32 0)
%6 = icmp slt i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i8*, i8** %0
%9 = tail call i32 @execv(i8* %8, i8** %0)
br label %10
10: ; preds = %1, %7
%11 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %1 ]
%12 = tail call i32 @perror(i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
ret i32 %13
}