#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ PTRACE_TRACEME;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *,
                           char *);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void do_child(char const *program_name, char **argv) {
  assert(program_name != (char *)0);
  assert(argv[0] != (char *)0);
  if (ptrace(PTRACE_TRACEME, (pid_t)0, 0, 0) < 0) {
    fprintf(stderr, "%s: could not trace %s due to %s\n", program_name, argv[0],
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  execv(argv[0], argv);
  fprintf(stderr, "%s: could not exec %s due to %s\n", program_name, argv[0],
          strerror(errno));
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<do_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1050 <ptrace@plt>
cmp    $0x0,%rax
jge    120a <do_child+0xaa>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    %rax,%r8
lea    0xe09(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <execv@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %rax,%r8
lea    0xdc6(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<do_child>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%rbx)
setne  %dil
call   1030 <assert@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
test   %rax,%rax
jns    11c3 <do_child+0x63>
mov    0x2e39(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe3f(%rip),%rsi
jmp    11ef <do_child+0x8f>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1080 <execv@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe33(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PTRACE_TRACEME = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"%s: could not trace %s due to %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [33 x i8] c"%s: could not exec %s due to %s\0A\00"
define void @do_child(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
store i8* %0, i8** %3
store i8** %1, i8*** %4
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* @PTRACE_TRACEME
%16 = call i64 @ptrace(i32 %15, i32 0, i32 0, i32 0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %3
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %23, i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %2
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %4
%34 = call i32 @execv(i8* %32, i8** %33)
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %3
%37 = load i8**, i8*** %4
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %39, i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
}

LLVM IR (-O2):
@PTRACE_TRACEME = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"%s: could not trace %s due to %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [33 x i8] c"%s: could not exec %s due to %s\0A\00"
define void @do_child(i8* %0, i8** %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = load i8*, i8** %1
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = load i32, i32* @PTRACE_TRACEME
%11 = tail call i64 @ptrace(i32 %10, i32 0, i32 0, i32 0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %15, i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8*, i8** %1
%23 = tail call i32 @execv(i8* %22, i8** %1)
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %1
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %25, i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
}