#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(int);
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, ...);
int vfork();
int main(int argc, char *argv[]) {
  int count = 1;
  int child;
  printf("before create son, parent count is %d!\n", count);
  if (!(child = vfork())) {
    int i;
    for (i = 0; i < 100; i++) {
      printf("This is son, the i is %d\n", i);
      if (70 == i) {
        exit(1);
      }
    }
    printf("I am child process, the count is %d, my process ID %d ,my parent "
           "process ID is %d\n",
           ++count, getpid(), getppid());
    exit(1);
  } else {
    printf("after son, I am parent process, the count is %d, my process ID %d "
           ",the child is %d\n",
           count, getpid(), child);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
call   1050 <vfork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    1219 <main+0xc9>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    11dc <main+0x8c>
mov    -0x1c(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x46,%eax
cmp    -0x1c(%rbp),%eax
jne    11c9 <main+0x79>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11ce <main+0x7e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1196 <main+0x46>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
mov    -0x18(%rbp),%ecx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
xor    %ebx,%ebx
mov    %ebx,%eax
mov    $0x1,%esi
call   1040 <printf@plt>
call   1050 <vfork@plt>
test   %eax,%eax
je     118f <main+0x4f>
mov    %eax,%ebp
xor    %r14d,%r14d
mov    %r14d,%eax
call   1030 <getpid@plt>
lea    0xecc(%rip),%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %ebp,%ecx
mov    %r14d,%eax
call   1040 <printf@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe92(%rip),%r14
mov    %ebx,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x1,%eax
mov    %eax,%ebp
cmp    $0x47,%eax
jne    11a0 <main+0x60>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"before create son, parent count is %d!\0A\00"
@.str.1 = [26 x i8] c"This is son, the i is %d\0A\00"
@.str.2 = [83 x i8] c"I am child process, the count is %d, my process ID %d ,my parent process ID is %d\0A\00"
@.str.3 = [84 x i8] c"after son, I am parent process, the count is %d, my process ID %d ,the child is %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%9 = load i32, i32* %6
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @vfork()
store i32 %11, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %35, label %13
13: ; preds = %2
store i32 0, i32* %8
br label %14
14: ; preds = %25, %13
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 100
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = load i32, i32* %8
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %8
%21 = icmp eq i32 70, %20
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %14
28: ; preds = %14
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
%31 = call i32 (...) @getpid()
%32 = call i32 (...) @getppid()
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %2
%36 = load i32, i32* %6
%37 = call i32 (...) @getpid()
%38 = load i32, i32* %7
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
br label %40
40: ; preds = %35
ret i32 0
}

LLVM IR (-O2):
@.str = [40 x i8] c"before create son, parent count is %d!\0A\00"
@.str.1 = [26 x i8] c"This is son, the i is %d\0A\00"
@.str.3 = [84 x i8] c"after son, I am parent process, the count is %d, my process ID %d ,the child is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 1)
%4 = call i32 @vfork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %2, %6
%7 = phi i32 [ %10, %6 ], [ 0, %2 ]
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %7, 70
%10 = add nuw nsw i32 %7, 1
br i1 %9, label %11, label %6
11: ; preds = %6
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 (...) @getpid()
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 %14, i32 %4)
ret i32 0
}