#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 */
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, int);
int main() {
  pid_t pid;
  int count = 0;
  while (1) {
    pid = fork();
    if (pid == 0)
      break;
    else if (pid < 0) {
      printf("\nMax number of child processes: %d\n", count);
      return 0;
    }
    count++;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1151 <main+0x31>
jmp    118a <main+0x6a>
cmpq   $0x0,-0x10(%rbp)
jge    1177 <main+0x57>
mov    -0x14(%rbp),%esi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    118a <main+0x6a>
jmp    117c <main+0x5c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <main+0x16>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <fork@plt>
test   %rax,%rax
je     1154 <main+0x34>
xor    %ebx,%ebx
nop
test   %rax,%rax
js     1146 <main+0x26>
add    $0x1,%ebx
xor    %eax,%eax
call   1040 <fork@plt>
test   %rax,%rax
jne    1130 <main+0x10>
jmp    1154 <main+0x34>
lea    0xeb3(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"\0AMax number of child processes: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %0, %16
%5 = call i64 (...) @fork()
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %4
br label %19
9: ; preds = %4
%10 = load i64, i64* %2
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %3
%14 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 0, i32* %1
br label %19
15: ; preds = %9
br label %16
16: ; preds = %15
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %4
19: ; preds = %12, %8
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [36 x i8] c"\0AMax number of child processes: %d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %13, label %3
3: ; preds = %0, %9
%4 = phi i64 [ %11, %9 ], [ %1, %0 ]
%5 = phi i32 [ %10, %9 ], [ 0, %0 ]
%6 = icmp slt i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %13
9: ; preds = %3
%10 = add nuw nsw i32 %5, 1
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %3
13: ; preds = %9, %0, %7
ret i32 0
}