#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 *);
scalar_t__ sqrt(int);
int main() {
  int number, denominator, is_prime = 1;
  printf("Enter the number: ");
  scanf("%d", &number);
  if (number < 0) {
    printf("Number must be positive");
    return 0;
  }
  if (number <= 3) {
    printf("Number is prime");
    return 0;
  }
  for (denominator = 2; denominator <= (int)sqrt(number); denominator++) {
    if ((number % denominator) == 0) {
      printf("Number %d is not prime, denominator is %d\n\n", number,
             denominator);
      is_prime = 0;
      break;
    }
  }
  if (is_prime) {
    printf("Number %d is prime\n\n", number);
  }
  is_prime = 1;
  denominator = 2;
  while (denominator <= (int)sqrt(number)) {
    if ((number % denominator) == 0) {
      printf("Number %d is not prime, denominator is %d\n\n", number,
             denominator);
      is_prime = 0;
      break;
    }
    denominator++;
  }
  if (is_prime) {
    printf("Number %d is prime\n\n", number);
  }
  is_prime = 1;
  denominator = 2;
  do {
    if ((number % denominator) == 0) {
      printf("Number %d is not prime, denominator is %d\n\n", number,
             denominator);
      is_prime = 0;
      break;
    }
    denominator++;
  } while (denominator <= (int)sqrt(number));
  if (is_prime) {
    printf("Number %d is prime\n\n", number);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1188 <main+0x58>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1335 <main+0x205>
cmpl   $0x3,-0x8(%rbp)
jg     11ac <main+0x7c>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1335 <main+0x205>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <sqrt@plt>
mov    %rax,%rcx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     1212 <main+0xe2>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11ff <main+0xcf>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
jmp    1212 <main+0xe2>
jmp    1204 <main+0xd4>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b3 <main+0x83>
cmpl   $0x0,-0x10(%rbp)
je     122d <main+0xfd>
mov    -0x8(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <sqrt@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jg     1295 <main+0x165>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1287 <main+0x157>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
jmp    1295 <main+0x165>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <main+0x10b>
cmpl   $0x0,-0x10(%rbp)
je     12b0 <main+0x180>
mov    -0x8(%rbp),%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    12ee <main+0x1be>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
jmp    1313 <main+0x1e3>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <sqrt@plt>
mov    %rax,%rcx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jle    12be <main+0x18e>
cmpl   $0x0,-0x10(%rbp)
je     132e <main+0x1fe>
mov    -0x8(%rbp),%esi
lea    0xd43(%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   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
js     1168 <main+0x38>
cmp    $0x4,%edi
jae    117f <main+0x4f>
lea    0xec8(%rip),%rdi
jmp    116f <main+0x3f>
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
call   1050 <sqrt@plt>
cmp    $0x2,%eax
jl     11ad <main+0x7d>
mov    $0x2,%ebx
xchg   %ax,%ax
mov    0x4(%rsp),%esi
mov    %esi,%eax
cltd
idiv   %ebx
test   %edx,%edx
je     11c1 <main+0x91>
lea    0x1(%rbx),%ebp
mov    %esi,%edi
call   1050 <sqrt@plt>
cmp    %eax,%ebx
mov    %ebp,%ebx
jl     1190 <main+0x60>
mov    0x4(%rsp),%esi
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11d1 <main+0xa1>
lea    0xe76(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%edi
call   1050 <sqrt@plt>
cmp    $0x2,%eax
jl     120d <main+0xdd>
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x4(%rsp),%esi
mov    %esi,%eax
cltd
idiv   %ebx
test   %edx,%edx
je     1221 <main+0xf1>
lea    0x1(%rbx),%ebp
mov    %esi,%edi
call   1050 <sqrt@plt>
cmp    %eax,%ebx
mov    %ebp,%ebx
jl     11f0 <main+0xc0>
mov    0x4(%rsp),%esi
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1231 <main+0x101>
lea    0xe16(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x4(%rsp),%esi
mov    %esi,%eax
cltd
idiv   %ebx
test   %edx,%edx
je     1274 <main+0x144>
lea    0x1(%rbx),%ebp
mov    %esi,%edi
call   1050 <sqrt@plt>
cmp    %eax,%ebx
mov    %ebp,%ebx
jl     1240 <main+0x110>
mov    0x4(%rsp),%esi
lea    0xe02(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1176 <main+0x46>
lea    0xdc3(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1176 <main+0x46>

LLVM IR (-O0):
@.str = [19 x i8] c"Enter the number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"Number must be positive\00"
@.str.3 = [16 x i8] c"Number is prime\00"
@.str.4 = [44 x i8] c"Number %d is not prime, denominator is %d\0A\0A\00"
@.str.5 = [21 x i8] c"Number %d is prime\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 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)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %93
11: ; preds = %0
%12 = load i32, i32* %2
%13 = icmp sle i32 %12, 3
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %93
16: ; preds = %11
store i32 2, i32* %3
br label %17
17: ; preds = %33, %16
%18 = load i32, i32* %3
%19 = load i32, i32* %2
%20 = call i64 @sqrt(i32 %19)
%21 = trunc i64 %20 to i32
%22 = icmp sle i32 %18, %21
br i1 %22, label %23, label %36
23: ; preds = %17
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = srem i32 %24, %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %29, i32 %30)
store i32 0, i32* %4
br label %36
32: ; preds = %23
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %17
36: ; preds = %28, %17
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %36
store i32 1, i32* %4
store i32 2, i32* %3
br label %43
43: ; preds = %58, %42
%44 = load i32, i32* %3
%45 = load i32, i32* %2
%46 = call i64 @sqrt(i32 %45)
%47 = trunc i64 %46 to i32
%48 = icmp sle i32 %44, %47
br i1 %48, label %49, label %61
49: ; preds = %43
%50 = load i32, i32* %2
%51 = load i32, i32* %3
%52 = srem i32 %50, %51
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load i32, i32* %2
%56 = load i32, i32* %3
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %55, i32 %56)
store i32 0, i32* %4
br label %61
58: ; preds = %49
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 1
store i32 %60, i32* %3
br label %43
61: ; preds = %54, %43
%62 = load i32, i32* %4
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* %2
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64, %61
store i32 1, i32* %4
store i32 2, i32* %3
br label %68
68: ; preds = %80, %67
%69 = load i32, i32* %2
%70 = load i32, i32* %3
%71 = srem i32 %69, %70
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %77
73: ; preds = %68
%74 = load i32, i32* %2
%75 = load i32, i32* %3
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %74, i32 %75)
store i32 0, i32* %4
br label %86
77: ; preds = %68
%78 = load i32, i32* %3
%79 = add nsw i32 %78, 1
store i32 %79, i32* %3
br label %80
80: ; preds = %77
%81 = load i32, i32* %3
%82 = load i32, i32* %2
%83 = call i64 @sqrt(i32 %82)
%84 = trunc i64 %83 to i32
%85 = icmp sle i32 %81, %84
br i1 %85, label %68, label %86
86: ; preds = %80, %73
%87 = load i32, i32* %4
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i32, i32* %2
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %89, %86
store i32 0, i32* %1
br label %93
93: ; preds = %92, %14, %9
%94 = load i32, i32* %1
ret i32 %94
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter the number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"Number must be positive\00"
@.str.3 = [16 x i8] c"Number is prime\00"
@.str.4 = [44 x i8] c"Number %d is not prime, denominator is %d\0A\0A\00"
@.str.5 = [21 x i8] c"Number %d is prime\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 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, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %68
9: ; preds = %0
%10 = icmp ult i32 %5, 4
br i1 %10, label %15, label %11
11: ; preds = %9
%12 = call i64 @sqrt(i32 %5)
%13 = trunc i64 %12 to i32
%14 = icmp slt i32 %13, 2
br i1 %14, label %29, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %68
17: ; preds = %11, %24
%18 = phi i32 [ %25, %24 ], [ 2, %11 ]
%19 = load i32, i32* %1
%20 = srem i32 %19, %18
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %19, i32 %18)
br label %32
24: ; preds = %17
%25 = add nuw nsw i32 %18, 1
%26 = call i64 @sqrt(i32 %19)
%27 = trunc i64 %26 to i32
%28 = icmp slt i32 %18, %27
br i1 %28, label %17, label %29
29: ; preds = %24, %11
%30 = load i32, i32* %1
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %22, %29
%33 = load i32, i32* %1
%34 = call i64 @sqrt(i32 %33)
%35 = trunc i64 %34 to i32
%36 = icmp slt i32 %35, 2
br i1 %36, label %49, label %37
37: ; preds = %32, %44
%38 = phi i32 [ %45, %44 ], [ 2, %32 ]
%39 = load i32, i32* %1
%40 = srem i32 %39, %38
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %39, i32 %38)
br label %52
44: ; preds = %37
%45 = add nuw nsw i32 %38, 1
%46 = call i64 @sqrt(i32 %39)
%47 = trunc i64 %46 to i32
%48 = icmp slt i32 %38, %47
br i1 %48, label %37, label %49
49: ; preds = %44, %32
%50 = load i32, i32* %1
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %42, %49
br label %53
53: ; preds = %52, %60
%54 = phi i32 [ %61, %60 ], [ 2, %52 ]
%55 = load i32, i32* %1
%56 = srem i32 %55, %54
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %55, i32 %54)
br label %68
60: ; preds = %53
%61 = add nuw nsw i32 %54, 1
%62 = call i64 @sqrt(i32 %55)
%63 = trunc i64 %62 to i32
%64 = icmp slt i32 %54, %63
br i1 %64, label %53, label %65
65: ; preds = %60
%66 = load i32, i32* %1
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %58, %65, %15, %7
ret i32 0
}