int ibdg(long long n) {
  switch (n) {
  case 1LL ... 9LL:
    return 1;
  case 10LL ... 99LL:
    return 2;
  case 100LL ... 999LL:
    return 3;
  case 1000LL ... 9999LL:
    return 4;
  case 10000LL ... 99999LL:
    return 5;
  case 100000LL ... 999999LL:
    return 6;
  case 1000000LL ... 9999999LL:
    return 7;
  case 10000000LL ... 99999999LL:
    return 8;
  case 100000000LL ... 999999999LL:
    return 9;
  case 1000000000LL ... 9999999999LL:
    return 10;
  case 10000000000LL ... 99999999999LL:
    return 11;
  case 100000000000LL ... 999999999999LL:
    return 12;
  case 1000000000000LL ... 9999999999999LL:
    return 13;
  case 10000000000000LL ... 99999999999999LL:
    return 14;
  case 100000000000000LL ... 999999999999999LL:
    return 15;
  case 1000000000000000LL ... 9999999999999999LL:
    return 16;
  case 10000000000000000LL ... 99999999999999999LL:
    return 17;
  case 100000000000000000LL ... 999999999999999999LL:
    return 18;
  case 1000000000000000000LL ... 9223372036854775807LL:
    return 19;
  case -9223372036854775807LL - 1LL ... - 1LL:
    return 20;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ibdg>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
add    $0xffffffffffffffff,%rax
sub    $0x8,%rax
ja     1478 <ibdg+0x378>
jmp    1123 <ibdg+0x23>
movl   $0x1,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
movl   $0x2,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
sub    $0xa,%rax
cmp    $0x59,%rax
jbe    112f <ibdg+0x2f>
jmp    14a1 <ibdg+0x3a1>
movl   $0x3,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
sub    $0x64,%rax
cmp    $0x383,%rax
jbe    1152 <ibdg+0x52>
jmp    113b <ibdg+0x3b>
movl   $0x4,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
sub    $0x3e8,%rax
cmp    $0x2327,%rax
jbe    1177 <ibdg+0x77>
jmp    115e <ibdg+0x5e>
movl   $0x5,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
sub    $0x2710,%rax
cmp    $0x15f8f,%rax
jbe    119e <ibdg+0x9e>
jmp    1183 <ibdg+0x83>
movl   $0x6,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
sub    $0x186a0,%rax
cmp    $0xdbb9f,%rax
jbe    11c5 <ibdg+0xc5>
jmp    11aa <ibdg+0xaa>
movl   $0x7,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
sub    $0xf4240,%rax
cmp    $0x89543f,%rax
jbe    11ec <ibdg+0xec>
jmp    11d1 <ibdg+0xd1>
movl   $0x8,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
sub    $0x989680,%rax
cmp    $0x55d4a7f,%rax
jbe    1213 <ibdg+0x113>
jmp    11f8 <ibdg+0xf8>
movl   $0x9,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
sub    $0x5f5e100,%rax
cmp    $0x35a4e8ff,%rax
jbe    123a <ibdg+0x13a>
jmp    121f <ibdg+0x11f>
movl   $0xa,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
sub    $0x3b9aca00,%rax
movabs $0x2187119ff,%rcx
cmp    %rcx,%rax
jbe    1261 <ibdg+0x161>
jmp    1246 <ibdg+0x146>
movl   $0xb,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0x2540be400,%rcx
sub    %rcx,%rax
movabs $0x14f46b03ff,%rcx
cmp    %rcx,%rax
jbe    128f <ibdg+0x18f>
jmp    126d <ibdg+0x16d>
movl   $0xc,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0x174876e800,%rcx
sub    %rcx,%rax
movabs $0xd18c2e27ff,%rcx
cmp    %rcx,%rax
jbe    12c4 <ibdg+0x1c4>
jmp    129b <ibdg+0x19b>
movl   $0xd,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0xe8d4a51000,%rcx
sub    %rcx,%rax
movabs $0x82f79cd8fff,%rcx
cmp    %rcx,%rax
jbe    12f9 <ibdg+0x1f9>
jmp    12d0 <ibdg+0x1d0>
movl   $0xe,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0x9184e72a000,%rcx
sub    %rcx,%rax
movabs $0x51dac2079fff,%rcx
cmp    %rcx,%rax
jbe    132e <ibdg+0x22e>
jmp    1305 <ibdg+0x205>
movl   $0xf,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0x5af3107a4000,%rcx
sub    %rcx,%rax
movabs $0x3328b944c3fff,%rcx
cmp    %rcx,%rax
jbe    1363 <ibdg+0x263>
jmp    133a <ibdg+0x23a>
movl   $0x10,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0x38d7ea4c68000,%rcx
sub    %rcx,%rax
movabs $0x1ff973cafa7fff,%rcx
cmp    %rcx,%rax
jbe    1398 <ibdg+0x298>
jmp    136f <ibdg+0x26f>
movl   $0x11,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0x2386f26fc10000,%rcx
sub    %rcx,%rax
movabs $0x13fbe85edc8ffff,%rcx
be 3f 01
cmp    %rcx,%rax
jbe    13cd <ibdg+0x2cd>
jmp    13a4 <ibdg+0x2a4>
movl   $0x12,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0x16345785d8a0000,%rcx
45 63 01
sub    %rcx,%rax
movabs $0xc7d713b49d9ffff,%rcx
71 7d 0c
cmp    %rcx,%rax
jbe    1402 <ibdg+0x302>
jmp    13d9 <ibdg+0x2d9>
movl   $0x13,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0xde0b6b3a7640000,%rcx
b6 e0 0d
sub    %rcx,%rax
movabs $0x721f494c589bffff,%rcx
49 1f 72
cmp    %rcx,%rax
jbe    1437 <ibdg+0x337>
jmp    140e <ibdg+0x30e>
movl   $0x14,-0x4(%rbp)
jmp    14a8 <ibdg+0x3a8>
mov    -0x18(%rbp),%rax
movabs $0x8000000000000000,%rcx
sub    %rcx,%rax
movabs $0x7fffffffffffffff,%rcx
ff ff 7f
cmp    %rcx,%rax
jbe    146c <ibdg+0x36c>
jmp    1443 <ibdg+0x343>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibdg>:
lea    -0x1(%rdi),%rcx
mov    $0x1,%eax
cmp    $0x9,%rcx
jb     1305 <ibdg+0x205>
test   %rdi,%rdi
js     1306 <ibdg+0x206>
mov    $0x13,%eax
movabs $0xde0b6b3a763ffff,%rcx
b6 e0 0d
cmp    %rcx,%rdi
ja     1305 <ibdg+0x205>
movabs $0xfe9cba87a2760000,%rcx
ba 9c fe
add    %rdi,%rcx
mov    $0x12,%eax
movabs $0xc7d713b49da0000,%rdx
71 7d 0c
cmp    %rdx,%rcx
jb     1305 <ibdg+0x205>
movabs $0xffdc790d903f0000,%rcx
79 dc ff
add    %rdi,%rcx
mov    $0x11,%eax
movabs $0x13fbe85edc90000,%rdx
be 3f 01
cmp    %rdx,%rcx
jb     1305 <ibdg+0x205>
movabs $0xfffc72815b398000,%rcx
72 fc ff
add    %rdi,%rcx
mov    $0x10,%eax
movabs $0x1ff973cafa8000,%rdx
cmp    %rdx,%rcx
jb     1305 <ibdg+0x205>
movabs $0xffffa50cef85c000,%rcx
a5 ff ff
add    %rdi,%rcx
mov    $0xf,%eax
movabs $0x3328b944c4000,%rdx
cmp    %rdx,%rcx
jb     1305 <ibdg+0x205>
movabs $0xfffff6e7b18d6000,%rcx
f6 ff ff
add    %rdi,%rcx
mov    $0xe,%eax
movabs $0x51dac207a000,%rdx
cmp    %rdx,%rcx
jb     1305 <ibdg+0x205>
movabs $0xffffff172b5af000,%rcx
ff ff ff
add    %rdi,%rcx
mov    $0xd,%eax
movabs $0x82f79cd9000,%rdx
cmp    %rdx,%rcx
jb     1305 <ibdg+0x205>
movabs $0xffffffe8b7891800,%rcx
ff ff ff
add    %rdi,%rcx
shr    $0xb,%rcx
mov    $0xc,%eax
cmp    $0x1a3185c5,%rcx
jb     1305 <ibdg+0x205>
movabs $0xfffffffdabf41c00,%rcx
ff ff ff
add    %rdi,%rcx
shr    $0xa,%rcx
mov    $0xb,%eax
cmp    $0x53d1ac1,%rcx
jb     1305 <ibdg+0x205>
lea    -0x3b9aca00(%rdi),%rcx
shr    $0x9,%rcx
mov    $0xa,%eax
cmp    $0x10c388d,%rcx
jb     1305 <ibdg+0x205>
lea    -0x5f5e100(%rdi),%rcx
mov    $0x9,%eax
cmp    $0x35a4e900,%rcx
jb     1305 <ibdg+0x205>
lea    -0x989680(%rdi),%rcx
mov    $0x8,%eax
cmp    $0x55d4a80,%rcx
jb     1305 <ibdg+0x205>
lea    -0xf4240(%rdi),%rcx
mov    $0x7,%eax
cmp    $0x895440,%rcx
jb     1305 <ibdg+0x205>
lea    -0x186a0(%rdi),%rcx
mov    $0x6,%eax
cmp    $0xdbba0,%rcx
jb     1305 <ibdg+0x205>
lea    -0x2710(%rdi),%rcx
mov    $0x5,%eax
cmp    $0x15f90,%rcx
jb     1305 <ibdg+0x205>
lea    -0x3e8(%rdi),%rcx
mov    $0x4,%eax
cmp    $0x2328,%rcx
jb     1305 <ibdg+0x205>
lea    -0x64(%rdi),%rcx
mov    $0x3,%eax
cmp    $0x384,%rcx
jae    130c <ibdg+0x20c>
ret
mov    $0x14,%eax
ret
add    $0xfffffffffffffff6,%rdi
xor    %eax,%eax
cmp    $0x5a,%rdi
setb   %al
add    %eax,%eax
ret

LLVM IR (-O0):
define i32 @ibdg(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
switch i64 %4, label %79 [
i64 1, label %5
i64 2, label %5
i64 3, label %5
i64 4, label %5
i64 5, label %5
i64 6, label %5
i64 7, label %5
i64 8, label %5
i64 9, label %5
]
5: ; preds = %1, %1, %1, %1, %1, %1, %1, %1, %1
store i32 1, i32* %2
br label %83
6: ; preds = %7
store i32 2, i32* %2
br label %83
7: ; preds = %11
%8 = sub i64 %4, 10
%9 = icmp ule i64 %8, 89
br i1 %9, label %6, label %82
10: ; preds = %11
store i32 3, i32* %2
br label %83
11: ; preds = %15
%12 = sub i64 %4, 100
%13 = icmp ule i64 %12, 899
br i1 %13, label %10, label %7
14: ; preds = %15
store i32 4, i32* %2
br label %83
15: ; preds = %19
%16 = sub i64 %4, 1000
%17 = icmp ule i64 %16, 8999
br i1 %17, label %14, label %11
18: ; preds = %19
store i32 5, i32* %2
br label %83
19: ; preds = %23
%20 = sub i64 %4, 10000
%21 = icmp ule i64 %20, 89999
br i1 %21, label %18, label %15
22: ; preds = %23
store i32 6, i32* %2
br label %83
23: ; preds = %27
%24 = sub i64 %4, 100000
%25 = icmp ule i64 %24, 899999
br i1 %25, label %22, label %19
26: ; preds = %27
store i32 7, i32* %2
br label %83
27: ; preds = %31
%28 = sub i64 %4, 1000000
%29 = icmp ule i64 %28, 8999999
br i1 %29, label %26, label %23
30: ; preds = %31
store i32 8, i32* %2
br label %83
31: ; preds = %35
%32 = sub i64 %4, 10000000
%33 = icmp ule i64 %32, 89999999
br i1 %33, label %30, label %27
34: ; preds = %35
store i32 9, i32* %2
br label %83
35: ; preds = %39
%36 = sub i64 %4, 100000000
%37 = icmp ule i64 %36, 899999999
br i1 %37, label %34, label %31
38: ; preds = %39
store i32 10, i32* %2
br label %83
39: ; preds = %43
%40 = sub i64 %4, 1000000000
%41 = icmp ule i64 %40, 8999999999
br i1 %41, label %38, label %35
42: ; preds = %43
store i32 11, i32* %2
br label %83
43: ; preds = %47
%44 = sub i64 %4, 10000000000
%45 = icmp ule i64 %44, 89999999999
br i1 %45, label %42, label %39
46: ; preds = %47
store i32 12, i32* %2
br label %83
47: ; preds = %51
%48 = sub i64 %4, 100000000000
%49 = icmp ule i64 %48, 899999999999
br i1 %49, label %46, label %43
50: ; preds = %51
store i32 13, i32* %2
br label %83
51: ; preds = %55
%52 = sub i64 %4, 1000000000000
%53 = icmp ule i64 %52, 8999999999999
br i1 %53, label %50, label %47
54: ; preds = %55
store i32 14, i32* %2
br label %83
55: ; preds = %59
%56 = sub i64 %4, 10000000000000
%57 = icmp ule i64 %56, 89999999999999
br i1 %57, label %54, label %51
58: ; preds = %59
store i32 15, i32* %2
br label %83
59: ; preds = %63
%60 = sub i64 %4, 100000000000000
%61 = icmp ule i64 %60, 899999999999999
br i1 %61, label %58, label %55
62: ; preds = %63
store i32 16, i32* %2
br label %83
63: ; preds = %67
%64 = sub i64 %4, 1000000000000000
%65 = icmp ule i64 %64, 8999999999999999
br i1 %65, label %62, label %59
66: ; preds = %67
store i32 17, i32* %2
br label %83
67: ; preds = %71
%68 = sub i64 %4, 10000000000000000
%69 = icmp ule i64 %68, 89999999999999999
br i1 %69, label %66, label %63
70: ; preds = %71
store i32 18, i32* %2
br label %83
71: ; preds = %75
%72 = sub i64 %4, 100000000000000000
%73 = icmp ule i64 %72, 899999999999999999
br i1 %73, label %70, label %67
74: ; preds = %75
store i32 19, i32* %2
br label %83
75: ; preds = %79
%76 = sub i64 %4, 1000000000000000000
%77 = icmp ule i64 %76, 8223372036854775807
br i1 %77, label %74, label %71
78: ; preds = %79
store i32 20, i32* %2
br label %83
79: ; preds = %1
%80 = sub i64 %4, -9223372036854775808
%81 = icmp ule i64 %80, 9223372036854775807
br i1 %81, label %78, label %75
82: ; preds = %7
store i32 0, i32* %2
br label %83
83: ; preds = %82, %78, %74, %70, %66, %62, %58, %54, %50, %46, %42, %38, %34, %30, %26, %22, %18, %14, %10, %6, %5
%84 = load i32, i32* %2
ret i32 %84
}

LLVM IR (-O2):
define i32 @ibdg(i64 %0) {
%2 = add i64 %0, -1
%3 = icmp ult i64 %2, 9
br i1 %3, label %60, label %58
4: ; preds = %8
%5 = add nsw i64 %0, -10
%6 = icmp ult i64 %5, 90
%7 = select i1 %6, i32 2, i32 0
br label %60
8: ; preds = %11
%9 = add nsw i64 %0, -100
%10 = icmp ult i64 %9, 900
br i1 %10, label %60, label %4
11: ; preds = %14
%12 = add nsw i64 %0, -1000
%13 = icmp ult i64 %12, 9000
br i1 %13, label %60, label %8
14: ; preds = %17
%15 = add nsw i64 %0, -10000
%16 = icmp ult i64 %15, 90000
br i1 %16, label %60, label %11
17: ; preds = %20
%18 = add nsw i64 %0, -100000
%19 = icmp ult i64 %18, 900000
br i1 %19, label %60, label %14
20: ; preds = %23
%21 = add nsw i64 %0, -1000000
%22 = icmp ult i64 %21, 9000000
br i1 %22, label %60, label %17
23: ; preds = %26
%24 = add nsw i64 %0, -10000000
%25 = icmp ult i64 %24, 90000000
br i1 %25, label %60, label %20
26: ; preds = %29
%27 = add nsw i64 %0, -100000000
%28 = icmp ult i64 %27, 900000000
br i1 %28, label %60, label %23
29: ; preds = %32
%30 = add nsw i64 %0, -1000000000
%31 = icmp ult i64 %30, 9000000000
br i1 %31, label %60, label %26
32: ; preds = %35
%33 = add nsw i64 %0, -10000000000
%34 = icmp ult i64 %33, 90000000000
br i1 %34, label %60, label %29
35: ; preds = %38
%36 = add nsw i64 %0, -100000000000
%37 = icmp ult i64 %36, 900000000000
br i1 %37, label %60, label %32
38: ; preds = %41
%39 = add nsw i64 %0, -1000000000000
%40 = icmp ult i64 %39, 9000000000000
br i1 %40, label %60, label %35
41: ; preds = %44
%42 = add nsw i64 %0, -10000000000000
%43 = icmp ult i64 %42, 90000000000000
br i1 %43, label %60, label %38
44: ; preds = %47
%45 = add nsw i64 %0, -100000000000000
%46 = icmp ult i64 %45, 900000000000000
br i1 %46, label %60, label %41
47: ; preds = %50
%48 = add nsw i64 %0, -1000000000000000
%49 = icmp ult i64 %48, 9000000000000000
br i1 %49, label %60, label %44
50: ; preds = %53
%51 = add nsw i64 %0, -10000000000000000
%52 = icmp ult i64 %51, 90000000000000000
br i1 %52, label %60, label %47
53: ; preds = %56
%54 = add nsw i64 %0, -100000000000000000
%55 = icmp ult i64 %54, 900000000000000000
br i1 %55, label %60, label %50
56: ; preds = %58
%57 = icmp ugt i64 %0, 999999999999999999
br i1 %57, label %60, label %53
58: ; preds = %1
%59 = icmp slt i64 %0, 0
br i1 %59, label %60, label %56
60: ; preds = %4, %58, %56, %53, %50, %47, %44, %41, %38, %35, %32, %29, %26, %23, %20, %17, %14, %11, %8, %1
%61 = phi i32 [ 1, %1 ], [ 3, %8 ], [ 4, %11 ], [ 5, %14 ], [ 6, %17 ], [ 7, %20 ], [ 8, %23 ], [ 9, %26 ], [ 10, %29 ], [ 11, %32 ], [ 12, %35 ], [ 13, %38 ], [ 14, %41 ], [ 15, %44 ], [ 16, %47 ], [ 17, %50 ], [ 18, %53 ], [ 19, %56 ], [ 20, %58 ], [ %7, %4 ]
ret i32 %61
}