#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*/ execle(char *, char *, char *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ vfork();
int /*<<< orphan*/ wait(int *);
int main(int argc, const char *argv[]) {
  pid_t child;
  int status;
  child = vfork();
  if (child < 0) {
    fprintf(stderr, "fork failed!\n");
    return -1;
  }
  if (child == 0)
    printf("Parent %d\n", getpid());
  else {
    execle("/bin/ls", "/bin/ls", "/proc/self/exe", NULL, NULL);
  }
  wait(&status);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <vfork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11ad <main+0x4d>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <main+0xa0>
cmpq   $0x0,-0x18(%rbp)
jne    11d2 <main+0x72>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
jmp    11f0 <main+0x90>
lea    0xe40(%rip),%rsi
lea    0xe41(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
mov    %r8,%rcx
call   1070 <execle@plt>
lea    -0x1c(%rbp),%rdi
call   1080 <wait@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <vfork@plt>
test   %rax,%rax
js     118c <main+0x2c>
je     11a8 <main+0x48>
lea    0xea3(%rip),%rdi
lea    0xea4(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <execle@plt>
jmp    11bd <main+0x5d>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe58(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0x4(%rsp),%rdi
call   1080 <wait@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"fork failed!\0A\00"
@.str.1 = [11 x i8] c"Parent %d\0A\00"
@.str.2 = [8 x i8] c"/bin/ls\00"
@.str.3 = [15 x i8] c"/proc/self/exe\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @vfork()
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %24
14: ; preds = %2
%15 = load i64, i64* %6
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 (...) @getpid()
%19 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %22
20: ; preds = %14
%21 = call i32 @execle(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32* null, i32* null)
br label %22
22: ; preds = %20, %17
%23 = call i32 @wait(i32* %7)
store i32 0, i32* %3
br label %24
24: ; preds = %22, %11
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"fork failed!\0A\00"
@.str.1 = [11 x i8] c"Parent %d\0A\00"
@.str.2 = [8 x i8] c"/bin/ls\00"
@.str.3 = [15 x i8] c"/proc/self/exe\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @vfork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %19
10: ; preds = %2
%11 = icmp eq i64 %5, 0
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = tail call i32 (...) @getpid()
%14 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %17
15: ; preds = %10
%16 = tail call i32 @execle(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32* null, i32* null)
br label %17
17: ; preds = %15, %12
%18 = call i32 @wait(i32* %3)
br label %19
19: ; preds = %17, %7
%20 = phi i32 [ -1, %7 ], [ 0, %17 ]
ret i32 %20
}