#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*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ isPrime(int);
int /*<<< orphan*/ wait(int *);
int parallel() {
  int i, j, pid;
  for (i = 1; i <= 3; i++) {
    pid = fork();
    if (pid == 0) {
      for (j = (i - 1) * (1500000 / 3) + 1; j <= i * (1500000 / 3); j++) {
        if (isPrime(j)) {
        }
      }
      exit(0);
    }
  }
  for (i = 1; i <= 3; i++) {
    wait(&i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<parallel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
jg     11d5 <parallel+0x95>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11c2 <parallel+0x82>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
imul   $0x7a120,%eax,%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
imul   $0x7a120,-0x4(%rbp),%ecx
cmp    %ecx,%eax
jg     11bb <parallel+0x7b>
mov    -0x8(%rbp),%edi
call   1030 <isPrime@plt>
cmp    $0x0,%rax
je     11a8 <parallel+0x68>
jmp    11a8 <parallel+0x68>
jmp    11ad <parallel+0x6d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117f <parallel+0x3f>
xor    %edi,%edi
call   1040 <exit@plt>
jmp    11c7 <parallel+0x87>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114f <parallel+0xf>
movl   $0x1,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
jg     11fd <parallel+0xbd>
lea    -0x4(%rbp),%rdi
call   1050 <wait@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11dc <parallel+0x9c>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parallel>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11a2 <parallel+0x62>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11a9 <parallel+0x69>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11b0 <parallel+0x70>
movl   $0x1,0x4(%rsp)
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <wait@plt>
mov    0x4(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
cmp    $0x3,%eax
jl     1180 <parallel+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%eax
jmp    11b5 <parallel+0x75>
mov    $0x2,%eax
jmp    11b5 <parallel+0x75>
mov    $0x3,%eax
mov    %eax,0x4(%rsp)
imul   $0x7a120,%eax,%r14d
add    $0xfff85ee1,%r14d
nopw   0x0(%rax,%rax,1)
lea    (%r14,%rbx,1),%edi
call   1030 <isPrime@plt>
add    $0x1,%ebx
cmp    $0x7a120,%ebx
jne    11d0 <parallel+0x90>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
define i32 @parallel() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 1, i32* %1
br label %4
4: ; preds = %33, %0
%5 = load i32, i32* %1
%6 = icmp sle i32 %5, 3
br i1 %6, label %7, label %36
7: ; preds = %4
%8 = call i32 (...) @fork()
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %32
11: ; preds = %7
%12 = load i32, i32* %1
%13 = sub nsw i32 %12, 1
%14 = mul nsw i32 %13, 500000
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %16
16: ; preds = %27, %11
%17 = load i32, i32* %2
%18 = load i32, i32* %1
%19 = mul nsw i32 %18, 500000
%20 = icmp sle i32 %17, %19
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = load i32, i32* %2
%23 = call i64 @isPrime(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
br label %26
26: ; preds = %25, %21
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %16
30: ; preds = %16
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %7
br label %33
33: ; preds = %32
%34 = load i32, i32* %1
%35 = add nsw i32 %34, 1
store i32 %35, i32* %1
br label %4
36: ; preds = %4
store i32 1, i32* %1
br label %37
37: ; preds = %42, %36
%38 = load i32, i32* %1
%39 = icmp sle i32 %38, 3
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = call i32 @wait(i32* %1)
br label %42
42: ; preds = %40
%43 = load i32, i32* %1
%44 = add nsw i32 %43, 1
store i32 %44, i32* %1
br label %37
45: ; preds = %37
ret i32 0
}

LLVM IR (-O2):
define i32 @parallel() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %0, %17, %20
%6 = phi i32 [ 1, %0 ], [ 2, %17 ], [ 3, %20 ]
store i32 %6, i32* %1
%7 = mul nuw nsw i32 %6, 500000
%8 = add nsw i32 %7, -499999
%9 = or i32 %7, 1
br label %10
10: ; preds = %5, %10
%11 = phi i32 [ %13, %10 ], [ %8, %5 ]
%12 = tail call i64 @isPrime(i32 %11)
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, %9
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %0
%18 = tail call i32 (...) @fork()
%19 = icmp eq i32 %18, 0
br i1 %19, label %5, label %20
20: ; preds = %17
%21 = tail call i32 (...) @fork()
%22 = icmp eq i32 %21, 0
br i1 %22, label %5, label %23
23: ; preds = %20
store i32 1, i32* %1
br label %24
24: ; preds = %23, %24
%25 = call i32 @wait(i32* %1)
%26 = load i32, i32* %1
%27 = add nsw i32 %26, 1
store i32 %27, i32* %1
%28 = icmp slt i32 %26, 3
br i1 %28, label %24, label %29
29: ; preds = %24
ret i32 0
}