int get_ddr2_module_size(int rank_density_byte, int rank_num_byte) {
  int module_size;
  switch (rank_density_byte) {
  case 1:
    module_size = 1024;
    break;
  case 2:
    module_size = 2048;
    break;
  case 4:
    module_size = 4096;
    break;
  case 8:
    module_size = 8192;
    break;
  case 16:
    module_size = 16384;
    break;
  case 32:
    module_size = 128;
    break;
  case 64:
    module_size = 256;
    break;
  default:
  case 128:
    module_size = 512;
    break;
  }
  module_size *= (rank_num_byte & 7) + 1;
  return module_size;
}


x86 assembly (clang, -O0):
<get_ddr2_module_size>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1,%eax
je     1197 <get_ddr2_module_size+0x97>
jmp    111e <get_ddr2_module_size+0x1e>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     11a3 <get_ddr2_module_size+0xa3>
jmp    112f <get_ddr2_module_size+0x2f>
mov    -0x10(%rbp),%eax
sub    $0x4,%eax
je     11af <get_ddr2_module_size+0xaf>
jmp    1140 <get_ddr2_module_size+0x40>
mov    -0x10(%rbp),%eax
sub    $0x8,%eax
je     11bb <get_ddr2_module_size+0xbb>
jmp    1151 <get_ddr2_module_size+0x51>
mov    -0x10(%rbp),%eax
sub    $0x10,%eax
je     11c7 <get_ddr2_module_size+0xc7>
jmp    1162 <get_ddr2_module_size+0x62>
mov    -0x10(%rbp),%eax
sub    $0x20,%eax
je     11d3 <get_ddr2_module_size+0xd3>
jmp    1173 <get_ddr2_module_size+0x73>
mov    -0x10(%rbp),%eax
sub    $0x40,%eax
je     11df <get_ddr2_module_size+0xdf>
jmp    1184 <get_ddr2_module_size+0x84>
mov    -0x10(%rbp),%eax
sub    $0x80,%eax
je     11f0 <get_ddr2_module_size+0xf0>
jmp    11eb <get_ddr2_module_size+0xeb>
movl   $0x400,-0xc(%rbp)
jmp    11f7 <get_ddr2_module_size+0xf7>
movl   $0x800,-0xc(%rbp)
jmp    11f7 <get_ddr2_module_size+0xf7>
movl   $0x1000,-0xc(%rbp)
jmp    11f7 <get_ddr2_module_size+0xf7>
movl   $0x2000,-0xc(%rbp)
jmp    11f7 <get_ddr2_module_size+0xf7>
movl   $0x4000,-0xc(%rbp)
jmp    11f7 <get_ddr2_module_size+0xf7>
movl   $0x80,-0xc(%rbp)
jmp    11f7 <get_ddr2_module_size+0xf7>
movl   $0x100,-0xc(%rbp)
jmp    11f7 <get_ddr2_module_size+0xf7>
jmp    11f0 <get_ddr2_module_size+0xf0>
movl   $0x200,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x7,%eax
add    $0x1,%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ddr2_module_size>:
mov    %esi,%eax
add    $0xffffffff,%edi
cmp    $0x3f,%edi
ja     1126 <get_ddr2_module_size+0x26>
mov    $0x400,%ecx
lea    0xeea(%rip),%rdx
movslq (%rdx,%rdi,4),%rsi
add    %rdx,%rsi
jmp    *%rsi
mov    $0x800,%ecx
jmp    114e <get_ddr2_module_size+0x4e>
mov    $0x200,%ecx
jmp    114e <get_ddr2_module_size+0x4e>
mov    $0x1000,%ecx
jmp    114e <get_ddr2_module_size+0x4e>
mov    $0x2000,%ecx
jmp    114e <get_ddr2_module_size+0x4e>
mov    $0x80,%ecx
jmp    114e <get_ddr2_module_size+0x4e>
mov    $0x100,%ecx
jmp    114e <get_ddr2_module_size+0x4e>
mov    $0x4000,%ecx
and    $0x7,%eax
add    $0x1,%eax
imul   %ecx,%eax
ret

LLVM IR (-O0):
define i32 @get_ddr2_module_size(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
switch i32 %6, label %14 [
i32 1, label %7
i32 2, label %8
i32 4, label %9
i32 8, label %10
i32 16, label %11
i32 32, label %12
i32 64, label %13
i32 128, label %15
]
7: ; preds = %2
store i32 1024, i32* %5
br label %16
8: ; preds = %2
store i32 2048, i32* %5
br label %16
9: ; preds = %2
store i32 4096, i32* %5
br label %16
10: ; preds = %2
store i32 8192, i32* %5
br label %16
11: ; preds = %2
store i32 16384, i32* %5
br label %16
12: ; preds = %2
store i32 128, i32* %5
br label %16
13: ; preds = %2
store i32 256, i32* %5
br label %16
14: ; preds = %2
br label %15
15: ; preds = %2, %14
store i32 512, i32* %5
br label %16
16: ; preds = %15, %13, %12, %11, %10, %9, %8, %7
%17 = load i32, i32* %4
%18 = and i32 %17, 7
%19 = add nsw i32 %18, 1
%20 = load i32, i32* %5
%21 = mul nsw i32 %20, %19
store i32 %21, i32* %5
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
define i32 @get_ddr2_module_size(i32 %0, i32 %1) {
switch i32 %0, label %9 [
i32 1, label %10
i32 2, label %3
i32 4, label %4
i32 8, label %5
i32 16, label %6
i32 32, label %7
i32 64, label %8
]
3: ; preds = %2
br label %10
4: ; preds = %2
br label %10
5: ; preds = %2
br label %10
6: ; preds = %2
br label %10
7: ; preds = %2
br label %10
8: ; preds = %2
br label %10
9: ; preds = %2
br label %10
10: ; preds = %2, %9, %8, %7, %6, %5, %4, %3
%11 = phi i32 [ 512, %9 ], [ 256, %8 ], [ 128, %7 ], [ 16384, %6 ], [ 8192, %5 ], [ 4096, %4 ], [ 2048, %3 ], [ 1024, %2 ]
%12 = and i32 %1, 7
%13 = add nuw nsw i32 %12, 1
%14 = mul nuw nsw i32 %11, %13
ret i32 %14
}