#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);
void factor_rec(int num) {
  static int factor = 2;
  if (num == 1) {
    return;
  }
  if (num % factor == 0) {
    printf("%d\n", factor);
    while (num % factor == 0) {
      num = num / factor;
    }
  }
  factor++;
  factor_rec(num);
}


x86 assembly (clang, -O0):
<factor_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    113a <factor_rec+0x1a>
jmp    11a0 <factor_rec+0x80>
mov    -0x4(%rbp),%eax
cltd
idivl  0x2eec(%rip)
cmp    $0x0,%edx
jne    1189 <factor_rec+0x69>
mov    0x2edd(%rip),%esi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
cltd
idivl  0x2ec7(%rip)
cmp    $0x0,%edx
jne    1184 <factor_rec+0x64>
mov    -0x4(%rbp),%eax
cltd
idivl  0x2eb4(%rip)
mov    %eax,-0x4(%rbp)
jmp    115f <factor_rec+0x3f>
jmp    1189 <factor_rec+0x69>
mov    0x2ea1(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e98(%rip)
mov    -0x4(%rbp),%edi
call   1040 <factor_rec@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factor_rec>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    1121 <factor_rec+0x11>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %edi,%ebx
mov    0x2eff(%rip),%esi
lea    0xed0(%rip),%r14
jmp    114e <factor_rec+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%esi
mov    %esi,0x2edf(%rip)
cmp    $0x1,%ebx
je     1119 <factor_rec+0x9>
mov    %ebx,%eax
cltd
idiv   %esi
test   %edx,%edx
jne    1140 <factor_rec+0x30>
mov    %r14,%rdi
call   1030 <printf@plt>
mov    0x2ec3(%rip),%esi
mov    %ebx,%eax
nopw   0x0(%rax,%rax,1)
cltd
idiv   %esi
test   %edx,%edx
jne    1140 <factor_rec+0x30>
mov    %ebx,%eax
cltd
idiv   %esi
mov    %eax,%ebx
jmp    1170 <factor_rec+0x60>

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

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