int wav_channels(int flags, unsigned int *speaker_flags) {
  static const unsigned short speaker_tbl[] = {3,    4,    3, 7, 0x103, 0x107,
                                               0x33, 0x37, 4, 4, 3};
  static const unsigned char nfchans_tbl[] = {2, 1, 2, 3, 3, 4, 4, 5, 1, 1, 2};
  int chans;
  *speaker_flags = speaker_tbl[flags & 15];
  chans = nfchans_tbl[flags & 15];
  if (flags & 16) {
    *speaker_flags |= 8;
    chans++;
  }
  return chans;
}


x86 assembly (clang, -O0):
<wav_channels>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xee5(%rip),%rax
movzwl (%rax,%rcx,2),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xee1(%rip),%rax
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     115f <wav_channels+0x5f>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
or     $0x8,%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<wav_channels>:
mov    %edi,%eax
and    $0xf,%eax
lea    0xef4(%rip),%rcx
movzwl (%rcx,%rax,2),%ecx
mov    %ecx,(%rsi)
lea    0xefd(%rip),%rdx
movzbl (%rax,%rdx,1),%eax
test   $0x10,%dil
je     112b <wav_channels+0x2b>
or     $0x8,%ecx
mov    %ecx,(%rsi)
add    $0x1,%eax
ret

LLVM IR (-O0):
@wav_channels.speaker_tbl = internal constant [11 x i16] [i16 3, i16 4, i16 3, i16 7, i16 259, i16 263, i16 51, i16 55, i16 4, i16 4, i16 3]
@wav_channels.nfchans_tbl = internal constant [11 x i8] c"\02\01\02\03\03\04\04\05\01\01\02"
define i32 @wav_channels(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
%7 = and i32 %6, 15
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [11 x i16], [11 x i16]* @wav_channels.speaker_tbl, i64 0, i64 %8
%10 = load i16, i16* %9
%11 = zext i16 %10 to i32
%12 = load i32*, i32** %4
store i32 %11, i32* %12
%13 = load i32, i32* %3
%14 = and i32 %13, 15
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [11 x i8], [11 x i8]* @wav_channels.nfchans_tbl, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
store i32 %18, i32* %5
%19 = load i32, i32* %3
%20 = and i32 %19, 16
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = load i32*, i32** %4
%24 = load i32, i32* %23
%25 = or i32 %24, 8
store i32 %25, i32* %23
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %28
28: ; preds = %22, %2
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
@wav_channels.speaker_tbl = internal unnamed_addr constant [11 x i16] [i16 3, i16 4, i16 3, i16 7, i16 259, i16 263, i16 51, i16 55, i16 4, i16 4, i16 3]
@wav_channels.nfchans_tbl = internal unnamed_addr constant [11 x i8] c"\02\01\02\03\03\04\04\05\01\01\02"
define i32 @wav_channels(i32 %0, i32* nocapture writeonly %1) {
%3 = and i32 %0, 15
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds [11 x i16], [11 x i16]* @wav_channels.speaker_tbl, i64 0, i64 %4
%6 = load i16, i16* %5
%7 = zext i16 %6 to i32
store i32 %7, i32* %1
%8 = getelementptr inbounds [11 x i8], [11 x i8]* @wav_channels.nfchans_tbl, i64 0, i64 %4
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = and i32 %0, 16
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = or i32 %7, 8
store i32 %14, i32* %1
%15 = add nuw nsw i32 %10, 1
br label %16
16: ; preds = %13, %2
%17 = phi i32 [ %15, %13 ], [ %10, %2 ]
ret i32 %17
}