#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() {
  int n, i;
  printf("Enter a number: \n");
  scanf("%d", &n);
  for (i = 2; i <= sqrt(n); i++)
    if (n % i == 0)
      printf("Not a prime");
  if (i - 1 == (int)sqrt(n))
    printf("It is a prime");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
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     11ac <main+0x7c>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1199 <main+0x69>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
jmp    119e <main+0x6e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1162 <main+0x32>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jne    11d6 <main+0xa6>
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaa(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
call   1060 <sqrt@plt>
mov    $0x1,%ebp
cmp    $0x2,%eax
jge    1195 <main+0x55>
mov    0x4(%rsp),%edi
call   1060 <sqrt@plt>
cmp    %eax,%ebp
jne    118c <main+0x4c>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x1,%ebp
lea    0xe62(%rip),%rbx
jmp    11b9 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1060 <sqrt@plt>
cmp    %eax,%ebp
jge    1173 <main+0x33>
add    $0x1,%ebp
mov    0x4(%rsp),%edi
mov    %edi,%eax
cltd
idiv   %ebp
test   %edx,%edx
jne    11b0 <main+0x70>
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@.str = [18 x i8] c"Enter a number: \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"Not a prime\00"
@.str.3 = [14 x i8] c"It is a prime\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 2, i32* %3
br label %6
6: ; preds = %19, %0
%7 = load i32, i32* %3
%8 = load i32, i32* %2
%9 = call i32 @sqrt(i32 %8)
%10 = icmp sle i32 %7, %9
br i1 %10, label %11, label %22
11: ; preds = %6
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = srem i32 %12, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
br label %19
19: ; preds = %18
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %6
22: ; preds = %6
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
%25 = load i32, i32* %2
%26 = call i32 @sqrt(i32 %25)
%27 = icmp eq i32 %24, %26
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"Not a prime\00"
@.str.3 = [14 x i8] c"It is a prime\00"
@str = [17 x i8] c"Enter a number: \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%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 @sqrt(i32 %5)
%7 = icmp slt i32 %6, 2
br i1 %7, label %21, label %8
8: ; preds = %0, %16
%9 = phi i32 [ %18, %16 ], [ 2, %0 ]
%10 = load i32, i32* %1
%11 = srem i32 %10, %9
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* %1
br label %16
16: ; preds = %8, %13
%17 = phi i32 [ %10, %8 ], [ %15, %13 ]
%18 = add nuw nsw i32 %9, 1
%19 = call i32 @sqrt(i32 %17)
%20 = icmp slt i32 %9, %19
br i1 %20, label %8, label %21
21: ; preds = %16, %0
%22 = phi i32 [ 1, %0 ], [ %9, %16 ]
%23 = load i32, i32* %1
%24 = call i32 @sqrt(i32 %23)
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
ret i32 0
}