#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 EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int vfork();
int main(void) {
  int count = 1;
  int child;
  printf("Before create son, the father's count is:%d\n", count);
  if ((child = vfork()) < 0) {
    perror("fork error : ");
  } else if (child == 0) {
    printf("This is son, his count is: %d (%p). and his pid is: %d\n", ++count,
           &count, getpid());
    exit(0);
  } else {
    printf("After son, This is father, his count is: %d (%p), his pid is: %d\n",
           ++count, &count, getpid());
    exit(0);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
call   1060 <vfork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1199 <main+0x49>
lea    0xe9e(%rip),%rdi
call   1050 <perror@plt>
jmp    1205 <main+0xb5>
cmpl   $0x0,-0xc(%rbp)
jne    11d4 <main+0x84>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%ecx
lea    0xe79(%rip),%rdi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%ecx
lea    0xe80(%rip),%rdi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
xor    %eax,%eax
mov    $0x1,%esi
call   1040 <printf@plt>
call   1060 <vfork@plt>
test   %eax,%eax
jns    118c <main+0x3c>
lea    0xeb5(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    %eax,%ebx
movl   $0x2,0xc(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ecx
test   %ebx,%ebx
jne    11ac <main+0x5c>
lea    0xe91(%rip),%rdi
jmp    11b3 <main+0x63>
lea    0xec0(%rip),%rdi
xor    %ebx,%ebx
mov    %ebx,%eax
mov    $0x2,%esi
lea    0xc(%rsp),%rdx
call   1040 <printf@plt>
mov    %ebx,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"Before create son, the father's count is:%d\0A\00"
@.str.1 = [14 x i8] c"fork error : \00"
@.str.2 = [56 x i8] c"This is son, his count is: %d (%p). and his pid is: %d\0A\00"
@.str.3 = [66 x i8] c"After son, This is father, his count is: %d (%p), his pid is: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
%4 = load i32, i32* %2
%5 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @vfork()
store i32 %6, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %25
10: ; preds = %0
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
%16 = call i32 (...) @getpid()
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32* %2, i32 %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %10
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
%22 = call i32 (...) @getpid()
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32* %2, i32 %22)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %8
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}

LLVM IR (-O2):
@.str = [45 x i8] c"Before create son, the father's count is:%d\0A\00"
@.str.1 = [14 x i8] c"fork error : \00"
@.str.2 = [56 x i8] c"This is son, his count is: %d (%p). and his pid is: %d\0A\00"
@.str.3 = [66 x i8] c"After son, This is father, his count is: %d (%p), his pid is: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 1)
%4 = call i32 @vfork()
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_SUCCESS
ret i32 %8
9: ; preds = %0
%10 = icmp eq i32 %4, 0
store i32 2, i32* %1
%11 = call i32 (...) @getpid()
br i1 %10, label %12, label %15
12: ; preds = %9
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 2, i32* %1, i32 %11)
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %9
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i32 2, i32* %1, i32 %11)
%17 = call i32 @exit(i32 0)
unreachable
}