#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ child(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int *);
int main() {
  const int NUM_CHILDREN = 100;
  pid_t pid;
  int childId;
  int status[NUM_CHILDREN];
  for (childId = 0; childId < NUM_CHILDREN; childId++) {
    pid = fork();
    switch (pid) {
    case -1:
      perror("fork");
      exit(EXIT_FAILURE);
    case 0:
      child(childId);
      exit(EXIT_SUCCESS);
    default:
      break;
    }
  }
  for (childId = 0; childId < NUM_CHILDREN; childId++) {
    wait(&status[childId]);
  }
  printf("detske procesy ukoncene\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x64,-0x10(%rbp)
jge    120d <main+0xad>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1b4(%rbp)
sub    $0xffffffff,%eax
je     11c5 <main+0x65>
jmp    11b2 <main+0x52>
mov    -0x1b4(%rbp),%eax
test   %eax,%eax
je     11df <main+0x7f>
jmp    11f5 <main+0x95>
lea    0xe34(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%edi
call   1030 <child@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    11fa <main+0x9a>
jmp    11ff <main+0x9f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1187 <main+0x27>
movl   $0x0,-0x10(%rbp)
cmpl   $0x64,-0x10(%rbp)
jge    1243 <main+0xe3>
movslq -0x10(%rbp),%rax
lea    -0x1b0(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
call   1070 <wait@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1214 <main+0xb4>
lea    0xdbb(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x190,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11b4 <main+0x54>
cmp    $0xffffffff,%eax
je     11c9 <main+0x69>
add    $0x1,%ebx
cmp    $0x64,%ebx
jne    1170 <main+0x10>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    (%rsp,%rbx,1),%rdi
call   1070 <wait@plt>
add    $0x4,%rbx
cmp    $0x190,%rbx
jne    1190 <main+0x30>
lea    0xe58(%rip),%rdi
call   1040 <puts@plt>
jmp    11bb <main+0x5b>
mov    %ebx,%edi
call   1030 <child@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe30(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [25 x i8] c"detske procesy ukoncene\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
store i32 100, i32* %2
%6 = call i8* @llvm.stacksave()
store i8* %6, i8** %5
%7 = alloca i32, i64 100
store i32 0, i32* %4
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 100
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = call i32 (...) @fork()
store i32 %12, i32* %3
%13 = load i32, i32* %3
switch i32 %13, label %23 [
i32 -1, label %14
i32 0, label %18
]
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %11
%19 = load i32, i32* %4
%20 = call i32 @child(i32 %19)
%21 = load i32, i32* @EXIT_SUCCESS
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %11
br label %24
24: ; preds = %23
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %8
28: ; preds = %8
store i32 0, i32* %4
br label %29
29: ; preds = %37, %28
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 100
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %7, i64 %34
%36 = call i32 @wait(i32* %35)
br label %37
37: ; preds = %32
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %29
40: ; preds = %29
%41 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%42 = load i32, i32* @EXIT_SUCCESS
%43 = call i32 @exit(i32 %42)
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [24 x i8] c"detske procesy ukoncene\00"
define i32 @main() {
%1 = alloca [100 x i32]
br label %2
2: ; preds = %0, %13
%3 = phi i32 [ 0, %0 ], [ %14, %13 ]
%4 = tail call i32 (...) @fork()
switch i32 %4, label %13 [
i32 -1, label %5
i32 0, label %9
]
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = tail call i32 @child(i32 %3)
%11 = load i32, i32* @EXIT_SUCCESS
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = add nuw nsw i32 %3, 1
%15 = icmp eq i32 %14, 100
br i1 %15, label %16, label %2
16: ; preds = %13, %16
%17 = phi i64 [ %20, %16 ], [ 0, %13 ]
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %17
%19 = call i32 @wait(i32* %18)
%20 = add nuw nsw i64 %17, 1
%21 = icmp eq i64 %20, 100
br i1 %21, label %22, label %16
22: ; preds = %16
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_SUCCESS
%25 = call i32 @exit(i32 %24)
unreachable
}