#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 *);
double sqrt(int);
int main() {
  int i, n;
  int flag;
  double a;
  printf("enter an integer:");
  scanf("%d", &n);
  a = sqrt(n);
  for (i = 2; i < a; i++)
    if (n % i == 0)
      break;
  if (i > a)
    printf("%d is a prime number", n);
  else
    printf("%d is not a prime number", n);
  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    0xebe(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x2,-0x8(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ad <main+0x7d>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    119a <main+0x6a>
jmp    11ad <main+0x7d>
jmp    119f <main+0x6f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1171 <main+0x41>
cvtsi2sdl -0x8(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11d3 <main+0xa3>
mov    -0xc(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e4 <main+0xb4>
mov    -0xc(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%edi
call   1050 <sqrt@plt>
movsd  0xe9f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1199 <main+0x69>
mov    0x4(%rsp),%ecx
test   $0x1,%cl
je     1199 <main+0x69>
mov    $0x3,%esi
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm1,%xmm1
cvtsi2sd %esi,%xmm1
ucomisd %xmm1,%xmm0
jbe    1199 <main+0x69>
mov    %ecx,%eax
cltd
idiv   %esi
add    $0x1,%esi
test   %edx,%edx
jne    1180 <main+0x50>
ucomisd %xmm0,%xmm1
mov    0x4(%rsp),%esi
lea    0xe75(%rip),%rax
lea    0xe83(%rip),%rdi
cmova  %rax,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"enter an integer:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"%d is a prime number\00"
@.str.3 = [25 x i8] c"%d is not a prime number\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 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* %3)
%8 = load i32, i32* %3
%9 = call double @sqrt(i32 %8)
store double %9, double* %5
store i32 2, i32* %2
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %2
%12 = sitofp i32 %11 to double
%13 = load double, double* %5
%14 = fcmp olt double %12, %13
br i1 %14, label %15, label %25
15: ; preds = %10
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = srem i32 %16, %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %25
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %10
25: ; preds = %20, %10
%26 = load i32, i32* %2
%27 = sitofp i32 %26 to double
%28 = load double, double* %5
%29 = fcmp ogt double %27, %28
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %36
33: ; preds = %25
%34 = load i32, i32* %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %30
ret i32 0
}

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