int ZopfliGetDistExtraBits(int dist) {
  if (dist < 5)
    return 0;
  else if (dist < 9)
    return 1;
  else if (dist < 17)
    return 2;
  else if (dist < 33)
    return 3;
  else if (dist < 65)
    return 4;
  else if (dist < 129)
    return 5;
  else if (dist < 257)
    return 6;
  else if (dist < 513)
    return 7;
  else if (dist < 1025)
    return 8;
  else if (dist < 2049)
    return 9;
  else if (dist < 4097)
    return 10;
  else if (dist < 8193)
    return 11;
  else if (dist < 16385)
    return 12;
  else
    return 13;
}


x86 assembly (clang, -O0):
<ZopfliGetDistExtraBits>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    111d <ZopfliGetDistExtraBits+0x1d>
movl   $0x0,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x9,-0x8(%rbp)
jge    1133 <ZopfliGetDistExtraBits+0x33>
movl   $0x1,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x11,-0x8(%rbp)
jge    1149 <ZopfliGetDistExtraBits+0x49>
movl   $0x2,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x21,-0x8(%rbp)
jge    115f <ZopfliGetDistExtraBits+0x5f>
movl   $0x3,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x41,-0x8(%rbp)
jge    1175 <ZopfliGetDistExtraBits+0x75>
movl   $0x4,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x81,-0x8(%rbp)
jge    118e <ZopfliGetDistExtraBits+0x8e>
movl   $0x5,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x101,-0x8(%rbp)
jge    11a7 <ZopfliGetDistExtraBits+0xa7>
movl   $0x6,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x201,-0x8(%rbp)
jge    11c0 <ZopfliGetDistExtraBits+0xc0>
movl   $0x7,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x401,-0x8(%rbp)
jge    11d9 <ZopfliGetDistExtraBits+0xd9>
movl   $0x8,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x801,-0x8(%rbp)
jge    11f2 <ZopfliGetDistExtraBits+0xf2>
movl   $0x9,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x1001,-0x8(%rbp)
jge    120b <ZopfliGetDistExtraBits+0x10b>
movl   $0xa,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x2001,-0x8(%rbp)
jge    1224 <ZopfliGetDistExtraBits+0x124>
movl   $0xb,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
cmpl   $0x4001,-0x8(%rbp)
jge    123d <ZopfliGetDistExtraBits+0x13d>
movl   $0xc,-0x4(%rbp)
jmp    1244 <ZopfliGetDistExtraBits+0x144>
movl   $0xd,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ZopfliGetDistExtraBits>:
xor    %eax,%eax
cmp    $0x5,%edi
jl     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0x1,%eax
cmp    $0x9,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0x2,%eax
cmp    $0x11,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0x3,%eax
cmp    $0x21,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0x4,%eax
cmp    $0x41,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0x5,%eax
cmp    $0x81,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0x6,%eax
cmp    $0x101,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0x7,%eax
cmp    $0x201,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0x8,%eax
cmp    $0x401,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0x9,%eax
cmp    $0x801,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0xa,%eax
cmp    $0x1001,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
mov    $0xb,%eax
cmp    $0x2001,%edi
jb     11a0 <ZopfliGetDistExtraBits+0xa0>
cmp    $0x4001,%edi
mov    $0xd,%eax
sbb    $0x0,%eax
ret

LLVM IR (-O0):
define i32 @ZopfliGetDistExtraBits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 5
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 0, i32* %2
br label %56
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 9
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 1, i32* %2
br label %56
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 17
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 2, i32* %2
br label %56
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 33
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 3, i32* %2
br label %56
19: ; preds = %15
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 65
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 4, i32* %2
br label %56
23: ; preds = %19
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 129
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 5, i32* %2
br label %56
27: ; preds = %23
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 257
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 6, i32* %2
br label %56
31: ; preds = %27
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 513
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 7, i32* %2
br label %56
35: ; preds = %31
%36 = load i32, i32* %3
%37 = icmp slt i32 %36, 1025
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 8, i32* %2
br label %56
39: ; preds = %35
%40 = load i32, i32* %3
%41 = icmp slt i32 %40, 2049
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 9, i32* %2
br label %56
43: ; preds = %39
%44 = load i32, i32* %3
%45 = icmp slt i32 %44, 4097
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 10, i32* %2
br label %56
47: ; preds = %43
%48 = load i32, i32* %3
%49 = icmp slt i32 %48, 8193
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 11, i32* %2
br label %56
51: ; preds = %47
%52 = load i32, i32* %3
%53 = icmp slt i32 %52, 16385
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 12, i32* %2
br label %56
55: ; preds = %51
store i32 13, i32* %2
br label %56
56: ; preds = %55, %54, %50, %46, %42, %38, %34, %30, %26, %22, %18, %14, %10, %6
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
define i32 @ZopfliGetDistExtraBits(i32 %0) {
%2 = icmp slt i32 %0, 5
br i1 %2, label %28, label %3
3: ; preds = %1
%4 = icmp ult i32 %0, 9
br i1 %4, label %28, label %5
5: ; preds = %3
%6 = icmp ult i32 %0, 17
br i1 %6, label %28, label %7
7: ; preds = %5
%8 = icmp ult i32 %0, 33
br i1 %8, label %28, label %9
9: ; preds = %7
%10 = icmp ult i32 %0, 65
br i1 %10, label %28, label %11
11: ; preds = %9
%12 = icmp ult i32 %0, 129
br i1 %12, label %28, label %13
13: ; preds = %11
%14 = icmp ult i32 %0, 257
br i1 %14, label %28, label %15
15: ; preds = %13
%16 = icmp ult i32 %0, 513
br i1 %16, label %28, label %17
17: ; preds = %15
%18 = icmp ult i32 %0, 1025
br i1 %18, label %28, label %19
19: ; preds = %17
%20 = icmp ult i32 %0, 2049
br i1 %20, label %28, label %21
21: ; preds = %19
%22 = icmp ult i32 %0, 4097
br i1 %22, label %28, label %23
23: ; preds = %21
%24 = icmp ult i32 %0, 8193
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = icmp ult i32 %0, 16385
%27 = select i1 %26, i32 12, i32 13
br label %28
28: ; preds = %25, %23, %21, %19, %17, %15, %13, %11, %9, %7, %5, %3, %1
%29 = phi i32 [ 0, %1 ], [ 1, %3 ], [ 2, %5 ], [ 3, %7 ], [ 4, %9 ], [ 5, %11 ], [ 6, %13 ], [ 7, %15 ], [ 8, %17 ], [ 9, %19 ], [ 10, %21 ], [ 11, %23 ], [ %27, %25 ]
ret i32 %29
}