#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*/ _exit(int);
int /*<<< orphan*/ execlp(char *, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int vfork();
main() {
  int pid;
  pid = vfork();
  if (pid == 0) {
    printf("I'm the child!\n");
    execlp("gdb.base/vforked-prog", "gdb.base/vforked-prog", (char *)0);
    perror("exec failed");
    _exit(1);
  } else {
    printf("I'm the proud parent of child #%d!\n", pid);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
call   1060 <vfork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11a1 <main+0x51>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe91(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1070 <execlp@plt>
lea    0xe94(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x4(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
call   1070 <vfork@plt>
test   %eax,%eax
je     1180 <main+0x20>
mov    %eax,%esi
lea    0xeaf(%rip),%rdi
xor    %ebx,%ebx
mov    %ebx,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdi,%rsi
call   1080 <execlp@plt>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"I'm the child!\0A\00"
@.str.1 = [22 x i8] c"gdb.base/vforked-prog\00"
@.str.2 = [12 x i8] c"exec failed\00"
@.str.3 = [36 x i8] c"I'm the proud parent of child #%d!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = call i32 @vfork()
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @execlp(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* null)
%8 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @_exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"gdb.base/vforked-prog\00"
@.str.2 = [12 x i8] c"exec failed\00"
@.str.3 = [36 x i8] c"I'm the proud parent of child #%d!\0A\00"
@str = [15 x i8] c"I'm the child!\00"
define i32 @main() {
%1 = call i32 @vfork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %8
3: ; preds = %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%5 = call i32 @execlp(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* null)
%6 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @_exit(i32 1)
unreachable
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %1)
ret i32 0
}