#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);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ parent();
int /*<<< orphan*/ printf(char *);
test10() {
  int i, n, pid;
  n = 4;
  for (i = 0; i < n; i++) {
    if ((pid = fork())) {
      if (pid < 0) {
        printf("\nTest 1 fork failed\n");
        exit(1);
      }
      parent();
    } else
      child(i);
  }
}


x86 assembly (clang, -O0):
<test10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x4,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cc <test10+0x7c>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     11b1 <test10+0x61>
cmpl   $0x0,-0x10(%rbp)
jge    11a5 <test10+0x55>
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1040 <parent@plt>
jmp    11b9 <test10+0x69>
mov    -0x8(%rbp),%edi
call   1030 <child@plt>
jmp    11be <test10+0x6e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1166 <test10+0x16>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test10>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1167 <test10+0x17>
js     11d0 <test10+0x80>
xor    %eax,%eax
call   1040 <parent@plt>
jmp    116e <test10+0x1e>
xor    %edi,%edi
call   1030 <child@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1184 <test10+0x34>
js     11d0 <test10+0x80>
xor    %eax,%eax
call   1040 <parent@plt>
jmp    118e <test10+0x3e>
mov    $0x1,%edi
call   1030 <child@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11a4 <test10+0x54>
js     11d0 <test10+0x80>
xor    %eax,%eax
call   1040 <parent@plt>
jmp    11ae <test10+0x5e>
mov    $0x2,%edi
call   1030 <child@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11c4 <test10+0x74>
js     11d0 <test10+0x80>
xor    %eax,%eax
call   1040 <parent@plt>
pop    %rcx
ret
mov    $0x3,%edi
call   1030 <child@plt>
pop    %rcx
ret
lea    0xe29(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"\0ATest 1 fork failed\0A\00"
define i32 @test10() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 4, i32* %3
store i32 0, i32* %2
br label %5
5: ; preds = %24, %0
%6 = load i32, i32* %2
%7 = load i32, i32* %3
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %27
9: ; preds = %5
%10 = call i32 (...) @fork()
store i32 %10, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = call i32 (...) @parent()
br label %23
20: ; preds = %9
%21 = load i32, i32* %2
%22 = call i32 @child(i32 %21)
br label %23
23: ; preds = %20, %18
br label %24
24: ; preds = %23
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %5
27: ; preds = %5
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@str = [20 x i8] c"\0ATest 1 fork failed\00"
define i32 @test10() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = icmp slt i32 %1, 0
br i1 %4, label %5, label %8
5: ; preds = %33, %24, %15, %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %3
%9 = tail call i32 (...) @parent()
br label %12
10: ; preds = %0
%11 = tail call i32 @child(i32 0)
br label %12
12: ; preds = %8, %10
%13 = tail call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = icmp slt i32 %13, 0
br i1 %16, label %5, label %17
17: ; preds = %15
%18 = tail call i32 (...) @parent()
br label %21
19: ; preds = %12
%20 = tail call i32 @child(i32 1)
br label %21
21: ; preds = %19, %17
%22 = tail call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = icmp slt i32 %22, 0
br i1 %25, label %5, label %26
26: ; preds = %24
%27 = tail call i32 (...) @parent()
br label %30
28: ; preds = %21
%29 = tail call i32 @child(i32 2)
br label %30
30: ; preds = %28, %26
%31 = tail call i32 (...) @fork()
%32 = icmp eq i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = icmp slt i32 %31, 0
br i1 %34, label %5, label %35
35: ; preds = %33
%36 = tail call i32 (...) @parent()
br label %39
37: ; preds = %30
%38 = tail call i32 @child(i32 3)
br label %39
39: ; preds = %37, %35
ret i32 undef
}