#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 *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ kill_it();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int i;
  int num_procs = atoi(argv[1]);
  if (num_procs < 1) {
    fprintf(stderr, "Give me a number from 1 to max int\n");
    exit(1);
  }
  for (i = 0; i < num_procs; i++) {
    pid_t pid;
    pid = fork();
    if (pid < 0) {
      fprintf(stderr, "Could not create process %d\n", i + 1);
    }
    if (pid == 0) {
      kill_it();
    }
  }
  for (i = 0; i < num_procs; i++) {
    wait(NULL);
  }
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    11b1 <main+0x51>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    121c <main+0xbc>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11f7 <main+0x97>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1209 <main+0xa9>
mov    $0x0,%al
call   1030 <kill_it@plt>
jmp    120e <main+0xae>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <main+0x58>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1246 <main+0xe6>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1223 <main+0xc3>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
test   %eax,%eax
jle    11f7 <main+0x97>
mov    %eax,%ebp
mov    %eax,%r15d
neg    %r15d
mov    $0x1,%ebx
mov    0x2e53(%rip),%r12
lea    0xe90(%rip),%r14
jmp    11c3 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     11da <main+0x7a>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11a0 <main+0x40>
jne    11b0 <main+0x50>
xor    %eax,%eax
call   1030 <kill_it@plt>
jmp    11b0 <main+0x50>
test   %ebp,%ebp
jle    11ec <main+0x8c>
xchg   %ax,%ax
xor    %edi,%edi
call   1070 <wait@plt>
add    $0xffffffff,%ebp
jne    11e0 <main+0x80>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Give me a number from 1 to max int\0A\00"
@.str.1 = [29 x i8] c"Could not create process %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 i64
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* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
store i32 0, i32* %6
br label %20
20: ; preds = %39, %19
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %42
24: ; preds = %20
%25 = call i64 (...) @fork()
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %28, %24
%34 = load i64, i64* %8
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 (...) @kill_it()
br label %38
38: ; preds = %36, %33
br label %39
39: ; preds = %38
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %20
42: ; preds = %20
store i32 0, i32* %6
br label %43
43: ; preds = %49, %42
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = call i32 @wait(i32* null)
br label %49
49: ; preds = %47
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %43
52: ; preds = %43
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Give me a number from 1 to max int\0A\00"
@.str.1 = [29 x i8] c"Could not create process %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 slt i32 %5, 1
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %25
%12 = icmp sgt i32 %5, 0
br i1 %12, label %28, label %33
13: ; preds = %2, %25
%14 = phi i32 [ %26, %25 ], [ 0, %2 ]
%15 = tail call i64 (...) @fork()
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = add nuw nsw i32 %14, 1
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %25
21: ; preds = %13
%22 = icmp eq i64 %15, 0
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = tail call i32 (...) @kill_it()
br label %25
25: ; preds = %17, %23, %21
%26 = add nuw nsw i32 %14, 1
%27 = icmp eq i32 %26, %5
br i1 %27, label %11, label %13
28: ; preds = %11, %28
%29 = phi i32 [ %31, %28 ], [ 0, %11 ]
%30 = tail call i32 @wait(i32* null)
%31 = add nuw nsw i32 %29, 1
%32 = icmp eq i32 %31, %5
br i1 %32, label %33, label %28
33: ; preds = %28, %11
ret i32 0
}