long Log10Apx(unsigned long Value) {
  long Result;
  const unsigned int Log10Table[] = {
      0,     0,     3010,  4771,  6021,  6990,  7782,  8451,  9031,  9542,
      10000, 10414, 10792, 11139, 11461, 11761, 12041, 12304, 12553, 12788,
      13010, 13222, 13424, 13617, 13802, 13979, 14150, 14314, 14472, 14624,
      14771, 14914, 15051, 15185, 15315, 15441, 15563, 15682, 15798, 15911,
      16021, 16128, 16232, 16335, 16435, 16532, 16628, 16721, 16812, 16902,
      16990, 17076, 17160, 17243, 17324, 17404, 17482, 17559, 17634, 17709,
      17782, 17853, 17924, 17993, 18062, 18129, 18195, 18261, 18325, 18388,
      18451, 18513, 18573, 18633, 18692, 18751, 18808, 18865, 18921, 18976,
      19031, 19085, 19138, 19191, 19243, 19294, 19345, 19395, 19445, 19494,
      19542, 19590, 19638, 19685, 19731, 19777, 19823, 19868, 19912, 19956,
      20000,
  };
  if (Value < 100)
    Result = Log10Table[Value];
  else if (Value < 1000)
    Result = Log10Table[Value / 10] + 10000;
  else if (Value < 10000)
    Result = Log10Table[Value / 100] + 20000;
  else
    Result = Log10Table[Value / 1000] + 30000;
  return Result;
}


