int fxp_prec2digits(int prec) {
  switch (prec) {
  case 10:
    return 1;
  case 100:
    return 2;
  case 1000:
    return 3;
  case 10000:
    return 4;
  case 100000:
    return 5;
  case 1000000:
    return 6;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<fxp_prec2digits>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0xa,%eax
je     1178 <fxp_prec2digits+0x78>
jmp    111b <fxp_prec2digits+0x1b>
mov    -0xc(%rbp),%eax
sub    $0x64,%eax
je     1184 <fxp_prec2digits+0x84>
jmp    112c <fxp_prec2digits+0x2c>
mov    -0xc(%rbp),%eax
sub    $0x3e8,%eax
je     1190 <fxp_prec2digits+0x90>
jmp    113f <fxp_prec2digits+0x3f>
mov    -0xc(%rbp),%eax
sub    $0x2710,%eax
je     119c <fxp_prec2digits+0x9c>
jmp    1152 <fxp_prec2digits+0x52>
mov    -0xc(%rbp),%eax
sub    $0x186a0,%eax
je     11a8 <fxp_prec2digits+0xa8>
jmp    1165 <fxp_prec2digits+0x65>
mov    -0xc(%rbp),%eax
sub    $0xf4240,%eax
je     11b4 <fxp_prec2digits+0xb4>
jmp    11c0 <fxp_prec2digits+0xc0>
movl   $0x1,-0x4(%rbp)
jmp    11c7 <fxp_prec2digits+0xc7>
movl   $0x2,-0x4(%rbp)
jmp    11c7 <fxp_prec2digits+0xc7>
movl   $0x3,-0x4(%rbp)
jmp    11c7 <fxp_prec2digits+0xc7>
movl   $0x4,-0x4(%rbp)
jmp    11c7 <fxp_prec2digits+0xc7>
movl   $0x5,-0x4(%rbp)
jmp    11c7 <fxp_prec2digits+0xc7>
movl   $0x6,-0x4(%rbp)
jmp    11c7 <fxp_prec2digits+0xc7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fxp_prec2digits>:
cmp    $0x270f,%edi
jg     1120 <fxp_prec2digits+0x20>
cmp    $0xa,%edi
je     113e <fxp_prec2digits+0x3e>
cmp    $0x64,%edi
je     1144 <fxp_prec2digits+0x44>
cmp    $0x3e8,%edi
jne    1156 <fxp_prec2digits+0x56>
mov    $0x3,%eax
ret
cmp    $0x2710,%edi
je     114a <fxp_prec2digits+0x4a>
cmp    $0x186a0,%edi
je     1150 <fxp_prec2digits+0x50>
cmp    $0xf4240,%edi
jne    1156 <fxp_prec2digits+0x56>
mov    $0x6,%eax
ret
mov    $0x1,%eax
ret
mov    $0x2,%eax
ret
mov    $0x4,%eax
ret
mov    $0x5,%eax
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @fxp_prec2digits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %11 [
i32 10, label %5
i32 100, label %6
i32 1000, label %7
i32 10000, label %8
i32 100000, label %9
i32 1000000, label %10
]
5: ; preds = %1
store i32 1, i32* %2
br label %12
6: ; preds = %1
store i32 2, i32* %2
br label %12
7: ; preds = %1
store i32 3, i32* %2
br label %12
8: ; preds = %1
store i32 4, i32* %2
br label %12
9: ; preds = %1
store i32 5, i32* %2
br label %12
10: ; preds = %1
store i32 6, i32* %2
br label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %12
12: ; preds = %11, %10, %9, %8, %7, %6, %5
%13 = load i32, i32* %2
ret i32 %13
}

LLVM IR (-O2):
define i32 @fxp_prec2digits(i32 %0) {
switch i32 %0, label %7 [
i32 10, label %8
i32 100, label %2
i32 1000, label %3
i32 10000, label %4
i32 100000, label %5
i32 1000000, label %6
]
2: ; preds = %1
br label %8
3: ; preds = %1
br label %8
4: ; preds = %1
br label %8
5: ; preds = %1
br label %8
6: ; preds = %1
br label %8
7: ; preds = %1
br label %8
8: ; preds = %1, %7, %6, %5, %4, %3, %2
%9 = phi i32 [ -1, %7 ], [ 6, %6 ], [ 5, %5 ], [ 4, %4 ], [ 3, %3 ], [ 2, %2 ], [ 1, %1 ]
ret i32 %9
}