#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*/ PTRACE_TRACEME;
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int run_target(char *app_name) {
  printf("target started. will run '%s' \n", app_name);
  if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
    perror("ptrace");
    return -1;
  }
  execl(app_name, app_name, NULL);
  printf("[child] finished execl!\n");
  return 0;
}


x86 assembly (clang, -O0):
<run_target>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1040 <ptrace@plt>
cmp    $0x0,%rax
jge    1194 <run_target+0x54>
lea    0xe9d(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <run_target+0x7a>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execl@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_target>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xea2(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
test   %rax,%rax
js     11a8 <run_target+0x58>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <execl@plt>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe71(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%r14d
jmp    119d <run_target+0x4d>

LLVM IR (-O0):
@.str = [32 x i8] c"target started. will run '%s' \0A\00"
@PTRACE_TRACEME = global i32 0
@.str.1 = [7 x i8] c"ptrace\00"
@.str.2 = [25 x i8] c"[child] finished execl!\0A\00"
define i32 @run_target(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i32, i32* @PTRACE_TRACEME
%7 = call i64 @ptrace(i32 %6, i32 0, i32 0, i32 0)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %16
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @execl(i8* %12, i8* %13, i32* null)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %16
16: ; preds = %11, %9
%17 = load i32, i32* %2
ret i32 %17
}

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