#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 scanf(char *, unsigned long *);
int main(void) {
  unsigned long num;
  unsigned long div;
  bool isPrime;
  printf("Please enter an integer for analysis; Enter q to quit.\n");
  while (scanf("%lu", &num) == 1) {
    for (div = 2, isPrime = true; (div * div) <= num; div++) {
      if (num % div == 0) {
        if ((div * div) != num)
          printf("%lu is divisible by %lu and %lu.\n", num, div, num / div);
        else
          printf("%lu is divisible by %lu.\n", num, div);
        isPrime = false;
      }
    }
    if (isPrime)
      printf("%lu is prime.\n", num);
    printf("Please enter another integer for analysis; Enter q to quit.\n");
  }
  printf("Bye.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef4(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1235 <main+0x115>
movq   $0x2,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1206 <main+0xe6>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
jne    11f0 <main+0xd0>
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11d3 <main+0xb3>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e9 <main+0xc9>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    11f5 <main+0xd5>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1165 <main+0x45>
cmpl   $0x0,-0x1c(%rbp)
je     1222 <main+0x102>
mov    -0x10(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113d <main+0x1d>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf0d(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb2(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1255 <main+0x125>
lea    0xf25(%rip),%r14
lea    0xe93(%rip),%rbp
mov    %rsp,%rbx
lea    0xeaf(%rip),%r12
lea    0xe86(%rip),%r13
jmp    11b5 <main+0x85>
test   %r15d,%r15d
mov    %rbx,%r14
mov    %rsp,%rbx
je     1199 <main+0x69>
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1255 <main+0x125>
mov    (%rsp),%rsi
cmp    $0x4,%rsi
jb     118b <main+0x5b>
mov    %r14,%rbx
mov    $0x1,%r15d
mov    $0x4,%edi
mov    $0x3,%r14d
jmp    1208 <main+0xd8>
mov    %r12,%rdi
mov    %rcx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
imul   %r14,%rdi
mov    (%rsp),%rsi
add    $0x1,%r14
cmp    %rsi,%rdi
ja     1180 <main+0x50>
lea    -0x1(%r14),%rcx
mov    %rsi,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1230 <main+0x100>
mov    %rsi,%rax
xor    %edx,%edx
div    %rcx
test   %rdx,%rdx
jne    11f0 <main+0xc0>
jmp    123b <main+0x10b>
nopw   0x0(%rax,%rax,1)
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
test   %rdx,%rdx
jne    11f0 <main+0xc0>
xor    %r15d,%r15d
cmp    %rsi,%rdi
je     11d5 <main+0xa5>
mov    %r13,%rdi
mov    %rcx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f0 <main+0xc0>
lea    0xe2a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Please enter an integer for analysis; Enter q to quit.\0A\00"
@.str.1 = [4 x i8] c"%lu\00"
@.str.2 = [34 x i8] c"%lu is divisible by %lu and %lu.\0A\00"
@.str.3 = [26 x i8] c"%lu is divisible by %lu.\0A\00"
@.str.4 = [15 x i8] c"%lu is prime.\0A\00"
@.str.5 = [61 x i8] c"Please enter another integer for analysis; Enter q to quit.\0A\00"
@.str.6 = [6 x i8] c"Bye.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %49, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %51
9: ; preds = %6
store i64 2, i64* %3
store i32 1, i32* %4
br label %10
10: ; preds = %40, %9
%11 = load i64, i64* %3
%12 = load i64, i64* %3
%13 = mul i64 %11, %12
%14 = load i64, i64* %2
%15 = icmp ule i64 %13, %14
br i1 %15, label %16, label %43
16: ; preds = %10
%17 = load i64, i64* %2
%18 = load i64, i64* %3
%19 = urem i64 %17, %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %39
21: ; preds = %16
%22 = load i64, i64* %3
%23 = load i64, i64* %3
%24 = mul i64 %22, %23
%25 = load i64, i64* %2
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %21
%28 = load i64, i64* %2
%29 = load i64, i64* %3
%30 = load i64, i64* %2
%31 = load i64, i64* %3
%32 = udiv i64 %30, %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %28, i64 %29, i64 %32)
br label %38
34: ; preds = %21
%35 = load i64, i64* %2
%36 = load i64, i64* %3
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %35, i64 %36)
br label %38
38: ; preds = %34, %27
store i32 0, i32* %4
br label %39
39: ; preds = %38, %16
br label %40
40: ; preds = %39
%41 = load i64, i64* %3
%42 = add i64 %41, 1
store i64 %42, i64* %3
br label %10
43: ; preds = %10
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i64, i64* %2
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i64 %47)
br label %49
49: ; preds = %46, %43
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0))
br label %6
51: ; preds = %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%lu\00"
@.str.2 = [34 x i8] c"%lu is divisible by %lu and %lu.\0A\00"
@.str.3 = [26 x i8] c"%lu is divisible by %lu.\0A\00"
@.str.4 = [15 x i8] c"%lu is prime.\0A\00"
@str = [55 x i8] c"Please enter an integer for analysis; Enter q to quit.\00"
@str.7 = [5 x i8] c"Bye.\00"
@str.8 = [60 x i8] c"Please enter another integer for analysis; Enter q to quit.\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %38
6: ; preds = %0, %34
%7 = load i64, i64* %1
%8 = icmp ult i64 %7, 4
br i1 %8, label %31, label %9
9: ; preds = %6, %23
%10 = phi i64 [ %27, %23 ], [ %7, %6 ]
%11 = phi i64 [ %26, %23 ], [ 4, %6 ]
%12 = phi i32 [ %24, %23 ], [ 1, %6 ]
%13 = phi i64 [ %25, %23 ], [ 2, %6 ]
%14 = urem i64 %10, %13
%15 = udiv i64 %10, %13
%16 = icmp eq i64 %14, 0
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = icmp eq i64 %11, %10
br i1 %18, label %21, label %19
19: ; preds = %17
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %10, i64 %13, i64 %15)
br label %23
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %10, i64 %13)
br label %23
23: ; preds = %19, %21, %9
%24 = phi i32 [ %12, %9 ], [ 0, %21 ], [ 0, %19 ]
%25 = add i64 %13, 1
%26 = mul i64 %25, %25
%27 = load i64, i64* %1
%28 = icmp ugt i64 %26, %27
br i1 %28, label %29, label %9
29: ; preds = %23
%30 = icmp eq i32 %24, 0
br i1 %30, label %34, label %31
31: ; preds = %6, %29
%32 = phi i64 [ %27, %29 ], [ %7, %6 ]
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i64 %32)
br label %34
34: ; preds = %31, %29
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.8, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%37 = icmp eq i32 %36, 1
br i1 %37, label %6, label %38
38: ; preds = %34, %0
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}