#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpz_divisible_p(int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sqrtrem(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/ const);
int /*<<< orphan*/ mpz_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int mpz_count_divisors(const mpz_t num) {
  int count = 0;
  mpz_t div;
  mpz_t sqt;
  mpz_init(sqt);
  mpz_init(div);
  mpz_sqrtrem(sqt, div, num);
  if (!mpz_cmp_ui(div, 0)) {
    count--;
    if (1) {
    }
  }
  mpz_set(div, sqt);
  do {
    if (mpz_divisible_p(num, div)) {
      count++;
      count++;
    }
    mpz_sub_ui(div, div, 1);
  } while (mpz_cmp_ui(div, 0));
  mpz_clear(div);
  mpz_clear(sqt);
  return count;
}


x86 assembly (clang, -O0):
<mpz_count_divisors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0xc(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1080 <mpz_sqrtrem@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1070 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    11bd <mpz_count_divisors+0x4d>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <mpz_divisible_p@plt>
cmp    $0x0,%rax
je     11ef <mpz_count_divisors+0x7f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   1060 <mpz_sub_ui@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1070 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    11c8 <mpz_count_divisors+0x58>
mov    -0xc(%rbp),%edi
call   1090 <mpz_clear@plt>
mov    -0x10(%rbp),%edi
call   1090 <mpz_clear@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpz_count_divisors>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
call   1050 <mpz_init@plt>
call   1050 <mpz_init@plt>
mov    %r14d,%edx
call   1080 <mpz_sqrtrem@plt>
xor    %esi,%esi
call   1070 <mpz_cmp_ui@plt>
cmp    $0x1,%rax
sbb    %ebp,%ebp
call   1040 <mpz_set@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ebx
mov    %r14d,%edi
call   1030 <mpz_divisible_p@plt>
lea    0x2(%rbx),%ebp
test   %rax,%rax
cmove  %ebx,%ebp
mov    $0x1,%edx
call   1060 <mpz_sub_ui@plt>
xor    %esi,%esi
call   1070 <mpz_cmp_ui@plt>
test   %rax,%rax
jne    11a0 <mpz_count_divisors+0x30>
call   1090 <mpz_clear@plt>
call   1090 <mpz_clear@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mpz_count_divisors(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = load i32, i32* %5
%7 = call i32 @mpz_init(i32 %6)
%8 = load i32, i32* %4
%9 = call i32 @mpz_init(i32 %8)
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = call i32 @mpz_sqrtrem(i32 %10, i32 %11, i32 %12)
%14 = load i32, i32* %4
%15 = call i64 @mpz_cmp_ui(i32 %14, i32 0)
%16 = icmp ne i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %1
%18 = load i32, i32* %3
%19 = add nsw i32 %18, -1
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %1
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @mpz_set(i32 %21, i32 %22)
br label %24
24: ; preds = %38, %20
%25 = load i32, i32* %2
%26 = load i32, i32* %4
%27 = call i64 @mpz_divisible_p(i32 %25, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %34
34: ; preds = %29, %24
%35 = load i32, i32* %4
%36 = load i32, i32* %4
%37 = call i32 @mpz_sub_ui(i32 %35, i32 %36, i32 1)
br label %38
38: ; preds = %34
%39 = load i32, i32* %4
%40 = call i64 @mpz_cmp_ui(i32 %39, i32 0)
%41 = icmp ne i64 %40, 0
br i1 %41, label %24, label %42
42: ; preds = %38
%43 = load i32, i32* %4
%44 = call i32 @mpz_clear(i32 %43)
%45 = load i32, i32* %5
%46 = call i32 @mpz_clear(i32 %45)
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @mpz_count_divisors(i32 %0) {
%2 = tail call i32 @mpz_init(i32 undef)
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_sqrtrem(i32 undef, i32 undef, i32 %0)
%5 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%6 = icmp eq i64 %5, 0
%7 = sext i1 %6 to i32
%8 = tail call i32 @mpz_set(i32 undef, i32 undef)
br label %9
9: ; preds = %9, %1
%10 = phi i32 [ %7, %1 ], [ %14, %9 ]
%11 = tail call i64 @mpz_divisible_p(i32 %0, i32 undef)
%12 = icmp eq i64 %11, 0
%13 = add nsw i32 %10, 2
%14 = select i1 %12, i32 %10, i32 %13
%15 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 1)
%16 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %9
18: ; preds = %9
%19 = tail call i32 @mpz_clear(i32 undef)
%20 = tail call i32 @mpz_clear(i32 undef)
ret i32 %14
}