int iw_get_channeltype(int imgtype, int channel) {
  switch (imgtype) {
  case 0x0001:
    if (channel == 0)
      return 4;
    break;
  case 0x0101:
    if (channel == 0)
      return 4;
    if (channel == 1)
      return 3;
    break;
  case 0x0010:
    if (channel == 0)
      return 0;
    if (channel == 1)
      return 1;
    if (channel == 2)
      return 2;
    break;
  case 0x0110:
    if (channel == 0)
      return 0;
    if (channel == 1)
      return 1;
    if (channel == 2)
      return 2;
    if (channel == 3)
      return 3;
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<iw_get_channeltype>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1,%eax
je     1155 <iw_get_channeltype+0x55>
jmp    111e <iw_get_channeltype+0x1e>
mov    -0x10(%rbp),%eax
sub    $0x10,%eax
je     11a1 <iw_get_channeltype+0xa1>
jmp    112f <iw_get_channeltype+0x2f>
mov    -0x10(%rbp),%eax
sub    $0x101,%eax
je     1170 <iw_get_channeltype+0x70>
jmp    1142 <iw_get_channeltype+0x42>
mov    -0x10(%rbp),%eax
sub    $0x110,%eax
je     11e8 <iw_get_channeltype+0xe8>
jmp    1245 <iw_get_channeltype+0x145>
cmpl   $0x0,-0xc(%rbp)
jne    116b <iw_get_channeltype+0x6b>
movl   $0x4,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
jmp    1245 <iw_get_channeltype+0x145>
cmpl   $0x0,-0xc(%rbp)
jne    1186 <iw_get_channeltype+0x86>
movl   $0x4,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
cmpl   $0x1,-0xc(%rbp)
jne    119c <iw_get_channeltype+0x9c>
movl   $0x3,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
jmp    1245 <iw_get_channeltype+0x145>
cmpl   $0x0,-0xc(%rbp)
jne    11b7 <iw_get_channeltype+0xb7>
movl   $0x0,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
cmpl   $0x1,-0xc(%rbp)
jne    11cd <iw_get_channeltype+0xcd>
movl   $0x1,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
cmpl   $0x2,-0xc(%rbp)
jne    11e3 <iw_get_channeltype+0xe3>
movl   $0x2,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
jmp    1245 <iw_get_channeltype+0x145>
cmpl   $0x0,-0xc(%rbp)
jne    11fe <iw_get_channeltype+0xfe>
movl   $0x0,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
cmpl   $0x1,-0xc(%rbp)
jne    1214 <iw_get_channeltype+0x114>
movl   $0x1,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
cmpl   $0x2,-0xc(%rbp)
jne    122a <iw_get_channeltype+0x12a>
movl   $0x2,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
cmpl   $0x3,-0xc(%rbp)
jne    1240 <iw_get_channeltype+0x140>
movl   $0x3,-0x4(%rbp)
jmp    124c <iw_get_channeltype+0x14c>
jmp    1245 <iw_get_channeltype+0x145>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<iw_get_channeltype>:
mov    %esi,%eax
cmp    $0x100,%edi
jg     111a <iw_get_channeltype+0x1a>
cmp    $0x1,%edi
je     1131 <iw_get_channeltype+0x31>
cmp    $0x10,%edi
jne    1135 <iw_get_channeltype+0x35>
cmp    $0x3,%eax
jae    1135 <iw_get_channeltype+0x35>
ret
cmp    $0x101,%edi
je     1138 <iw_get_channeltype+0x38>
cmp    $0x110,%edi
jne    1135 <iw_get_channeltype+0x35>
cmp    $0x4,%eax
jb     1119 <iw_get_channeltype+0x19>
jmp    1135 <iw_get_channeltype+0x35>
test   %eax,%eax
je     114e <iw_get_channeltype+0x4e>
xor    %eax,%eax
ret
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
lea    (%rcx,%rcx,2),%ecx
test   %eax,%eax
mov    $0x4,%eax
cmovne %ecx,%eax
ret
mov    $0x4,%eax
ret

LLVM IR (-O0):
define i32 @iw_get_channeltype(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
switch i32 %6, label %51 [
i32 1, label %7
i32 257, label %12
i32 16, label %21
i32 272, label %34
]
7: ; preds = %2
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 4, i32* %3
br label %52
11: ; preds = %7
br label %51
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 4, i32* %3
br label %52
16: ; preds = %12
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 3, i32* %3
br label %52
20: ; preds = %16
br label %51
21: ; preds = %2
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 0, i32* %3
br label %52
25: ; preds = %21
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 1, i32* %3
br label %52
29: ; preds = %25
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 2, i32* %3
br label %52
33: ; preds = %29
br label %51
34: ; preds = %2
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 0, i32* %3
br label %52
38: ; preds = %34
%39 = load i32, i32* %5
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 1, i32* %3
br label %52
42: ; preds = %38
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 2
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 2, i32* %3
br label %52
46: ; preds = %42
%47 = load i32, i32* %5
%48 = icmp eq i32 %47, 3
br i1 %48, label %49, label %50
49: ; preds = %46
store i32 3, i32* %3
br label %52
50: ; preds = %46
br label %51
51: ; preds = %2, %50, %33, %20, %11
store i32 0, i32* %3
br label %52
52: ; preds = %51, %49, %45, %41, %37, %32, %28, %24, %19, %15, %10
%53 = load i32, i32* %3
ret i32 %53
}

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