int colorstobpp(colors)
int colors;
{
  int bpp;
  if (colors <= 2)
    bpp = 1;
  else if (colors <= 4)
    bpp = 2;
  else if (colors <= 8)
    bpp = 3;
  else if (colors <= 16)
    bpp = 4;
  else if (colors <= 32)
    bpp = 5;
  else if (colors <= 64)
    bpp = 6;
  else if (colors <= 128)
    bpp = 7;
  else if (colors <= 256)
    bpp = 8;
  else
    XgError("can't happen");
  return bpp;
}


x86 assembly (clang, -O0):
<colorstobpp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x2,-0x4(%rbp)
jg     1131 <colorstobpp+0x21>
movl   $0x1,-0x8(%rbp)
jmp    1202 <colorstobpp+0xf2>
cmpl   $0x4,-0x4(%rbp)
jg     1147 <colorstobpp+0x37>
movl   $0x2,-0x8(%rbp)
jmp    11fd <colorstobpp+0xed>
cmpl   $0x8,-0x4(%rbp)
jg     115d <colorstobpp+0x4d>
movl   $0x3,-0x8(%rbp)
jmp    11f8 <colorstobpp+0xe8>
cmpl   $0x10,-0x4(%rbp)
jg     1173 <colorstobpp+0x63>
movl   $0x4,-0x8(%rbp)
jmp    11f3 <colorstobpp+0xe3>
cmpl   $0x20,-0x4(%rbp)
jg     1189 <colorstobpp+0x79>
movl   $0x5,-0x8(%rbp)
jmp    11ee <colorstobpp+0xde>
cmpl   $0x40,-0x4(%rbp)
jg     119f <colorstobpp+0x8f>
movl   $0x6,-0x8(%rbp)
jmp    11e9 <colorstobpp+0xd9>
cmpl   $0x80,-0x4(%rbp)
jg     11b8 <colorstobpp+0xa8>
movl   $0x7,-0x8(%rbp)
jmp    11e4 <colorstobpp+0xd4>
cmpl   $0x100,-0x4(%rbp)
jg     11d1 <colorstobpp+0xc1>
movl   $0x8,-0x8(%rbp)
jmp    11df <colorstobpp+0xcf>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <XgError@plt>
jmp    11e4 <colorstobpp+0xd4>
jmp    11e9 <colorstobpp+0xd9>
jmp    11ee <colorstobpp+0xde>
jmp    11f3 <colorstobpp+0xe3>
jmp    11f8 <colorstobpp+0xe8>
jmp    11fd <colorstobpp+0xed>
jmp    1202 <colorstobpp+0xf2>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colorstobpp>:
mov    $0x1,%eax
cmp    $0x3,%edi
jl     1179 <colorstobpp+0x69>
mov    $0x2,%eax
cmp    $0x5,%edi
jb     1179 <colorstobpp+0x69>
mov    $0x3,%eax
cmp    $0x9,%edi
jb     1179 <colorstobpp+0x69>
mov    $0x4,%eax
cmp    $0x11,%edi
jb     1179 <colorstobpp+0x69>
mov    $0x5,%eax
cmp    $0x21,%edi
jb     1179 <colorstobpp+0x69>
mov    $0x6,%eax
cmp    $0x41,%edi
jb     1179 <colorstobpp+0x69>
mov    $0x7,%eax
cmp    $0x81,%edi
jb     1179 <colorstobpp+0x69>
mov    $0x8,%eax
cmp    $0x101,%edi
jb     1179 <colorstobpp+0x69>
push   %rax
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1030 <XgError@plt>
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"can't happen\00"
define i32 @colorstobpp(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sle i32 %4, 2
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 1, i32* %3
br label %44
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp sle i32 %8, 4
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 2, i32* %3
br label %43
11: ; preds = %7
%12 = load i32, i32* %2
%13 = icmp sle i32 %12, 8
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 3, i32* %3
br label %42
15: ; preds = %11
%16 = load i32, i32* %2
%17 = icmp sle i32 %16, 16
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 4, i32* %3
br label %41
19: ; preds = %15
%20 = load i32, i32* %2
%21 = icmp sle i32 %20, 32
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 5, i32* %3
br label %40
23: ; preds = %19
%24 = load i32, i32* %2
%25 = icmp sle i32 %24, 64
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 6, i32* %3
br label %39
27: ; preds = %23
%28 = load i32, i32* %2
%29 = icmp sle i32 %28, 128
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 7, i32* %3
br label %38
31: ; preds = %27
%32 = load i32, i32* %2
%33 = icmp sle i32 %32, 256
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 8, i32* %3
br label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) bitcast (i32 (...)* @XgError to i32 (i8*, ...)*)(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %34
br label %38
38: ; preds = %37, %30
br label %39
39: ; preds = %38, %26
br label %40
40: ; preds = %39, %22
br label %41
41: ; preds = %40, %18
br label %42
42: ; preds = %41, %14
br label %43
43: ; preds = %42, %10
br label %44
44: ; preds = %43, %6
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [13 x i8] c"can't happen\00"
define i32 @colorstobpp(i32 %0) {
%2 = icmp slt i32 %0, 3
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = icmp ult i32 %0, 5
br i1 %4, label %19, label %5
5: ; preds = %3
%6 = icmp ult i32 %0, 9
br i1 %6, label %19, label %7
7: ; preds = %5
%8 = icmp ult i32 %0, 17
br i1 %8, label %19, label %9
9: ; preds = %7
%10 = icmp ult i32 %0, 33
br i1 %10, label %19, label %11
11: ; preds = %9
%12 = icmp ult i32 %0, 65
br i1 %12, label %19, label %13
13: ; preds = %11
%14 = icmp ult i32 %0, 129
br i1 %14, label %19, label %15
15: ; preds = %13
%16 = icmp ult i32 %0, 257
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = tail call i32 (i8*, ...) bitcast (i32 (...)* @XgError to i32 (i8*, ...)*)(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %15, %13, %11, %9, %7, %5, %3, %1, %17
%20 = phi i32 [ undef, %17 ], [ 1, %1 ], [ 2, %3 ], [ 3, %5 ], [ 4, %7 ], [ 5, %9 ], [ 6, %11 ], [ 7, %13 ], [ 8, %15 ]
ret i32 %20
}