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

/* Variables and functions */
int atoi(char *);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ run();
int /*<<< orphan*/ sleep(int);
int usage();
int main(int argc, char **argv) {
  int nb;
  pid_t pid;
  if (argc != 2)
    return usage();
  for (nb = atoi(argv[1]); nb; nb--) {
    pid = fork();
    if (pid == -1)
      perror("cannot fork");
    else if (pid == 0)
      run();
  }
  while (42)
    sleep(30);
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
je     118d <main+0x2d>
mov    $0x0,%al
call   1040 <usage@plt>
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f5 <main+0x95>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11cc <main+0x6c>
lea    0xe3e(%rip),%rdi
call   1050 <perror@plt>
jmp    11e2 <main+0x82>
cmpl   $0x0,-0x18(%rbp)
jne    11dd <main+0x7d>
mov    $0x0,%al
call   1030 <run@plt>
jmp    11e2 <main+0x82>
jmp    11e7 <main+0x87>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    119d <main+0x3d>
jmp    11fa <main+0x9a>
mov    $0x1e,%edi
call   1070 <sleep@plt>
jmp    11fa <main+0x9a>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11cc <main+0x6c>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
je     11c0 <main+0x60>
mov    %eax,%ebx
lea    0xe81(%rip),%r14
jmp    119c <main+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <run@plt>
add    $0xffffffff,%ebx
je     11c0 <main+0x60>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1190 <main+0x30>
cmp    $0xffffffff,%eax
jne    1197 <main+0x37>
mov    %r14,%rdi
call   1050 <perror@plt>
jmp    1197 <main+0x37>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1e,%edi
call   1070 <sleep@plt>
jmp    11c0 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <usage@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"cannot fork\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @usage()
ret i32 %11
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
br label %17
17: ; preds = %33, %12
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = call i32 (...) @fork()
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %32
26: ; preds = %20
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (...) @run()
br label %31
31: ; preds = %29, %26
br label %32
32: ; preds = %31, %24
br label %33
33: ; preds = %32
%34 = load i32, i32* %6
%35 = add nsw i32 %34, -1
store i32 %35, i32* %6
br label %17
36: ; preds = %17
br label %37
37: ; preds = %36, %37
%38 = call i32 @sleep(i32 30)
br label %37
}

LLVM IR (-O2):
@.str = [12 x i8] c"cannot fork\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
ret i32 %5
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %6, %18
%12 = phi i32 [ %19, %18 ], [ %9, %6 ]
%13 = tail call i32 (...) @fork()
switch i32 %13, label %18 [
i32 -1, label %14
i32 0, label %16
]
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %18
16: ; preds = %11
%17 = tail call i32 (...) @run()
br label %18
18: ; preds = %11, %14, %16
%19 = add nsw i32 %12, -1
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %11
21: ; preds = %18, %6
br label %22
22: ; preds = %21, %22
%23 = tail call i32 @sleep(i32 30)
br label %22
}