#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 floor(int);
int sqrt(unsigned int);
int factor_count(unsigned num) {
  int counter = 0;
  for (int i = 1; i <= sqrt(num); i++)
    if (!(num % i))
      ++counter;
  counter *= 2;
  if (floor(sqrt(num)) == sqrt(num))
    counter--;
  return counter;
}


x86 assembly (clang, -O0):
<factor_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     1181 <factor_count+0x61>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
cmp    $0x0,%edx
jne    116e <factor_count+0x4e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1173 <factor_count+0x53>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <factor_count+0x19>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,%edi
call   1040 <floor@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jne    11ba <factor_count+0x9a>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factor_count>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
call   1030 <sqrt@plt>
test   %eax,%eax
jle    1160 <factor_count+0x40>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
cmp    $0x1,%edx
adc    $0x0,%ebp
mov    %r15d,%edi
call   1030 <sqrt@plt>
cmp    %eax,%ebx
jl     1140 <factor_count+0x20>
add    %ebp,%ebp
jmp    1162 <factor_count+0x42>
xor    %ebp,%ebp
mov    %r15d,%edi
call   1030 <sqrt@plt>
mov    %eax,%edi
call   1040 <floor@plt>
mov    %eax,%r14d
mov    %r15d,%edi
call   1030 <sqrt@plt>
xor    %ecx,%ecx
cmp    %eax,%r14d
sete   %cl
sub    %ecx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @factor_count(i32 %0) {
%2 = tail call i32 @sqrt(i32 %0)
%3 = icmp slt i32 %2, 1
br i1 %3, label %6, label %14
4: ; preds = %14
%5 = shl nuw i32 %20, 1
br label %6
6: ; preds = %4, %1
%7 = phi i32 [ 0, %1 ], [ %5, %4 ]
%8 = tail call i32 @sqrt(i32 %0)
%9 = tail call i32 @floor(i32 %8)
%10 = tail call i32 @sqrt(i32 %0)
%11 = icmp eq i32 %9, %10
%12 = sext i1 %11 to i32
%13 = add nsw i32 %7, %12
ret i32 %13
14: ; preds = %1, %14
%15 = phi i32 [ %21, %14 ], [ 1, %1 ]
%16 = phi i32 [ %20, %14 ], [ 0, %1 ]
%17 = urem i32 %0, %15
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %16, %19
%21 = add nuw nsw i32 %15, 1
%22 = tail call i32 @sqrt(i32 %0)
%23 = icmp slt i32 %15, %22
br i1 %23, label %14, label %4
}