x86 assembly (clang, -O0):
<Log10Apx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x1b0(%rbp),%rdi
lea    0xed3(%rip),%rsi
mov    $0x194,%edx
call   1030 <memcpy@plt>
cmpq   $0x64,-0x8(%rbp)
jae    1156 <Log10Apx+0x46>
mov    -0x8(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%eax
mov    %rax,-0x10(%rbp)
jmp    11e6 <Log10Apx+0xd6>
cmpq   $0x3e8,-0x8(%rbp)
jae    1189 <Log10Apx+0x79>
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x1b0(%rbp,%rax,4),%eax
add    $0x2710,%eax
mov    %eax,%eax
mov    %rax,-0x10(%rbp)
jmp    11e1 <Log10Apx+0xd1>
cmpq   $0x2710,-0x8(%rbp)
jae    11bc <Log10Apx+0xac>
mov    -0x8(%rbp),%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x1b0(%rbp,%rax,4),%eax
add    $0x4e20,%eax
mov    %eax,%eax
mov    %rax,-0x10(%rbp)
jmp    11dc <Log10Apx+0xcc>
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x1b0(%rbp,%rax,4),%eax
add    $0x7530,%eax
mov    %eax,%eax
mov    %rax,-0x10(%rbp)
jmp    11e1 <Log10Apx+0xd1>
jmp    11e6 <Log10Apx+0xd6>
mov    -0x10(%rbp),%rax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Log10Apx>:
cmp    $0x63,%rdi
ja     1113 <Log10Apx+0x13>
lea    0xef3(%rip),%rax
mov    (%rax,%rdi,4),%eax
mov    %eax,%eax
ret
cmp    $0x3e7,%rdi
ja     1136 <Log10Apx+0x36>
movzwl %di,%eax
imul   $0xcccd,%eax,%ecx
shr    $0x13,%ecx
lea    0xed1(%rip),%rdx
mov    $0x2710,%eax
jmp    115a <Log10Apx+0x5a>
cmp    $0x270f,%rdi
ja     1160 <Log10Apx+0x60>
movzwl %di,%eax
shr    $0x2,%eax
imul   $0x147b,%eax,%ecx
shr    $0x11,%ecx
lea    0xeab(%rip),%rdx
mov    $0x4e20,%eax
add    (%rdx,%rcx,4),%eax
mov    %eax,%eax
ret
shr    $0x3,%rdi
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mov    %rdi,%rax
mul    %rcx
shr    $0x4,%rdx
lea    0xe81(%rip),%rcx
mov    $0x7530,%eax
add    (%rcx,%rdx,4),%eax
mov    %eax,%eax
ret

LLVM IR (-O0):
@__const.Log10Apx.Log10Table = [101 x i32] [i32 0, i32 0, i32 3010, i32 4771, i32 6021, i32 6990, i32 7782, i32 8451, i32 9031, i32 9542, i32 10000, i32 10414, i32 10792, i32 11139, i32 11461, i32 11761, i32 12041, i32 12304, i32 12553, i32 12788, i32 13010, i32 13222, i32 13424, i32 13617, i32 13802, i32 13979, i32 14150, i32 14314, i32 14472, i32 14624, i32 14771, i32 14914, i32 15051, i32 15185, i32 15315, i32 15441, i32 15563, i32 15682, i32 15798, i32 15911, i32 16021, i32 16128, i32 16232, i32 16335, i32 16435, i32 16532, i32 16628, i32 16721, i32 16812, i32 16902, i32 16990, i32 17076, i32 17160, i32 17243, i32 17324, i32 17404, i32 17482, i32 17559, i32 17634, i32 17709, i32 17782, i32 17853, i32 17924, i32 17993, i32 18062, i32 18129, i32 18195, i32 18261, i32 18325, i32 18388, i32 18451, i32 18513, i32 18573, i32 18633, i32 18692, i32 18751, i32 18808, i32 18865, i32 18921, i32 18976, i32 19031, i32 19085, i32 19138, i32 19191, i32 19243, i32 19294, i32 19345, i32 19395, i32 19445, i32 19494, i32 19542, i32 19590, i32 19638, i32 19685, i32 19731, i32 19777, i32 19823, i32 19868, i32 19912, i32 19956, i32 20000]
define i64 @Log10Apx(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca [101 x i32]
store i64 %0, i64* %2
%5 = bitcast [101 x i32]* %4 to i8*
%6 = load i64, i64* %2
%7 = icmp ult i64 %6, 100
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i64, i64* %2
%10 = getelementptr inbounds [101 x i32], [101 x i32]* %4, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = zext i32 %11 to i64
store i64 %12, i64* %3
br label %42
13: ; preds = %1
%14 = load i64, i64* %2
%15 = icmp ult i64 %14, 1000
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i64, i64* %2
%18 = udiv i64 %17, 10
%19 = getelementptr inbounds [101 x i32], [101 x i32]* %4, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = add i32 %20, 10000
%22 = zext i32 %21 to i64
store i64 %22, i64* %3
br label %41
23: ; preds = %13
%24 = load i64, i64* %2
%25 = icmp ult i64 %24, 10000
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i64, i64* %2
%28 = udiv i64 %27, 100
%29 = getelementptr inbounds [101 x i32], [101 x i32]* %4, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = add i32 %30, 20000
%32 = zext i32 %31 to i64
store i64 %32, i64* %3
br label %40
33: ; preds = %23
%34 = load i64, i64* %2
%35 = udiv i64 %34, 1000
%36 = getelementptr inbounds [101 x i32], [101 x i32]* %4, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = add i32 %37, 30000
%39 = zext i32 %38 to i64
store i64 %39, i64* %3
br label %40
40: ; preds = %33, %26
br label %41
41: ; preds = %40, %16
br label %42
42: ; preds = %41, %8
%43 = load i64, i64* %3
ret i64 %43
}

LLVM IR (-O2):
@__const.Log10Apx.Log10Table = [101 x i32] [i32 0, i32 0, i32 3010, i32 4771, i32 6021, i32 6990, i32 7782, i32 8451, i32 9031, i32 9542, i32 10000, i32 10414, i32 10792, i32 11139, i32 11461, i32 11761, i32 12041, i32 12304, i32 12553, i32 12788, i32 13010, i32 13222, i32 13424, i32 13617, i32 13802, i32 13979, i32 14150, i32 14314, i32 14472, i32 14624, i32 14771, i32 14914, i32 15051, i32 15185, i32 15315, i32 15441, i32 15563, i32 15682, i32 15798, i32 15911, i32 16021, i32 16128, i32 16232, i32 16335, i32 16435, i32 16532, i32 16628, i32 16721, i32 16812, i32 16902, i32 16990, i32 17076, i32 17160, i32 17243, i32 17324, i32 17404, i32 17482, i32 17559, i32 17634, i32 17709, i32 17782, i32 17853, i32 17924, i32 17993, i32 18062, i32 18129, i32 18195, i32 18261, i32 18325, i32 18388, i32 18451, i32 18513, i32 18573, i32 18633, i32 18692, i32 18751, i32 18808, i32 18865, i32 18921, i32 18976, i32 19031, i32 19085, i32 19138, i32 19191, i32 19243, i32 19294, i32 19345, i32 19395, i32 19445, i32 19494, i32 19542, i32 19590, i32 19638, i32 19685, i32 19731, i32 19777, i32 19823, i32 19868, i32 19912, i32 19956, i32 20000]
define i64 @Log10Apx(i64 %0) {
%2 = icmp ult i64 %0, 100
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = getelementptr inbounds [101 x i32], [101 x i32]* @__const.Log10Apx.Log10Table, i64 0, i64 %0
%5 = load i32, i32* %4
br label %29
6: ; preds = %1
%7 = icmp ult i64 %0, 1000
br i1 %7, label %8, label %15
8: ; preds = %6
%9 = trunc i64 %0 to i16
%10 = udiv i16 %9, 10
%11 = zext i16 %10 to i64
%12 = getelementptr inbounds [101 x i32], [101 x i32]* @__const.Log10Apx.Log10Table, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = add i32 %13, 10000
br label %29
15: ; preds = %6
%16 = icmp ult i64 %0, 10000
br i1 %16, label %17, label %24
17: ; preds = %15
%18 = trunc i64 %0 to i16
%19 = udiv i16 %18, 100
%20 = zext i16 %19 to i64
%21 = getelementptr inbounds [101 x i32], [101 x i32]* @__const.Log10Apx.Log10Table, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = add i32 %22, 20000
br label %29
24: ; preds = %15
%25 = udiv i64 %0, 1000
%26 = getelementptr inbounds [101 x i32], [101 x i32]* @__const.Log10Apx.Log10Table, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = add i32 %27, 30000
br label %29
29: ; preds = %8, %24, %17, %3
%30 = phi i32 [ %5, %3 ], [ %14, %8 ], [ %23, %17 ], [ %28, %24 ]
%31 = zext i32 %30 to i64
ret i64 %31
}