#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 const *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ procmsg(char *, char const *);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
void run_target(const char *programname) {
  procmsg("target started. will run '%s'\n", programname);
  if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
    perror("ptrace1");
    return;
  }
  execl(programname, programname, 0);
  perror("ERROR, could not open program");
}


x86 assembly (clang, -O0):
<run_target>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1030 <procmsg@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1040 <ptrace@plt>
cmp    $0x0,%rax
jge    118b <run_target+0x4b>
lea    0xe9e(%rip),%rdi
call   1050 <perror@plt>
jmp    11a6 <run_target+0x66>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1060 <execl@plt>
lea    0xe86(%rip),%rdi
call   1050 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_target>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rdi
mov    %rbx,%rsi
call   1030 <procmsg@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    1179 <run_target+0x39>
lea    0xeac(%rip),%rdi
pop    %rbx
jmp    1050 <perror@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <execl@plt>
lea    0xe9a(%rip),%rdi
pop    %rbx
jmp    1050 <perror@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"target started. will run '%s'\0A\00"
@PTRACE_TRACEME = global i32 0
@.str.1 = [8 x i8] c"ptrace1\00"
@.str.2 = [30 x i8] c"ERROR, could not open program\00"
define void @run_target(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = call i32 @procmsg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = load i32, i32* @PTRACE_TRACEME
%6 = call i64 @ptrace(i32 %5, i32 0, i32 0, i32 0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %15
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @execl(i8* %11, i8* %12, i32 0)
%14 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %10, %8
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"target started. will run '%s'\0A\00"
@PTRACE_TRACEME = global i32 0
@.str.1 = [8 x i8] c"ptrace1\00"
@.str.2 = [30 x i8] c"ERROR, could not open program\00"
define void @run_target(i8* %0) {
%2 = tail call i32 @procmsg(i8* getelementptr inbounds ([31 x i8], [31 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 %8, label %6
6: ; preds = %1
%7 = tail call i32 @execl(i8* %0, i8* %0, i32 0)
br label %8
8: ; preds = %1, %6
%9 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), %6 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %1 ]
%10 = tail call i32 @perror(i8* %9)
ret void
}