#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 prime(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  printf("PRIMES: ENTER A NUMBER: ");
  int c;
  scanf("%d", &c);
  int v = prime(c);
  if (v == 1)
    printf("PRIME!\n");
  else
    printf("NOT A PRIME!\n");
  int y = c + 1;
  while (prime(y) != 1) {
    y += 1;
  }
  printf("Next Prime: %d\n", y);
  y = c - 1;
  while (prime(y) != 1 && y > 0) {
    y -= 1;
  }
  printf("Prev Prime: %d\n", y);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1050 <prime@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1185 <main+0x55>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1193 <main+0x63>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
je     11bb <main+0x8b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119c <main+0x6c>
mov    -0x10(%rbp),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <prime@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x11(%rbp)
je     11f7 <main+0xc7>
cmpl   $0x0,-0x10(%rbp)
setg   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1207 <main+0xd7>
jmp    1215 <main+0xe5>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d5 <main+0xa5>
mov    -0x10(%rbp),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec0(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
call   1060 <prime@plt>
cmp    $0x1,%eax
lea    0xecc(%rip),%rax
lea    0xebf(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%ebx
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %ebx,%edi
call   1060 <prime@plt>
cmp    $0x1,%eax
jne    1190 <main+0x50>
lea    0xe76(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%r14d
lea    -0x1(%r14),%ebx
mov    %ebx,%edi
call   1060 <prime@plt>
cmp    $0x2,%r14d
jl     11d9 <main+0x99>
cmp    $0x1,%eax
jne    11c0 <main+0x80>
lea    0xe4c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"PRIMES: ENTER A NUMBER: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"PRIME!\0A\00"
@.str.3 = [14 x i8] c"NOT A PRIME!\0A\00"
@.str.4 = [16 x i8] c"Next Prime: %d\0A\00"
@.str.5 = [16 x i8] c"Prev Prime: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = call i32 @prime(i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %18
18: ; preds = %22, %15
%19 = load i32, i32* %4
%20 = call i32 @prime(i32 %19)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %18
25: ; preds = %18
%26 = load i32, i32* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %2
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %4
br label %30
30: ; preds = %39, %25
%31 = load i32, i32* %4
%32 = call i32 @prime(i32 %31)
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %4
%36 = icmp sgt i32 %35, 0
br label %37
37: ; preds = %34, %30
%38 = phi i1 [ false, %30 ], [ %36, %34 ]
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = load i32, i32* %4
%41 = sub nsw i32 %40, 1
store i32 %41, i32* %4
br label %30
42: ; preds = %37
%43 = load i32, i32* %4
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"PRIMES: ENTER A NUMBER: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [16 x i8] c"Next Prime: %d\0A\00"
@.str.5 = [16 x i8] c"Prev Prime: %d\0A\00"
@str = [13 x i8] c"NOT A PRIME!\00"
@str.6 = [7 x i8] c"PRIME!\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 @prime(i32 %5)
%7 = icmp eq i32 %6, 1
%8 = select i1 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0)
%9 = call i32 @puts(i8* dereferenceable(1) %8)
%10 = load i32, i32* %1
br label %11
11: ; preds = %11, %0
%12 = phi i32 [ %10, %0 ], [ %13, %11 ]
%13 = add nsw i32 %12, 1
%14 = call i32 @prime(i32 %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %11
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%18 = load i32, i32* %1
br label %19
19: ; preds = %19, %16
%20 = phi i32 [ %18, %16 ], [ %21, %19 ]
%21 = add nsw i32 %20, -1
%22 = call i32 @prime(i32 %21)
%23 = icmp ne i32 %22, 1
%24 = icmp sgt i32 %20, 1
%25 = and i1 %24, %23
br i1 %25, label %19, label %26
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %21)
ret i32 0
}