#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*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sqrt(double);
int /*<<< orphan*/ stdout;
void factor(int number, int n, int j) {
  int i;
  if (n == 1) {
    printf("1 is a unit\n");
    return;
  }
  i = j;
  while (i <= (int)(sqrt((double)n))) {
    if (n % i == 0) {
      fprintf(stdout, "%d\n", i);
      factor(number, (int)(n / i), i);
      return;
    } else {
      i++;
    }
  }
  if (n == number)
    printf("%d is prime\n", number);
  else
    printf("%d\n", n);
  return;
}


x86 assembly (clang, -O0):
<factor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    116e <factor+0x2e>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1219 <factor+0xd9>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
call   1060 <sqrt@plt>
mov    %rax,%rcx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     11e1 <factor+0xa1>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11d3 <factor+0x93>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xe58(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%edx
call   1050 <factor@plt>
jmp    1219 <factor+0xd9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1174 <factor+0x34>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1203 <factor+0xc3>
mov    -0x4(%rbp),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1214 <factor+0xd4>
mov    -0x8(%rbp),%esi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1219 <factor+0xd9>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%esi
jne    116a <factor+0x2a>
lea    0xeba(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
mov    %edx,%ebx
mov    %esi,%r12d
mov    %edi,%r14d
mov    0x2e67(%rip),%r13
lea    0xe80(%rip),%r15
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
movsd  %xmm0,(%rsp)
call   1060 <sqrt@plt>
cmp    %eax,%ebx
jg     11dd <factor+0x9d>
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%eax
cltd
idiv   %ebx
test   %edx,%edx
je     11c0 <factor+0x80>
lea    0x1(%rbx),%ebp
movsd  (%rsp),%xmm0
call   1060 <sqrt@plt>
cmp    %eax,%ebx
mov    %ebp,%ebx
jl     11a0 <factor+0x60>
jmp    11dd <factor+0x9d>
nop
mov    %eax,%ebp
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
mov    %ebp,%r12d
cmp    $0x1,%ebp
jne    1180 <factor+0x40>
jmp    1150 <factor+0x10>
cmp    %r14d,%r12d
jne    11ee <factor+0xae>
lea    0xe1b(%rip),%rdi
mov    %r14d,%esi
jmp    11f8 <factor+0xb8>
lea    0xe0b(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

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

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