#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, int, int);
int main() {
  pid_t pid;
  pid = fork();
  int i = 1;
  printf("xx当前进程的ID为：%d   fork返回值为：%d, ++i 的值为：%d\n", getpid(),
         pid, ++i);
  pid = fork();
  printf("yy当前进程的ID为：%d   fork返回值为：%d,  ++i 的值为：%d\n", getpid(),
         pid, ++i);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xea8(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    $0x2,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xecc(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    $0x3,%ecx
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [73 x i8] c"xx\E5\BD\93\E5\89\8D\E8\BF\9B\E7\A8\8B\E7\9A\84ID\E4\B8\BA\EF\BC\9A%d fork\E8\BF\94\E5\9B\9E\E5\80\BC\E4\B8\BA\EF\BC\9A%d, ++i \E7\9A\84\E5\80\BC\E4\B8\BA\EF\BC\9A%d\0A\00"
@.str.1 = [74 x i8] c"yy\E5\BD\93\E5\89\8D\E8\BF\9B\E7\A8\8B\E7\9A\84ID\E4\B8\BA\EF\BC\9A%d fork\E8\BF\94\E5\9B\9E\E5\80\BC\E4\B8\BA\EF\BC\9A%d, ++i \E7\9A\84\E5\80\BC\E4\B8\BA\EF\BC\9A%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @fork()
store i32 %4, i32* %2
store i32 1, i32* %3
%5 = call i32 (...) @getpid()
%6 = load i32, i32* %2
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 1
store i32 %8, i32* %3
%9 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %8)
%10 = call i32 (...) @fork()
store i32 %10, i32* %2
%11 = call i32 (...) @getpid()
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12, i32 %14)
%16 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [73 x i8] c"xx\E5\BD\93\E5\89\8D\E8\BF\9B\E7\A8\8B\E7\9A\84ID\E4\B8\BA\EF\BC\9A%d fork\E8\BF\94\E5\9B\9E\E5\80\BC\E4\B8\BA\EF\BC\9A%d, ++i \E7\9A\84\E5\80\BC\E4\B8\BA\EF\BC\9A%d\0A\00"
@.str.1 = [74 x i8] c"yy\E5\BD\93\E5\89\8D\E8\BF\9B\E7\A8\8B\E7\9A\84ID\E4\B8\BA\EF\BC\9A%d fork\E8\BF\94\E5\9B\9E\E5\80\BC\E4\B8\BA\EF\BC\9A%d, ++i \E7\9A\84\E5\80\BC\E4\B8\BA\EF\BC\9A%d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %1, i32 2)
%4 = tail call i32 (...) @fork()
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %4, i32 3)
%7 = tail call i32 @exit(i32 0)
unreachable
}