#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 numToCheck, isPrime = 1, i;
  printf("Please enter an integer number to check(n ≤ 100): ");
  scanf("%d", &numToCheck);
  int maxDividor = sqrt(numToCheck);
  if (numToCheck == 1 || numToCheck == 0 || numToCheck < 0) {
    isPrime = 0;
    printf("Is %d prime? -> %s\n", numToCheck, isPrime ? "true" : "false");
    return 0;
  }
  for (i = 2; i <= maxDividor; i++) {
    if (numToCheck % i == 0) {
      isPrime = 0;
      break;
    }
  }
  printf("Is %d prime? -> %s\n", numToCheck, isPrime ? "true" : "false");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     118d <main+0x5d>
cmpl   $0x0,-0x8(%rbp)
je     118d <main+0x5d>
cmpl   $0x0,-0x8(%rbp)
jge    11c9 <main+0x99>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%ecx
lea    0xeb0(%rip),%rdx
lea    0xea4(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123b <main+0x10b>
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     120b <main+0xdb>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11f8 <main+0xc8>
movl   $0x0,-0xc(%rbp)
jmp    120b <main+0xdb>
jmp    11fd <main+0xcd>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d0 <main+0xa0>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%ecx
lea    0xe39(%rip),%rdx
lea    0xe2d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeef(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%edi
call   1050 <sqrt@plt>
mov    0x4(%rsp),%esi
cmp    $0x2,%esi
jge    1172 <main+0x42>
lea    0xecf(%rip),%rdi
lea    0xee1(%rip),%rdx
jmp    11b6 <main+0x86>
mov    %eax,%edi
lea    0xed1(%rip),%r9
cmp    $0x2,%eax
jl     11ac <main+0x7c>
neg    %edi
mov    $0x2,%ecx
lea    0xec3(%rip),%r8
xchg   %ax,%ax
mov    %esi,%eax
cltd
idiv   %ecx
test   %edx,%edx
je     11a9 <main+0x79>
lea    (%rdi,%rcx,1),%eax
add    $0x1,%eax
add    $0x1,%ecx
cmp    $0x1,%eax
jne    1190 <main+0x60>
jmp    11ac <main+0x7c>
mov    %r8,%r9
lea    0xe85(%rip),%rdi
mov    %r9,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [53 x i8] c"Please enter an integer number to check(n \E2\89\A4 100): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Is %d prime? -> %s\0A\00"
@.str.3 = [5 x i8] c"true\00"
@.str.4 = [6 x i8] c"false\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 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* %2)
%8 = load i32, i32* %2
%9 = call i32 @sqrt(i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 1
br i1 %11, label %18, label %12
12: ; preds = %0
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15, %12, %0
store i32 0, i32* %3
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %23)
store i32 0, i32* %1
br label %47
25: ; preds = %15
store i32 2, i32* %4
br label %26
26: ; preds = %37, %25
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = load i32, i32* %2
%32 = load i32, i32* %4
%33 = srem i32 %31, %32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 0, i32* %3
br label %40
36: ; preds = %30
br label %37
37: ; preds = %36
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %26
40: ; preds = %35, %26
%41 = load i32, i32* %2
%42 = load i32, i32* %3
%43 = icmp ne i32 %42, 0
%44 = zext i1 %43 to i64
%45 = select i1 %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %41, i8* %45)
store i32 0, i32* %1
br label %47
47: ; preds = %40, %18
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [53 x i8] c"Please enter an integer number to check(n \E2\89\A4 100): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Is %d prime? -> %s\0A\00"
@.str.3 = [5 x i8] c"true\00"
@.str.4 = [6 x i8] c"false\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 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 = load i32, i32* %1
%8 = icmp slt i32 %7, 2
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = icmp slt i32 %6, 2
br i1 %10, label %20, label %16
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %23
13: ; preds = %16
%14 = add nuw i32 %17, 1
%15 = icmp eq i32 %17, %6
br i1 %15, label %20, label %16
16: ; preds = %9, %13
%17 = phi i32 [ %14, %13 ], [ 2, %9 ]
%18 = srem i32 %7, %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %13
20: ; preds = %13, %16, %9
%21 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %9 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %16 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %13 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %21)
br label %23
23: ; preds = %20, %11
ret i32 0
}