#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 */
double sqrt(long);
int factorCount(long n) {
  double square = sqrt(n);
  int isquare = (int)square;
  int count = isquare == square ? -1 : 0;
  long candidate;
  for (candidate = 1; candidate <= isquare; candidate++)
    if (0 == n % candidate)
      count += 2;
  return count;
}


x86 assembly (clang, -O0):
<factorCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
cvttsd2si -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
xor    %eax,%eax
mov    $0xffffffff,%ecx
ucomisd %xmm1,%xmm0
setnp  %sil
sete   %dl
test   %sil,%dl
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jg     11a4 <factorCount+0x94>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x20(%rbp)
xor    %eax,%eax
cmp    %rdx,%rax
jne    118e <factorCount+0x7e>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    1193 <factorCount+0x83>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115f <factorCount+0x4f>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorCount>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <sqrt@plt>
cvttsd2si %xmm0,%eax
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
cmpeqsd %xmm0,%xmm1
movq   %xmm1,%rcx
test   %eax,%eax
jle    120b <factorCount+0xfb>
mov    %eax,%r8d
cmp    $0x1,%eax
jne    1156 <factorCount+0x46>
mov    $0x1,%esi
test   $0x1,%r8b
jne    11e3 <factorCount+0xd3>
jmp    120b <factorCount+0xfb>
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
mov    $0x1,%eax
jmp    118a <factorCount+0x7a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rax
cqto
idiv   %rbx
lea    0x2(%rdi),%ecx
test   %rdx,%rdx
cmovne %edi,%ecx
lea    0x1(%rbx),%rax
cmp    %r9,%rbx
je     11d9 <factorCount+0xc9>
mov    %rax,%rsi
mov    %r14,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     11b0 <factorCount+0xa0>
mov    %r14,%rax
cqto
idiv   %rsi
jmp    11b7 <factorCount+0xa7>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14d,%eax
xor    %edx,%edx
div    %esi
lea    0x2(%rcx),%edi
test   %rdx,%rdx
cmovne %ecx,%edi
lea    0x1(%rsi),%rbx
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1170 <factorCount+0x60>
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
jmp    1178 <factorCount+0x68>
add    $0x2,%rsi
test   $0x1,%r8b
je     120b <factorCount+0xfb>
mov    %r14,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     11f9 <factorCount+0xe9>
mov    %r14,%rax
cqto
idiv   %rsi
jmp    1200 <factorCount+0xf0>
mov    %r14d,%eax
xor    %edx,%edx
div    %esi
lea    0x2(%rcx),%eax
test   %rdx,%rdx
cmovne %ecx,%eax
mov    %eax,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @factorCount(i64 %0) {
%2 = tail call double @sqrt(i64 %0)
%3 = fptosi double %2 to i32
%4 = sitofp i32 %3 to double
%5 = fcmp oeq double %2, %4
%6 = sext i1 %5 to i32
%7 = icmp slt i32 %3, 1
br i1 %7, label %40, label %8
8: ; preds = %1
%9 = zext i32 %3 to i64
%10 = and i64 %9, 1
%11 = icmp eq i32 %3, 1
br i1 %11, label %30, label %12
12: ; preds = %8
%13 = and i64 %9, 4294967294
br label %14
14: ; preds = %14, %12
%15 = phi i64 [ 1, %12 ], [ %27, %14 ]
%16 = phi i32 [ %6, %12 ], [ %26, %14 ]
%17 = phi i64 [ 0, %12 ], [ %28, %14 ]
%18 = srem i64 %0, %15
%19 = icmp eq i64 %18, 0
%20 = add nsw i32 %16, 2
%21 = select i1 %19, i32 %20, i32 %16
%22 = add nuw nsw i64 %15, 1
%23 = srem i64 %0, %22
%24 = icmp eq i64 %23, 0
%25 = add nsw i32 %21, 2
%26 = select i1 %24, i32 %25, i32 %21
%27 = add nuw nsw i64 %15, 2
%28 = add i64 %17, 2
%29 = icmp eq i64 %28, %13
br i1 %29, label %30, label %14
30: ; preds = %14, %8
%31 = phi i32 [ undef, %8 ], [ %26, %14 ]
%32 = phi i64 [ 1, %8 ], [ %27, %14 ]
%33 = phi i32 [ %6, %8 ], [ %26, %14 ]
%34 = icmp eq i64 %10, 0
br i1 %34, label %40, label %35
35: ; preds = %30
%36 = srem i64 %0, %32
%37 = icmp eq i64 %36, 0
%38 = add nsw i32 %33, 2
%39 = select i1 %37, i32 %38, i32 %33
br label %40
40: ; preds = %35, %30, %1
%41 = phi i32 [ %6, %1 ], [ %31, %30 ], [ %39, %35 ]
ret i32 %41
}