#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(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ mpz_powm(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
void num_bits(mpz_t bits, mpz_t number) {
  mpz_t pow, ground, counter, module;
  mpz_init_set_str(counter, "100", 10);
  mpz_init_set_str(pow, "0", 10);
  mpz_init_set_str(ground, "2", 10);
  mpz_init_set_str(module, "1000000000000000000000000000", 10);
  do {
    mpz_powm(counter, ground, pow, module);
    mpz_add(pow, bits, pow);
  } while (mpz_cmp(number, counter) >= 0);
  mpz_sub(bits, pow, bits);
  mpz_clear(pow);
  mpz_clear(ground);
  mpz_clear(counter);
  mpz_clear(module);
}


x86 assembly (clang, -O0):
<num_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x14(%rbp),%edi
lea    0xe88(%rip),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
mov    -0xc(%rbp),%edi
lea    0xe95(%rip),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
mov    -0x10(%rbp),%edi
lea    0xe64(%rip),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
mov    -0x18(%rbp),%edi
lea    0xe52(%rip),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <mpz_powm@plt>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <mpz_add@plt>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <mpz_cmp@plt>
cmp    $0x0,%rax
jge    11be <num_bits+0x5e>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1040 <mpz_sub@plt>
mov    -0xc(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x10(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x14(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x18(%rbp),%edi
call   1080 <mpz_clear@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_bits>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xe92(%rip),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
lea    0xea2(%rip),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
lea    0xe74(%rip),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
lea    0xe65(%rip),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
nopl   0x0(%rax,%rax,1)
call   1030 <mpz_powm@plt>
mov    %ebx,%esi
call   1060 <mpz_add@plt>
mov    %ebp,%edi
call   1070 <mpz_cmp@plt>
test   %rax,%rax
jns    11b0 <num_bits+0x50>
mov    %ebx,%edi
mov    %ebx,%edx
call   1040 <mpz_sub@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1080 <mpz_clear@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"100\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c"2\00"
@.str.3 = [29 x i8] c"1000000000000000000000000000\00"
define void @num_bits(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %7
%10 = call i32 @mpz_init_set_str(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 10)
%11 = load i32, i32* %5
%12 = call i32 @mpz_init_set_str(i32 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 10)
%13 = load i32, i32* %6
%14 = call i32 @mpz_init_set_str(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 10)
%15 = load i32, i32* %8
%16 = call i32 @mpz_init_set_str(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 10)
br label %17
17: ; preds = %27, %2
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = load i32, i32* %5
%21 = load i32, i32* %8
%22 = call i32 @mpz_powm(i32 %18, i32 %19, i32 %20, i32 %21)
%23 = load i32, i32* %5
%24 = load i32, i32* %3
%25 = load i32, i32* %5
%26 = call i32 @mpz_add(i32 %23, i32 %24, i32 %25)
br label %27
27: ; preds = %17
%28 = load i32, i32* %4
%29 = load i32, i32* %7
%30 = call i64 @mpz_cmp(i32 %28, i32 %29)
%31 = icmp sge i64 %30, 0
br i1 %31, label %17, label %32
32: ; preds = %27
%33 = load i32, i32* %3
%34 = load i32, i32* %5
%35 = load i32, i32* %3
%36 = call i32 @mpz_sub(i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* %5
%38 = call i32 @mpz_clear(i32 %37)
%39 = load i32, i32* %6
%40 = call i32 @mpz_clear(i32 %39)
%41 = load i32, i32* %7
%42 = call i32 @mpz_clear(i32 %41)
%43 = load i32, i32* %8
%44 = call i32 @mpz_clear(i32 %43)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"100\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c"2\00"
@.str.3 = [29 x i8] c"1000000000000000000000000000\00"
define void @num_bits(i32 %0, i32 %1) {
%3 = tail call i32 @mpz_init_set_str(i32 undef, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 10)
%4 = tail call i32 @mpz_init_set_str(i32 undef, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 10)
%5 = tail call i32 @mpz_init_set_str(i32 undef, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 10)
%6 = tail call i32 @mpz_init_set_str(i32 undef, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 10)
br label %7
7: ; preds = %7, %2
%8 = tail call i32 @mpz_powm(i32 undef, i32 undef, i32 undef, i32 undef)
%9 = tail call i32 @mpz_add(i32 undef, i32 %0, i32 undef)
%10 = tail call i64 @mpz_cmp(i32 %1, i32 undef)
%11 = icmp sgt i64 %10, -1
br i1 %11, label %7, label %12
12: ; preds = %7
%13 = tail call i32 @mpz_sub(i32 %0, i32 undef, i32 %0)
%14 = tail call i32 @mpz_clear(i32 undef)
%15 = tail call i32 @mpz_clear(i32 undef)
%16 = tail call i32 @mpz_clear(i32 undef)
%17 = tail call i32 @mpz_clear(i32 undef)
ret void
}