void primefac(unsigned n) {
  unsigned i = 2;
  printf("Prime Factors: ");
  while (n > 1)
    if (n % i == 0 && isprime(i))
      printf(" %u", i), n /= i;
    else
      ++i;
  putchar('\n');
}


x86 assembly (clang, -O0):
<primefac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x4(%rbp)
jbe    11af <primefac+0x7f>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
cmp    $0x0,%edx
jne    11a1 <primefac+0x71>
mov    -0x8(%rbp),%edi
mov    $0x0,%al
call   1050 <isprime@plt>
cmp    $0x0,%eax
je     11a1 <primefac+0x71>
mov    -0x8(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %eax,-0x4(%rbp)
jmp    11aa <primefac+0x7a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1150 <primefac+0x20>
mov    $0xa,%edi
mov    $0x0,%al
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primefac>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jb     1196 <primefac+0x66>
mov    $0x2,%ebp
lea    0xeb8(%rip),%r14
jmp    1168 <primefac+0x38>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x1,%ebx
jbe    1196 <primefac+0x66>
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
test   %edx,%edx
jne    1160 <primefac+0x30>
mov    %eax,%r15d
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <isprime@plt>
test   %eax,%eax
je     1160 <primefac+0x30>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%ebx
cmp    $0x1,%ebx
ja     1168 <primefac+0x38>
mov    $0xa,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"Prime Factors: \00"
@.str.1 = [4 x i8] c" %u\00"
define void @primefac(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 2, i32* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %26, %1
%6 = load i32, i32* %2
%7 = icmp ugt i32 %6, 1
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = urem i32 %9, %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = load i32, i32* %3
%15 = call i32 (i32, ...) bitcast (i32 (...)* @isprime to i32 (i32, ...)*)(i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = udiv i32 %21, %20
store i32 %22, i32* %2
br label %26
23: ; preds = %13, %8
%24 = load i32, i32* %3
%25 = add i32 %24, 1
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %17
br label %5
27: ; preds = %5
%28 = call i32 (i32, ...) bitcast (i32 (...)* @putchar to i32 (i32, ...)*)(i32 10)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Prime Factors: \00"
@.str.1 = [4 x i8] c" %u\00"
define void @primefac(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%3 = icmp ugt i32 %0, 1
br i1 %3, label %4, label %21
4: ; preds = %1, %17
%5 = phi i32 [ %19, %17 ], [ 2, %1 ]
%6 = phi i32 [ %18, %17 ], [ %0, %1 ]
%7 = urem i32 %6, %5
%8 = udiv i32 %6, %5
%9 = icmp eq i32 %7, 0
br i1 %9, label %10, label %15
10: ; preds = %4
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @isprime to i32 (i32, ...)*)(i32 %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %17
15: ; preds = %10, %4
%16 = add i32 %5, 1
br label %17
17: ; preds = %15, %13
%18 = phi i32 [ %8, %13 ], [ %6, %15 ]
%19 = phi i32 [ %5, %13 ], [ %16, %15 ]
%20 = icmp ugt i32 %18, 1
br i1 %20, label %4, label %21
21: ; preds = %17, %1
%22 = tail call i32 (i32, ...) bitcast (i32 (...)* @putchar to i32 (i32, ...)*)(i32 10)
ret void
}