#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 atoi(char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int getpid();
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int i, n;
  n = atoi(argv[1]);
  fprintf(stdout, "Father PID=%d\n", getpid());
  for (i = 0; i < n; i++)
    if (fork() == 0) {
      fprintf(stdout, "Child %d: PID=%d\n", i + 1, getpid());
      break;
    }
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11fa <main+0xba>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11e7 <main+0xa7>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11fa <main+0xba>
jmp    11ec <main+0xac>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <main+0x53>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
mov    0x2e89(%rip),%rbp
mov    0x0(%rbp),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe98(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r14d,%r14d
jle    11bf <main+0x7f>
neg    %r14d
mov    $0x1,%ebx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     11a1 <main+0x61>
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1180 <main+0x40>
jmp    11bf <main+0x7f>
mov    0x0(%rbp),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe5d(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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