#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 fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int *, int);
int main(void) {
  int count = 1;
  int child;
  child = fork();
  if (child < 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());
  } else {
    printf("This is father, his count is: %d (%p), his pid is: %d\n", count,
           &count, getpid());
  }
  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    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    117b <main+0x3b>
lea    0xe8f(%rip),%rdi
call   1050 <perror@plt>
jmp    11d9 <main+0x99>
cmpl   $0x0,-0xc(%rbp)
jne    11b2 <main+0x72>
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    0xe6a(%rip),%rdi
lea    -0x8(%rbp),%rdx
call   1040 <printf@plt>
jmp    11d4 <main+0x94>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%ecx
lea    0xe7b(%rip),%rdi
lea    -0x8(%rbp),%rdx
call   1040 <printf@plt>
jmp    11d9 <main+0x99>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x1,0x4(%rsp)
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
js     11a2 <main+0x62>
je     1170 <main+0x30>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xee2(%rip),%rdi
lea    0x4(%rsp),%rdx
mov    $0x1,%esi
jmp    1190 <main+0x50>
movl   $0x2,0x4(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe88(%rip),%rdi
lea    0x4(%rsp),%rdx
mov    $0x2,%esi
mov    %eax,%ecx
call   1040 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
jmp    1197 <main+0x57>

LLVM IR (-O0):
@.str = [14 x i8] c"fork error : \00"
@.str.1 = [56 x i8] c"This is son, his count is: %d (%p). and his pid is: %d\0A\00"
@.str.2 = [55 x i8] c"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 = call i32 (...) @fork()
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %22
9: ; preds = %0
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
%15 = call i32 (...) @getpid()
%16 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32* %2, i32 %15)
br label %21
17: ; preds = %9
%18 = load i32, i32* %2
%19 = call i32 (...) @getpid()
%20 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32* %2, i32 %19)
br label %21
21: ; preds = %17, %12
br label %22
22: ; preds = %21, %7
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}

LLVM IR (-O2):
@.str = [14 x i8] c"fork error : \00"
@.str.1 = [56 x i8] c"This is son, his count is: %d (%p). and his pid is: %d\0A\00"
@.str.2 = [55 x i8] c"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*
store i32 1, i32* %1
%3 = tail call i32 (...) @fork()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %0
%8 = icmp eq i32 %3, 0
br i1 %8, label %9, label %12
9: ; preds = %7
store i32 2, i32* %1
%10 = tail call i32 (...) @getpid()
%11 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 2, i32* %1, i32 %10)
br label %15
12: ; preds = %7
%13 = tail call i32 (...) @getpid()
%14 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32 1, i32* %1, i32 %13)
br label %15
15: ; preds = %9, %12, %5
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}