#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 sqrt(int);
void prime_factors(int n) {
  int i;
  while (n % 2 == 0) {
    n = n / 2;
    printf("%d ", 2);
  }
  for (i = 3; i <= sqrt(n); i += 2) {
    while (n % i == 0) {
      n = n / i;
      printf("%d ", i);
    }
  }
  if (n > 2) {
    printf("%d", n);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<prime_factors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1165 <prime_factors+0x45>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    112b <prime_factors+0xb>
movl   $0x3,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    %ecx,%eax
jg     11cf <prime_factors+0xaf>
jmp    118c <prime_factors+0x6c>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    11bc <prime_factors+0x9c>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118c <prime_factors+0x6c>
jmp    11c1 <prime_factors+0xa1>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    116c <prime_factors+0x4c>
cmpl   $0x2,-0x4(%rbp)
jle    11ea <prime_factors+0xca>
mov    -0x4(%rbp),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime_factors>:
push   %rbp
push   %r14
push   %rbx
test   $0x1,%dil
jne    116f <prime_factors+0x3f>
lea    0xebf(%rip),%rbp
mov    %edi,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
shr    $0x1f,%ebx
add    %edi,%ebx
sar    %ebx
mov    %rbp,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
test   $0x1,%bl
je     1150 <prime_factors+0x20>
jmp    1171 <prime_factors+0x41>
mov    %edi,%ebx
mov    %ebx,%edi
call   1050 <sqrt@plt>
cmp    $0x3,%eax
jl     11ba <prime_factors+0x8a>
mov    $0x3,%ebp
lea    0xe77(%rip),%r14
jmp    11a3 <prime_factors+0x73>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
cltd
idiv   %ebp
mov    %eax,%ebx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     1190 <prime_factors+0x60>
add    $0x2,%ebp
mov    %ebx,%edi
call   1050 <sqrt@plt>
cmp    %eax,%ebp
jle    11a3 <prime_factors+0x73>
cmp    $0x3,%ebx
jl     11cf <prime_factors+0x9f>
lea    0xe3e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

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

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