int L3_find_samplerate_index(long freq, int mpegtype) {
  static long mpeg1[3] = {44100, 48000, 32000};
  static long mpeg2LSF[3] = {22050, 24000, 16000};
  int i;
  if (mpegtype == 1) {
    for (i = 0; i < 3; i++)
      if (freq == mpeg1[i])
        return i;
  } else {
    for (i = 0; i < 3; i++)
      if (freq == mpeg2LSF[i])
        return i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<L3_find_samplerate_index>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1162 <L3_find_samplerate_index+0x62>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    115d <L3_find_samplerate_index+0x5d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rdx
lea    0x2efb(%rip),%rcx
cmp    (%rcx,%rdx,8),%rax
jne    114a <L3_find_samplerate_index+0x4a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b6 <L3_find_samplerate_index+0xb6>
jmp    114f <L3_find_samplerate_index+0x4f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    111c <L3_find_samplerate_index+0x1c>
jmp    11af <L3_find_samplerate_index+0xaf>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11aa <L3_find_samplerate_index+0xaa>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rdx
lea    0x2ece(%rip),%rcx
cmp    (%rcx,%rdx,8),%rax
jne    1197 <L3_find_samplerate_index+0x97>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b6 <L3_find_samplerate_index+0xb6>
jmp    119c <L3_find_samplerate_index+0x9c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1169 <L3_find_samplerate_index+0x69>
jmp    11af <L3_find_samplerate_index+0xaf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<L3_find_samplerate_index>:
cmp    $0x1,%esi
jne    1126 <L3_find_samplerate_index+0x26>
cmp    $0x7d00,%rdi
je     1147 <L3_find_samplerate_index+0x47>
cmp    $0xac44,%rdi
je     114d <L3_find_samplerate_index+0x4d>
cmp    $0xbb80,%rdi
jne    1150 <L3_find_samplerate_index+0x50>
mov    $0x1,%eax
ret
cmp    $0x3e80,%rdi
je     1147 <L3_find_samplerate_index+0x47>
cmp    $0x5622,%rdi
je     114d <L3_find_samplerate_index+0x4d>
cmp    $0x5dc0,%rdi
jne    1150 <L3_find_samplerate_index+0x50>
mov    $0x1,%eax
ret
mov    $0x2,%eax
ret
xor    %eax,%eax
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
@L3_find_samplerate_index.mpeg1 = internal global [3 x i64] [i64 44100, i64 48000, i64 32000]
@L3_find_samplerate_index.mpeg2LSF = internal global [3 x i64] [i64 22050, i64 24000, i64 16000]
define i32 @L3_find_samplerate_index(i64 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %27
9: ; preds = %2
store i32 0, i32* %6
br label %10
10: ; preds = %23, %9
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i64, i64* %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [3 x i64], [3 x i64]* @L3_find_samplerate_index.mpeg1, i64 0, i64 %16
%18 = load i64, i64* %17
%19 = icmp eq i64 %14, %18
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = load i32, i32* %6
store i32 %21, i32* %3
br label %46
22: ; preds = %13
br label %23
23: ; preds = %22
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %10
26: ; preds = %10
br label %45
27: ; preds = %2
store i32 0, i32* %6
br label %28
28: ; preds = %41, %27
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 3
br i1 %30, label %31, label %44
31: ; preds = %28
%32 = load i64, i64* %4
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x i64], [3 x i64]* @L3_find_samplerate_index.mpeg2LSF, i64 0, i64 %34
%36 = load i64, i64* %35
%37 = icmp eq i64 %32, %36
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = load i32, i32* %6
store i32 %39, i32* %3
br label %46
40: ; preds = %31
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %28
44: ; preds = %28
br label %45
45: ; preds = %44, %26
store i32 -1, i32* %3
br label %46
46: ; preds = %45, %38, %20
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @L3_find_samplerate_index(i64 %0, i32 %1) {
%3 = icmp eq i32 %1, 1
br i1 %3, label %5, label %4
4: ; preds = %2
switch i64 %0, label %7 [
i64 22050, label %12
i64 24000, label %10
i64 16000, label %11
]
5: ; preds = %2
switch i64 %0, label %6 [
i64 44100, label %12
i64 48000, label %8
i64 32000, label %9
]
6: ; preds = %5
br label %12
7: ; preds = %4
br label %12
8: ; preds = %5
br label %12
9: ; preds = %5
br label %12
10: ; preds = %4
br label %12
11: ; preds = %4
br label %12
12: ; preds = %4, %11, %10, %5, %9, %8, %7, %6
%13 = phi i32 [ 0, %5 ], [ -1, %6 ], [ 0, %4 ], [ -1, %7 ], [ 1, %8 ], [ 2, %9 ], [ 1, %10 ], [ 2, %11 ]
ret i32 %13
}