#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(void) {
  pid_t pid;
  pid = fork();
  fork();
  fork();
  fork();
  if (pid == 0) {
    int j;
    for (j = 0; j < 10; j++) {
      printf("child: %d\n", j);
      sleep(1);
    }
    _exit(0);
  } else if (pid > 0) {
    int i;
    for (i = 0; i < 10; i++) {
      printf("parent: %d\n", i);
      sleep(1);
    }
    exit(0);
  } else {
    fprintf(stderr, "can't fork, error %d\n", errno);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    $0x0,%al
call   1080 <fork@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11d9 <main+0x79>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11d2 <main+0x72>
mov    -0x14(%rbp),%esi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a1 <main+0x41>
xor    %edi,%edi
call   1030 <_exit@plt>
cmpq   $0x0,-0x10(%rbp)
jle    1223 <main+0xc3>
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    121c <main+0xbc>
mov    -0x18(%rbp),%esi
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11eb <main+0x8b>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
lea    0xddb(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
xor    %eax,%eax
call   1080 <fork@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rbx,%rbx
jne    127a <main+0x11a>
lea    0xe70(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
jle    1371 <main+0x211>
lea    0xd84(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
mov    0x2c57(%rip),%rax
mov    (%rax),%edx
lea    0xc8d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"child: %d\0A\00"
@.str.1 = [12 x i8] c"parent: %d\0A\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i64 (...) @fork()
store i64 %5, i64* %2
%6 = call i64 (...) @fork()
%7 = call i64 (...) @fork()
%8 = call i64 (...) @fork()
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %0
store i32 0, i32* %3
br label %12
12: ; preds = %19, %11
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call i32 @sleep(i32 1)
br label %19
19: ; preds = %15
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %12
22: ; preds = %12
%23 = call i32 @_exit(i32 0)
unreachable
24: ; preds = %0
%25 = load i64, i64* %2
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %24
store i32 0, i32* %4
br label %28
28: ; preds = %35, %27
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 10
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i32, i32* %4
%33 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i32 @sleep(i32 1)
br label %35
35: ; preds = %31
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %28
38: ; preds = %28
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %24
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"child: %d\0A\00"
@.str.1 = [12 x i8] c"parent: %d\0A\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = tail call i64 (...) @fork()
%3 = tail call i64 (...) @fork()
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %1, 0
br i1 %5, label %6, label %28
6: ; preds = %0
%7 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = tail call i32 @sleep(i32 1)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = tail call i32 @sleep(i32 1)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 2)
%12 = tail call i32 @sleep(i32 1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 3)
%14 = tail call i32 @sleep(i32 1)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 4)
%16 = tail call i32 @sleep(i32 1)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 5)
%18 = tail call i32 @sleep(i32 1)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 6)
%20 = tail call i32 @sleep(i32 1)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 7)
%22 = tail call i32 @sleep(i32 1)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 8)
%24 = tail call i32 @sleep(i32 1)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 9)
%26 = tail call i32 @sleep(i32 1)
%27 = tail call i32 @_exit(i32 0)
unreachable
28: ; preds = %0
%29 = icmp sgt i64 %1, 0
br i1 %29, label %30, label %52
30: ; preds = %28
%31 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 0)
%32 = tail call i32 @sleep(i32 1)
%33 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 1)
%34 = tail call i32 @sleep(i32 1)
%35 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 2)
%36 = tail call i32 @sleep(i32 1)
%37 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 3)
%38 = tail call i32 @sleep(i32 1)
%39 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 4)
%40 = tail call i32 @sleep(i32 1)
%41 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 5)
%42 = tail call i32 @sleep(i32 1)
%43 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 6)
%44 = tail call i32 @sleep(i32 1)
%45 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 7)
%46 = tail call i32 @sleep(i32 1)
%47 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 8)
%48 = tail call i32 @sleep(i32 1)
%49 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 9)
%50 = tail call i32 @sleep(i32 1)
%51 = tail call i32 @exit(i32 0)
unreachable
52: ; preds = %28
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = tail call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = tail call i32 @exit(i32 %56)
unreachable
}