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

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ execve(char *, char **, char **);
scalar_t__ vfork();
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(void) {
  pid_t pid;
  int status;
  char *cmd[] = {"./xhello", NULL};
  char *env[] = {NULL};
  if ((pid = vfork()) < 0) {
    return 13;
  } else if (pid) {
    return (waitpid(pid, &status, 0) < 0 ? 17 : 0);
  } else {
    execve(*cmd, cmd, env);
    _exit(5);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2caa(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ca7(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    $0x0,%al
call   1070 <vfork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    11a6 <main+0x56>
movl   $0xd,-0x4(%rbp)
jmp    11f4 <main+0xa4>
cmpq   $0x0,-0x10(%rbp)
je     11d9 <main+0x89>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x11,%ecx
cmp    $0x0,%rdx
cmovl  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <main+0xa4>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <execve@plt>
mov    $0x5,%edi
call   1030 <_exit@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movaps 0x2cc5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,(%rsp)
xor    %eax,%eax
call   1060 <vfork@plt>
test   %rax,%rax
js     1181 <main+0x41>
je     118b <main+0x4b>
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1050 <waitpid@plt>
sar    $0x3f,%rax
and    $0x11,%eax
add    $0x28,%rsp
ret
mov    $0xd,%eax
add    $0x28,%rsp
ret
lea    0xe6e(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <execve@plt>
mov    $0x5,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"./xhello\00"
@__const.main.cmd = [2 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* null]
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca [2 x i8*]
%5 = alloca [1 x i8*]
store i32 0, i32* %1
%6 = bitcast [2 x i8*]* %4 to i8*
%7 = bitcast [1 x i8*]* %5 to i8*
%8 = call i64 (...) @vfork()
store i64 %8, i64* %2
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 13, i32* %1
br label %27
11: ; preds = %0
%12 = load i64, i64* %2
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i64, i64* %2
%16 = call i64 @waitpid(i64 %15, i32* %3, i32 0)
%17 = icmp slt i64 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 17, i32 0
store i32 %19, i32* %1
br label %27
20: ; preds = %11
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%22 = load i8*, i8** %21
%23 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%24 = getelementptr inbounds [1 x i8*], [1 x i8*]* %5, i64 0, i64 0
%25 = call i32 @execve(i8* %22, i8** %23, i8** %24)
%26 = call i32 @_exit(i32 5)
unreachable
27: ; preds = %14, %10
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [9 x i8] c"./xhello\00"
@__const.main.cmd = [2 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* null]
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i8*]
%3 = alloca [1 x i8*]
%4 = bitcast i32* %1 to i8*
%5 = bitcast [2 x i8*]* %2 to i8*
%6 = bitcast [1 x i8*]* %3 to i8*
%7 = bitcast [1 x i8*]* %3 to i64*
store i64 0, i64* %7
%8 = tail call i64 (...) @vfork()
%9 = icmp slt i64 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %0
%11 = icmp eq i64 %8, 0
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = call i64 @waitpid(i64 %8, i32* %1, i32 0)
%14 = icmp slt i64 %13, 0
%15 = select i1 %14, i32 17, i32 0
br label %21
16: ; preds = %10
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%18 = getelementptr inbounds [1 x i8*], [1 x i8*]* %3, i64 0, i64 0
%19 = call i32 @execve(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %17, i8** %18)
%20 = call i32 @_exit(i32 5)
unreachable
21: ; preds = %0, %12
%22 = phi i32 [ %15, %12 ], [ 13, %0 ]
ret i32 %22
}