#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 */
size_t atoi(char const *);
int /*<<< orphan*/ c_sleep();
scalar_t__ fork();
int wait(int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  for (size_t i = 0; i < atoi(argv[1]); i++) {
    pid_t pid = fork();
    if (pid == 0) {
      c_sleep();
      break;
    }
  }
  while (wait(0) > -1)
    ;
  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)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    11bb <main+0x7b>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a5 <main+0x65>
mov    $0x0,%al
call   1030 <c_sleep@plt>
jmp    11bb <main+0x7b>
jmp    11aa <main+0x6a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115e <main+0x1e>
jmp    11c0 <main+0x80>
xor    %edi,%edi
call   1050 <wait@plt>
cmp    $0xffffffff,%eax
jle    11d5 <main+0x95>
jmp    11c0 <main+0x80>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
test   %rax,%rax
je     1190 <main+0x50>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1180 <main+0x40>
add    $0x1,%rbx
mov    0x8(%r14),%rdi
call   1040 <atoi@plt>
cmp    %rax,%rbx
jb     1160 <main+0x20>
jmp    1190 <main+0x50>
xor    %eax,%eax
call   1030 <c_sleep@plt>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1050 <wait@plt>
test   %eax,%eax
jns    1190 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
br label %8
8: ; preds = %22, %2
%9 = load i64, i64* %6
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @atoi(i8* %12)
%14 = icmp ult i64 %9, %13
br i1 %14, label %15, label %25
15: ; preds = %8
%16 = call i64 (...) @fork()
store i64 %16, i64* %7
%17 = load i64, i64* %7
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (...) @c_sleep()
br label %25
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = load i64, i64* %6
%24 = add i64 %23, 1
store i64 %24, i64* %6
br label %8
25: ; preds = %19, %8
br label %26
26: ; preds = %29, %25
%27 = call i32 @wait(i32 0)
%28 = icmp sgt i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %26
br label %26
30: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i64 @atoi(i8* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %18, label %11
7: ; preds = %11
%8 = load i8*, i8** %3
%9 = tail call i64 @atoi(i8* %8)
%10 = icmp ult i64 %15, %9
br i1 %10, label %11, label %18
11: ; preds = %2, %7
%12 = phi i64 [ %15, %7 ], [ 0, %2 ]
%13 = tail call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
%15 = add nuw i64 %12, 1
br i1 %14, label %16, label %7
16: ; preds = %11
%17 = tail call i32 (...) @c_sleep()
br label %18
18: ; preds = %7, %2, %16
br label %19
19: ; preds = %18, %19
%20 = tail call i32 @wait(i32 0)
%21 = icmp sgt i32 %20, -1
br i1 %21, label %19, label %22
22: ; preds = %19
ret i32 0
}