#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 *, ...);
unsigned long sqrt(unsigned long);
void primeFactors(unsigned long n) {
  unsigned long orgNum = n;
  while (n % 2 == 0) {
    printf("2 * ");
    n /= 2;
  }
  unsigned long i;
  for (i = 3; i <= sqrt(n); i += 2) {
    while (n % i == 0) {
      printf("%lu * ", i);
      n /= i;
    }
  }
  if (n > 2) {
    printf("%lu ", n);
  }
  printf("= %lu\n", orgNum);
}


x86 assembly (clang, -O0):
<primeFactors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1165 <primeFactors+0x45>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1134 <primeFactors+0x14>
movq   $0x3,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
ja     11e7 <primeFactors+0xc7>
jmp    1193 <primeFactors+0x73>
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
jne    11d1 <primeFactors+0xb1>
mov    -0x18(%rbp),%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
jmp    1193 <primeFactors+0x73>
jmp    11d6 <primeFactors+0xb6>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    116d <primeFactors+0x4d>
cmpq   $0x2,-0x8(%rbp)
jbe    1204 <primeFactors+0xe4>
mov    -0x8(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primeFactors>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rdi,%r15
test   $0x1,%r14b
jne    1165 <primeFactors+0x45>
lea    0xec5(%rip),%r12
mov    %r14,%rbx
mov    %r14,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
shr    %r15
test   $0x2,%bl
mov    %r15,%rbx
je     1150 <primeFactors+0x30>
mov    %r15,%rdi
call   1040 <sqrt@plt>
cmp    $0x3,%rax
jb     11fd <primeFactors+0xdd>
mov    $0x3,%ebx
lea    0xe82(%rip),%r12
jmp    119b <primeFactors+0x7b>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rax
xor    %edx,%edx
div    %rbx
mov    %rax,%r15
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     11e0 <primeFactors+0xc0>
mov    %r15,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
jne    11ec <primeFactors+0xcc>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1190 <primeFactors+0x70>
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%r15d
jmp    119b <primeFactors+0x7b>
nopl   0x0(%rax)
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
je     11b4 <primeFactors+0x94>
add    $0x2,%rbx
mov    %r15,%rdi
call   1040 <sqrt@plt>
cmp    %rax,%rbx
jbe    119b <primeFactors+0x7b>
cmp    $0x3,%r15
jb     1214 <primeFactors+0xf4>
lea    0xe02(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdf6(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"2 * \00"
@.str.1 = [7 x i8] c"%lu * \00"
@.str.2 = [5 x i8] c"%lu \00"
@.str.3 = [7 x i8] c"= %lu\0A\00"
define void @primeFactors(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
%5 = load i64, i64* %2
store i64 %5, i64* %3
br label %6
6: ; preds = %10, %1
%7 = load i64, i64* %2
%8 = urem i64 %7, 2
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = load i64, i64* %2
%13 = udiv i64 %12, 2
store i64 %13, i64* %2
br label %6
14: ; preds = %6
store i64 3, i64* %4
br label %15
15: ; preds = %33, %14
%16 = load i64, i64* %4
%17 = load i64, i64* %2
%18 = call i64 @sqrt(i64 %17)
%19 = icmp ule i64 %16, %18
br i1 %19, label %20, label %36
20: ; preds = %15
br label %21
21: ; preds = %26, %20
%22 = load i64, i64* %2
%23 = load i64, i64* %4
%24 = urem i64 %22, %23
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i64, i64* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %27)
%29 = load i64, i64* %4
%30 = load i64, i64* %2
%31 = udiv i64 %30, %29
store i64 %31, i64* %2
br label %21
32: ; preds = %21
br label %33
33: ; preds = %32
%34 = load i64, i64* %4
%35 = add i64 %34, 2
store i64 %35, i64* %4
br label %15
36: ; preds = %15
%37 = load i64, i64* %2
%38 = icmp ugt i64 %37, 2
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i64, i64* %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %40)
br label %42
42: ; preds = %39, %36
%43 = load i64, i64* %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %43)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"2 * \00"
@.str.1 = [7 x i8] c"%lu * \00"
@.str.2 = [5 x i8] c"%lu \00"
@.str.3 = [7 x i8] c"= %lu\0A\00"
define void @primeFactors(i64 %0) {
%2 = and i64 %0, 1
%3 = icmp eq i64 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %8, %1
%5 = phi i64 [ %0, %1 ], [ %11, %8 ]
%6 = tail call i64 @sqrt(i64 %5)
%7 = icmp ult i64 %6, 3
br i1 %7, label %30, label %14
8: ; preds = %1, %8
%9 = phi i64 [ %11, %8 ], [ %0, %1 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = lshr i64 %9, 1
%12 = and i64 %9, 2
%13 = icmp eq i64 %12, 0
br i1 %13, label %8, label %4
14: ; preds = %4, %25
%15 = phi i64 [ %27, %25 ], [ 3, %4 ]
%16 = phi i64 [ %26, %25 ], [ %5, %4 ]
%17 = urem i64 %16, %15
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14, %19
%20 = phi i64 [ %22, %19 ], [ %16, %14 ]
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %15)
%22 = udiv i64 %20, %15
%23 = urem i64 %22, %15
%24 = icmp eq i64 %23, 0
br i1 %24, label %19, label %25
25: ; preds = %19, %14
%26 = phi i64 [ %16, %14 ], [ %22, %19 ]
%27 = add i64 %15, 2
%28 = tail call i64 @sqrt(i64 %26)
%29 = icmp ugt i64 %27, %28
br i1 %29, label %30, label %14
30: ; preds = %25, %4
%31 = phi i64 [ %5, %4 ], [ %26, %25 ]
%32 = icmp ugt i64 %31, 2
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %31)
br label %35
35: ; preds = %33, %30
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %0)
ret void
}