#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int get_number_of_cores();
int handle_args(int, char **);
int /*<<< orphan*/ launch_child_processes(int, int, char **, int);
int launch_process(int, char **, int);
int /*<<< orphan*/ print_logs(int, char **);
int wait_for_child_processes(int, int);
int main(int argc, char *argv[]) {
  int verbose = 0;
  const int cores = get_number_of_cores();
  const int suites = argc - 1;
  int retval = 0;
  int allocated_cores = ((suites < cores) ? suites : cores);
  verbose = handle_args(argc, argv);
  if (allocated_cores > 1) {
    launch_child_processes(allocated_cores, argc, argv, verbose);
    retval = wait_for_child_processes(allocated_cores, verbose);
    print_logs(argc, argv);
  } else {
    retval = launch_process(argc, argv, verbose);
    if (0 != retval) {
      retval = EXIT_FAILURE;
    } else {
      retval = EXIT_SUCCESS;
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <get_number_of_cores@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ae <main+0x4e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11b4 <main+0x54>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <handle_args@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x24(%rbp)
jle    1204 <main+0xa4>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1050 <launch_child_processes@plt>
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <wait_for_child_processes@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <print_logs@plt>
jmp    1243 <main+0xe3>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1080 <launch_process@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
je     1232 <main+0xd2>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    123e <main+0xde>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1243 <main+0xe3>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <get_number_of_cores@plt>
mov    %eax,%ebp
lea    -0x1(%rbx),%eax
cmp    %ebp,%eax
cmovl  %eax,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <handle_args@plt>
mov    %eax,%r15d
cmp    $0x2,%ebp
jl     11b8 <main+0x58>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1050 <launch_child_processes@plt>
mov    %ebp,%edi
mov    %r15d,%esi
call   1070 <wait_for_child_processes@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <print_logs@plt>
mov    %ebp,%eax
jmp    11db <main+0x7b>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   1080 <launch_process@plt>
test   %eax,%eax
je     11d2 <main+0x72>
mov    0x2e10(%rip),%rax
jmp    11d9 <main+0x79>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = call i32 (...) @get_number_of_cores()
store i32 %11, i32* %7
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %8
store i32 0, i32* %9
%14 = load i32, i32* %8
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = load i32, i32* %8
br label %21
19: ; preds = %2
%20 = load i32, i32* %7
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ %18, %17 ], [ %20, %19 ]
store i32 %22, i32* %10
%23 = load i32, i32* %4
%24 = load i8**, i8*** %5
%25 = call i32 @handle_args(i32 %23, i8** %24)
store i32 %25, i32* %6
%26 = load i32, i32* %10
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %40
28: ; preds = %21
%29 = load i32, i32* %10
%30 = load i32, i32* %4
%31 = load i8**, i8*** %5
%32 = load i32, i32* %6
%33 = call i32 @launch_child_processes(i32 %29, i32 %30, i8** %31, i32 %32)
%34 = load i32, i32* %10
%35 = load i32, i32* %6
%36 = call i32 @wait_for_child_processes(i32 %34, i32 %35)
store i32 %36, i32* %9
%37 = load i32, i32* %4
%38 = load i8**, i8*** %5
%39 = call i32 @print_logs(i32 %37, i8** %38)
br label %52
40: ; preds = %21
%41 = load i32, i32* %4
%42 = load i8**, i8*** %5
%43 = load i32, i32* %6
%44 = call i32 @launch_process(i32 %41, i8** %42, i32 %43)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = icmp ne i32 0, %45
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %9
br label %51
49: ; preds = %40
%50 = load i32, i32* @EXIT_SUCCESS
store i32 %50, i32* %9
br label %51
51: ; preds = %49, %47
br label %52
52: ; preds = %51, %28
%53 = load i32, i32* %9
ret i32 %53
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @get_number_of_cores()
%4 = add nsw i32 %0, -1
%5 = icmp slt i32 %4, %3
%6 = select i1 %5, i32 %4, i32 %3
%7 = tail call i32 @handle_args(i32 %0, i8** %1)
%8 = icmp sgt i32 %6, 1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = tail call i32 @launch_child_processes(i32 %6, i32 %0, i8** %1, i32 %7)
%11 = tail call i32 @wait_for_child_processes(i32 %6, i32 %7)
%12 = tail call i32 @print_logs(i32 %0, i8** %1)
br label %20
13: ; preds = %2
%14 = tail call i32 @launch_process(i32 %0, i8** %1, i32 %7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = load i32, i32* @EXIT_FAILURE
br label %20
18: ; preds = %13
%19 = load i32, i32* @EXIT_SUCCESS
br label %20
20: ; preds = %16, %18, %9
%21 = phi i32 [ %11, %9 ], [ %17, %16 ], [ %19, %18 ]
ret i32 %21
}