#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int vfork();
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(void) {
  int local = 2;
  pid_t childPid;
  switch (vfork()) {
  case -1:
    perror("vfork");
    exit(1);
    break;
  case 0:
    sleep(3);
    write(STDOUT_FILENO, "CHILD: Child executing\n", 16);
    local *= 10;
    break;
  default:
    write(STDOUT_FILENO, "PARENT: Parent executing\n", 17);
    printf("local=%d\n", local);
    break;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
call   1060 <vfork@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
sub    $0xffffffff,%eax
je     119e <main+0x3e>
jmp    118e <main+0x2e>
mov    -0x10(%rbp),%eax
test   %eax,%eax
je     11b4 <main+0x54>
jmp    11e4 <main+0x84>
lea    0xe5b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x3,%edi
call   1080 <sleep@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    120d <main+0xad>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    $0x11,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%esi
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
call   1060 <vfork@plt>
test   %eax,%eax
je     1185 <main+0x25>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x50>
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x3,%edi
call   1080 <sleep@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x11,%edx
call   1030 <write@plt>
lea    0xe67(%rip),%rdi
mov    $0x2,%esi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"vfork\00"
@STDOUT_FILENO = global i32 0
@.str.1 = [24 x i8] c"CHILD: Child executing\0A\00"
@.str.2 = [26 x i8] c"PARENT: Parent executing\0A\00"
@.str.3 = [10 x i8] c"local=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %2
%4 = call i32 @vfork()
switch i32 %4, label %14 [
i32 -1, label %5
i32 0, label %8
]
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = call i32 @sleep(i32 3)
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @write(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 16)
%12 = load i32, i32* %2
%13 = mul nsw i32 %12, 10
store i32 %13, i32* %2
br label %19
14: ; preds = %0
%15 = load i32, i32* @STDOUT_FILENO
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 17)
%17 = load i32, i32* %2
%18 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %14, %8
%20 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"vfork\00"
@STDOUT_FILENO = global i32 0
@.str.1 = [24 x i8] c"CHILD: Child executing\0A\00"
@.str.2 = [26 x i8] c"PARENT: Parent executing\0A\00"
@.str.3 = [10 x i8] c"local=%d\0A\00"
define i32 @main() {
%1 = call i32 @vfork()
switch i32 %1, label %9 [
i32 -1, label %2
i32 0, label %5
]
2: ; preds = %0
%3 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @exit(i32 1)
unreachable
5: ; preds = %0
%6 = call i32 @sleep(i32 3)
%7 = load i32, i32* @STDOUT_FILENO
%8 = call i32 @write(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 16)
br label %13
9: ; preds = %0
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @write(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 17)
%12 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 2)
br label %13
13: ; preds = %9, %5
%14 = call i32 @exit(i32 0)
unreachable
}