#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 *);
int fork();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int start = atoi(argv[1]);
  int i;
  for (i = 0; i < start; i++) {
    int child = fork();
    if (child == -1)
      return -1;
    else if (child > 0) {
      break;
    }
  }
  wait(NULL);
  printf("%d\n", i);
}


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    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c0 <main+0x80>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1199 <main+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <main+0x98>
cmpl   $0x0,-0x1c(%rbp)
jle    11a8 <main+0x68>
jmp    11c0 <main+0x80>
jmp    11ad <main+0x6d>
jmp    11b2 <main+0x72>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <main+0x2d>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
mov    -0x18(%rbp),%esi
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
test   %eax,%eax
jle    11a2 <main+0x62>
mov    %eax,%r14d
mov    $0x1,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <fork@plt>
xor    %ecx,%ecx
test   %eax,%eax
setg   %cl
add    %ecx,%ecx
cmp    $0xffffffff,%eax
cmove  %eax,%ebx
cmove  %r15d,%ecx
test   %ecx,%ecx
jne    119b <main+0x5b>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1170 <main+0x30>
mov    %r14d,%ebp
jmp    11a6 <main+0x66>
cmp    $0x2,%ecx
je     11a6 <main+0x66>
jmp    11bb <main+0x7b>
xor    %ebp,%ebp
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <wait@plt>
lea    0xe4c(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%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
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %6
store i32 0, i32* %7
br label %13
13: ; preds = %28, %2
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %31
17: ; preds = %13
%18 = call i32 (...) @fork()
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %3
br label %35
22: ; preds = %17
%23 = load i32, i32* %8
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
br label %31
26: ; preds = %22
br label %27
27: ; preds = %26
br label %28
28: ; preds = %27
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %13
31: ; preds = %25, %13
%32 = call i32 @wait(i32* null)
%33 = load i32, i32* %7
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %31, %21
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [4 x i8] c"%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 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %2, %16
%8 = phi i32 [ %14, %16 ], [ 0, %2 ]
%9 = phi i32 [ %17, %16 ], [ 0, %2 ]
%10 = tail call i32 (...) @fork()
%11 = icmp eq i32 %10, -1
%12 = icmp sgt i32 %10, 0
%13 = select i1 %12, i32 2, i32 0
%14 = select i1 %11, i32 -1, i32 %8
%15 = select i1 %11, i32 1, i32 %13
switch i32 %15, label %24 [
i32 0, label %16
i32 2, label %19
]
16: ; preds = %7
%17 = add nuw nsw i32 %9, 1
%18 = icmp eq i32 %17, %5
br i1 %18, label %19, label %7
19: ; preds = %16, %7, %2
%20 = phi i32 [ 0, %2 ], [ %9, %7 ], [ %5, %16 ]
%21 = phi i32 [ 0, %2 ], [ %14, %7 ], [ %14, %16 ]
%22 = tail call i32 @wait(i32* null)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %24
24: ; preds = %7, %19
%25 = phi i32 [ %21, %19 ], [ %14, %7 ]
ret i32 %25
}