#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_cmpabs(int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
unsigned int mpz_sizeinbase(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ mpz_ui_pow_ui(int /*<<< orphan*/, int, unsigned int);
unsigned int b10_digits(const mpz_t n) {
  mpz_t x;
  unsigned int size;
  size = mpz_sizeinbase(n, 10);
  mpz_init(x);
  mpz_ui_pow_ui(x, 10, size - 1);
  if (mpz_cmpabs(n, x) < 0)
    size--;
  mpz_clear(x);
  return size;
}


x86 assembly (clang, -O0):
<b10_digits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xa,%esi
call   1040 <mpz_sizeinbase@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <mpz_init@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
mov    $0xa,%esi
call   1070 <mpz_ui_pow_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <mpz_cmpabs@plt>
cmp    $0x0,%rax
jge    11a4 <b10_digits+0x54>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <mpz_clear@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b10_digits>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0xa,%esi
call   1040 <mpz_sizeinbase@plt>
mov    %eax,%ebx
call   1030 <mpz_init@plt>
lea    -0x1(%rbx),%ebp
mov    $0xa,%esi
mov    %ebp,%edx
call   1070 <mpz_ui_pow_ui@plt>
mov    %r14d,%edi
call   1050 <mpz_cmpabs@plt>
test   %rax,%rax
cmovs  %ebp,%ebx
call   1060 <mpz_clear@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @b10_digits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @mpz_sizeinbase(i32 %5, i32 10)
store i32 %6, i32* %4
%7 = load i32, i32* %3
%8 = call i32 @mpz_init(i32 %7)
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = sub i32 %10, 1
%12 = call i32 @mpz_ui_pow_ui(i32 %9, i32 10, i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = call i64 @mpz_cmpabs(i32 %13, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i32, i32* %4
%19 = add i32 %18, -1
store i32 %19, i32* %4
br label %20
20: ; preds = %17, %1
%21 = load i32, i32* %3
%22 = call i32 @mpz_clear(i32 %21)
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
define i32 @b10_digits(i32 %0) {
%2 = tail call i32 @mpz_sizeinbase(i32 %0, i32 10)
%3 = tail call i32 @mpz_init(i32 undef)
%4 = add i32 %2, -1
%5 = tail call i32 @mpz_ui_pow_ui(i32 undef, i32 10, i32 %4)
%6 = tail call i64 @mpz_cmpabs(i32 %0, i32 undef)
%7 = icmp slt i64 %6, 0
%8 = select i1 %7, i32 %4, i32 %2
%9 = tail call i32 @mpz_clear(i32 undef)
ret i32 %8
}