#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 */
long long ceil(int);
long long floor(int);
scalar_t__ log10(long long);
int log2(double);
long long calc(long long x) {
  int i;
  int len_x = (int)log10(x) + 1;
  long long low, high;
  for (i = len_x + 1; 1; ++i) {
    low = ceil(log2(x) + i * log2(10.0));
    high = floor(log2(x + 1) + i * log2(10.0));
    if (high == low)
      return high;
  }
  return high;
}


x86 assembly (clang, -O0):
<calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <log10@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    1173 <calc+0x33>
jmp    1216 <calc+0xd6>
cvtsi2sdq -0x10(%rbp),%xmm0
call   1030 <log2@plt>
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
movsd  0xe71(%rip),%xmm0
call   1030 <log2@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
imul   %ecx,%eax
add    %eax,%edi
call   1040 <ceil@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
call   1030 <log2@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movsd  0xe33(%rip),%xmm0
call   1030 <log2@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
imul   %ecx,%eax
add    %eax,%edi
call   1060 <floor@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1203 <calc+0xc3>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121e <calc+0xde>
jmp    1208 <calc+0xc8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <calc+0x24>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
call   1050 <log10@plt>
mov    %rax,%rbx
add    $0x2,%ebx
cvtsi2sd %r14,%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0x1,%r14
xorps  %xmm0,%xmm0
cvtsi2sd %r14,%xmm0
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x8(%rsp),%xmm0
call   1030 <log2@plt>
mov    %eax,%ebp
movsd  0xe6b(%rip),%xmm0
call   1030 <log2@plt>
imul   %ebx,%eax
add    %eax,%ebp
mov    %ebp,%edi
call   1040 <ceil@plt>
mov    %rax,%r14
movsd  (%rsp),%xmm0
call   1030 <log2@plt>
mov    %eax,%ebp
movsd  0xe43(%rip),%xmm0
call   1030 <log2@plt>
imul   %ebx,%eax
add    %eax,%ebp
mov    %ebp,%edi
call   1060 <floor@plt>
add    $0x1,%ebx
cmp    %r14,%rax
jne    1180 <calc+0x40>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i64 @calc(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %3
%8 = load i64, i64* %3
%9 = call i64 @log10(i64 %8)
%10 = trunc i64 %9 to i32
%11 = add nsw i32 %10, 1
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
br label %14
14: ; preds = %39, %1
br i1 true, label %15, label %42
15: ; preds = %14
%16 = load i64, i64* %3
%17 = sitofp i64 %16 to double
%18 = call i32 @log2(double %17)
%19 = load i32, i32* %4
%20 = call i32 @log2(double 1.000000e+01)
%21 = mul nsw i32 %19, %20
%22 = add nsw i32 %18, %21
%23 = call i64 @ceil(i32 %22)
store i64 %23, i64* %6
%24 = load i64, i64* %3
%25 = add nsw i64 %24, 1
%26 = sitofp i64 %25 to double
%27 = call i32 @log2(double %26)
%28 = load i32, i32* %4
%29 = call i32 @log2(double 1.000000e+01)
%30 = mul nsw i32 %28, %29
%31 = add nsw i32 %27, %30
%32 = call i64 @floor(i32 %31)
store i64 %32, i64* %7
%33 = load i64, i64* %7
%34 = load i64, i64* %6
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %15
%37 = load i64, i64* %7
store i64 %37, i64* %2
br label %44
38: ; preds = %15
br label %39
39: ; preds = %38
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %14
42: ; preds = %14
%43 = load i64, i64* %7
store i64 %43, i64* %2
br label %44
44: ; preds = %42, %36
%45 = load i64, i64* %2
ret i64 %45
}

LLVM IR (-O2):
define i64 @calc(i64 %0) {
%2 = tail call i64 @log10(i64 %0)
%3 = trunc i64 %2 to i32
%4 = add nsw i32 %3, 2
%5 = sitofp i64 %0 to double
%6 = add nsw i64 %0, 1
%7 = sitofp i64 %6 to double
br label %8
8: ; preds = %8, %1
%9 = phi i32 [ %4, %1 ], [ %21, %8 ]
%10 = tail call i32 @log2(double %5)
%11 = tail call i32 @log2(double 1.000000e+01)
%12 = mul nsw i32 %11, %9
%13 = add nsw i32 %12, %10
%14 = tail call i64 @ceil(i32 %13)
%15 = tail call i32 @log2(double %7)
%16 = tail call i32 @log2(double 1.000000e+01)
%17 = mul nsw i32 %16, %9
%18 = add nsw i32 %17, %15
%19 = tail call i64 @floor(i32 %18)
%20 = icmp eq i64 %19, %14
%21 = add nsw i32 %9, 1
br i1 %20, label %22, label %8
22: ; preds = %8
ret i64 %14
}