#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 *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  pid_t childpid = 0;
  int i, n;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s processes\n", argv[0]);
    return 1;
  }
  n = atoi(argv[1]);
  for (i = 1; i < n; i++)
    if ((childpid = fork()) == 0)
      break;
  fprintf(stderr, "i:%d  process ID:%ld  parent ID:%ld  child ID:%ld\n", i,
          (long)getpid(), (long)getppid(), (long)childpid);
  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)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a2 <main+0x52>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123c <main+0xec>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11f2 <main+0xa2>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11df <main+0x8f>
jmp    11f2 <main+0xa2>
jmp    11e4 <main+0x94>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b9 <main+0x69>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    %rax,%r8
mov    -0x18(%rbp),%r9
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jne    119a <main+0x4a>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
xor    %r15d,%r15d
cmp    $0x2,%eax
jl     11bc <main+0x6c>
mov    %eax,%ebx
mov    $0x1,%ebp
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11c4 <main+0x74>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1180 <main+0x30>
mov    %ebx,%ebp
mov    %rax,%r14
jmp    11c4 <main+0x74>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe53(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%r15d
jmp    11fb <main+0xab>
mov    $0x1,%ebp
xor    %r14d,%r14d
mov    0x2e15(%rip),%rax
mov    (%rax),%r12d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe2f(%rip),%rsi
mov    %r12d,%edi
mov    %ebp,%edx
mov    %rbx,%rcx
mov    %rax,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s processes\0A\00"
@.str.1 = [51 x i8] c"i:%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 i64
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
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 ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %41
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %8
store i32 1, i32* %7
br label %22
22: ; preds = %31, %17
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = call i64 (...) @fork()
store i64 %27, i64* %6
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %34
30: ; preds = %26
br label %31
31: ; preds = %30
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %22
34: ; preds = %29, %22
%35 = load i32, i32* @stderr
%36 = load i32, i32* %7
%37 = call i64 (...) @getpid()
%38 = call i64 (...) @getppid()
%39 = load i64, i64* %6
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %36, i64 %37, i64 %38, i64 %39)
store i32 0, i32* %3
br label %41
41: ; preds = %34, %11
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s processes\0A\00"
@.str.1 = [51 x i8] c"i:%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
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %27
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %20
13: ; preds = %8, %17
%14 = phi i32 [ %18, %17 ], [ 1, %8 ]
%15 = tail call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = add nuw nsw i32 %14, 1
%19 = icmp eq i32 %18, %11
br i1 %19, label %20, label %13
20: ; preds = %17, %13, %8
%21 = phi i32 [ 1, %8 ], [ %14, %13 ], [ %11, %17 ]
%22 = phi i64 [ 0, %8 ], [ 0, %13 ], [ %15, %17 ]
%23 = load i32, i32* @stderr
%24 = tail call i64 (...) @getpid()
%25 = tail call i64 (...) @getppid()
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %21, i64 %24, i64 %25, i64 %22)
br label %27
27: ; preds = %20, %4
%28 = phi i32 [ 1, %4 ], [ 0, %20 ]
ret i32 %28
}