#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*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  int i, j, n, mark;
  pid_t pid;
  for (n = 0; n < 3; n++) {
    pid = fork();
    if (pid < 0) {
      perror("fork()");
      exit(1);
    }
    if (pid == 0) {
      for (i = 30000000 + n; i <= 30000200; i += 3) {
        mark = 1;
        for (j = 2; j < i / 2; j++) {
          if (i % j == 0) {
            mark = 0;
            break;
          }
        }
        if (mark)
          printf("[%d]%d is a primer.\n", n, i);
      }
      exit(0);
    }
  }
  for (n = 0; n < 3; n++)
    wait(NULL);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    1263 <main+0x113>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    119c <main+0x4c>
lea    0xe73(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1250 <main+0x100>
mov    -0x10(%rbp),%eax
add    $0x1c9c380,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x1c9c448,-0x8(%rbp)
jg     1249 <main+0xf9>
movl   $0x1,-0x14(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    121a <main+0xca>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1207 <main+0xb7>
movl   $0x0,-0x14(%rbp)
jmp    121a <main+0xca>
jmp    120c <main+0xbc>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11cd <main+0x7d>
cmpl   $0x0,-0x14(%rbp)
je     1236 <main+0xe6>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xdd6(%rip),%rdi
call   1030 <printf@plt>
jmp    123b <main+0xeb>
mov    -0x8(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x8(%rbp)
jmp    11b2 <main+0x62>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    1255 <main+0x105>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1166 <main+0x16>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    128b <main+0x13b>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    126a <main+0x11a>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1186 <main+0x36>
je     11a4 <main+0x54>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1186 <main+0x36>
mov    $0x1,%r14d
je     11a4 <main+0x54>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jns    119c <main+0x4c>
lea    0xe73(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    $0x2,%r14d
jne    1207 <main+0xb7>
lea    0x1c9c380(%r14),%ebx
lea    0xe55(%rip),%r15
jmp    11cd <main+0x7d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x3(%rbx),%eax
cmp    $0x1c9c446,%ebx
mov    %eax,%ebx
jae    1200 <main+0xb0>
mov    %ebx,%ecx
shr    %ecx
mov    $0x2,%esi
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
test   %edx,%edx
je     11c0 <main+0x70>
add    $0x1,%esi
cmp    %esi,%ecx
jne    11e0 <main+0x90>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
jmp    11c0 <main+0x70>
xor    %edi,%edi
call   1050 <exit@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"fork()\00"
@.str.1 = [21 x i8] c"[%d]%d is a primer.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %4
br label %7
7: ; preds = %56, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %59
10: ; preds = %7
%11 = call i64 (...) @fork()
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = load i64, i64* %6
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %55
20: ; preds = %17
%21 = load i32, i32* %4
%22 = add nsw i32 30000000, %21
store i32 %22, i32* %2
br label %23
23: ; preds = %50, %20
%24 = load i32, i32* %2
%25 = icmp sle i32 %24, 30000200
br i1 %25, label %26, label %53
26: ; preds = %23
store i32 1, i32* %5
store i32 2, i32* %3
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %3
%29 = load i32, i32* %2
%30 = sdiv i32 %29, 2
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %42
32: ; preds = %27
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = srem i32 %33, %34
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 0, i32* %5
br label %42
38: ; preds = %32
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %27
42: ; preds = %37, %27
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* %4
%47 = load i32, i32* %2
%48 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %46, i32 %47)
br label %49
49: ; preds = %45, %42
br label %50
50: ; preds = %49
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 3
store i32 %52, i32* %2
br label %23
53: ; preds = %23
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %17
br label %56
56: ; preds = %55
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %7
59: ; preds = %7
store i32 0, i32* %4
br label %60
60: ; preds = %65, %59
%61 = load i32, i32* %4
%62 = icmp slt i32 %61, 3
br i1 %62, label %63, label %68
63: ; preds = %60
%64 = call i32 @wait(i32* null)
br label %65
65: ; preds = %63
%66 = load i32, i32* %4
%67 = add nsw i32 %66, 1
store i32 %67, i32* %4
br label %60
68: ; preds = %60
%69 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"fork()\00"
@.str.1 = [21 x i8] c"[%d]%d is a primer.\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %33, %28, %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = icmp eq i64 %1, 0
br i1 %7, label %8, label %28
8: ; preds = %6, %31, %36
%9 = phi i32 [ 0, %6 ], [ 1, %31 ], [ 2, %36 ]
%10 = or i32 %9, 30000000
br label %11
11: ; preds = %23, %8
%12 = phi i32 [ %24, %23 ], [ %10, %8 ]
%13 = lshr i32 %12, 1
br label %16
14: ; preds = %16
%15 = icmp eq i32 %20, %13
br i1 %15, label %21, label %16
16: ; preds = %11, %14
%17 = phi i32 [ %20, %14 ], [ 2, %11 ]
%18 = urem i32 %12, %17
%19 = icmp eq i32 %18, 0
%20 = add nuw nsw i32 %17, 1
br i1 %19, label %23, label %14
21: ; preds = %14
%22 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %12)
br label %23
23: ; preds = %16, %21
%24 = add nuw nsw i32 %12, 3
%25 = icmp ult i32 %12, 30000198
br i1 %25, label %11, label %26
26: ; preds = %23
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %6
%29 = tail call i64 (...) @fork()
%30 = icmp slt i64 %29, 0
br i1 %30, label %3, label %31
31: ; preds = %28
%32 = icmp eq i64 %29, 0
br i1 %32, label %8, label %33
33: ; preds = %31
%34 = tail call i64 (...) @fork()
%35 = icmp slt i64 %34, 0
br i1 %35, label %3, label %36
36: ; preds = %33
%37 = icmp eq i64 %34, 0
br i1 %37, label %8, label %38
38: ; preds = %36
%39 = tail call i32 @wait(i32* null)
%40 = tail call i32 @wait(i32* null)
%41 = tail call i32 @wait(i32* null)
%42 = tail call i32 @exit(i32 0)
unreachable
}