#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 main(void) {
  int n, count = 0;
  printf("Enter any number to test whether it is prime or not: ");
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    if (n % i == 0)
      count++;
  }
  if (count == 2) {
    printf("\n%d is a prime number", n);
  } else {
    printf("\n%d is not a prime number", n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeeb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1193 <main+0x73>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    1180 <main+0x60>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1185 <main+0x65>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115b <main+0x3b>
cmpl   $0x2,-0xc(%rbp)
jne    11b3 <main+0x93>
mov    -0x8(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c4 <main+0xa4>
mov    -0x8(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xefa(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    11b0 <main+0x90>
cmp    $0x1,%esi
jne    115a <main+0x3a>
mov    $0x1,%ecx
jmp    1191 <main+0x71>
mov    %esi,%r8d
and    $0xfffffffe,%r8d
xor    %ebx,%ebx
mov    $0x1,%ecx
nopl   0x0(%rax,%rax,1)
mov    %esi,%eax
cltd
idiv   %ecx
cmp    $0x1,%edx
adc    $0x0,%ebx
lea    0x1(%rcx),%edi
mov    %esi,%eax
cltd
idiv   %edi
cmp    $0x1,%edx
adc    $0x0,%ebx
add    $0x2,%ecx
cmp    %r8d,%edi
jne    1170 <main+0x50>
test   $0x1,%sil
je     11a2 <main+0x82>
mov    %esi,%eax
cltd
idiv   %ecx
cmp    $0x1,%edx
adc    $0x0,%ebx
cmp    $0x2,%ebx
jne    11b0 <main+0x90>
lea    0xe8b(%rip),%rdi
jmp    11b7 <main+0x97>
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [54 x i8] c"Enter any number to test whether it is prime or not: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"\0A%d is a prime number\00"
@.str.3 = [26 x i8] c"\0A%d is not a prime number\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 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)
store i32 1, i32* %4
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %4
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = srem i32 %12, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %11
br label %20
20: ; preds = %19
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %7
23: ; preds = %7
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %32
29: ; preds = %23
%30 = load i32, i32* %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %26
ret i32 0
}

LLVM IR (-O2):
@.str = [54 x i8] c"Enter any number to test whether it is prime or not: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"\0A%d is a prime number\00"
@.str.3 = [26 x i8] c"\0A%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 ([54 x i8], [54 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 = icmp slt i32 %5, 1
br i1 %6, label %41, label %7
7: ; preds = %0
%8 = and i32 %5, 1
%9 = icmp eq i32 %5, 1
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = and i32 %5, -2
br label %25
12: ; preds = %25, %7
%13 = phi i32 [ undef, %7 ], [ %37, %25 ]
%14 = phi i32 [ 1, %7 ], [ %38, %25 ]
%15 = phi i32 [ 0, %7 ], [ %37, %25 ]
%16 = icmp eq i32 %8, 0
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = srem i32 %5, %14
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %15, %20
br label %22
22: ; preds = %12, %17
%23 = phi i32 [ %13, %12 ], [ %21, %17 ]
%24 = icmp eq i32 %23, 2
br i1 %24, label %42, label %41
25: ; preds = %25, %10
%26 = phi i32 [ 1, %10 ], [ %38, %25 ]
%27 = phi i32 [ 0, %10 ], [ %37, %25 ]
%28 = phi i32 [ 0, %10 ], [ %39, %25 ]
%29 = srem i32 %5, %26
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
%32 = add nuw nsw i32 %27, %31
%33 = add nuw i32 %26, 1
%34 = srem i32 %5, %33
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i32
%37 = add nuw nsw i32 %32, %36
%38 = add nuw i32 %26, 2
%39 = add i32 %28, 2
%40 = icmp eq i32 %39, %11
br i1 %40, label %12, label %25
41: ; preds = %0, %22
br label %42
42: ; preds = %22, %41
%43 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), %41 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), %22 ]
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %43, i32 %5)
ret i32 0
}