#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 execl(char const *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ procprint(char *);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
void run_target(const char *name) {
  if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
    perror("error ptrace()\n");
  }
  if (execl(name, name, NULL) == -1) {
    procprint("cannot execute the target\n");
  }
}


x86 assembly (clang, -O0):
<run_target>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1030 <ptrace@plt>
cmp    $0x0,%rax
jge    1176 <run_target+0x36>
lea    0xe8f(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execl@plt>
cmp    $0xffffffff,%eax
jne    119c <run_target+0x5c>
lea    0xe79(%rip),%rdi
call   1040 <procprint@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_target>:
push   %rbx
mov    %rdi,%rbx
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <ptrace@plt>
test   %rax,%rax
js     117e <run_target+0x3e>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <execl@plt>
cmp    $0xffffffff,%eax
je     1171 <run_target+0x31>
pop    %rbx
ret
lea    0xe98(%rip),%rdi
pop    %rbx
jmp    1040 <procprint@plt>
lea    0xe7b(%rip),%rdi
call   1050 <perror@plt>
jmp    115d <run_target+0x1d>

LLVM IR (-O0):
@PTRACE_TRACEME = global i32 0
@.str = [16 x i8] c"error ptrace()\0A\00"
@.str.1 = [27 x i8] c"cannot execute the target\0A\00"
define void @run_target(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i32, i32* @PTRACE_TRACEME
%4 = 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 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i8*, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @execl(i8* %9, i8* %10, i32* null)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @procprint(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
ret void
}

LLVM IR (-O2):
@PTRACE_TRACEME = global i32 0
@.str = [16 x i8] c"error ptrace()\0A\00"
@.str.1 = [27 x i8] c"cannot execute the target\0A\00"
define void @run_target(i8* %0) {
%2 = load i32, i32* @PTRACE_TRACEME
%3 = tail call i64 @ptrace(i32 %2, i32 0, i32 0, i32 0)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = tail call i32 @execl(i8* %0, i8* %0, i32* null)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @procprint(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
ret void
}