#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*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, ...);
int main() {
  int fd[2], nbytes;
  pid_t pid;
  char readbuffer[14];
  char string[] = "Hello World! \n";
  if (pipe(fd) < 0) {
    perror("pipe error");
    exit(1);
  }
  if ((pid = fork()) < 0) {
    perror("fork error");
    exit(1);
  }
  if (pid) {
    int n;
    char rasp[3];
    printf("Numarul este: ");
    scanf("%d", &n);
    write(fd[1], &n, 4);
    wait(NULL);
    read(fd[0], rasp, 3);
    close(fd[0]);
    close(fd[1]);
    printf("\n%s\n", rasp);
  } else {
    int nr, i, ok = 1;
    char raspuns[3];
    strcpy(raspuns, 0);
    read(fd[0], &nr, 4);
    if (nr == 2)
      strcpy(raspuns, "YES");
    if (nr % 2 == 0)
      strcpy(raspuns, "NO");
    else {
      if (nr != 3)
        for (i = 3; i <= nr / 2; i = i + 2)
          if (nr % i == 0)
            ok = 0;
      if (ok)
        strcpy(raspuns, "YES");
      else
        strcpy(raspuns, "NO");
    }
    write(fd[1], raspuns, strlen(raspuns));
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe2a(%rip),%rax
mov    %rax,-0x35(%rbp)
mov    0xe28(%rip),%eax
mov    %eax,-0x2d(%rbp)
mov    0xe22(%rip),%ax
mov    %ax,-0x29(%rbp)
mov    0xe1a(%rip),%al
mov    %al,-0x27(%rbp)
lea    -0xc(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jge    1220 <main+0x60>
lea    0xdfe(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    124b <main+0x8b>
lea    0xdde(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
je     12ca <main+0x10a>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdc9(%rip),%rdi
lea    -0x3c(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x8(%rbp),%edi
lea    -0x3c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <write@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <wait@plt>
mov    -0xc(%rbp),%edi
lea    -0x3f(%rbp),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1090 <read@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
lea    -0x3f(%rbp),%rsi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13f4 <main+0x234>
movl   $0x1,-0x4c(%rbp)
lea    -0x4f(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1090 <read@plt>
cmpl   $0x2,-0x44(%rbp)
jne    130b <main+0x14b>
lea    -0x4f(%rbp),%rdi
lea    0xd36(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x44(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1334 <main+0x174>
lea    -0x4f(%rbp),%rdi
lea    0xd16(%rip),%rsi
call   1030 <strcpy@plt>
jmp    13c6 <main+0x206>
cmpl   $0x3,-0x44(%rbp)
je     1392 <main+0x1d2>
movl   $0x3,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x44(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
jg     138d <main+0x1cd>
mov    -0x44(%rbp),%eax
cltd
idivl  -0x48(%rbp)
cmp    $0x0,%edx
jne    137a <main+0x1ba>
movl   $0x0,-0x4c(%rbp)
jmp    137f <main+0x1bf>
mov    -0x48(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x48(%rbp)
jmp    1345 <main+0x185>
jmp    1392 <main+0x1d2>
cmpl   $0x0,-0x4c(%rbp)
je     13b1 <main+0x1f1>
lea    -0x4f(%rbp),%rdi
lea    0xc95(%rip),%rsi
call   1030 <strcpy@plt>
jmp    13c1 <main+0x201>
lea    -0x4f(%rbp),%rdi
lea    0xc84(%rip),%rsi
call   1030 <strcpy@plt>
jmp    13c6 <main+0x206>
mov    -0x8(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    -0x4f(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x4f(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
mov    $0x0,%al
call   1040 <write@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
call   1080 <pipe@plt>
test   %rax,%rax
js     126f <main+0xaf>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
js     1278 <main+0xb8>
je     128e <main+0xce>
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe21(%rip),%rdi
lea    0xc(%rsp),%rbx
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    0x14(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <write@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
mov    0x10(%rsp),%edi
lea    0x9(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1090 <read@plt>
mov    0x10(%rsp),%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
lea    0xdcc(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd8a(%rip),%rdi
jmp    127f <main+0xbf>
lea    0xd8c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0x9(%rsp),%rdi
xor    %esi,%esi
call   1030 <strcpy@plt>
mov    0x10(%rsp),%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1090 <read@plt>
mov    0xc(%rsp),%ecx
cmp    $0x2,%ecx
jne    12cd <main+0x10d>
lea    0xd6e(%rip),%rsi
lea    0x9(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0xc(%rsp),%ecx
test   $0x1,%cl
jne    12db <main+0x11b>
lea    0xd58(%rip),%rsi
jmp    1324 <main+0x164>
lea    0xd4b(%rip),%rsi
cmp    $0x3,%ecx
je     1324 <main+0x164>
cmp    $0x6,%ecx
jl     1324 <main+0x164>
mov    %ecx,%esi
shr    $0x1f,%esi
add    %ecx,%esi
sar    %esi
mov    $0x3,%ebp
mov    $0x1,%edi
mov    %ecx,%eax
cltd
idiv   %ebp
test   %edx,%edx
cmove  %edx,%edi
add    $0x2,%ebp
cmp    %esi,%ebp
jle    12ff <main+0x13f>
test   %edi,%edi
lea    0xd18(%rip),%rax
lea    0xd0d(%rip),%rsi
cmove  %rax,%rsi
lea    0x9(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    0x14(%rsp),%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <write@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.main.string = [15 x i8] c"Hello World! \0A\00"
@.str = [11 x i8] c"pipe error\00"
@.str.1 = [11 x i8] c"fork error\00"
@.str.2 = [15 x i8] c"Numarul este: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [5 x i8] c"\0A%s\0A\00"
@.str.5 = [4 x i8] c"YES\00"
@.str.6 = [3 x i8] c"NO\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i64
%5 = alloca [14 x i8]
%6 = alloca [15 x i8]
%7 = alloca i32
%8 = alloca [3 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [3 x i8]
store i32 0, i32* %1
%13 = bitcast [15 x i8]* %6 to i8*
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%15 = call i64 @pipe(i32* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = call i64 (...) @fork()
store i64 %21, i64* %4
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = load i64, i64* %4
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %48
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 (i32, ...) @write(i32 %33, i32* %7, i32 4)
%35 = call i32 @wait(i32* null)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%39 = call i32 (i32, ...) @read(i32 %37, i8* %38, i32 3)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%44 = load i32, i32* %43
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %46)
br label %104
48: ; preds = %26
store i32 1, i32* %11
%49 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%50 = call i32 @strcpy(i8* %49, i8* null)
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%52 = load i32, i32* %51
%53 = call i32 (i32, ...) @read(i32 %52, i32* %9, i32 4)
%54 = load i32, i32* %9
%55 = icmp eq i32 %54, 2
br i1 %55, label %56, label %59
56: ; preds = %48
%57 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%58 = call i32 @strcpy(i8* %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %59
59: ; preds = %56, %48
%60 = load i32, i32* %9
%61 = srem i32 %60, 2
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%65 = call i32 @strcpy(i8* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %96
66: ; preds = %59
%67 = load i32, i32* %9
%68 = icmp ne i32 %67, 3
br i1 %68, label %69, label %86
69: ; preds = %66
store i32 3, i32* %10
br label %70
70: ; preds = %82, %69
%71 = load i32, i32* %10
%72 = load i32, i32* %9
%73 = sdiv i32 %72, 2
%74 = icmp sle i32 %71, %73
br i1 %74, label %75, label %85
75: ; preds = %70
%76 = load i32, i32* %9
%77 = load i32, i32* %10
%78 = srem i32 %76, %77
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %75
store i32 0, i32* %11
br label %81
81: ; preds = %80, %75
br label %82
82: ; preds = %81
%83 = load i32, i32* %10
%84 = add nsw i32 %83, 2
store i32 %84, i32* %10
br label %70
85: ; preds = %70
br label %86
86: ; preds = %85, %66
%87 = load i32, i32* %11
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%91 = call i32 @strcpy(i8* %90, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %95
92: ; preds = %86
%93 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%94 = call i32 @strcpy(i8* %93, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %95
95: ; preds = %92, %89
br label %96
96: ; preds = %95, %63
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%98 = load i32, i32* %97
%99 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%100 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%101 = call i32 @strlen(i8* %100)
%102 = call i32 (i32, ...) @write(i32 %98, i8* %99, i32 %101)
%103 = call i32 @exit(i32 0)
unreachable
104: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"pipe error\00"
@.str.1 = [11 x i8] c"fork error\00"
@.str.2 = [15 x i8] c"Numarul este: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [5 x i8] c"\0A%s\0A\00"
@.str.5 = [4 x i8] c"YES\00"
@.str.6 = [3 x i8] c"NO\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = alloca i32
%5 = alloca [3 x i8]
%6 = bitcast [2 x i32]* %1 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i64 (...) @fork()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = icmp eq i64 %14, 0
br i1 %20, label %37, label %21
21: ; preds = %19
%22 = bitcast i32* %2 to i8*
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 (i32, ...) @write(i32 %27, i32* %2, i32 4)
%29 = call i32 @wait(i32* null)
%30 = load i32, i32* %7
%31 = call i32 (i32, ...) @read(i32 %30, i8* %23, i32 3)
%32 = load i32, i32* %7
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* %26
%35 = call i32 @close(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %23)
ret i32 0
37: ; preds = %19
%38 = bitcast i32* %4 to i8*
%39 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%40 = call i32 @strcpy(i8* %39, i8* null)
%41 = load i32, i32* %7
%42 = call i32 (i32, ...) @read(i32 %41, i32* %4, i32 4)
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 2
br i1 %44, label %45, label %48
45: ; preds = %37
%46 = call i32 @strcpy(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* %4
br label %48
48: ; preds = %45, %37
%49 = phi i32 [ %47, %45 ], [ %43, %37 ]
%50 = and i32 %49, 1
%51 = icmp eq i32 %50, 0
br i1 %51, label %68, label %52
52: ; preds = %48
%53 = icmp eq i32 %49, 3
br i1 %53, label %68, label %54
54: ; preds = %52
%55 = sdiv i32 %49, 2
%56 = icmp slt i32 %49, 6
br i1 %56, label %68, label %57
57: ; preds = %54, %57
%58 = phi i32 [ %62, %57 ], [ 1, %54 ]
%59 = phi i32 [ %63, %57 ], [ 3, %54 ]
%60 = srem i32 %49, %59
%61 = icmp eq i32 %60, 0
%62 = select i1 %61, i32 0, i32 %58
%63 = add nuw nsw i32 %59, 2
%64 = icmp sgt i32 %63, %55
br i1 %64, label %65, label %57
65: ; preds = %57
%66 = icmp eq i32 %62, 0
%67 = select i1 %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0)
br label %68
68: ; preds = %65, %52, %54, %48
%69 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), %48 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), %54 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), %52 ], [ %67, %65 ]
%70 = call i32 @strcpy(i8* %39, i8* %69)
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%72 = load i32, i32* %71
%73 = call i32 @strlen(i8* %39)
%74 = call i32 (i32, ...) @write(i32 %72, i8* %39, i32 %73)
%75 = call i32 @exit(i32 0)
unreachable
}