#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: ");
  printf("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: ");
    printf("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    0xee3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1251 <main+0x131>
movq   $0x2,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1214 <main+0xf4>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
jne    11fe <main+0xde>
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11e1 <main+0xc1>
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    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f7 <main+0xd7>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1203 <main+0xe3>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1173 <main+0x53>
cmpl   $0x0,-0x1c(%rbp)
je     1230 <main+0x110>
mov    -0x10(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    114b <main+0x2b>
lea    0xe5c(%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    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf57(%rip),%rdi
call   1030 <puts@plt>
lea    0xecb(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1285 <main+0x155>
lea    0xf02(%rip),%r15
lea    0xf2c(%rip),%r12
lea    0xea5(%rip),%rbx
mov    %rsp,%rbp
lea    0xec1(%rip),%r13
lea    0xe98(%rip),%r14
jmp    11e9 <main+0xb9>
cs nopw 0x0(%rax,%rax,1)
nop
test   %r12d,%r12d
mov    %rbx,%r15
mov    %rbp,%r12
lea    0xe77(%rip),%rbx
mov    %rsp,%rbp
je     11c3 <main+0x93>
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1285 <main+0x155>
mov    (%rsp),%rsi
cmp    $0x4,%rsi
jb     11b5 <main+0x85>
mov    %r12,%rbp
mov    %r15,%rbx
mov    $0x1,%r12d
mov    $0x4,%edi
mov    $0x3,%r15d
jmp    1238 <main+0x108>
mov    %r13,%rdi
mov    %rcx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
nopl   0x0(%rax)
mov    %r15,%rdi
imul   %r15,%rdi
mov    (%rsp),%rsi
add    $0x1,%r15
cmp    %rsi,%rdi
ja     11a0 <main+0x70>
lea    -0x1(%r15),%rcx
mov    %rsi,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1260 <main+0x130>
mov    %rsi,%rax
xor    %edx,%edx
div    %rcx
test   %rdx,%rdx
jne    1220 <main+0xf0>
jmp    126b <main+0x13b>
nopw   0x0(%rax,%rax,1)
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
test   %rdx,%rdx
jne    1220 <main+0xf0>
xor    %r12d,%r12d
cmp    %rsi,%rdi
je     120c <main+0xdc>
mov    %r14,%rdi
mov    %rcx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1220 <main+0xf0>
lea    0xe16(%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 = [39 x i8] c"Please enter an integer for analysis: \00"
@.str.1 = [18 x i8] c"Enter q to quit.\0A\00"
@.str.2 = [4 x i8] c"%lu\00"
@.str.3 = [34 x i8] c"%lu is divisible by %lu and %lu.\0A\00"
@.str.4 = [26 x i8] c"%lu is divisible by %lu.\0A\00"
@.str.5 = [15 x i8] c"%lu is prime.\0A\00"
@.str.6 = [44 x i8] c"Please enter another integer for analysis: \00"
@.str.7 = [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 ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %50, %0
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %53
10: ; preds = %7
store i64 2, i64* %3
store i32 1, i32* %4
br label %11
11: ; preds = %41, %10
%12 = load i64, i64* %3
%13 = load i64, i64* %3
%14 = mul i64 %12, %13
%15 = load i64, i64* %2
%16 = icmp ule i64 %14, %15
br i1 %16, label %17, label %44
17: ; preds = %11
%18 = load i64, i64* %2
%19 = load i64, i64* %3
%20 = urem i64 %18, %19
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %17
%23 = load i64, i64* %3
%24 = load i64, i64* %3
%25 = mul i64 %23, %24
%26 = load i64, i64* %2
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %22
%29 = load i64, i64* %2
%30 = load i64, i64* %3
%31 = load i64, i64* %2
%32 = load i64, i64* %3
%33 = udiv i64 %31, %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %29, i64 %30, i64 %33)
br label %39
35: ; preds = %22
%36 = load i64, i64* %2
%37 = load i64, i64* %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i64 %36, i64 %37)
br label %39
39: ; preds = %35, %28
store i32 0, i32* %4
br label %40
40: ; preds = %39, %17
br label %41
41: ; preds = %40
%42 = load i64, i64* %3
%43 = add i64 %42, 1
store i64 %43, i64* %3
br label %11
44: ; preds = %11
%45 = load i32, i32* %4
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i64, i64* %2
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i64 %48)
br label %50
50: ; preds = %47, %44
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0))
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %7
53: ; preds = %7
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

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