#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() {
  int n, c;
  printf("Enter a number\n");
  scanf("%d", &n);
  printf("The number is: %d\n", n);
  if (n == 2)
    printf("Prime number.\n");
  else {
    for (c = 2; c <= n - 1; c++) {
      if (n % c == 0)
        break;
    }
    if (c != n)
      printf("Not prime.\n");
    else
      printf("Prime number.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jne    117b <main+0x5b>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ed <main+0xcd>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11bb <main+0x9b>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11a8 <main+0x88>
jmp    11bb <main+0x9b>
jmp    11ad <main+0x8d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <main+0x62>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     11da <main+0xba>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e8 <main+0xc8>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ed <main+0xcd>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xebc(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%ecx
lea    0xec5(%rip),%rdi
cmp    $0x2,%ecx
je     119d <main+0x6d>
mov    $0x2,%esi
jle    1192 <main+0x62>
mov    $0x2,%esi
nopl   0x0(%rax)
mov    %ecx,%eax
cltd
idiv   %esi
test   %edx,%edx
je     1192 <main+0x62>
add    $0x1,%esi
cmp    %esi,%ecx
jne    1180 <main+0x50>
jmp    119d <main+0x6d>
cmp    %ecx,%esi
je     119d <main+0x6d>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Enter a number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"The number is: %d\0A\00"
@.str.3 = [15 x i8] c"Prime number.\0A\00"
@.str.4 = [12 x i8] c"Not prime.\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 ([16 x i8], [16 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)
%6 = load i32, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %37
12: ; preds = %0
store i32 2, i32* %3
br label %13
13: ; preds = %25, %12
%14 = load i32, i32* %3
%15 = load i32, i32* %2
%16 = sub nsw i32 %15, 1
%17 = icmp sle i32 %14, %16
br i1 %17, label %18, label %28
18: ; preds = %13
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = srem i32 %19, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
br label %28
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %13
28: ; preds = %23, %13
%29 = load i32, i32* %3
%30 = load i32, i32* %2
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %36
34: ; preds = %28
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %32
br label %37
37: ; preds = %36, %10
ret i32 0
}

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