#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*/ SIGSTOP;
int /*<<< orphan*/ SIGTRAP;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int process_child(char *us) {
  if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
    perror("ptrace(TRACEME) failed");
    return 1;
  }
  kill(getpid(), SIGSTOP);
  kill(getpid(), SIGTRAP);
  char *argv[] = {us, "arg", NULL};
  execvp(argv[0], argv);
  return 2;
}


x86 assembly (clang, -O0):
<process_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1050 <ptrace@plt>
cmp    $0x0,%rax
jge    1192 <process_child+0x42>
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ef <process_child+0x9f>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe48(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <execvp@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_child>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
test   %rax,%rax
js     11ce <process_child+0x7e>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x2e51(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1040 <kill@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x2e42(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1040 <kill@plt>
mov    %rbx,(%rsp)
lea    0xe6d(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <execvp@plt>
mov    $0x2,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    11c8 <process_child+0x78>

LLVM IR (-O0):
@PTRACE_TRACEME = global i32 0
@.str = [23 x i8] c"ptrace(TRACEME) failed\00"
@SIGSTOP = global i32 0
@SIGTRAP = global i32 0
@.str.1 = [4 x i8] c"arg\00"
define i32 @process_child(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [3 x i8*]
store i8* %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 ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %25
10: ; preds = %1
%11 = call i32 (...) @getpid()
%12 = load i32, i32* @SIGSTOP
%13 = call i32 @kill(i32 %11, i32 %12)
%14 = call i32 (...) @getpid()
%15 = load i32, i32* @SIGTRAP
%16 = call i32 @kill(i32 %14, i32 %15)
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%18 = load i8*, i8** %3
store i8* %18, i8** %17
%19 = getelementptr inbounds i8*, i8** %17, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %19
%20 = getelementptr inbounds i8*, i8** %19, i64 1
store i8* null, i8** %20
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%22 = load i8*, i8** %21
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%24 = call i32 @execvp(i8* %22, i8** %23)
store i32 2, i32* %2
br label %25
25: ; preds = %10, %8
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@PTRACE_TRACEME = global i32 0
@.str = [23 x i8] c"ptrace(TRACEME) failed\00"
@SIGSTOP = global i32 0
@SIGTRAP = global i32 0
@.str.1 = [4 x i8] c"arg\00"
define i32 @process_child(i8* %0) {
%2 = alloca [3 x i8*]
%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 ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %20
8: ; preds = %1
%9 = tail call i32 (...) @getpid()
%10 = load i32, i32* @SIGSTOP
%11 = tail call i32 @kill(i32 %9, i32 %10)
%12 = tail call i32 (...) @getpid()
%13 = load i32, i32* @SIGTRAP
%14 = tail call i32 @kill(i32 %12, i32 %13)
%15 = bitcast [3 x i8*]* %2 to i8*
%16 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
store i8* %0, i8** %16
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 2
store i8* null, i8** %18
%19 = call i32 @execvp(i8* %0, i8** %16)
br label %20
20: ; preds = %8, %6
%21 = phi i32 [ 1, %6 ], [ 2, %8 ]
ret i32 %21
}