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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i;
  pid_t childpid;
  int n;
  if (argc != 2) {
    fprintf(stderr, "Usage : %s <no_processes>\n", argv[0]);
    exit(1);
  }
  fprintf(stderr, "Start: my PID = %ld\n", getpid());
  n = atoi(argv[1]);
  childpid = 0;
  for (i = 1; i < n; ++i)
    if ((childpid = fork()) <= 0)
      break;
  fprintf(stderr, "\ni:%d  process ID:%ld   parent ID:%ld   child ID:%ld\n", i,
          (long)getpid(), (long)getppid(), (long)childpid);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x48>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1227 <main+0xc7>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jg     1214 <main+0xb4>
jmp    1227 <main+0xc7>
jmp    1219 <main+0xb9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ee <main+0x8e>
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    %rax,%r8
mov    -0x20(%rbp),%r9
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e6f(%rip),%r15
mov    (%r15),%ebp
cmp    $0x2,%edi
jne    11cc <main+0x6c>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe92(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x8(%r14),%rdi
call   1050 <atoi@plt>
cmp    $0x2,%eax
jl     11e9 <main+0x89>
mov    %eax,%r14d
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
jle    11ee <main+0x8e>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    11b0 <main+0x50>
mov    %r14d,%ebp
jmp    11ee <main+0x8e>
mov    (%r14),%rdx
lea    0xe2a(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x1,%ebp
mov    (%r15),%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe27(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %r15,%rcx
mov    %rax,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Usage : %s <no_processes>\0A\00"
@.str.1 = [21 x i8] c"Start: my PID = %ld\0A\00"
@.str.2 = [54 x i8] c"\0Ai:%d process ID:%ld parent ID:%ld child ID:%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i64 (...) @getpid()
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %8
store i64 0, i64* %7
store i32 1, i32* %6
br label %26
26: ; preds = %35, %18
%27 = load i32, i32* %6
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = call i64 (...) @fork()
store i64 %31, i64* %7
%32 = icmp sle i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
br label %38
34: ; preds = %30
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %26
38: ; preds = %33, %26
%39 = load i32, i32* @stderr
%40 = load i32, i32* %6
%41 = call i64 (...) @getpid()
%42 = call i64 (...) @getppid()
%43 = load i64, i64* %7
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %40, i64 %41, i64 %42, i64 %43)
%45 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Usage : %s <no_processes>\0A\00"
@.str.1 = [21 x i8] c"Start: my PID = %ld\0A\00"
@.str.2 = [54 x i8] c"\0Ai:%d process ID:%ld parent ID:%ld child ID:%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
%4 = load i32, i32* @stderr
br i1 %3, label %9, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i64 (...) @getpid()
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %23
16: ; preds = %9, %20
%17 = phi i32 [ %21, %20 ], [ 1, %9 ]
%18 = tail call i64 (...) @fork()
%19 = icmp slt i64 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = add nuw nsw i32 %17, 1
%22 = icmp eq i32 %21, %14
br i1 %22, label %23, label %16
23: ; preds = %20, %16, %9
%24 = phi i32 [ 1, %9 ], [ %17, %16 ], [ %14, %20 ]
%25 = phi i64 [ 0, %9 ], [ %18, %16 ], [ %18, %20 ]
%26 = load i32, i32* @stderr
%27 = tail call i64 (...) @getpid()
%28 = tail call i64 (...) @getppid()
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %24, i64 %27, i64 %28, i64 %25)
%30 = tail call i32 @exit(i32 0)
unreachable
}