#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 execvp(char *, char **);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char **, char **, int);
int /*<<< orphan*/ ptrace(int /*<<< orphan*/);
int do_child(int argc, char **argv) {
  char *args[argc + 1];
  memcpy(args, argv, argc * sizeof(char *));
  args[argc] = NULL;
  ptrace(PTRACE_TRACEME);
  kill(getpid(), SIGSTOP);
  return execvp(args[0], args);
}


x86 assembly (clang, -O0):
<do_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <ptrace@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    -0x28(%rbp),%rsi
mov    (%rsi),%rdi
call   1070 <execvp@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_child>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0x1(%rdi),%eax
mov    %rsp,%r14
lea    0xf(,%rax,8),%rbx
and    $0xfffffffffffffff0,%rbx
mov    %r14,%r15
sub    %rbx,%r15
mov    %r15,%rsp
neg    %rbx
movslq %edi,%r12
lea    0x0(,%r12,8),%edx
mov    %r15,%rdi
call   1040 <memcpy@plt>
movq   $0x0,(%r15,%r12,8)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1060 <ptrace@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x2e28(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1050 <kill@plt>
mov    (%r14,%rbx,1),%rdi
mov    %r15,%rsi
call   1070 <execvp@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PTRACE_TRACEME = global i32 0
@SIGSTOP = global i32 0
define i32 @do_child(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8*, i64 %9
store i64 %9, i64* %6
%12 = load i8**, i8*** %4
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = trunc i64 %15 to i32
%17 = call i32 @memcpy(i8** %11, i8** %12, i32 %16)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %11, i64 %19
store i8* null, i8** %20
%21 = load i32, i32* @PTRACE_TRACEME
%22 = call i32 @ptrace(i32 %21)
%23 = call i32 (...) @getpid()
%24 = load i32, i32* @SIGSTOP
%25 = call i32 @kill(i32 %23, i32 %24)
%26 = getelementptr inbounds i8*, i8** %11, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @execvp(i8* %27, i8** %11)
%29 = load i8*, i8** %5
ret i32 %28
}

LLVM IR (-O2):
@PTRACE_TRACEME = global i32 0
@SIGSTOP = global i32 0
define i32 @do_child(i32 %0, i8** %1) {
%3 = add nsw i32 %0, 1
%4 = zext i32 %3 to i64
%5 = alloca i8*, i64 %4
%6 = sext i32 %0 to i64
%7 = shl i32 %0, 3
%8 = call i32 @memcpy(i8** %5, i8** %1, i32 %7)
%9 = getelementptr inbounds i8*, i8** %5, i64 %6
store i8* null, i8** %9
%10 = load i32, i32* @PTRACE_TRACEME
%11 = call i32 @ptrace(i32 %10)
%12 = call i32 (...) @getpid()
%13 = load i32, i32* @SIGSTOP
%14 = call i32 @kill(i32 %12, i32 %13)
%15 = load i8*, i8** %5
%16 = call i32 @execvp(i8* %15, i8** %5)
ret i32 %16
}