#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*/ err(int, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ go(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ status_is_failure(int);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *);
void makeprocs(void) {
  int i, status, failcount;
  pid_t pids[24];
  printf("Job size approximately %lu bytes\n",
         (unsigned long)((11 + 1) * 35 * 35 * sizeof(int)));
  printf("Forking %d jobs; total load %luk\n", 24,
         (unsigned long)(24 * ((11 + 1) * 35 * 35 * sizeof(int))) / 1024);
  for (i = 0; i < 24; i++) {
    pids[i] = fork();
    if (pids[i] < 0) {
      warn("fork");
    }
    if (pids[i] == 0) {
      go(i);
    }
  }
  failcount = 0;
  for (i = 0; i < 24; i++) {
    if (pids[i] < 0) {
      failcount++;
    } else {
      if (waitpid(pids[i], &status, 0) < 0) {
        err(1, "waitpid");
      }
      if (status_is_failure(status)) {
        failcount++;
      }
    }
  }
  if (failcount > 0) {
    printf("%d subprocesses failed\n", failcount);
    exit(1);
  }
  printf("Test complete\n");
}


x86 assembly (clang, -O0):
<makeprocs>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
lea    0xe6e(%rip),%rdi
mov    $0xe5b0,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7d(%rip),%rdi
mov    $0x18,%esi
mov    $0x562,%edx
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x18,-0x4(%rbp)
jge    122a <makeprocs+0xaa>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
mov    %rcx,-0xd0(%rbp,%rax,8)
ff
movslq -0x4(%rbp),%rax
cmpq   $0x0,-0xd0(%rbp,%rax,8)
jge    11fc <makeprocs+0x7c>
lea    0xe4d(%rip),%rdi
call   1030 <warn@plt>
movslq -0x4(%rbp),%rax
cmpq   $0x0,-0xd0(%rbp,%rax,8)
jne    1217 <makeprocs+0x97>
mov    -0x4(%rbp),%edi
call   1040 <go@plt>
jmp    121c <makeprocs+0x9c>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <makeprocs+0x3d>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x18,-0x4(%rbp)
jge    12c8 <makeprocs+0x148>
movslq -0x4(%rbp),%rax
cmpq   $0x0,-0xd0(%rbp,%rax,8)
jge    1263 <makeprocs+0xe3>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12b5 <makeprocs+0x135>
movslq -0x4(%rbp),%rax
mov    -0xd0(%rbp,%rax,8),%rdi
ff
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0x0,%rax
jge    1295 <makeprocs+0x115>
mov    $0x1,%edi
lea    0xdb9(%rip),%rsi
call   1060 <err@plt>
mov    -0x8(%rbp),%edi
call   1070 <status_is_failure@plt>
cmp    $0x0,%rax
je     12b0 <makeprocs+0x130>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12b5 <makeprocs+0x135>
jmp    12ba <makeprocs+0x13a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1238 <makeprocs+0xb8>
cmpl   $0x0,-0xc(%rbp)
jle    12ed <makeprocs+0x16d>
mov    -0xc(%rbp),%esi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeprocs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xd8,%rsp
lea    0xe5c(%rip),%rdi
mov    $0xe5b0,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    $0x562,%edx
mov    $0x18,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe75(%rip),%r14
xor    %ebx,%ebx
jmp    11f2 <makeprocs+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1030 <warn@plt>
add    $0x1,%rbx
cmp    $0x18,%rbx
je     120e <makeprocs+0x7e>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %rax,0x10(%rsp,%rbx,8)
test   %rax,%rax
js     11e0 <makeprocs+0x50>
jne    11e8 <makeprocs+0x58>
mov    %ebx,%edi
call   1050 <go@plt>
jmp    11e8 <makeprocs+0x58>
xor    %ebx,%ebx
lea    0xc(%rsp),%r14
lea    0xe2d(%rip),%r15
xor    %ebp,%ebp
jmp    123d <makeprocs+0xad>
mov    0xc(%rsp),%edi
call   1080 <status_is_failure@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
add    %ecx,%ebp
add    $0x1,%rbx
cmp    $0x18,%rbx
je     126a <makeprocs+0xda>
mov    0x10(%rsp,%rbx,8),%rdi
mov    $0x1,%ecx
test   %rdi,%rdi
js     1231 <makeprocs+0xa1>
mov    %r14,%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
test   %rax,%rax
jns    1220 <makeprocs+0x90>
mov    $0x1,%edi
mov    %r15,%rsi
call   1070 <err@plt>
jmp    1220 <makeprocs+0x90>
test   %ebp,%ebp
jne    1288 <makeprocs+0xf8>
lea    0xdf4(%rip),%rdi
call   1040 <puts@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc2(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Job size approximately %lu bytes\0A\00"
@.str.1 = [34 x i8] c"Forking %d jobs; total load %luk\0A\00"
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [8 x i8] c"waitpid\00"
@.str.4 = [24 x i8] c"%d subprocesses failed\0A\00"
@.str.5 = [15 x i8] c"Test complete\0A\00"
define void @makeprocs() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [24 x i64]
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 58800)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 24, i64 1378)
store i32 0, i32* %1
br label %7
7: ; preds = %32, %0
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 24
br i1 %9, label %10, label %35
10: ; preds = %7
%11 = call i64 (...) @fork()
%12 = load i32, i32* %1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [24 x i64], [24 x i64]* %4, i64 0, i64 %13
store i64 %11, i64* %14
%15 = load i32, i32* %1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [24 x i64], [24 x i64]* %4, i64 0, i64 %16
%18 = load i64, i64* %17
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %10
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [24 x i64], [24 x i64]* %4, i64 0, i64 %24
%26 = load i64, i64* %25
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %1
%30 = call i32 @go(i32 %29)
br label %31
31: ; preds = %28, %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %1
%34 = add nsw i32 %33, 1
store i32 %34, i32* %1
br label %7
35: ; preds = %7
store i32 0, i32* %3
store i32 0, i32* %1
br label %36
36: ; preds = %66, %35
%37 = load i32, i32* %1
%38 = icmp slt i32 %37, 24
br i1 %38, label %39, label %69
39: ; preds = %36
%40 = load i32, i32* %1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [24 x i64], [24 x i64]* %4, i64 0, i64 %41
%43 = load i64, i64* %42
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %65
48: ; preds = %39
%49 = load i32, i32* %1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [24 x i64], [24 x i64]* %4, i64 0, i64 %50
%52 = load i64, i64* %51
%53 = call i64 @waitpid(i64 %52, i32* %2, i32 0)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %55, %48
%58 = load i32, i32* %2
%59 = call i64 @status_is_failure(i32 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i32, i32* %3
%63 = add nsw i32 %62, 1
store i32 %63, i32* %3
br label %64
64: ; preds = %61, %57
br label %65
65: ; preds = %64, %45
br label %66
66: ; preds = %65
%67 = load i32, i32* %1
%68 = add nsw i32 %67, 1
store i32 %68, i32* %1
br label %36
69: ; preds = %36
%70 = load i32, i32* %3
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = load i32, i32* %3
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %73)
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %69
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"Job size approximately %lu bytes\0A\00"
@.str.1 = [34 x i8] c"Forking %d jobs; total load %luk\0A\00"
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [8 x i8] c"waitpid\00"
@.str.4 = [24 x i8] c"%d subprocesses failed\0A\00"
@str = [14 x i8] c"Test complete\00"
define void @makeprocs() {
%1 = alloca i32
%2 = alloca [24 x i64]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [24 x i64]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 58800)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 24, i64 1378)
br label %7
7: ; preds = %0, %19
%8 = phi i64 [ 0, %0 ], [ %20, %19 ]
%9 = tail call i64 (...) @fork()
%10 = getelementptr inbounds [24 x i64], [24 x i64]* %2, i64 0, i64 %8
store i64 %9, i64* %10
%11 = icmp slt i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %19
14: ; preds = %7
%15 = icmp eq i64 %9, 0
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = trunc i64 %8 to i32
%18 = tail call i32 @go(i32 %17)
br label %19
19: ; preds = %12, %14, %16
%20 = add nuw nsw i64 %8, 1
%21 = icmp eq i64 %20, 24
br i1 %21, label %22, label %7
22: ; preds = %19, %38
%23 = phi i64 [ %41, %38 ], [ 0, %19 ]
%24 = phi i32 [ %40, %38 ], [ 0, %19 ]
%25 = getelementptr inbounds [24 x i64], [24 x i64]* %2, i64 0, i64 %23
%26 = load i64, i64* %25
%27 = icmp slt i64 %26, 0
br i1 %27, label %38, label %28
28: ; preds = %22
%29 = call i64 @waitpid(i64 %26, i32* %1, i32 0)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* %1
%35 = call i64 @status_is_failure(i32 %34)
%36 = icmp ne i64 %35, 0
%37 = zext i1 %36 to i32
br label %38
38: ; preds = %22, %33
%39 = phi i32 [ %37, %33 ], [ 1, %22 ]
%40 = add nuw nsw i32 %24, %39
%41 = add nuw nsw i64 %23, 1
%42 = icmp eq i64 %41, 24
br i1 %42, label %43, label %22
43: ; preds = %38
%44 = icmp eq i32 %40, 0
br i1 %44, label %48, label %45
45: ; preds = %43
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %43
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
ret void
}