#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 *, long long *);
void Problem3() {
  long long int i, n, j, temp;
  int count1 = 0, count2 = 0;
  printf("Problem 3: Given an input n, the program will print out its prime "
         "factorization.\n");
  printf("Please enter input n: ");
  scanf("%lld", &n);
  temp = 2;
  printf("The output is: %lld = ", n);
  for (i = 2; (i < 100000); i++) {
    for (j = 2; j <= (i / j); j++) {
      if (!(i % j)) {
        break;
      }
    }
    if (j > (i / j)) {
      while (n > 0) {
        if (n % i != 0) {
          break;
        } else {
          if (temp == i) {
            while (n % i == 0) {
              count1++;
              n = n / i;
            }
            if (count2 == 0) {
              printf("%lld", i);
              count2++;
            }
            if (count1 > 1) {
              printf("^%d", count1);
            }
          } else {
            count1 = 0;
            temp = i;
            count2 = 0;
            printf(" x ");
            continue;
          }
        }
      }
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<Problem3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf10(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movq   $0x2,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xef9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x2,-0x8(%rbp)
cmpq   $0x186a0,-0x8(%rbp)
jge    130c <Problem3+0x1ec>
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jg     11eb <Problem3+0xcb>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    11d5 <Problem3+0xb5>
jmp    11eb <Problem3+0xcb>
jmp    11da <Problem3+0xba>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    119a <Problem3+0x7a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jle    12f6 <Problem3+0x1d6>
jmp    1212 <Problem3+0xf2>
cmpq   $0x0,-0x10(%rbp)
jle    12f1 <Problem3+0x1d1>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x8(%rbp)
cmp    $0x0,%rdx
je     1236 <Problem3+0x116>
jmp    12f1 <Problem3+0x1d1>
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    12be <Problem3+0x19e>
jmp    1249 <Problem3+0x129>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x8(%rbp)
cmp    $0x0,%rdx
jne    1279 <Problem3+0x159>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
cqto
idivq  -0x8(%rbp)
mov    %rax,-0x10(%rbp)
jmp    1249 <Problem3+0x129>
cmpl   $0x0,-0x28(%rbp)
jne    129e <Problem3+0x17e>
mov    -0x8(%rbp),%rsi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x24(%rbp)
jle    12b9 <Problem3+0x199>
mov    -0x24(%rbp),%esi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12e7 <Problem3+0x1c7>
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <Problem3+0xf2>
jmp    12ec <Problem3+0x1cc>
jmp    1212 <Problem3+0xf2>
jmp    12f6 <Problem3+0x1d6>
jmp    12fb <Problem3+0x1db>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1184 <Problem3+0x64>
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Problem3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xee9(%rip),%rdi
call   1040 <puts@plt>
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeab(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%rsi
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%esi
lea    0xea1(%rip),%r15
lea    0xe9e(%rip),%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
mov    $0x2,%r13d
jmp    11c4 <Problem3+0x84>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rsi
add    $0x1,%r13
cmp    $0x186a0,%r13
je     1341 <Problem3+0x201>
mov    $0x1,%ecx
cmp    $0x4,%r13
jae    1310 <Problem3+0x1d0>
mov    (%rsp),%rcx
test   %rcx,%rcx
jg     11ec <Problem3+0xac>
jmp    11b3 <Problem3+0x73>
xchg   %ax,%ax
mov    (%rsp),%rcx
mov    %r13,%rsi
test   %rcx,%rcx
jle    11b0 <Problem3+0x70>
mov    %rcx,%rax
or     %r13,%rax
shr    $0x20,%rax
je     1210 <Problem3+0xd0>
mov    %rcx,%rax
cqto
idiv   %r13
test   %rdx,%rdx
je     121c <Problem3+0xdc>
jmp    11b3 <Problem3+0x73>
nopw   0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %r13d
test   %rdx,%rdx
jne    11b3 <Problem3+0x73>
cmp    %r13,%rsi
je     1250 <Problem3+0x110>
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
jmp    11e0 <Problem3+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rax
cqto
idiv   %r13
add    $0x1,%ebx
test   %rdx,%rdx
jne    1290 <Problem3+0x150>
mov    %rcx,%rax
or     %r13,%rax
shr    $0x20,%rax
je     1270 <Problem3+0x130>
mov    %rcx,%rax
cqto
idiv   %r13
mov    %rax,%rcx
jmp    1279 <Problem3+0x139>
nopl   0x0(%rax)
mov    %ecx,%eax
xor    %edx,%edx
div    %r13d
mov    %eax,%ecx
mov    %rcx,%rax
or     %r13,%rax
shr    $0x20,%rax
jne    1240 <Problem3+0x100>
mov    %ecx,%eax
xor    %edx,%edx
div    %r13d
jmp    1248 <Problem3+0x108>
xchg   %ax,%ax
mov    %rcx,(%rsp)
lea    -0x1(%rbx),%r14d
test   %ebp,%ebp
jne    12ad <Problem3+0x16d>
lea    0xd74(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebp
test   %r14d,%r14d
jle    11e0 <Problem3+0xa0>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11e0 <Problem3+0xa0>
nopl   0x0(%rax)
mov    %r13,%rax
xor    %edx,%edx
div    %rdi
cmp    %rax,%rcx
jb     1310 <Problem3+0x1d0>
jmp    11d3 <Problem3+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x2,%rdi
mov    %r13,%rax
or     %rdi,%rax
shr    $0x20,%rax
jne    12d0 <Problem3+0x190>
mov    %r13d,%eax
xor    %edx,%edx
div    %edi
cmp    %rax,%rcx
jae    11d3 <Problem3+0x93>
mov    %rcx,%rdi
add    $0x1,%rcx
mov    %r13,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1330 <Problem3+0x1f0>
mov    %r13,%rax
xor    %edx,%edx
div    %rcx
jmp    1337 <Problem3+0x1f7>
nopl   (%rax)
mov    %r13d,%eax
xor    %edx,%edx
div    %ecx
test   %rdx,%rdx
jne    12f0 <Problem3+0x1b0>
jmp    11b3 <Problem3+0x73>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [82 x i8] c"Problem 3: Given an input n, the program will print out its prime factorization.\0A\00"
@.str.1 = [23 x i8] c"Please enter input n: \00"
@.str.2 = [5 x i8] c"%lld\00"
@.str.3 = [23 x i8] c"The output is: %lld = \00"
@.str.4 = [4 x i8] c"^%d\00"
@.str.5 = [4 x i8] c" x \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @Problem3() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %5
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %2)
store i64 2, i64* %4
%10 = load i64, i64* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i64 %10)
store i64 2, i64* %1
br label %12
12: ; preds = %86, %0
%13 = load i64, i64* %1
%14 = icmp slt i64 %13, 100000
br i1 %14, label %15, label %89
15: ; preds = %12
store i64 2, i64* %3
br label %16
16: ; preds = %29, %15
%17 = load i64, i64* %3
%18 = load i64, i64* %1
%19 = load i64, i64* %3
%20 = sdiv i64 %18, %19
%21 = icmp sle i64 %17, %20
br i1 %21, label %22, label %32
22: ; preds = %16
%23 = load i64, i64* %1
%24 = load i64, i64* %3
%25 = srem i64 %23, %24
%26 = icmp ne i64 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
br label %32
28: ; preds = %22
br label %29
29: ; preds = %28
%30 = load i64, i64* %3
%31 = add nsw i64 %30, 1
store i64 %31, i64* %3
br label %16
32: ; preds = %27, %16
%33 = load i64, i64* %3
%34 = load i64, i64* %1
%35 = load i64, i64* %3
%36 = sdiv i64 %34, %35
%37 = icmp sgt i64 %33, %36
br i1 %37, label %38, label %85
38: ; preds = %32
br label %39
39: ; preds = %83, %79, %38
%40 = load i64, i64* %2
%41 = icmp sgt i64 %40, 0
br i1 %41, label %42, label %84
42: ; preds = %39
%43 = load i64, i64* %2
%44 = load i64, i64* %1
%45 = srem i64 %43, %44
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %42
br label %84
48: ; preds = %42
%49 = load i64, i64* %4
%50 = load i64, i64* %1
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %79
52: ; preds = %48
br label %53
53: ; preds = %58, %52
%54 = load i64, i64* %2
%55 = load i64, i64* %1
%56 = srem i64 %54, %55
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %53
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
%61 = load i64, i64* %2
%62 = load i64, i64* %1
%63 = sdiv i64 %61, %62
store i64 %63, i64* %2
br label %53
64: ; preds = %53
%65 = load i32, i32* %6
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load i64, i64* %1
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %68)
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %72
72: ; preds = %67, %64
%73 = load i32, i32* %5
%74 = icmp sgt i32 %73, 1
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = load i32, i32* %5
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %75, %72
br label %82
79: ; preds = %48
store i32 0, i32* %5
%80 = load i64, i64* %1
store i64 %80, i64* %4
store i32 0, i32* %6
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %39
82: ; preds = %78
br label %83
83: ; preds = %82
br label %39
84: ; preds = %47, %39
br label %85
85: ; preds = %84, %32
br label %86
86: ; preds = %85
%87 = load i64, i64* %1
%88 = add nsw i64 %87, 1
store i64 %88, i64* %1
br label %12
89: ; preds = %12
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"Please enter input n: \00"
@.str.2 = [5 x i8] c"%lld\00"
@.str.3 = [23 x i8] c"The output is: %lld = \00"
@.str.4 = [4 x i8] c"^%d\00"
@.str.5 = [4 x i8] c" x \00"
@str = [81 x i8] c"Problem 3: Given an input n, the program will print out its prime factorization.\00"
define void @Problem3() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%6 = load i64, i64* %1
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i64 %6)
br label %8
8: ; preds = %0, %56
%9 = phi i32 [ 0, %0 ], [ %59, %56 ]
%10 = phi i32 [ 0, %0 ], [ %58, %56 ]
%11 = phi i64 [ 2, %0 ], [ %57, %56 ]
%12 = phi i64 [ 2, %0 ], [ %60, %56 ]
%13 = icmp ult i64 %12, 4
br i1 %13, label %22, label %17
14: ; preds = %17
%15 = udiv i64 %12, %21
%16 = icmp ult i64 %18, %15
br i1 %16, label %17, label %22
17: ; preds = %8, %14
%18 = phi i64 [ %21, %14 ], [ 2, %8 ]
%19 = urem i64 %12, %18
%20 = icmp eq i64 %19, 0
%21 = add nuw nsw i64 %18, 1
br i1 %20, label %56, label %14
22: ; preds = %14, %8
%23 = load i64, i64* %1
%24 = icmp sgt i64 %23, 0
br i1 %24, label %30, label %56
25: ; preds = %50, %52, %54
%26 = phi i32 [ 0, %54 ], [ %42, %52 ], [ %42, %50 ]
%27 = phi i32 [ 0, %54 ], [ 1, %52 ], [ 1, %50 ]
%28 = load i64, i64* %1
%29 = icmp sgt i64 %28, 0
br i1 %29, label %30, label %56
30: ; preds = %22, %25
%31 = phi i64 [ %28, %25 ], [ %23, %22 ]
%32 = phi i64 [ %12, %25 ], [ %11, %22 ]
%33 = phi i32 [ %26, %25 ], [ %10, %22 ]
%34 = phi i32 [ %27, %25 ], [ %9, %22 ]
%35 = srem i64 %31, %12
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %56
37: ; preds = %30
%38 = icmp eq i64 %32, %12
br i1 %38, label %39, label %54
39: ; preds = %37, %39
%40 = phi i32 [ %42, %39 ], [ %33, %37 ]
%41 = phi i64 [ %43, %39 ], [ %31, %37 ]
%42 = add nsw i32 %40, 1
%43 = sdiv i64 %41, %12
%44 = srem i64 %43, %12
%45 = icmp eq i64 %44, 0
br i1 %45, label %39, label %46
46: ; preds = %39
store i64 %43, i64* %1
%47 = icmp eq i32 %34, 0
br i1 %47, label %48, label %50
48: ; preds = %46
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %12)
br label %50
50: ; preds = %48, %46
%51 = icmp sgt i32 %40, 0
br i1 %51, label %52, label %25
52: ; preds = %50
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %42)
br label %25
54: ; preds = %37
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %25
56: ; preds = %17, %30, %25, %22
%57 = phi i64 [ %11, %22 ], [ %12, %25 ], [ %32, %30 ], [ %11, %17 ]
%58 = phi i32 [ %10, %22 ], [ %26, %25 ], [ %33, %30 ], [ %10, %17 ]
%59 = phi i32 [ %9, %22 ], [ %27, %25 ], [ %34, %30 ], [ %9, %17 ]
%60 = add nuw nsw i64 %12, 1
%61 = icmp eq i64 %60, 100000
br i1 %61, label %62, label %8
62: ; preds = %56
%63 = call i32 @putchar(i32 10)
ret void
}