#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int sqrt(int);
int main() {
  printf("Prime Number Checker \n");
  printf("\n");
  int number;
  printf("Enter a Natural Number (Greater than 1): \n");
  scanf("%d", &number);
  printf("\n");
  if (number < 2) {
    printf("Invalid Input \n");
    printf("\n");
    return 1;
  }
  for (int i = 2; i <= sqrt(number); i++) {
    if (!(number % i)) {
      printf("Number (%d) is Not a Prime Number \n", number);
      printf("\n");
      return 1;
    }
  }
  printf("Number (%d) is a Prime Number \n", number);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11b9 <main+0x89>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124f <main+0x11f>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     1229 <main+0xf9>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1216 <main+0xe6>
mov    -0x8(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124f <main+0x11f>
jmp    121b <main+0xeb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c0 <main+0x90>
mov    -0x8(%rbp),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeeb(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xeeb(%rip),%rdi
call   1040 <puts@plt>
lea    0xe82(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%edi
cmp    $0x2,%edi
jge    11a9 <main+0x59>
lea    0xee5(%rip),%rdi
call   1040 <puts@plt>
jmp    11ff <main+0xaf>
call   1070 <sqrt@plt>
cmp    $0x2,%eax
jl     11db <main+0x8b>
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    0xc(%rsp),%esi
mov    %esi,%eax
cltd
idiv   %ebx
test   %edx,%edx
je     11f1 <main+0xa1>
mov    %esi,%edi
call   1070 <sqrt@plt>
cmp    %eax,%ebx
jl     11c0 <main+0x70>
mov    0xc(%rsp),%esi
lea    0xe41(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1204 <main+0xb4>
lea    0xe0b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Prime Number Checker \0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [43 x i8] c"Enter a Natural Number (Greater than 1): \0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [16 x i8] c"Invalid Input \0A\00"
@.str.5 = [36 x i8] c"Number (%d) is Not a Prime Number \0A\00"
@.str.6 = [32 x i8] c"Number (%d) is a Prime Number \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %37
14: ; preds = %0
store i32 2, i32* %3
br label %15
15: ; preds = %30, %14
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = call i32 @sqrt(i32 %17)
%19 = icmp sle i32 %16, %18
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = srem i32 %21, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %37
29: ; preds = %20
br label %30
30: ; preds = %29
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %15
33: ; preds = %15
%34 = load i32, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %37
37: ; preds = %33, %25, %11
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [36 x i8] c"Number (%d) is Not a Prime Number \0A\00"
@.str.6 = [32 x i8] c"Number (%d) is a Prime Number \0A\00"
@str = [22 x i8] c"Prime Number Checker \00"
@str.7 = [42 x i8] c"Enter a Natural Number (Greater than 1): \00"
@str.8 = [15 x i8] c"Invalid Input \00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @putchar(i32 10)
%4 = bitcast i32* %1 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.7, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%7 = call i32 @putchar(i32 10)
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 2
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i32 @sqrt(i32 %8)
%12 = icmp slt i32 %11, 2
br i1 %12, label %26, label %19
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
br label %29
15: ; preds = %19
%16 = add nuw nsw i32 %20, 1
%17 = call i32 @sqrt(i32 %21)
%18 = icmp slt i32 %20, %17
br i1 %18, label %19, label %26
19: ; preds = %10, %15
%20 = phi i32 [ %16, %15 ], [ 2, %10 ]
%21 = load i32, i32* %1
%22 = srem i32 %21, %20
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %15
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %29
26: ; preds = %15, %10
%27 = load i32, i32* %1
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %24, %26, %13
%30 = phi i32 [ 1, %13 ], [ 0, %26 ], [ 1, %24 ]
%31 = call i32 @putchar(i32 10)
ret i32 %30
}