#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_TRACEME;
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/);
int exec(char **command, pid_t *pidptr) {
  pid_t child;
  child = fork();
  if (child == -1)
    return (-1);
  else if (child == 0) {
    if (ptrace(PTRACE_TRACEME, 0, 0, 0) == -1)
      return (-1);
    execvp(command[0], command);
    return (-1);
  } else
    *pidptr = child;
  return (0);
}


x86 assembly (clang, -O0):
<exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1160 <exec+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <exec+0x94>
cmpl   $0x0,-0x1c(%rbp)
jne    11af <exec+0x7f>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1030 <ptrace@plt>
cmp    $0xffffffff,%eax
jne    1193 <exec+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <exec+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <execvp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <exec+0x94>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11bd <exec+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <fork@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     117b <exec+0x4b>
test   %ebp,%ebp
jne    1177 <exec+0x47>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <ptrace@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     117b <exec+0x4b>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1040 <execvp@plt>
jmp    117b <exec+0x4b>
mov    %ebp,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PTRACE_TRACEME = global i32 0
define i32 @exec(i8** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %30
11: ; preds = %2
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i32, i32* @PTRACE_TRACEME
%16 = call i32 @ptrace(i32 %15, i32 0, i32 0, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -1, i32* %3
br label %30
19: ; preds = %14
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %4
%24 = call i32 @execvp(i8* %22, i8** %23)
store i32 -1, i32* %3
br label %30
25: ; preds = %11
%26 = load i32, i32* %6
%27 = load i32*, i32** %5
store i32 %26, i32* %27
br label %28
28: ; preds = %25
br label %29
29: ; preds = %28
store i32 0, i32* %3
br label %30
30: ; preds = %29, %19, %18, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@PTRACE_TRACEME = global i32 0
define i32 @exec(i8** %0, i32* nocapture writeonly %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %11 [
i32 -1, label %12
i32 0, label %4
]
4: ; preds = %2
%5 = load i32, i32* @PTRACE_TRACEME
%6 = tail call i32 @ptrace(i32 %5, i32 0, i32 0, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i8*, i8** %0
%10 = tail call i32 @execvp(i8* %9, i8** %0)
br label %12
11: ; preds = %2
store i32 %3, i32* %1
br label %12
12: ; preds = %4, %2, %11, %8
%13 = phi i32 [ -1, %8 ], [ 0, %11 ], [ %3, %2 ], [ -1, %4 ]
ret i32 %13
}