#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;
  }
  printf("[child] start to run %s!\n", app_name);
  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    11cc <run_target+0x8c>
mov    -0x10(%rbp),%rsi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execl@plt>
lea    0xe83(%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     11b9 <run_target+0x69>
lea    0xe9c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <execl@plt>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe60(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%r14d
jmp    11ae <run_target+0x5e>

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 = [26 x i8] c"[child] start to run %s!\0A\00"
@.str.3 = [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 %18
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i32 @execl(i8* %14, i8* %15, i32* null)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %18
18: ; preds = %11, %9
%19 = load i32, i32* %2
ret i32 %19
}

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.2 = [26 x i8] c"[child] start to run %s!\0A\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 %12
8: ; preds = %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%10 = tail call i32 @execl(i8* %0, i8* %0, i32* null)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ -1, %6 ], [ 0, %8 ]
ret i32 %13
}