int layout_to_rlq(int level, int layout, int raiddisks) {
  switch (level) {
  case 0:
    return 0x00;
  case 1:
    switch (raiddisks) {
    case 2:
      return 0x00;
    case 3:
      return 0x01;
    default:
      return -1;
    }
  case 4:
    switch (layout) {
    case 0:
      return 0x01;
    }
    break;
  case 5:
    switch (layout) {
    case 0:
      return 0x02;
    case 1:
      return 0x00;
    case 2:
      return 0x03;
    case 3:
      return -1;
    }
  case 6:
    switch (layout) {
    case 9:
      return 0x02;
    case 8:
      return 0x01;
    case 10:
      return 0x03;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<layout_to_rlq>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x6,%rax
ja     1261 <layout_to_rlq+0x161>
mov    -0x18(%rbp),%rax
lea    0xed7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x2,%eax
je     1163 <layout_to_rlq+0x63>
jmp    1152 <layout_to_rlq+0x52>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     116f <layout_to_rlq+0x6f>
jmp    117b <layout_to_rlq+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
movl   $0x1,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
movl   $0xffffffff,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
mov    -0xc(%rbp),%eax
test   %eax,%eax
jne    11a3 <layout_to_rlq+0xa3>
jmp    1197 <layout_to_rlq+0x97>
movl   $0x1,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
jmp    1261 <layout_to_rlq+0x161>
mov    -0xc(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x3,%rax
ja     11fd <layout_to_rlq+0xfd>
mov    -0x28(%rbp),%rax
lea    0xe58(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x2,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
movl   $0x0,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
movl   $0x3,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
movl   $0xffffffff,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
jmp    1202 <layout_to_rlq+0x102>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x8,%eax
je     1244 <layout_to_rlq+0x144>
jmp    1216 <layout_to_rlq+0x116>
mov    -0x2c(%rbp),%eax
sub    $0x9,%eax
je     1238 <layout_to_rlq+0x138>
jmp    1227 <layout_to_rlq+0x127>
mov    -0x2c(%rbp),%eax
sub    $0xa,%eax
je     1250 <layout_to_rlq+0x150>
jmp    125c <layout_to_rlq+0x15c>
movl   $0x2,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
movl   $0x1,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
movl   $0x3,-0x4(%rbp)
jmp    1268 <layout_to_rlq+0x168>
jmp    1261 <layout_to_rlq+0x161>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<layout_to_rlq>:
cmp    $0x6,%edi
ja     115b <layout_to_rlq+0x5b>
mov    %edi,%eax
mov    %edi,%ecx
lea    0xef0(%rip),%rdi
movslq (%rdi,%rcx,4),%rcx
add    %rdi,%rcx
jmp    *%rcx
xor    %eax,%eax
cmp    $0x3,%edx
sete   %al
lea    (%rax,%rax,1),%ecx
add    $0xffffffff,%ecx
xor    %eax,%eax
cmp    $0x2,%edx
cmovne %ecx,%eax
ret
test   %esi,%esi
jne    115b <layout_to_rlq+0x5b>
mov    $0x1,%eax
ret
cmp    $0xb,%esi
jae    115b <layout_to_rlq+0x5b>
movslq %esi,%rax
lea    0xed3(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret
lea    -0x8(%rsi),%eax
cmp    $0x3,%eax
jae    115b <layout_to_rlq+0x5b>
add    $0xfffffff9,%esi
mov    %esi,%eax
ret
mov    $0xffffffff,%eax
ret

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

LLVM IR (-O2):
@switch.table.layout_to_rlq = [11 x i32] [i32 2, i32 0, i32 3, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 1, i32 2, i32 3]
define i32 @layout_to_rlq(i32 %0, i32 %1, i32 %2) {
switch i32 %0, label %16 [
i32 0, label %23
i32 1, label %4
i32 4, label %9
i32 5, label %11
i32 6, label %13
]
4: ; preds = %3
%5 = icmp eq i32 %2, 3
%6 = select i1 %5, i32 1, i32 -1
%7 = icmp eq i32 %2, 2
%8 = select i1 %7, i32 0, i32 %6
br label %23
9: ; preds = %3
%10 = icmp eq i32 %1, 0
br i1 %10, label %23, label %16
11: ; preds = %3
%12 = icmp ult i32 %1, 11
br i1 %12, label %17, label %16
13: ; preds = %3
%14 = add i32 %1, -8
%15 = icmp ult i32 %14, 3
br i1 %15, label %21, label %16
16: ; preds = %13, %11, %9, %3
br label %23
17: ; preds = %11
%18 = sext i32 %1 to i64
%19 = getelementptr inbounds [11 x i32], [11 x i32]* @switch.table.layout_to_rlq, i64 0, i64 %18
%20 = load i32, i32* %19
br label %23
21: ; preds = %13
%22 = add i32 %1, -7
br label %23
23: ; preds = %21, %17, %9, %4, %3, %16
%24 = phi i32 [ -1, %16 ], [ %0, %3 ], [ %8, %4 ], [ 1, %9 ], [ %20, %17 ], [ %22, %21 ]
ret i32 %24
}