#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 fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int getpid();
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int i, pid;
  pid = fork();
  fprintf(stdout, "Forking...the pid: %d\n", pid);
  for (i = 0; i < 5; i++)
    fprintf(stdout, "%d\t%d\n", i, getpid());
  if (pid)
    wait(NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11c8 <main+0x88>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <main+0x41>
cmpl   $0x0,-0x18(%rbp)
je     11db <main+0x9b>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%r14d
mov    0x2e88(%rip),%rbx
mov    (%rbx),%edi
lea    0xe9f(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe9d(%rip),%r15
mov    %ebp,%edi
mov    %r15,%rsi
xor    %edx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x3,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r14d,%r14d
je     1206 <main+0xc6>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [23 x i8] c"Forking...the pid: %d\0A\00"
@.str.1 = [7 x i8] c"%d\09%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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @fork()
store i32 %8, i32* %7
%9 = load i32, i32* @stdout
%10 = load i32, i32* %7
%11 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 0, i32* %6
br label %12
12: ; preds = %20, %2
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 5
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32, i32* @stdout
%17 = load i32, i32* %6
%18 = call i32 (...) @getpid()
%19 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
br label %20
20: ; preds = %15
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %12
23: ; preds = %12
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @wait(i32* null)
br label %28
28: ; preds = %26, %23
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [23 x i8] c"Forking...the pid: %d\0A\00"
@.str.1 = [7 x i8] c"%d\09%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = load i32, i32* @stdout
%5 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %3)
%6 = load i32, i32* @stdout
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %7)
%9 = load i32, i32* @stdout
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %10)
%12 = load i32, i32* @stdout
%13 = tail call i32 (...) @getpid()
%14 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %13)
%15 = load i32, i32* @stdout
%16 = tail call i32 (...) @getpid()
%17 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %16)
%18 = load i32, i32* @stdout
%19 = tail call i32 (...) @getpid()
%20 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 %19)
%21 = icmp eq i32 %3, 0
br i1 %21, label %24, label %22
22: ; preds = %2
%23 = tail call i32 @wait(i32* null)
br label %24
24: ; preds = %22, %2
ret i32 0
}