#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*/ chdir(char *);
int /*<<< orphan*/ execl(char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ mkfiles();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quit();
int rand();
int /*<<< orphan*/ rmfiles();
int /*<<< orphan*/ spawn(int);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wait(int *);
int main() {
  int i, n, pid, r;
  printf("Test 10 ");
  fflush(stdout);
  system("rm -rf DIR_10; mkdir DIR_10; cp t10a DIR_10");
  chdir("DIR_10");
  pid = getpid();
  mkfiles();
  if (getpid() == pid)
    if (fork() == 0) {
      execl("t10a", (char *)0);
      exit(0);
    }
  if (getpid() == pid)
    if (fork() == 0) {
      execl("t10b", (char *)0);
      exit(0);
    }
  if (getpid() == pid)
    if (fork() == 0) {
      execl("t10c", (char *)0);
      exit(0);
    }
  if (getpid() == pid)
    if (fork() == 0) {
      execl("t10d", (char *)0);
      exit(0);
    }
  srand(100);
  for (i = 0; i < 60; i++) {
    r = rand() & 07;
    spawn(r);
  }
  for (i = 0; i < 4; i++)
    wait(&n);
  rmfiles();
  quit();
  return (-1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xdfa(%rip),%rdi
call   1070 <printf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
lea    0xde9(%rip),%rdi
call   1060 <system@plt>
lea    0xe02(%rip),%rdi
call   1050 <chdir@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   10c0 <mkfiles@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
cmp    -0x10(%rbp),%eax
jne    127f <main+0x8f>
mov    $0x0,%al
call   1100 <fork@plt>
cmp    $0x0,%rax
jne    127a <main+0x8a>
lea    0xdcb(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <execl@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    127f <main+0x8f>
mov    $0x0,%al
call   1040 <getpid@plt>
cmp    -0x10(%rbp),%eax
jne    12bc <main+0xcc>
mov    $0x0,%al
call   1100 <fork@plt>
cmp    $0x0,%rax
jne    12b7 <main+0xc7>
lea    0xd93(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <execl@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    12bc <main+0xcc>
mov    $0x0,%al
call   1040 <getpid@plt>
cmp    -0x10(%rbp),%eax
jne    12f9 <main+0x109>
mov    $0x0,%al
call   1100 <fork@plt>
cmp    $0x0,%rax
jne    12f4 <main+0x104>
lea    0xd5b(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <execl@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    12f9 <main+0x109>
mov    $0x0,%al
call   1040 <getpid@plt>
cmp    -0x10(%rbp),%eax
jne    1336 <main+0x146>
mov    $0x0,%al
call   1100 <fork@plt>
cmp    $0x0,%rax
jne    1331 <main+0x141>
lea    0xd23(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <execl@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    1336 <main+0x146>
mov    $0x64,%edi
call   1090 <srand@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3c,-0x8(%rbp)
jge    1374 <main+0x184>
mov    $0x0,%al
call   1110 <rand@plt>
and    $0x7,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   10b0 <spawn@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1347 <main+0x157>
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    139c <main+0x1ac>
lea    -0xc(%rbp),%rdi
call   10f0 <wait@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    137b <main+0x18b>
mov    $0x0,%al
call   1030 <rmfiles@plt>
mov    $0x0,%al
call   1080 <quit@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe04(%rip),%rdi
call   1070 <printf@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
lea    0xdf3(%rip),%rdi
call   1060 <system@plt>
lea    0xe0c(%rip),%rdi
call   1050 <chdir@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10c0 <mkfiles@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
cmp    %ebx,%eax
jne    1252 <main+0x62>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
je     1314 <main+0x124>
xor    %eax,%eax
call   1040 <getpid@plt>
cmp    %ebx,%eax
jne    126d <main+0x7d>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
je     131d <main+0x12d>
xor    %eax,%eax
call   1040 <getpid@plt>
cmp    %ebx,%eax
jne    1288 <main+0x98>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
je     1326 <main+0x136>
xor    %eax,%eax
call   1040 <getpid@plt>
cmp    %ebx,%eax
jne    12a3 <main+0xb3>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
je     132f <main+0x13f>
mov    $0x64,%edi
call   1090 <srand@plt>
mov    $0x3c,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1110 <rand@plt>
and    $0x7,%eax
mov    %eax,%edi
call   10b0 <spawn@plt>
add    $0xffffffff,%ebx
jne    12c0 <main+0xd0>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10f0 <wait@plt>
mov    %rbx,%rdi
call   10f0 <wait@plt>
mov    %rbx,%rdi
call   10f0 <wait@plt>
mov    %rbx,%rdi
call   10f0 <wait@plt>
xor    %eax,%eax
call   1030 <rmfiles@plt>
xor    %eax,%eax
call   1080 <quit@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xd1a(%rip),%rdi
jmp    1336 <main+0x146>
lea    0xd16(%rip),%rdi
jmp    1336 <main+0x146>
lea    0xd12(%rip),%rdi
jmp    1336 <main+0x146>
lea    0xd0e(%rip),%rdi
xor    %esi,%esi
call   10e0 <execl@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"Test 10 \00"
@stdout = global i32 0
@.str.1 = [44 x i8] c"rm -rf DIR_10; mkdir DIR_10; cp t10a DIR_10\00"
@.str.2 = [7 x i8] c"DIR_10\00"
@.str.3 = [5 x i8] c"t10a\00"
@.str.4 = [5 x i8] c"t10b\00"
@.str.5 = [5 x i8] c"t10c\00"
@.str.6 = [5 x i8] c"t10d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
%9 = call i32 @system(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @chdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (...) @getpid()
store i32 %11, i32* %4
%12 = call i32 (...) @mkfiles()
%13 = call i32 (...) @getpid()
%14 = load i32, i32* %4
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %23
16: ; preds = %0
%17 = call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @execl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* null)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %16
br label %23
23: ; preds = %22, %0
%24 = call i32 (...) @getpid()
%25 = load i32, i32* %4
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = call i64 (...) @fork()
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = call i32 @execl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* null)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %27
br label %34
34: ; preds = %33, %23
%35 = call i32 (...) @getpid()
%36 = load i32, i32* %4
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = call i64 (...) @fork()
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @execl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* null)
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %38
br label %45
45: ; preds = %44, %34
%46 = call i32 (...) @getpid()
%47 = load i32, i32* %4
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = call i64 (...) @fork()
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i32 @execl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* null)
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %49
br label %56
56: ; preds = %55, %45
%57 = call i32 @srand(i32 100)
store i32 0, i32* %2
br label %58
58: ; preds = %66, %56
%59 = load i32, i32* %2
%60 = icmp slt i32 %59, 60
br i1 %60, label %61, label %69
61: ; preds = %58
%62 = call i32 (...) @rand()
%63 = and i32 %62, 7
store i32 %63, i32* %5
%64 = load i32, i32* %5
%65 = call i32 @spawn(i32 %64)
br label %66
66: ; preds = %61
%67 = load i32, i32* %2
%68 = add nsw i32 %67, 1
store i32 %68, i32* %2
br label %58
69: ; preds = %58
store i32 0, i32* %2
br label %70
70: ; preds = %75, %69
%71 = load i32, i32* %2
%72 = icmp slt i32 %71, 4
br i1 %72, label %73, label %78
73: ; preds = %70
%74 = call i32 @wait(i32* %3)
br label %75
75: ; preds = %73
%76 = load i32, i32* %2
%77 = add nsw i32 %76, 1
store i32 %77, i32* %2
br label %70
78: ; preds = %70
%79 = call i32 (...) @rmfiles()
%80 = call i32 (...) @quit()
ret i32 -1
}

LLVM IR (-O2):
@.str = [9 x i8] c"Test 10 \00"
@stdout = global i32 0
@.str.1 = [44 x i8] c"rm -rf DIR_10; mkdir DIR_10; cp t10a DIR_10\00"
@.str.2 = [7 x i8] c"DIR_10\00"
@.str.3 = [5 x i8] c"t10a\00"
@.str.4 = [5 x i8] c"t10b\00"
@.str.5 = [5 x i8] c"t10c\00"
@.str.6 = [5 x i8] c"t10d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = tail call i32 @system(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @chdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 (...) @mkfiles()
%10 = tail call i32 (...) @getpid()
%11 = icmp eq i32 %10, %8
br i1 %11, label %12, label %18
12: ; preds = %0
%13 = tail call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @execl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* null)
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %12, %0
%19 = tail call i32 (...) @getpid()
%20 = icmp eq i32 %19, %8
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = tail call i64 (...) @fork()
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call i32 @execl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* null)
%26 = tail call i32 @exit(i32 0)
unreachable
27: ; preds = %21, %18
%28 = tail call i32 (...) @getpid()
%29 = icmp eq i32 %28, %8
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = tail call i64 (...) @fork()
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = tail call i32 @execl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* null)
%35 = tail call i32 @exit(i32 0)
unreachable
36: ; preds = %30, %27
%37 = tail call i32 (...) @getpid()
%38 = icmp eq i32 %37, %8
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = tail call i64 (...) @fork()
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = tail call i32 @execl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* null)
%44 = tail call i32 @exit(i32 0)
unreachable
45: ; preds = %39, %36
%46 = tail call i32 @srand(i32 100)
br label %47
47: ; preds = %45, %47
%48 = phi i32 [ 0, %45 ], [ %52, %47 ]
%49 = tail call i32 (...) @rand()
%50 = and i32 %49, 7
%51 = tail call i32 @spawn(i32 %50)
%52 = add nuw nsw i32 %48, 1
%53 = icmp eq i32 %52, 60
br i1 %53, label %54, label %47
54: ; preds = %47
%55 = call i32 @wait(i32* %1)
%56 = call i32 @wait(i32* %1)
%57 = call i32 @wait(i32* %1)
%58 = call i32 @wait(i32* %1)
%59 = call i32 (...) @rmfiles()
%60 = call i32 (...) @quit()
ret i32 -1
}