#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 /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int get_ac3_header(int /*<<< orphan*/ *);
int get_ac3_samplerate(uint8_t *buf) {
  int fscod, sampling_rate;
  uint32_t tmp = get_ac3_header(buf);
  fscod = (tmp >> 6) & 0x3;
  if (fscod == 3) {
    return -1;
  } else if (fscod == 2) {
    sampling_rate = 32000;
  } else if (fscod == 1) {
    sampling_rate = 44100;
  } else {
    sampling_rate = 48000;
  }
  return sampling_rate;
}


x86 assembly (clang, -O0):
<get_ac3_samplerate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <get_ac3_header@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x6,%eax
and    $0x3,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jne    114a <get_ac3_samplerate+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <get_ac3_samplerate+0x7d>
cmpl   $0x2,-0x14(%rbp)
jne    1160 <get_ac3_samplerate+0x50>
movl   $0x7d00,-0x18(%rbp)
jmp    1182 <get_ac3_samplerate+0x72>
cmpl   $0x1,-0x14(%rbp)
jne    1176 <get_ac3_samplerate+0x66>
movl   $0xac44,-0x18(%rbp)
jmp    117d <get_ac3_samplerate+0x6d>
movl   $0xbb80,-0x18(%rbp)
jmp    1182 <get_ac3_samplerate+0x72>
jmp    1187 <get_ac3_samplerate+0x77>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ac3_samplerate>:
push   %rax
call   1030 <get_ac3_header@plt>
shr    $0x6,%eax
and    $0x3,%eax
cmp    $0x3,%eax
je     1132 <get_ac3_samplerate+0x22>
cmp    $0x2,%eax
je     1139 <get_ac3_samplerate+0x29>
cmp    $0x1,%eax
jne    1140 <get_ac3_samplerate+0x30>
mov    $0xac44,%eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    $0x7d00,%eax
pop    %rcx
ret
mov    $0xbb80,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @get_ac3_samplerate(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = call i32 @get_ac3_header(i32* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = ashr i32 %9, 6
%11 = and i32 %10, 3
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 -1, i32* %2
br label %28
15: ; preds = %1
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 32000, i32* %5
br label %25
19: ; preds = %15
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 44100, i32* %5
br label %24
23: ; preds = %19
store i32 48000, i32* %5
br label %24
24: ; preds = %23, %22
br label %25
25: ; preds = %24, %18
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %14
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @get_ac3_samplerate(i32* %0) {
%2 = tail call i32 @get_ac3_header(i32* %0)
%3 = lshr i32 %2, 6
%4 = and i32 %3, 3
switch i32 %4, label %6 [
i32 3, label %9
i32 2, label %7
i32 1, label %5
]
5: ; preds = %1
br label %7
6: ; preds = %1
br label %7
7: ; preds = %1, %6, %5
%8 = phi i32 [ 44100, %5 ], [ 48000, %6 ], [ 32000, %1 ]
br label %9
9: ; preds = %1, %7
%10 = phi i32 [ %8, %7 ], [ -1, %1 ]
ret i32 %10
}