#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 num, i = 0, test = 1, prime = 1;
  printf("Input: \n");
  do {
    printf("Enter a number between 2 and 1000: ");
    scanf("%d", &num);
    if (num < 1000 && num > 2)
      test = 0;
    else
      printf("That's not a number between 2 and 1000, try again. \n\n");
  } while (test);
  for (i = 2; i < num; i++) {
    if (num % i == 0)
      prime = 0;
  }
  printf("Output: \n");
  if (prime == 0)
    printf("The number you have entered, %d, IS NOT prime. \n\n", num);
  else
    printf("The number you have entered, %d, IS prime. \n\n", num);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x3e8,-0x8(%rbp)
jge    1193 <main+0x73>
cmpl   $0x2,-0x8(%rbp)
jle    1193 <main+0x73>
movl   $0x0,-0x10(%rbp)
jmp    11a1 <main+0x81>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a6 <main+0x86>
cmpl   $0x0,-0x10(%rbp)
jne    1152 <main+0x32>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ed <main+0xcd>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11da <main+0xba>
movl   $0x0,-0x14(%rbp)
jmp    11df <main+0xbf>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b7 <main+0x97>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    121b <main+0xfb>
mov    -0x8(%rbp),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122c <main+0x10c>
mov    -0x8(%rbp),%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xf48(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%r9d
lea    -0x3(%r9),%eax
cmp    $0x3e5,%eax
jb     11bd <main+0x8d>
lea    0xf15(%rip),%r14
lea    0xe7f(%rip),%r15
lea    0xe9c(%rip),%r12
lea    0x4(%rsp),%rbx
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%r9d
lea    -0x3(%r9),%eax
cmp    $0x3e5,%eax
jae    1190 <main+0x60>
cmp    $0x3,%r9d
jne    11cf <main+0x9f>
mov    $0x2,%esi
mov    $0x1,%ebx
jmp    1215 <main+0xe5>
lea    -0x2(%r9),%r8d
and    $0xfffffffe,%r8d
mov    $0x2,%esi
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %esi,%edi
mov    %r9d,%eax
cltd
idiv   %esi
mov    %edx,%esi
lea    0x1(%rdi),%ecx
mov    %r9d,%eax
cltd
idiv   %ecx
test   %esi,%esi
cmove  %esi,%ebx
test   %edx,%edx
cmove  %edx,%ebx
lea    0x2(%rdi),%esi
cmp    %r8d,%edi
jne    11f0 <main+0xc0>
test   $0x1,%r9b
je     1226 <main+0xf6>
mov    %r9d,%eax
cltd
idiv   %esi
test   %edx,%edx
cmove  %edx,%ebx
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
mov    0x4(%rsp),%esi
lea    0xde8(%rip),%rax
lea    0xe13(%rip),%rdi
cmove  %rax,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Input: \0A\00"
@.str.1 = [36 x i8] c"Enter a number between 2 and 1000: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [54 x i8] c"That's not a number between 2 and 1000, try again. \0A\0A\00"
@.str.4 = [10 x i8] c"Output: \0A\00"
@.str.5 = [50 x i8] c"The number you have entered, %d, IS NOT prime. \0A\0A\00"
@.str.6 = [46 x i8] c"The number you have entered, %d, IS prime. \0A\0A\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 0, i32* %3
store i32 1, i32* %4
store i32 1, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %19, %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 0, i32* %4
br label %18
16: ; preds = %12, %7
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %15
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %7, label %22
22: ; preds = %19
store i32 2, i32* %3
br label %23
23: ; preds = %34, %22
%24 = load i32, i32* %3
%25 = load i32, i32* %2
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = srem i32 %28, %29
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 0, i32* %5
br label %33
33: ; preds = %32, %27
br label %34
34: ; preds = %33
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %23
37: ; preds = %23
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* %5
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %2
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i32 %42)
br label %47
44: ; preds = %37
%45 = load i32, i32* %2
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %41
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [36 x i8] c"Enter a number between 2 and 1000: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.5 = [50 x i8] c"The number you have entered, %d, IS NOT prime. \0A\0A\00"
@.str.6 = [46 x i8] c"The number you have entered, %d, IS prime. \0A\0A\00"
@str = [8 x i8] c"Input: \00"
@str.7 = [53 x i8] c"That's not a number between 2 and 1000, try again. \0A\00"
@str.8 = [9 x i8] c"Output: \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add i32 %6, -3
%8 = icmp ult i32 %7, 997
br i1 %8, label %9, label %16
9: ; preds = %16, %0
%10 = phi i32 [ %6, %0 ], [ %20, %16 ]
%11 = and i32 %10, 1
%12 = icmp eq i32 %10, 3
br i1 %12, label %37, label %13
13: ; preds = %9
%14 = add i32 %10, -2
%15 = and i32 %14, -2
br label %23
16: ; preds = %0, %16
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.7, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%20 = load i32, i32* %1
%21 = add i32 %20, -3
%22 = icmp ult i32 %21, 997
br i1 %22, label %9, label %16
23: ; preds = %23, %13
%24 = phi i32 [ 1, %13 ], [ %33, %23 ]
%25 = phi i32 [ 2, %13 ], [ %34, %23 ]
%26 = phi i32 [ 0, %13 ], [ %35, %23 ]
%27 = srem i32 %10, %25
%28 = icmp eq i32 %27, 0
%29 = or i32 %25, 1
%30 = srem i32 %10, %29
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i1 true, i1 %28
%33 = select i1 %32, i32 0, i32 %24
%34 = add nuw nsw i32 %25, 2
%35 = add i32 %26, 2
%36 = icmp eq i32 %35, %15
br i1 %36, label %37, label %23
37: ; preds = %23, %9
%38 = phi i32 [ undef, %9 ], [ %33, %23 ]
%39 = phi i32 [ 1, %9 ], [ %33, %23 ]
%40 = phi i32 [ 2, %9 ], [ %34, %23 ]
%41 = icmp eq i32 %11, 0
br i1 %41, label %46, label %42
42: ; preds = %37
%43 = srem i32 %10, %40
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 0, i32 %39
br label %46
46: ; preds = %37, %42
%47 = phi i32 [ %38, %37 ], [ %45, %42 ]
%48 = icmp eq i32 %47, 0
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
%50 = load i32, i32* %1
%51 = select i1 %48, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %51, i32 %50)
ret i32 0
}