#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_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clears(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_pow_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned int);
int /*<<< orphan*/ mpz_ui_pow_ui(int /*<<< orphan*/, int, unsigned int);
int count(unsigned int exp) {
  int c = 0;
  mpz_t base;
  mpz_init_set_ui(base, 1);
  mpz_t min;
  mpz_init(min);
  mpz_ui_pow_ui(min, 10, exp - 1);
  mpz_t max;
  mpz_init(max);
  mpz_ui_pow_ui(max, 10, exp);
  mpz_t res;
  mpz_init(res);
  for (;; mpz_add_ui(base, base, 1)) {
    mpz_pow_ui(res, base, exp);
    if (mpz_cmp(res, min) >= 0) {
      if (mpz_cmp(res, max) < 0) {
        c += 1;
      } else {
        break;
      }
    }
  }
  mpz_clears(base, min, max, res, 0);
  return c;
}


x86 assembly (clang, -O0):
<count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   1060 <mpz_init_set_ui@plt>
mov    -0x10(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x10(%rbp),%edi
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
mov    $0xa,%esi
call   1090 <mpz_ui_pow_ui@plt>
mov    -0x14(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%edx
mov    $0xa,%esi
call   1090 <mpz_ui_pow_ui@plt>
mov    -0x18(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1070 <mpz_pow_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1080 <mpz_cmp@plt>
cmp    $0x0,%rax
jl     121a <count+0xaa>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1080 <mpz_cmp@plt>
cmp    $0x0,%rax
jge    1210 <count+0xa0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1215 <count+0xa5>
jmp    1234 <count+0xc4>
jmp    121a <count+0xaa>
jmp    121f <count+0xaf>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   1030 <mpz_add_ui@plt>
jmp    11ca <count+0x5a>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
xor    %r8d,%r8d
call   1040 <mpz_clears@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x1,%esi
call   1060 <mpz_init_set_ui@plt>
call   1050 <mpz_init@plt>
lea    -0x1(%rbx),%edx
mov    $0xa,%esi
call   1090 <mpz_ui_pow_ui@plt>
call   1050 <mpz_init@plt>
mov    $0xa,%esi
mov    %ebx,%edx
call   1090 <mpz_ui_pow_ui@plt>
call   1050 <mpz_init@plt>
xor    %ebp,%ebp
jmp    11ba <count+0x4a>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edx
call   1030 <mpz_add_ui@plt>
mov    %ebx,%edx
call   1070 <mpz_pow_ui@plt>
call   1080 <mpz_cmp@plt>
test   %rax,%rax
js     11b0 <count+0x40>
call   1080 <mpz_cmp@plt>
test   %rax,%rax
jns    11da <count+0x6a>
add    $0x1,%ebp
jmp    11b0 <count+0x40>
xor    %r8d,%r8d
call   1040 <mpz_clears@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @count(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%8 = load i32, i32* %4
%9 = call i32 @mpz_init_set_ui(i32 %8, i32 1)
%10 = load i32, i32* %5
%11 = call i32 @mpz_init(i32 %10)
%12 = load i32, i32* %5
%13 = load i32, i32* %2
%14 = sub i32 %13, 1
%15 = call i32 @mpz_ui_pow_ui(i32 %12, i32 10, i32 %14)
%16 = load i32, i32* %6
%17 = call i32 @mpz_init(i32 %16)
%18 = load i32, i32* %6
%19 = load i32, i32* %2
%20 = call i32 @mpz_ui_pow_ui(i32 %18, i32 10, i32 %19)
%21 = load i32, i32* %7
%22 = call i32 @mpz_init(i32 %21)
br label %23
23: ; preds = %43, %1
%24 = load i32, i32* %7
%25 = load i32, i32* %4
%26 = load i32, i32* %2
%27 = call i32 @mpz_pow_ui(i32 %24, i32 %25, i32 %26)
%28 = load i32, i32* %7
%29 = load i32, i32* %5
%30 = call i64 @mpz_cmp(i32 %28, i32 %29)
%31 = icmp sge i64 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %23
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = call i64 @mpz_cmp(i32 %33, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %41
40: ; preds = %32
br label %47
41: ; preds = %37
br label %42
42: ; preds = %41, %23
br label %43
43: ; preds = %42
%44 = load i32, i32* %4
%45 = load i32, i32* %4
%46 = call i32 @mpz_add_ui(i32 %44, i32 %45, i32 1)
br label %23
47: ; preds = %40
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = call i32 @mpz_clears(i32 %48, i32 %49, i32 %50, i32 %51, i32 0)
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
define i32 @count(i32 %0) {
%2 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%3 = tail call i32 @mpz_init(i32 undef)
%4 = add i32 %0, -1
%5 = tail call i32 @mpz_ui_pow_ui(i32 undef, i32 10, i32 %4)
%6 = tail call i32 @mpz_init(i32 undef)
%7 = tail call i32 @mpz_ui_pow_ui(i32 undef, i32 10, i32 %0)
%8 = tail call i32 @mpz_init(i32 undef)
br label %9
9: ; preds = %19, %1
%10 = phi i32 [ 0, %1 ], [ %20, %19 ]
%11 = tail call i32 @mpz_pow_ui(i32 undef, i32 undef, i32 %0)
%12 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%13 = icmp sgt i64 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = add nsw i32 %10, 1
br label %19
19: ; preds = %9, %17
%20 = phi i32 [ %18, %17 ], [ %10, %9 ]
%21 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 1)
br label %9
22: ; preds = %14
%23 = tail call i32 @mpz_clears(i32 undef, i32 undef, i32 undef, i32 undef, i32 0)
ret i32 %10
}