#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 isPrime(int, int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int input_num;
  int Primes[10000] = {2};
  int prime_test = 3;
  int cnt = 1;
  printf("Enter a number to judge if it is a Prime:");
  scanf("%d", &input_num);
  while (prime_test < input_num) {
    int judge_Prime = 0;
    for (int i = 2; i < prime_test; i++) {
      if (prime_test % i == 0) {
        judge_Prime = 1;
        break;
      }
    }
    if (judge_Prime == 0) {
      Primes[cnt] = prime_test;
      cnt++;
    }
    prime_test++;
  }
  if (isPrime(input_num, Primes, cnt - 1) == 1) {
    printf("Not a Prime\n");
  } else {
    printf("Yes, it is a Prime\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x9c50(%rbp),%rdi
xor    %esi,%esi
mov    $0x9c40,%edx
call   1040 <memset@plt>
movl   $0x2,-0x9c50(%rbp)
movl   $0x3,-0x9c54(%rbp)
movl   $0x1,-0x9c58(%rbp)
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x9c54(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1256 <main+0x116>
movl   $0x0,-0x9c5c(%rbp)
movl   $0x2,-0x9c60(%rbp)
mov    -0x9c60(%rbp),%eax
cmp    -0x9c54(%rbp),%eax
jge    1212 <main+0xd2>
mov    -0x9c54(%rbp),%eax
cltd
idivl  -0x9c60(%rbp)
cmp    $0x0,%edx
jne    11f9 <main+0xb9>
movl   $0x1,-0x9c5c(%rbp)
jmp    1212 <main+0xd2>
jmp    11fe <main+0xbe>
mov    -0x9c60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c60(%rbp)
jmp    11c2 <main+0x82>
cmpl   $0x0,-0x9c5c(%rbp)
jne    1242 <main+0x102>
mov    -0x9c54(%rbp),%ecx
movslq -0x9c58(%rbp),%rax
mov    %ecx,-0x9c50(%rbp,%rax,4)
mov    -0x9c58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c58(%rbp)
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
jmp    119f <main+0x5f>
mov    -0x8(%rbp),%edi
lea    -0x9c50(%rbp),%rsi
mov    -0x9c58(%rbp),%edx
sub    $0x1,%edx
call   1050 <isPrime@plt>
cmp    $0x1,%eax
jne    1288 <main+0x148>
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
jmp    1294 <main+0x154>
lea    0xdab(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x9c58,%rsp
lea    0x10(%rsp),%rdi
mov    $0x9c40,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x2,0x10(%rsp)
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%r8d
cmp    $0x4,%edi
jl     11e4 <main+0x94>
mov    $0x3,%esi
mov    $0x1,%r8d
mov    $0xffffffff,%r9d
jmp    11bb <main+0x6b>
nop
add    $0x1,%esi
add    $0xffffffff,%r9d
cmp    %edi,%esi
je     11e4 <main+0x94>
mov    $0x2,%ecx
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
test   %edx,%edx
je     11b0 <main+0x60>
add    $0x1,%ecx
lea    (%r9,%rcx,1),%eax
cmp    $0x2,%eax
jne    11c0 <main+0x70>
movslq %r8d,%r8
mov    %esi,0x10(%rsp,%r8,4)
add    $0x1,%r8d
jmp    11b0 <main+0x60>
add    $0xffffffff,%r8d
lea    0x10(%rsp),%rsi
mov    %r8d,%edx
call   1060 <isPrime@plt>
cmp    $0x1,%eax
lea    0xe41(%rip),%rax
lea    0xe27(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x9c58,%rsp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Enter a number to judge if it is a Prime:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Not a Prime\0A\00"
@.str.3 = [20 x i8] c"Yes, it is a Prime\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10000 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [10000 x i32]* %3 to i8*
%9 = bitcast i8* %8 to <{ i32, [9999 x i32] }>*
%10 = getelementptr inbounds <{ i32, [9999 x i32] }>, <{ i32, [9999 x i32] }>* %9, i32 0, i32 0
store i32 2, i32* %10
store i32 3, i32* %4
store i32 1, i32* %5
%11 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %13
13: ; preds = %42, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %45
17: ; preds = %13
store i32 0, i32* %6
store i32 2, i32* %7
br label %18
18: ; preds = %29, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %4
%24 = load i32, i32* %7
%25 = srem i32 %23, %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 1, i32* %6
br label %32
28: ; preds = %22
br label %29
29: ; preds = %28
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %18
32: ; preds = %27, %18
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i32, i32* %4
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 %38
store i32 %36, i32* %39
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %42
42: ; preds = %35, %32
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %13
45: ; preds = %13
%46 = load i32, i32* %2
%47 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 0
%48 = load i32, i32* %5
%49 = sub nsw i32 %48, 1
%50 = call i32 @isPrime(i32 %46, i32* %47, i32 %49)
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %56
54: ; preds = %45
%55 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
ret i32 0
}

LLVM IR (-O2):
@.str = [42 x i8] c"Enter a number to judge if it is a Prime:\00"
@.str.1 = [3 x i8] c"%d\00"
@str = [19 x i8] c"Yes, it is a Prime\00"
@str.4 = [12 x i8] c"Not a Prime\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [10000 x i32]* %2 to i8*
%5 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 0
store i32 2, i32* %5
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 3
br i1 %9, label %10, label %28
10: ; preds = %0, %24
%11 = phi i32 [ %25, %24 ], [ 1, %0 ]
%12 = phi i32 [ %26, %24 ], [ 3, %0 ]
br label %15
13: ; preds = %15
%14 = icmp eq i32 %19, %12
br i1 %14, label %20, label %15
15: ; preds = %10, %13
%16 = phi i32 [ %19, %13 ], [ 2, %10 ]
%17 = urem i32 %12, %16
%18 = icmp eq i32 %17, 0
%19 = add nuw nsw i32 %16, 1
br i1 %18, label %24, label %13
20: ; preds = %13
%21 = sext i32 %11 to i64
%22 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %21
store i32 %12, i32* %22
%23 = add nsw i32 %11, 1
br label %24
24: ; preds = %15, %20
%25 = phi i32 [ %23, %20 ], [ %11, %15 ]
%26 = add nuw nsw i32 %12, 1
%27 = icmp eq i32 %26, %8
br i1 %27, label %28, label %10
28: ; preds = %24, %0
%29 = phi i32 [ 1, %0 ], [ %25, %24 ]
%30 = add nsw i32 %29, -1
%31 = call i32 @isPrime(i32 %8, i32* %5, i32 %30)
%32 = icmp eq i32 %31, 1
%33 = select i1 %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0)
%34 = call i32 @puts(i8* dereferenceable(1) %33)
ret i32 0
}