#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*/ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t pid;
  int num;
  int i;
  if (!(pid = fork())) {
    printf("child 100 num:");
    for (num = 2; num < 100; num++) {
      int n = 1;
      for (i = 2; i < num; i++) {
        if (num % i == 0) {
          n = 0;
          break;
        }
      }
      if (n == 1) {
        printf(" %d ", num);
      }
    }
    printf("\n");
    return 0;
  }
  printf("parent 50 num:");
  for (num = 2; num < 50; num++) {
    int n = 1;
    for (i = 2; i < num; i++) {
      if (num % i == 0) {
        n = 0;
        break;
      }
    }
    if (n == 1) {
      printf(" %d ", num);
    }
  }
  printf("\n");
  wait(&pid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    1202 <main+0xd2>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    11e8 <main+0xb8>
movl   $0x1,-0x14(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ba <main+0x8a>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11a7 <main+0x77>
movl   $0x0,-0x14(%rbp)
jmp    11ba <main+0x8a>
jmp    11ac <main+0x7c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117f <main+0x4f>
cmpl   $0x1,-0x14(%rbp)
jne    11d5 <main+0xa5>
mov    -0xc(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11da <main+0xaa>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1167 <main+0x37>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b6 <main+0x186>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0xc(%rbp)
cmpl   $0x32,-0xc(%rbp)
jge    1298 <main+0x168>
movl   $0x1,-0x18(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126a <main+0x13a>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    1257 <main+0x127>
movl   $0x0,-0x18(%rbp)
jmp    126a <main+0x13a>
jmp    125c <main+0x12c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122f <main+0xff>
cmpl   $0x1,-0x18(%rbp)
jne    1285 <main+0x155>
mov    -0xc(%rbp),%esi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128a <main+0x15a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1217 <main+0xe7>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1040 <wait@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
je     11de <main+0x9e>
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%ebx
lea    0xe99(%rip),%r14
xor    %r15d,%r15d
jmp    1198 <main+0x58>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
add    $0xffffffff,%r15d
cmp    $0x32,%ebx
je     11c8 <main+0x88>
cmp    $0x3,%ebx
jb     1180 <main+0x40>
mov    $0x2,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
test   %edx,%edx
je     118c <main+0x4c>
add    $0x1,%ecx
lea    (%r15,%rcx,1),%eax
cmp    $0x2,%eax
jne    11b0 <main+0x70>
jmp    1180 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xc(%rsp),%rdi
call   1050 <wait@plt>
jmp    1252 <main+0x112>
lea    0xe1b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%ebx
lea    0xe17(%rip),%r14
xor    %r15d,%r15d
jmp    1218 <main+0xd8>
nopl   (%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
add    $0xffffffff,%r15d
cmp    $0x64,%ebx
je     1248 <main+0x108>
cmp    $0x3,%ebx
jb     1200 <main+0xc0>
mov    $0x2,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
test   %edx,%edx
je     120c <main+0xcc>
add    $0x1,%ecx
lea    (%r15,%rcx,1),%eax
cmp    $0x2,%eax
jne    1230 <main+0xf0>
jmp    1200 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"child 100 num:\00"
@.str.1 = [5 x i8] c" %d \00"
@.str.3 = [15 x i8] c"parent 50 num:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
store i32 %3, i32* %1
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %24
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %19
%8 = phi i32 [ 2, %5 ], [ %20, %19 ]
%9 = icmp ugt i32 %8, 2
br i1 %9, label %12, label %17
10: ; preds = %12
%11 = icmp eq i32 %16, %8
br i1 %11, label %17, label %12
12: ; preds = %7, %10
%13 = phi i32 [ %16, %10 ], [ 2, %7 ]
%14 = urem i32 %8, %13
%15 = icmp eq i32 %14, 0
%16 = add nuw nsw i32 %13, 1
br i1 %15, label %19, label %10
17: ; preds = %10, %7
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %19
19: ; preds = %12, %17
%20 = add nuw nsw i32 %8, 1
%21 = icmp eq i32 %20, 100
br i1 %21, label %22, label %7
22: ; preds = %19
%23 = tail call i32 @putchar(i32 10)
br label %44
24: ; preds = %0
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %38
%27 = phi i32 [ 2, %24 ], [ %39, %38 ]
%28 = icmp ugt i32 %27, 2
br i1 %28, label %31, label %36
29: ; preds = %31
%30 = icmp eq i32 %35, %27
br i1 %30, label %36, label %31
31: ; preds = %26, %29
%32 = phi i32 [ %35, %29 ], [ 2, %26 ]
%33 = urem i32 %27, %32
%34 = icmp eq i32 %33, 0
%35 = add nuw nsw i32 %32, 1
br i1 %34, label %38, label %29
36: ; preds = %29, %26
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %38
38: ; preds = %31, %36
%39 = add nuw nsw i32 %27, 1
%40 = icmp eq i32 %39, 50
br i1 %40, label %41, label %26
41: ; preds = %38
%42 = tail call i32 @putchar(i32 10)
%43 = call i32 @wait(i32* %1)
br label %44
44: ; preds = %41, %22
ret i32 0
}