#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_SUCCESS;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ pexit(char *);
int vfork();
int wait(int *);
void doBench(int forkSyscall) {
  int i, status;
  for (i = 0; i < (10000); ++i) {
    switch (forkSyscall ? fork() : vfork()) {
    case -1:
      pexit((forkSyscall ? "fork" : "vfork"));
      break;
    case 0:
      _exit(EXIT_SUCCESS);
      break;
    default:
      if (wait(&status) == -1) {
        pexit("wait");
      }
    }
  }
}


x86 assembly (clang, -O0):
<doBench>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jge    121a <doBench+0xca>
cmpl   $0x0,-0x4(%rbp)
je     1188 <doBench+0x38>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x10(%rbp)
jmp    1190 <doBench+0x40>
call   1040 <vfork@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0xffffffff,%eax
je     11b4 <doBench+0x64>
jmp    11a4 <doBench+0x54>
mov    -0x14(%rbp),%eax
test   %eax,%eax
je     11d6 <doBench+0x86>
jmp    11e4 <doBench+0x94>
mov    -0x4(%rbp),%ecx
lea    0xe42(%rip),%rdi
lea    0xe3c(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
call   1050 <pexit@plt>
jmp    1207 <doBench+0xb7>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
lea    -0xc(%rbp),%rdi
call   1060 <wait@plt>
cmp    $0xffffffff,%eax
jne    1202 <doBench+0xb2>
lea    0xe09(%rip),%rdi
call   1050 <pexit@plt>
jmp    1207 <doBench+0xb7>
jmp    120c <doBench+0xbc>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1162 <doBench+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doBench>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
test   %edi,%edi
lea    0xe99(%rip),%rax
lea    0xe93(%rip),%rbx
cmove  %rax,%rbx
mov    $0x2710,%ebp
lea    0x4(%rsp),%r14
lea    0xe83(%rip),%r15
xor    %r12d,%r12d
jmp    119a <doBench+0x4a>
nopl   0x0(%rax,%rax,1)
call   1050 <pexit@plt>
add    $0xffffffff,%ebp
je     11d3 <doBench+0x83>
test   %r13d,%r13d
je     11b0 <doBench+0x60>
mov    %r12d,%eax
call   1070 <fork@plt>
jmp    11b5 <doBench+0x65>
nopl   0x0(%rax)
call   1040 <vfork@plt>
mov    %rbx,%rdi
cmp    $0xffffffff,%eax
je     1190 <doBench+0x40>
test   %eax,%eax
je     11e2 <doBench+0x92>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %r15,%rdi
cmp    $0xffffffff,%eax
jne    1195 <doBench+0x45>
jmp    1190 <doBench+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [6 x i8] c"vfork\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [5 x i8] c"wait\00"
define void @doBench(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %5
5: ; preds = %33, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 10000
br i1 %7, label %8, label %36
8: ; preds = %5
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 (...) @fork()
br label %15
13: ; preds = %8
%14 = call i32 @vfork()
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %12, %11 ], [ %14, %13 ]
switch i32 %16, label %26 [
i32 -1, label %17
i32 0, label %23
]
17: ; preds = %15
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%22 = call i32 @pexit(i8* %21)
br label %32
23: ; preds = %15
%24 = load i32, i32* @EXIT_SUCCESS
%25 = call i32 @_exit(i32 %24)
unreachable
26: ; preds = %15
%27 = call i32 @wait(i32* %4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
br label %32
32: ; preds = %31, %17
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %5
36: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [6 x i8] c"vfork\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [5 x i8] c"wait\00"
define void @doBench(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i32 %0, 0
%5 = select i1 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0)
br label %6
6: ; preds = %1, %23
%7 = phi i32 [ 0, %1 ], [ %24, %23 ]
br i1 %4, label %10, label %8
8: ; preds = %6
%9 = call i32 (...) @fork()
br label %12
10: ; preds = %6
%11 = call i32 @vfork()
br label %12
12: ; preds = %10, %8
%13 = phi i32 [ %9, %8 ], [ %11, %10 ]
switch i32 %13, label %17 [
i32 -1, label %20
i32 0, label %14
]
14: ; preds = %12
%15 = load i32, i32* @EXIT_SUCCESS
%16 = call i32 @_exit(i32 %15)
unreachable
17: ; preds = %12
%18 = call i32 @wait(i32* %2)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %17, %12
%21 = phi i8* [ %5, %12 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %17 ]
%22 = call i32 @pexit(i8* %21)
br label %23
23: ; preds = %20, %17
%24 = add nuw nsw i32 %7, 1
%25 = icmp eq i32 %24, 10000
br i1 %25, label %26, label %6
26: ; preds = %23
ret void
}