#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*/ exit(int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int vfork();
int main() {
  pid_t pid;
  pid = vfork();
  if (pid == -1) {
    perror("failure");
  } else if (pid == 0) {
    printf("child process:%d\n", getpid());
    exit(0);
  } else {
    printf("parent process:%d\n", getpid());
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
call   1060 <vfork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1182 <main+0x32>
lea    0xe88(%rip),%rdi
call   1050 <perror@plt>
jmp    11c4 <main+0x74>
cmpl   $0x0,-0x8(%rbp)
jne    11a8 <main+0x58>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
call   1060 <vfork@plt>
cmp    $0xffffffff,%eax
jne    116b <main+0x1b>
lea    0xe9e(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
pop    %rbx
ret
xor    %ebx,%ebx
test   %eax,%eax
jne    1181 <main+0x31>
mov    %ebx,%eax
call   1030 <getpid@plt>
lea    0xe89(%rip),%rdi
jmp    118f <main+0x3f>
mov    %ebx,%eax
call   1030 <getpid@plt>
lea    0xe8b(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"failure\00"
@.str.1 = [18 x i8] c"child process:%d\0A\00"
@.str.2 = [19 x i8] c"parent process:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @vfork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %19
8: ; preds = %0
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i32 (...) @getpid()
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %8
%16 = call i32 (...) @getpid()
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"failure\00"
@.str.1 = [18 x i8] c"child process:%d\0A\00"
@.str.2 = [19 x i8] c"parent process:%d\0A\00"
define i32 @main() {
%1 = call i32 @vfork()
switch i32 %1, label %8 [
i32 -1, label %2
i32 0, label %4
]
2: ; preds = %0
%3 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
ret i32 0
4: ; preds = %0
%5 = call i32 (...) @getpid()
%6 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i32 @exit(i32 0)
unreachable
8: ; preds = %0
%9 = call i32 (...) @getpid()
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = call i32 @exit(i32 0)
unreachable
}