#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;

/* Variables and functions */
int dv_get_audio_sample_count(const uint8_t *buffer, int dsf) {
  int samples = buffer[0] & 0x3f;
  switch ((buffer[3] >> 3) & 0x07) {
  case 0:
    return samples + (dsf ? 1896 : 1580);
  case 1:
    return samples + (dsf ? 1742 : 1452);
  case 2:
  default:
    return samples + (dsf ? 1264 : 1053);
  }
}


x86 assembly (clang, -O0):
<dv_get_audio_sample_count>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x3f,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
shr    $0x3,%eax
and    $0x7,%eax
mov    %eax,-0x1c(%rbp)
je     1154 <dv_get_audio_sample_count+0x54>
jmp    1132 <dv_get_audio_sample_count+0x32>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     1174 <dv_get_audio_sample_count+0x74>
jmp    1143 <dv_get_audio_sample_count+0x43>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1194 <dv_get_audio_sample_count+0x94>
jmp    1199 <dv_get_audio_sample_count+0x99>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%esi
mov    $0x62c,%ecx
mov    $0x768,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <dv_get_audio_sample_count+0xb4>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%esi
mov    $0x5ac,%ecx
mov    $0x6ce,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <dv_get_audio_sample_count+0xb4>
jmp    1199 <dv_get_audio_sample_count+0x99>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%esi
mov    $0x41d,%ecx
mov    $0x4f0,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<dv_get_audio_sample_count>:
mov    (%rdi),%eax
mov    0xc(%rdi),%ecx
shr    $0x3,%ecx
and    $0x7,%ecx
cmp    $0x1,%ecx
je     1122 <dv_get_audio_sample_count+0x22>
test   %ecx,%ecx
jne    1130 <dv_get_audio_sample_count+0x30>
test   %esi,%esi
mov    $0x62c,%edx
mov    $0x768,%ecx
jmp    113c <dv_get_audio_sample_count+0x3c>
test   %esi,%esi
mov    $0x5ac,%edx
mov    $0x6ce,%ecx
jmp    113c <dv_get_audio_sample_count+0x3c>
test   %esi,%esi
mov    $0x41d,%edx
mov    $0x4f0,%ecx
cmove  %edx,%ecx
and    $0x3f,%eax
add    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @dv_get_audio_sample_count(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32*, i32** %4
%8 = getelementptr inbounds i32, i32* %7, i64 0
%9 = load i32, i32* %8
%10 = and i32 %9, 63
store i32 %10, i32* %6
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 3
%13 = load i32, i32* %12
%14 = ashr i32 %13, 3
%15 = and i32 %14, 7
switch i32 %15, label %31 [
i32 0, label %16
i32 1, label %23
i32 2, label %30
]
16: ; preds = %2
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 1896, i32 1580
%22 = add nsw i32 %17, %21
store i32 %22, i32* %3
br label %38
23: ; preds = %2
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 1742, i32 1452
%29 = add nsw i32 %24, %28
store i32 %29, i32* %3
br label %38
30: ; preds = %2
br label %31
31: ; preds = %2, %30
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 1264, i32 1053
%37 = add nsw i32 %32, %36
store i32 %37, i32* %3
br label %38
38: ; preds = %31, %23, %16
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @dv_get_audio_sample_count(i32* nocapture %0, i32 %1) {
%3 = load i32, i32* %0
%4 = getelementptr inbounds i32, i32* %0, i64 3
%5 = load i32, i32* %4
%6 = lshr i32 %5, 3
%7 = and i32 %6, 7
switch i32 %7, label %14 [
i32 0, label %8
i32 1, label %11
]
8: ; preds = %2
%9 = icmp eq i32 %1, 0
%10 = select i1 %9, i32 1580, i32 1896
br label %17
11: ; preds = %2
%12 = icmp eq i32 %1, 0
%13 = select i1 %12, i32 1452, i32 1742
br label %17
14: ; preds = %2
%15 = icmp eq i32 %1, 0
%16 = select i1 %15, i32 1053, i32 1264
br label %17
17: ; preds = %14, %11, %8
%18 = phi i32 [ %16, %14 ], [ %13, %11 ], [ %10, %8 ]
%19 = and i32 %3, 63
%20 = add nuw nsw i32 %18, %19
ret i32 %20
}