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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <vfork@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117b <main+0x4b>
mov    -0x8(%rbp),%esi
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jle    119c <main+0x6c>
mov    -0x8(%rbp),%esi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11a1 <main+0x71>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1040 <vfork@plt>
test   %rax,%rax
je     1143 <main+0x13>
jg     114c <main+0x1c>
xor    %eax,%eax
pop    %rcx
ret
lea    0xeb6(%rip),%rdi
jmp    1153 <main+0x23>
lea    0xebd(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@.str = [16 x i8] c"child count:%d\0A\00"
@.str.1 = [17 x i8] c"parent count:%d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @vfork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 1)
%5 = tail call i32 @exit(i32 0)
unreachable
6: ; preds = %0
%7 = icmp sgt i64 %1, 0
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 1)
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %6
ret i32 0
}