#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 const uint64_t;

/* Variables and functions */
int const UINT64_C(int);
int nlz(int const);
int lg(uint64_t u) {
  const uint64_t t[20] = {UINT64_C(0),
                          UINT64_C(9),
                          UINT64_C(99),
                          UINT64_C(999),
                          UINT64_C(9999),
                          UINT64_C(99999),
                          UINT64_C(999999),
                          UINT64_C(9999999),
                          UINT64_C(99999999),
                          UINT64_C(999999999),
                          UINT64_C(9999999999),
                          UINT64_C(99999999999),
                          UINT64_C(999999999999),
                          UINT64_C(9999999999999),
                          UINT64_C(99999999999999),
                          UINT64_C(999999999999999),
                          UINT64_C(9999999999999999),
                          UINT64_C(99999999999999999),
                          UINT64_C(999999999999999999),
                          UINT64_C(9999999999999999999)};
  int i = (19 * (63 - nlz(u))) >> 6;
  i += (int)((t[i + 1] - u) >> 63);
  return i;
}


x86 assembly (clang, -O0):
<lg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
xor    %edi,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x60(%rbp)
mov    $0x9,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x5c(%rbp)
mov    $0x63,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x58(%rbp)
mov    $0x3e7,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x54(%rbp)
mov    $0x270f,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x50(%rbp)
mov    $0x1869f,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x4c(%rbp)
mov    $0xf423f,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x48(%rbp)
mov    $0x98967f,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x44(%rbp)
mov    $0x5f5e0ff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x40(%rbp)
mov    $0x3b9ac9ff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x3c(%rbp)
mov    $0x540be3ff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x38(%rbp)
mov    $0x4876e7ff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x34(%rbp)
mov    $0xd4a50fff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x30(%rbp)
mov    $0x4e729fff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x107a3fff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x28(%rbp)
mov    $0xa4c67fff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x24(%rbp)
mov    $0x6fc0ffff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x20(%rbp)
mov    $0x5d89ffff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xa763ffff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x18(%rbp)
mov    $0x89e7ffff,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <nlz@plt>
mov    %eax,%ecx
mov    $0x3f,%eax
sub    %ecx,%eax
imul   $0x13,%eax,%eax
sar    $0x6,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x60(%rbp,%rax,4),%eax
sub    -0x4(%rbp),%eax
mov    $0x3f,%ecx
sar    %cl,%eax
add    -0x64(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lg>:
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
call   1030 <UINT64_C@plt>
mov    $0x9,%edi
call   1030 <UINT64_C@plt>
mov    $0x63,%edi
call   1030 <UINT64_C@plt>
mov    $0x3e7,%edi
call   1030 <UINT64_C@plt>
mov    $0x270f,%edi
call   1030 <UINT64_C@plt>
mov    $0x1869f,%edi
call   1030 <UINT64_C@plt>
mov    $0xf423f,%edi
call   1030 <UINT64_C@plt>
mov    $0x98967f,%edi
call   1030 <UINT64_C@plt>
mov    $0x5f5e0ff,%edi
call   1030 <UINT64_C@plt>
mov    $0x3b9ac9ff,%edi
call   1030 <UINT64_C@plt>
mov    $0x540be3ff,%edi
call   1030 <UINT64_C@plt>
mov    $0x4876e7ff,%edi
call   1030 <UINT64_C@plt>
mov    $0xd4a50fff,%edi
call   1030 <UINT64_C@plt>
mov    $0x4e729fff,%edi
call   1030 <UINT64_C@plt>
mov    $0x107a3fff,%edi
call   1030 <UINT64_C@plt>
mov    $0xa4c67fff,%edi
call   1030 <UINT64_C@plt>
mov    $0x6fc0ffff,%edi
call   1030 <UINT64_C@plt>
mov    $0x5d89ffff,%edi
call   1030 <UINT64_C@plt>
mov    $0xa763ffff,%edi
call   1030 <UINT64_C@plt>
mov    $0x89e7ffff,%edi
call   1030 <UINT64_C@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1040 <nlz@plt>

LLVM IR (-O0):
define i32 @lg(i32 %0) {
%2 = alloca i32
%3 = alloca [20 x i32]
%4 = alloca i32
store i32 %0, i32* %2
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%6 = call i32 @UINT64_C(i32 0)
store i32 %6, i32* %5
%7 = getelementptr inbounds i32, i32* %5, i64 1
%8 = call i32 @UINT64_C(i32 9)
store i32 %8, i32* %7
%9 = getelementptr inbounds i32, i32* %7, i64 1
%10 = call i32 @UINT64_C(i32 99)
store i32 %10, i32* %9
%11 = getelementptr inbounds i32, i32* %9, i64 1
%12 = call i32 @UINT64_C(i32 999)
store i32 %12, i32* %11
%13 = getelementptr inbounds i32, i32* %11, i64 1
%14 = call i32 @UINT64_C(i32 9999)
store i32 %14, i32* %13
%15 = getelementptr inbounds i32, i32* %13, i64 1
%16 = call i32 @UINT64_C(i32 99999)
store i32 %16, i32* %15
%17 = getelementptr inbounds i32, i32* %15, i64 1
%18 = call i32 @UINT64_C(i32 999999)
store i32 %18, i32* %17
%19 = getelementptr inbounds i32, i32* %17, i64 1
%20 = call i32 @UINT64_C(i32 9999999)
store i32 %20, i32* %19
%21 = getelementptr inbounds i32, i32* %19, i64 1
%22 = call i32 @UINT64_C(i32 99999999)
store i32 %22, i32* %21
%23 = getelementptr inbounds i32, i32* %21, i64 1
%24 = call i32 @UINT64_C(i32 999999999)
store i32 %24, i32* %23
%25 = getelementptr inbounds i32, i32* %23, i64 1
%26 = call i32 @UINT64_C(i32 1410065407)
store i32 %26, i32* %25
%27 = getelementptr inbounds i32, i32* %25, i64 1
%28 = call i32 @UINT64_C(i32 1215752191)
store i32 %28, i32* %27
%29 = getelementptr inbounds i32, i32* %27, i64 1
%30 = call i32 @UINT64_C(i32 -727379969)
store i32 %30, i32* %29
%31 = getelementptr inbounds i32, i32* %29, i64 1
%32 = call i32 @UINT64_C(i32 1316134911)
store i32 %32, i32* %31
%33 = getelementptr inbounds i32, i32* %31, i64 1
%34 = call i32 @UINT64_C(i32 276447231)
store i32 %34, i32* %33
%35 = getelementptr inbounds i32, i32* %33, i64 1
%36 = call i32 @UINT64_C(i32 -1530494977)
store i32 %36, i32* %35
%37 = getelementptr inbounds i32, i32* %35, i64 1
%38 = call i32 @UINT64_C(i32 1874919423)
store i32 %38, i32* %37
%39 = getelementptr inbounds i32, i32* %37, i64 1
%40 = call i32 @UINT64_C(i32 1569325055)
store i32 %40, i32* %39
%41 = getelementptr inbounds i32, i32* %39, i64 1
%42 = call i32 @UINT64_C(i32 -1486618625)
store i32 %42, i32* %41
%43 = getelementptr inbounds i32, i32* %41, i64 1
%44 = call i32 @UINT64_C(i32 -1981284353)
store i32 %44, i32* %43
%45 = load i32, i32* %2
%46 = call i32 @nlz(i32 %45)
%47 = sub nsw i32 63, %46
%48 = mul nsw i32 19, %47
%49 = ashr i32 %48, 6
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = load i32, i32* %2
%56 = sub nsw i32 %54, %55
%57 = ashr i32 %56, 63
%58 = load i32, i32* %4
%59 = add nsw i32 %58, %57
store i32 %59, i32* %4
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
define i32 @lg(i32 %0) {
%2 = tail call i32 @UINT64_C(i32 0)
%3 = tail call i32 @UINT64_C(i32 9)
%4 = tail call i32 @UINT64_C(i32 99)
%5 = tail call i32 @UINT64_C(i32 999)
%6 = tail call i32 @UINT64_C(i32 9999)
%7 = tail call i32 @UINT64_C(i32 99999)
%8 = tail call i32 @UINT64_C(i32 999999)
%9 = tail call i32 @UINT64_C(i32 9999999)
%10 = tail call i32 @UINT64_C(i32 99999999)
%11 = tail call i32 @UINT64_C(i32 999999999)
%12 = tail call i32 @UINT64_C(i32 1410065407)
%13 = tail call i32 @UINT64_C(i32 1215752191)
%14 = tail call i32 @UINT64_C(i32 -727379969)
%15 = tail call i32 @UINT64_C(i32 1316134911)
%16 = tail call i32 @UINT64_C(i32 276447231)
%17 = tail call i32 @UINT64_C(i32 -1530494977)
%18 = tail call i32 @UINT64_C(i32 1874919423)
%19 = tail call i32 @UINT64_C(i32 1569325055)
%20 = tail call i32 @UINT64_C(i32 -1486618625)
%21 = tail call i32 @UINT64_C(i32 -1981284353)
%22 = tail call i32 @nlz(i32 %0)
ret i32 poison
}