int copy_length_bits(int length) {
  if (length < 1)
    return 1;
  if (length < 2)
    return 2;
  else if (length < 5)
    return 4;
  else if (length < 8)
    return 6;
  else if (length < 15)
    return 9;
  else if (length < 270)
    return 17;
  else if (length < 33038)
    return 32;
  else
    return 1000000;
}


x86 assembly (clang, -O0):
<copy_length_bits>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    111d <copy_length_bits+0x1d>
movl   $0x1,-0x4(%rbp)
jmp    11ae <copy_length_bits+0xae>
cmpl   $0x2,-0x8(%rbp)
jge    1133 <copy_length_bits+0x33>
movl   $0x2,-0x4(%rbp)
jmp    11ae <copy_length_bits+0xae>
cmpl   $0x5,-0x8(%rbp)
jge    1149 <copy_length_bits+0x49>
movl   $0x4,-0x4(%rbp)
jmp    11ae <copy_length_bits+0xae>
cmpl   $0x8,-0x8(%rbp)
jge    115f <copy_length_bits+0x5f>
movl   $0x6,-0x4(%rbp)
jmp    11ae <copy_length_bits+0xae>
cmpl   $0xf,-0x8(%rbp)
jge    1175 <copy_length_bits+0x75>
movl   $0x9,-0x4(%rbp)
jmp    11ae <copy_length_bits+0xae>
cmpl   $0x10e,-0x8(%rbp)
jge    118e <copy_length_bits+0x8e>
movl   $0x11,-0x4(%rbp)
jmp    11ae <copy_length_bits+0xae>
cmpl   $0x810e,-0x8(%rbp)
jge    11a7 <copy_length_bits+0xa7>
movl   $0x20,-0x4(%rbp)
jmp    11ae <copy_length_bits+0xae>
movl   $0xf4240,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_length_bits>:
test   %edi,%edi
jle    114d <copy_length_bits+0x4d>
mov    $0x2,%eax
cmp    $0x1,%edi
je     114c <copy_length_bits+0x4c>
mov    $0x4,%eax
cmp    $0x5,%edi
jb     114c <copy_length_bits+0x4c>
mov    $0x6,%eax
cmp    $0x8,%edi
jb     114c <copy_length_bits+0x4c>
mov    $0x9,%eax
cmp    $0xf,%edi
jb     114c <copy_length_bits+0x4c>
mov    $0x11,%eax
cmp    $0x10e,%edi
jb     114c <copy_length_bits+0x4c>
cmp    $0x810e,%edi
mov    $0x20,%ecx
mov    $0xf4240,%eax
cmovb  %ecx,%eax
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i32 @copy_length_bits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 1, i32* %2
br label %32
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 2, i32* %2
br label %32
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 5
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 4, i32* %2
br label %32
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 8
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 6, i32* %2
br label %32
19: ; preds = %15
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 15
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 9, i32* %2
br label %32
23: ; preds = %19
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 270
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 17, i32* %2
br label %32
27: ; preds = %23
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 33038
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 32, i32* %2
br label %32
31: ; preds = %27
store i32 1000000, i32* %2
br label %32
32: ; preds = %31, %30, %26, %22, %18, %14, %10, %6
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @copy_length_bits(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = icmp eq i32 %0, 1
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = icmp ult i32 %0, 5
br i1 %6, label %16, label %7
7: ; preds = %5
%8 = icmp ult i32 %0, 8
br i1 %8, label %16, label %9
9: ; preds = %7
%10 = icmp ult i32 %0, 15
br i1 %10, label %16, label %11
11: ; preds = %9
%12 = icmp ult i32 %0, 270
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = icmp ult i32 %0, 33038
%15 = select i1 %14, i32 32, i32 1000000
br label %16
16: ; preds = %13, %11, %9, %7, %5, %3, %1
%17 = phi i32 [ 1, %1 ], [ 2, %3 ], [ 4, %5 ], [ 6, %7 ], [ 9, %9 ], [ 17, %11 ], [ %15, %13 ]
ret i32 %17
}