#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 */

/* Variables and functions */
int /*<<< orphan*/ child();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sched_exit(int /*<<< orphan*/);
int sched_fork();
int sched_getpid();
int /*<<< orphan*/ sched_wait(int *);
void init() {
  printf("Hello\n");
  int pid;
  for (int i = 0; i < 5; i++) {
    switch (pid = sched_fork()) {
    case -1:
      printf("sched_fork() error\n");
      sched_exit(0);
    case 0:
      child();
    default:
      printf("Created pid %d\n", pid);
      break;
    }
  }
  printf("In parent with pid %d\n", sched_getpid());
  int code;
  int order[5];
  for (int i = 0; i < 5; i++) {
    sched_wait(&code);
    order[i] = code;
    printf("Child returned with code %d\n", code);
  }
  printf("Children returned in order:");
  for (int i = 0; i < 5; i++)
    printf(" %d", order[i]);
  printf("\n");
  sched_exit(0);
  printf("Ending init process...\n");
  exit(0);
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    1204 <init+0x94>
xor    %eax,%eax
call   1090 <sched_fork@plt>
mov    %eax,-0x4(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0xffffffff,%eax
je     11c4 <init+0x54>
jmp    11b4 <init+0x44>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     11d9 <init+0x69>
jmp    11e0 <init+0x70>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <sched_exit@plt>
mov    $0x0,%al
call   1030 <child@plt>
mov    -0x4(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f6 <init+0x86>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118d <init+0x1d>
mov    $0x0,%al
call   1070 <sched_getpid@plt>
mov    %eax,%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    125f <init+0xef>
lea    -0xc(%rbp),%rdi
call   1050 <sched_wait@plt>
mov    -0xc(%rbp),%ecx
movslq -0x24(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0xc(%rbp),%esi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1222 <init+0xb2>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x5,-0x28(%rbp)
jge    12a2 <init+0x132>
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1274 <init+0x104>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <sched_exit@plt>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xebf(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   10b0 <sched_fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     11cf <init+0x3f>
cmp    $0xffffffff,%ebx
jne    11d6 <init+0x46>
lea    0xebe(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1080 <sched_exit@plt>
xor    %eax,%eax
call   1030 <child@plt>
lea    0xe23(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10b0 <sched_fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     120b <init+0x7b>
cmp    $0xffffffff,%ebx
jne    1212 <init+0x82>
lea    0xe82(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1080 <sched_exit@plt>
xor    %eax,%eax
call   1030 <child@plt>
lea    0xde7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10b0 <sched_fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1247 <init+0xb7>
cmp    $0xffffffff,%ebx
jne    124e <init+0xbe>
lea    0xe46(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1080 <sched_exit@plt>
xor    %eax,%eax
call   1030 <child@plt>
lea    0xdab(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10b0 <sched_fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1283 <init+0xf3>
cmp    $0xffffffff,%ebx
jne    128a <init+0xfa>
lea    0xe0a(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1080 <sched_exit@plt>
xor    %eax,%eax
call   1030 <child@plt>
lea    0xd6f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10b0 <sched_fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     12bf <init+0x12f>
cmp    $0xffffffff,%ebx
jne    12c6 <init+0x136>
lea    0xdce(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1080 <sched_exit@plt>
xor    %eax,%eax
call   1030 <child@plt>
lea    0xd33(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <sched_getpid@plt>
lea    0xd2c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc(%rsp),%r13
mov    %r13,%rdi
call   1070 <sched_wait@plt>
mov    0xc(%rsp),%esi
mov    %esi,0x14(%rsp)
lea    0xd1e(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1070 <sched_wait@plt>
mov    0xc(%rsp),%esi
mov    %esi,0x10(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1070 <sched_wait@plt>
mov    0xc(%rsp),%r12d
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1070 <sched_wait@plt>
mov    0xc(%rsp),%r15d
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1070 <sched_wait@plt>
mov    0xc(%rsp),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xcc4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xcd2(%rip),%rbp
mov    %rbp,%rdi
mov    0x14(%rsp),%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    0x10(%rsp),%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %edi,%edi
call   1080 <sched_exit@plt>
lea    0xc82(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"Hello\0A\00"
@.str.1 = [20 x i8] c"sched_fork() error\0A\00"
@.str.2 = [16 x i8] c"Created pid %d\0A\00"
@.str.3 = [23 x i8] c"In parent with pid %d\0A\00"
@.str.4 = [29 x i8] c"Child returned with code %d\0A\00"
@.str.5 = [28 x i8] c"Children returned in order:\00"
@.str.6 = [4 x i8] c" %d\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [24 x i8] c"Ending init process...\0A\00"
define void @init() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [5 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %8
8: ; preds = %22, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 5
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = call i32 (...) @sched_fork()
store i32 %12, i32* %1
switch i32 %12, label %18 [
i32 -1, label %13
i32 0, label %16
]
13: ; preds = %11
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @sched_exit(i32 0)
br label %16
16: ; preds = %11, %13
%17 = call i32 (...) @child()
br label %18
18: ; preds = %11, %16
%19 = load i32, i32* %1
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18
br label %22
22: ; preds = %21
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %8
25: ; preds = %8
%26 = call i32 (...) @sched_getpid()
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %26)
store i32 0, i32* %5
br label %28
28: ; preds = %39, %25
%29 = load i32, i32* %5
%30 = icmp slt i32 %29, 5
br i1 %30, label %31, label %42
31: ; preds = %28
%32 = call i32 @sched_wait(i32* %3)
%33 = load i32, i32* %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 %35
store i32 %33, i32* %36
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %31
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %28
42: ; preds = %28
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %6
br label %44
44: ; preds = %53, %42
%45 = load i32, i32* %6
%46 = icmp slt i32 %45, 5
br i1 %46, label %47, label %56
47: ; preds = %44
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %47
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
br label %44
56: ; preds = %44
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%58 = call i32 @sched_exit(i32 0)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%60 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.2 = [16 x i8] c"Created pid %d\0A\00"
@.str.3 = [23 x i8] c"In parent with pid %d\0A\00"
@.str.4 = [29 x i8] c"Child returned with code %d\0A\00"
@.str.5 = [28 x i8] c"Children returned in order:\00"
@.str.6 = [4 x i8] c" %d\00"
@str = [6 x i8] c"Hello\00"
@str.9 = [23 x i8] c"Ending init process...\00"
@str.10 = [19 x i8] c"sched_fork() error\00"
define void @init() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (...) @sched_fork()
switch i32 %3, label %9 [
i32 -1, label %4
i32 0, label %7
]
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0))
%6 = tail call i32 @sched_exit(i32 0)
br label %7
7: ; preds = %0, %4
%8 = tail call i32 (...) @child()
br label %9
9: ; preds = %0, %7
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%11 = tail call i32 (...) @sched_fork()
switch i32 %11, label %17 [
i32 -1, label %12
i32 0, label %15
]
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0))
%14 = tail call i32 @sched_exit(i32 0)
br label %15
15: ; preds = %12, %9
%16 = tail call i32 (...) @child()
br label %17
17: ; preds = %15, %9
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%19 = tail call i32 (...) @sched_fork()
switch i32 %19, label %25 [
i32 -1, label %20
i32 0, label %23
]
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0))
%22 = tail call i32 @sched_exit(i32 0)
br label %23
23: ; preds = %20, %17
%24 = tail call i32 (...) @child()
br label %25
25: ; preds = %23, %17
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%27 = tail call i32 (...) @sched_fork()
switch i32 %27, label %33 [
i32 -1, label %28
i32 0, label %31
]
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0))
%30 = tail call i32 @sched_exit(i32 0)
br label %31
31: ; preds = %28, %25
%32 = tail call i32 (...) @child()
br label %33
33: ; preds = %31, %25
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%35 = tail call i32 (...) @sched_fork()
switch i32 %35, label %41 [
i32 -1, label %36
i32 0, label %39
]
36: ; preds = %33
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0))
%38 = tail call i32 @sched_exit(i32 0)
br label %39
39: ; preds = %36, %33
%40 = tail call i32 (...) @child()
br label %41
41: ; preds = %39, %33
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%43 = tail call i32 (...) @sched_getpid()
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = bitcast i32* %1 to i8*
%46 = call i32 @sched_wait(i32* %1)
%47 = load i32, i32* %1
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = call i32 @sched_wait(i32* %1)
%50 = load i32, i32* %1
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %50)
%52 = call i32 @sched_wait(i32* %1)
%53 = load i32, i32* %1
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = call i32 @sched_wait(i32* %1)
%56 = load i32, i32* %1
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = call i32 @sched_wait(i32* %1)
%59 = load i32, i32* %1
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %47)
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %50)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %53)
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %59)
%67 = call i32 @putchar(i32 10)
%68 = call i32 @sched_exit(i32 0)
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
%70 = call i32 @exit(i32 0)
unreachable
}