#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int run_test_suites(int, int, int, char **, int, int);
int /*<<< orphan*/ stderr;
void launch_child_processes(int allocated_cores, int argc, char *argv[],
                            int verbose) {
  int idx = 0;
  pid_t pid[128];
  for (idx = 0; idx < allocated_cores; idx++) {
    if (0 > (pid[idx] = fork())) {
      fprintf(stderr, "ERROR: Failed to fork\n");
      exit(EXIT_FAILURE);
    } else if (pid[idx] == 0) {
      int r = run_test_suites(idx, allocated_cores, argc, argv, verbose, 1);
      if (0 != r) {
        r = EXIT_FAILURE;
      } else {
        r = EXIT_SUCCESS;
      }
      exit(r);
    }
  }
}


x86 assembly (clang, -O0):
<launch_child_processes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    123f <launch_child_processes+0xff>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
mov    %rcx,-0x420(%rbp,%rax,8)
ff
xor    %eax,%eax
cmp    %rcx,%rax
jle    11b6 <launch_child_processes+0x76>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movslq -0x18(%rbp),%rax
cmpq   $0x0,-0x420(%rbp,%rax,8)
jne    1227 <launch_child_processes+0xe7>
mov    -0x18(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    $0x1,%r9d
call   1030 <run_test_suites@plt>
mov    %eax,-0x424(%rbp)
xor    %eax,%eax
cmp    -0x424(%rbp),%eax
je     120d <launch_child_processes+0xcd>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
jmp    121c <launch_child_processes+0xdc>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    -0x424(%rbp),%edi
call   1050 <exit@plt>
jmp    122c <launch_child_processes+0xec>
jmp    1231 <launch_child_processes+0xf1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1166 <launch_child_processes+0x26>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch_child_processes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    1175 <launch_child_processes+0x35>
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%r12d
mov    %edi,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
js     117e <launch_child_processes+0x3e>
je     1195 <launch_child_processes+0x55>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1160 <launch_child_processes+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11bf <launch_child_processes+0x7f>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
mov    $0x1,%r9d
call   1030 <run_test_suites@plt>
test   %eax,%eax
jne    11bf <launch_child_processes+0x7f>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"ERROR: Failed to fork\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define void @launch_child_processes(i32 %0, i32 %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca [128 x i64]
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %9
br label %12
12: ; preds = %51, %4
%13 = load i32, i32* %9
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %54
16: ; preds = %12
%17 = call i64 (...) @fork()
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [128 x i64], [128 x i64]* %10, i64 0, i64 %19
store i64 %17, i64* %20
%21 = icmp sgt i64 0, %17
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %16
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [128 x i64], [128 x i64]* %10, i64 0, i64 %29
%31 = load i64, i64* %30
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %49
33: ; preds = %27
%34 = load i32, i32* %9
%35 = load i32, i32* %5
%36 = load i32, i32* %6
%37 = load i8**, i8*** %7
%38 = load i32, i32* %8
%39 = call i32 @run_test_suites(i32 %34, i32 %35, i32 %36, i8** %37, i32 %38, i32 1)
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = icmp ne i32 0, %40
br i1 %41, label %42, label %44
42: ; preds = %33
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %11
br label %46
44: ; preds = %33
%45 = load i32, i32* @EXIT_SUCCESS
store i32 %45, i32* %11
br label %46
46: ; preds = %44, %42
%47 = load i32, i32* %11
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %27
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %12
54: ; preds = %12
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"ERROR: Failed to fork\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define void @launch_child_processes(i32 %0, i32 %1, i8** %2, i32 %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %27
6: ; preds = %4, %24
%7 = phi i32 [ %25, %24 ], [ 0, %4 ]
%8 = tail call i64 (...) @fork()
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %6
%16 = icmp eq i64 %8, 0
br i1 %16, label %17, label %24
17: ; preds = %15
%18 = tail call i32 @run_test_suites(i32 %7, i32 %0, i32 %1, i8** %2, i32 %3, i32 1)
%19 = icmp eq i32 %18, 0
%20 = load i32, i32* @EXIT_SUCCESS
%21 = load i32, i32* @EXIT_FAILURE
%22 = select i1 %19, i32 %20, i32 %21
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %15
%25 = add nuw nsw i32 %7, 1
%26 = icmp eq i32 %25, %0
br i1 %26, label %27, label %6
27: ; preds = %24, %4
ret void
}