#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int wav_channels(int flags, uint32_t *speaker_flags) {
  static const uint32_t speaker_tbl[] = {
      0x4,
      0x1 | 0x2,
      0x1 | 0x2,
      0x1 | 0x2,
      0x1 | 0x2,
      0x1 | 0x2 | 0x4,
      0x1 | 0x2 | 0x100,
      0x1 | 0x2 | 0x4 | 0x100,
      0x1 | 0x2 | 0x10 | 0x20,
      0x1 | 0x2 | 0x4 | 0x10 | 0x20,
  };
  static const uint8_t nfchans_tbl[] = {1, 2, 2, 2, 2, 3, 3, 4,
                                        4, 5, 6, 6, 6, 7, 8, 8};
  int chans;
  *speaker_flags = speaker_tbl[flags & 0x3F];
  chans = nfchans_tbl[flags & 0x3F];
  if (flags & 0x80) {
    *speaker_flags |= 0x8;
    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    $0x3f,%eax
movslq %eax,%rcx
lea    0xee5(%rip),%rax
mov    (%rax,%rcx,4),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
and    $0x3f,%eax
movslq %eax,%rcx
lea    0xefc(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0x80,%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    $0x3f,%eax
lea    0xef4(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
mov    %ecx,(%rsi)
lea    0xf18(%rip),%rdx
mov    (%rdx,%rax,4),%eax
test   $0x80,%dil
je     1129 <wav_channels+0x29>
or     $0x8,%ecx
mov    %ecx,(%rsi)
add    $0x1,%eax
ret

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

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