unsigned int serial_bps(int bps) {
  switch (bps) {
  case 1200:
    return 0x02;
  case 2400:
    return 0x03;
  case 4800:
    return 0x04;
  case 9600:
    return 0x05;
  case 19200:
    return 0x06;
  case 38400:
    return 0x07;
  case 57600:
    return 0x08;
  case 115200:
    return 0x09;
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<serial_bps>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x4b0,%eax
je     11a2 <serial_bps+0xa2>
jmp    111d <serial_bps+0x1d>
mov    -0xc(%rbp),%eax
sub    $0x960,%eax
je     11ae <serial_bps+0xae>
jmp    1130 <serial_bps+0x30>
mov    -0xc(%rbp),%eax
sub    $0x12c0,%eax
je     11ba <serial_bps+0xba>
jmp    1143 <serial_bps+0x43>
mov    -0xc(%rbp),%eax
sub    $0x2580,%eax
je     11c6 <serial_bps+0xc6>
jmp    1156 <serial_bps+0x56>
mov    -0xc(%rbp),%eax
sub    $0x4b00,%eax
je     11d2 <serial_bps+0xd2>
jmp    1169 <serial_bps+0x69>
mov    -0xc(%rbp),%eax
sub    $0x9600,%eax
je     11de <serial_bps+0xde>
jmp    117c <serial_bps+0x7c>
mov    -0xc(%rbp),%eax
sub    $0xe100,%eax
je     11ea <serial_bps+0xea>
jmp    118f <serial_bps+0x8f>
mov    -0xc(%rbp),%eax
sub    $0x1c200,%eax
je     11f6 <serial_bps+0xf6>
jmp    1202 <serial_bps+0x102>
movl   $0x2,-0x4(%rbp)
jmp    1209 <serial_bps+0x109>
movl   $0x3,-0x4(%rbp)
jmp    1209 <serial_bps+0x109>
movl   $0x4,-0x4(%rbp)
jmp    1209 <serial_bps+0x109>
movl   $0x5,-0x4(%rbp)
jmp    1209 <serial_bps+0x109>
movl   $0x6,-0x4(%rbp)
jmp    1209 <serial_bps+0x109>
movl   $0x7,-0x4(%rbp)
jmp    1209 <serial_bps+0x109>
movl   $0x8,-0x4(%rbp)
jmp    1209 <serial_bps+0x109>
movl   $0x9,-0x4(%rbp)
jmp    1209 <serial_bps+0x109>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_bps>:
cmp    $0x4aff,%edi
jg     112b <serial_bps+0x2b>
cmp    $0x12bf,%edi
jg     1149 <serial_bps+0x49>
mov    $0x2,%eax
cmp    $0x4b0,%edi
je     1189 <serial_bps+0x89>
cmp    $0x960,%edi
jne    1187 <serial_bps+0x87>
mov    $0x3,%eax
ret
cmp    $0xe0ff,%edi
jg     115f <serial_bps+0x5f>
cmp    $0x4b00,%edi
je     1175 <serial_bps+0x75>
cmp    $0x9600,%edi
jne    1187 <serial_bps+0x87>
mov    $0x7,%eax
ret
cmp    $0x12c0,%edi
je     117b <serial_bps+0x7b>
cmp    $0x2580,%edi
jne    1187 <serial_bps+0x87>
mov    $0x5,%eax
ret
cmp    $0xe100,%edi
je     1181 <serial_bps+0x81>
cmp    $0x1c200,%edi
jne    1187 <serial_bps+0x87>
mov    $0x9,%eax
ret
mov    $0x6,%eax
ret
mov    $0x4,%eax
ret
mov    $0x8,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @serial_bps(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %13 [
i32 1200, label %5
i32 2400, label %6
i32 4800, label %7
i32 9600, label %8
i32 19200, label %9
i32 38400, label %10
i32 57600, label %11
i32 115200, label %12
]
5: ; preds = %1
store i32 2, i32* %2
br label %14
6: ; preds = %1
store i32 3, i32* %2
br label %14
7: ; preds = %1
store i32 4, i32* %2
br label %14
8: ; preds = %1
store i32 5, i32* %2
br label %14
9: ; preds = %1
store i32 6, i32* %2
br label %14
10: ; preds = %1
store i32 7, i32* %2
br label %14
11: ; preds = %1
store i32 8, i32* %2
br label %14
12: ; preds = %1
store i32 9, i32* %2
br label %14
13: ; preds = %1
store i32 0, i32* %2
br label %14
14: ; preds = %13, %12, %11, %10, %9, %8, %7, %6, %5
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
define i32 @serial_bps(i32 %0) {
switch i32 %0, label %9 [
i32 1200, label %10
i32 2400, label %2
i32 4800, label %3
i32 9600, label %4
i32 19200, label %5
i32 38400, label %6
i32 57600, label %7
i32 115200, label %8
]
2: ; preds = %1
br label %10
3: ; preds = %1
br label %10
4: ; preds = %1
br label %10
5: ; preds = %1
br label %10
6: ; preds = %1
br label %10
7: ; preds = %1
br label %10
8: ; preds = %1
br label %10
9: ; preds = %1
br label %10
10: ; preds = %1, %9, %8, %7, %6, %5, %4, %3, %2
%11 = phi i32 [ 0, %9 ], [ 9, %8 ], [ 8, %7 ], [ 7, %6 ], [ 6, %5 ], [ 5, %4 ], [ 4, %3 ], [ 3, %2 ], [ 2, %1 ]
ret i32 %11
}