#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();
scalar_t__ r_wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  pid_t childpid;
  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;
  while (r_wait(NULL) > 0)
    ;
  fprintf(stderr, "i:%d proc 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)
cmpl   $0x2,-0x8(%rbp)
je     11aa <main+0x4a>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1261 <main+0x101>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11fa <main+0x9a>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jg     11e7 <main+0x87>
jmp    11fa <main+0x9a>
jmp    11ec <main+0x8c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c1 <main+0x61>
jmp    11ff <main+0x9f>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <r_wait@plt>
cmp    $0x0,%rax
jle    1217 <main+0xb7>
jmp    11ff <main+0x9f>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    %rax,%r8
mov    -0x18(%rbp),%r9
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1050 <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    11aa <main+0x4a>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
cmp    $0x2,%eax
jl     11cb <main+0x6b>
mov    %eax,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%r14
test   %rax,%rax
jle    11d0 <main+0x70>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1190 <main+0x30>
mov    %ebp,%ebx
jmp    11d0 <main+0x70>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe43(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebp
jmp    1215 <main+0xb5>
mov    $0x1,%ebx
xor    %edi,%edi
call   1030 <r_wait@plt>
test   %rax,%rax
jg     11d0 <main+0x70>
mov    0x2dfd(%rip),%rax
mov    (%rax),%r15d
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1070 <getppid@plt>
lea    0xe15(%rip),%rsi
mov    %r15d,%edi
mov    %ebx,%edx
mov    %r12,%rcx
mov    %rax,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%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 = [46 x i8] c"i:%d proc 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
%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 %46
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 sle 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
br label %35
35: ; preds = %38, %34
%36 = call i64 @r_wait(i32* null)
%37 = icmp sgt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35
br label %35
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = load i32, i32* %7
%42 = call i64 (...) @getpid()
%43 = call i64 (...) @getppid()
%44 = load i64, i64* %6
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %41, i64 %42, i64 %43, i64 %44)
store i32 0, i32* %3
br label %46
46: ; preds = %39, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s processes\0A\00"
@.str.1 = [46 x i8] c"i:%d proc 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 %31
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 slt i64 %15, 1
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 [ undef, %8 ], [ %15, %13 ], [ %15, %17 ]
br label %23
23: ; preds = %23, %20
%24 = tail call i64 @r_wait(i32* null)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %23, label %26
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i64 (...) @getpid()
%29 = tail call i64 (...) @getppid()
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %21, i64 %28, i64 %29, i64 %22)
br label %31
31: ; preds = %26, %4
%32 = phi i32 [ 1, %4 ], [ 0, %26 ]
ret i32 %32
}