#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 next_prime(int, int *);
int /*<<< orphan*/ printf(char *, ...);
void prime_factors(int num, bool *primes) {
  int c;
  c = 2;
  while (num > 1) {
    c = next_prime(c, primes);
    if (num % c == 0) {
      num = num / c;
      printf("%d, ", c);
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<prime_factors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    117f <prime_factors+0x5f>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <next_prime@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    117a <prime_factors+0x5a>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1136 <prime_factors+0x16>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime_factors>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jl     117e <prime_factors+0x4e>
mov    %rsi,%r15
mov    %edi,%ebx
mov    $0x2,%ebp
lea    0xeb2(%rip),%r14
jmp    1155 <prime_factors+0x25>
cmp    $0x1,%ebx
jle    117e <prime_factors+0x4e>
mov    %ebp,%edi
mov    %r15,%rsi
call   1050 <next_prime@plt>
mov    %eax,%ebp
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
jne    1150 <prime_factors+0x20>
mov    %eax,%r12d
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%ebx
jmp    1150 <prime_factors+0x20>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%d, \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @prime_factors(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 2, i32* %5
br label %6
6: ; preds = %23, %2
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i32, i32* %5
%11 = load i32*, i32** %4
%12 = call i32 @next_prime(i32 %10, i32* %11)
store i32 %12, i32* %5
%13 = load i32, i32* %3
%14 = load i32, i32* %5
%15 = srem i32 %13, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = load i32, i32* %3
%19 = load i32, i32* %5
%20 = sdiv i32 %18, %19
store i32 %20, i32* %3
%21 = load i32, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %17, %9
br label %6
24: ; preds = %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d, \00"
define void @prime_factors(i32 %0, i32* %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %16
4: ; preds = %2, %13
%5 = phi i32 [ %7, %13 ], [ 2, %2 ]
%6 = phi i32 [ %14, %13 ], [ %0, %2 ]
%7 = tail call i32 @next_prime(i32 %5, i32* %1)
%8 = srem i32 %6, %7
%9 = sdiv i32 %6, %7
%10 = icmp eq i32 %8, 0
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %13
13: ; preds = %11, %4
%14 = phi i32 [ %9, %11 ], [ %6, %4 ]
%15 = icmp sgt i32 %14, 1
br i1 %15, label %4, label %16
16: ; preds = %13, %2
%17 = tail call i32 @putchar(i32 10)
ret void
}