#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 int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int get_nprocs();
scalar_t__ malloc(int);
int print_events(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ run_child(char **);
int /*<<< orphan*/ stderr;
scalar_t__ wait_child(char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <PROGRAM> [<ARGS>]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  fprintf(stderr, "%d CPUs online\n", get_nprocs());
  int nprocs = get_nprocs();
  pid_t *pids = (pid_t *)malloc(sizeof(pid_t) * nprocs);
  for (int i = 0; i < nprocs; i++) {
    pids[i] = run_child(&argv[1]);
  }
  int ret = 0;
  for (int i = 0; i < nprocs; i++) {
    if (wait_child(argv[0], pids[i]))
      ret = -1;
  }
  if (ret != -1) {
    printf("[\n");
    for (int i = 0; i < nprocs; i++) {
      if (print_events(pids[i]) == -1)
        ret = -1;
      if (i < nprocs - 1)
        printf(",");
    }
    printf("]\n");
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cc <main+0x4c>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   10a0 <get_nprocs@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%edx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   10a0 <get_nprocs@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    124a <main+0xca>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1080 <run_child@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1216 <main+0x96>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    129f <main+0x11f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1070 <wait_child@plt>
cmp    $0x0,%rax
je     128c <main+0x10c>
movl   $0xffffffff,-0x28(%rbp)
jmp    1291 <main+0x111>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1258 <main+0xd8>
cmpl   $0xffffffff,-0x28(%rbp)
je     1324 <main+0x1a4>
lea    0xd7e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1318 <main+0x198>
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <print_events@plt>
cmp    $0xffffffff,%eax
jne    12e8 <main+0x168>
movl   $0xffffffff,-0x28(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1305 <main+0x185>
lea    0xd31(%rip),%rdi
call   1040 <printf@plt>
jmp    130a <main+0x18a>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12bc <main+0x13c>
lea    0xcfc(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    0x2e3b(%rip),%rax
mov    (%rax),%ebx
cmp    $0x1,%edi
jle    12d2 <main+0x142>
xor    %r15d,%r15d
xor    %eax,%eax
call   10b0 <get_nprocs@plt>
lea    0xe5d(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   10b0 <get_nprocs@plt>
mov    %eax,%ebx
lea    0x0(,%rbx,4),%edi
call   1070 <malloc@plt>
test   %ebx,%ebx
jle    129b <main+0x10b>
mov    %rax,%r13
lea    0x8(%r12),%rbp
mov    %rbx,(%rsp)
mov    %ebx,%r14d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1090 <run_child@plt>
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1200 <main+0x70>
cmpl   $0x0,(%rsp)
jle    129b <main+0x10b>
xor    %ebp,%ebp
xor    %ebx,%ebx
mov    (%r12),%rdi
mov    0x0(%r13,%rbp,4),%esi
call   1080 <wait_child@plt>
neg    %rax
sbb    %eax,%eax
or     %eax,%ebx
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1220 <main+0x90>
cmp    $0xffffffff,%ebx
je     12c5 <main+0x135>
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rbx
test   %ebx,%ebx
jle    12cd <main+0x13d>
add    $0xffffffff,%ebx
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    1279 <main+0xe9>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
cmp    %rbp,%r14
je     12a7 <main+0x117>
mov    0x0(%r13,%rbp,4),%edi
call   1050 <print_events@plt>
cmp    $0xffffffff,%eax
cmove  %eax,%r15d
cmp    %rbx,%rbp
jae    1270 <main+0xe0>
mov    $0x2c,%edi
call   1030 <putchar@plt>
jmp    1270 <main+0xe0>
lea    0xd8c(%rip),%rdi
call   1040 <puts@plt>
lea    0xd82(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%r15d
jmp    12b3 <main+0x123>
xor    %r15d,%r15d
jmp    12a7 <main+0x117>
mov    (%r12),%rdx
lea    0xd23(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s <PROGRAM> [<ARGS>]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"%d CPUs online\0A\00"
@.str.2 = [3 x i8] c"[\0A\00"
@.str.3 = [2 x i8] c",\00"
@.str.4 = [3 x i8] c"]\0A\00"
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
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 (...) @get_nprocs()
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = call i32 (...) @get_nprocs()
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = mul i64 4, %28
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i32*
store i32* %32, i32** %7
store i32 0, i32* %8
br label %33
33: ; preds = %45, %22
%34 = load i32, i32* %8
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = call i32 @run_child(i8** %39)
%41 = load i32*, i32** %7
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %40, i32* %44
br label %45
45: ; preds = %37
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %33
48: ; preds = %33
store i32 0, i32* %9
store i32 0, i32* %10
br label %49
49: ; preds = %66, %48
%50 = load i32, i32* %10
%51 = load i32, i32* %6
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %69
53: ; preds = %49
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = load i32*, i32** %7
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = call i64 @wait_child(i8* %56, i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %53
store i32 -1, i32* %9
br label %65
65: ; preds = %64, %53
br label %66
66: ; preds = %65
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
store i32 %68, i32* %10
br label %49
69: ; preds = %49
%70 = load i32, i32* %9
%71 = icmp ne i32 %70, -1
br i1 %71, label %72, label %100
72: ; preds = %69
%73 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %11
br label %74
74: ; preds = %95, %72
%75 = load i32, i32* %11
%76 = load i32, i32* %6
%77 = icmp slt i32 %75, %76
br i1 %77, label %78, label %98
78: ; preds = %74
%79 = load i32*, i32** %7
%80 = load i32, i32* %11
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
%83 = load i32, i32* %82
%84 = call i32 @print_events(i32 %83)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %87
86: ; preds = %78
store i32 -1, i32* %9
br label %87
87: ; preds = %86, %78
%88 = load i32, i32* %11
%89 = load i32, i32* %6
%90 = sub nsw i32 %89, 1
%91 = icmp slt i32 %88, %90
br i1 %91, label %92, label %94
92: ; preds = %87
%93 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %94
94: ; preds = %92, %87
br label %95
95: ; preds = %94
%96 = load i32, i32* %11
%97 = add nsw i32 %96, 1
store i32 %97, i32* %11
br label %74
98: ; preds = %74
%99 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %100
100: ; preds = %98, %69
%101 = load i32, i32* %9
ret i32 %101
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s <PROGRAM> [<ARGS>]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"%d CPUs online\0A\00"
@str = [2 x i8] c"[\00"
@str.5 = [2 x i8] c"]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
%4 = load i32, i32* @stderr
br i1 %3, label %5, label %10
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = tail call i32 (...) @get_nprocs()
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i32 (...) @get_nprocs()
%14 = shl i32 %13, 2
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
%17 = icmp sgt i32 %13, 0
br i1 %17, label %18, label %30
18: ; preds = %10
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = zext i32 %13 to i64
br label %24
21: ; preds = %24
br i1 %17, label %22, label %30
22: ; preds = %21
%23 = zext i32 %13 to i64
br label %34
24: ; preds = %18, %24
%25 = phi i64 [ 0, %18 ], [ %28, %24 ]
%26 = tail call i32 @run_child(i8** %19)
%27 = getelementptr inbounds i32, i32* %16, i64 %25
store i32 %26, i32* %27
%28 = add nuw nsw i64 %25, 1
%29 = icmp eq i64 %28, %20
br i1 %29, label %21, label %24
30: ; preds = %10, %21
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %51
32: ; preds = %34
%33 = icmp eq i32 %42, -1
br i1 %33, label %68, label %45
34: ; preds = %22, %34
%35 = phi i64 [ 0, %22 ], [ %43, %34 ]
%36 = phi i32 [ 0, %22 ], [ %42, %34 ]
%37 = load i8*, i8** %1
%38 = getelementptr inbounds i32, i32* %16, i64 %35
%39 = load i32, i32* %38
%40 = tail call i64 @wait_child(i8* %37, i32 %39)
%41 = icmp eq i64 %40, 0
%42 = select i1 %41, i32 %36, i32 -1
%43 = add nuw nsw i64 %35, 1
%44 = icmp eq i64 %43, %23
br i1 %44, label %32, label %34
45: ; preds = %32
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br i1 %17, label %47, label %51
47: ; preds = %45
%48 = add nsw i32 %13, -1
%49 = zext i32 %48 to i64
%50 = zext i32 %13 to i64
br label %54
51: ; preds = %65, %30, %45
%52 = phi i32 [ 0, %45 ], [ 0, %30 ], [ %61, %65 ]
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
br label %68
54: ; preds = %47, %65
%55 = phi i64 [ 0, %47 ], [ %66, %65 ]
%56 = phi i32 [ 0, %47 ], [ %61, %65 ]
%57 = getelementptr inbounds i32, i32* %16, i64 %55
%58 = load i32, i32* %57
%59 = tail call i32 @print_events(i32 %58)
%60 = icmp eq i32 %59, -1
%61 = select i1 %60, i32 -1, i32 %56
%62 = icmp ult i64 %55, %49
br i1 %62, label %63, label %65
63: ; preds = %54
%64 = tail call i32 @putchar(i32 44)
br label %65
65: ; preds = %54, %63
%66 = add nuw nsw i64 %55, 1
%67 = icmp eq i64 %66, %50
br i1 %67, label %51, label %54
68: ; preds = %51, %32
%69 = phi i32 [ %52, %51 ], [ -1, %32 ]
ret i32 %69
}