#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 */
scalar_t__ ceil(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(double);
long long factor(const long long i) {
  long long max = (long long)ceil(sqrt((double)i));
  long long j = 2;
  while (j <= max) {
    if (i % j == 0)
      return j;
    else
      j++;
  }
  return i;
}


x86 assembly (clang, -O0):
<factor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm0
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %rax,-0x18(%rbp)
movq   $0x2,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     118a <factor+0x6a>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x20(%rbp)
cmp    $0x0,%rdx
jne    1179 <factor+0x59>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1192 <factor+0x72>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114a <factor+0x2a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factor>:
push   %rbx
mov    %rdi,%rbx
cvtsi2sd %rdi,%xmm0
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
cmp    $0x2,%rax
jl     1192 <factor+0x72>
mov    $0x1,%ecx
sub    %rax,%rcx
mov    $0x2,%esi
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1170 <factor+0x50>
mov    %rbx,%rax
cqto
idiv   %rsi
test   %rdx,%rdx
jne    117b <factor+0x5b>
jmp    118f <factor+0x6f>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
je     118f <factor+0x6f>
lea    (%rcx,%rsi,1),%rax
add    $0x1,%rax
add    $0x1,%rsi
cmp    $0x2,%rax
jne    1150 <factor+0x30>
jmp    1192 <factor+0x72>
mov    %rsi,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @factor(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %3
%6 = load i64, i64* %3
%7 = sitofp i64 %6 to double
%8 = call i32 @sqrt(double %7)
%9 = call i64 @ceil(i32 %8)
store i64 %9, i64* %4
store i64 2, i64* %5
br label %10
10: ; preds = %24, %1
%11 = load i64, i64* %5
%12 = load i64, i64* %4
%13 = icmp sle i64 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i64, i64* %3
%16 = load i64, i64* %5
%17 = srem i64 %15, %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = load i64, i64* %5
store i64 %20, i64* %2
br label %27
21: ; preds = %14
%22 = load i64, i64* %5
%23 = add nsw i64 %22, 1
store i64 %23, i64* %5
br label %24
24: ; preds = %21
br label %10
25: ; preds = %10
%26 = load i64, i64* %3
store i64 %26, i64* %2
br label %27
27: ; preds = %25, %19
%28 = load i64, i64* %2
ret i64 %28
}

LLVM IR (-O2):
define i64 @factor(i64 %0) {
%2 = sitofp i64 %0 to double
%3 = tail call i32 @sqrt(double %2)
%4 = tail call i64 @ceil(i32 %3)
%5 = icmp slt i64 %4, 2
br i1 %5, label %13, label %6
6: ; preds = %1, %10
%7 = phi i64 [ %11, %10 ], [ 2, %1 ]
%8 = srem i64 %0, %7
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = add nuw i64 %7, 1
%12 = icmp eq i64 %7, %4
br i1 %12, label %13, label %6
13: ; preds = %6, %10, %1
%14 = phi i64 [ %0, %1 ], [ %0, %10 ], [ %7, %6 ]
ret i64 %14
}