#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*/ sample_rates;
typedef int /*<<< orphan*/ filename;
typedef int /*<<< orphan*/ data_out;
typedef int /*<<< orphan*/ data_in;

/* Variables and functions */
scalar_t__ check_output(float *, int, float);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ gen_windowed_sine(float *, int, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read_vorbis_data_or_die(char *, int, float *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ set_data_in(float *, int, double);
int /*<<< orphan*/ snprintf(char *, int, char *, int, float, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write_vorbis_data_or_die(char *, int, float, float *, int,
                                            int);
int main(void) {
  static float data_out[2048];
  static float data_in[2048];
  int sample_rates[] = {44100, 48000, 32000, 22050, 16000, 96000};
  unsigned k;
  int errors = 0;
  int ch;
  gen_windowed_sine(data_out, (sizeof(data_out) / sizeof(data_out[0])), 0.95);
  for (ch = 1; ch <= 8; ch++) {
    float q = -.05;
    printf("\nTesting %d channel%s\n\n", ch, ch == 1 ? "" : "s");
    while (q < 1.) {
      for (k = 0; k < (sizeof(sample_rates) / sizeof(sample_rates[0])); k++) {
        char filename[64];
        snprintf(filename, sizeof(filename), "vorbis_%dch_q%.1f_%u.ogg", ch,
                 q * 10, sample_rates[k]);
        printf("    %-20s : ", filename);
        fflush(stdout);
        set_data_in(data_in, (sizeof(data_in) / sizeof(data_in[0])), 3.141);
        write_vorbis_data_or_die(filename, sample_rates[k], q, data_out,
                                 (sizeof(data_out) / sizeof(data_out[0])), ch);
        read_vorbis_data_or_die(filename, sample_rates[k], data_in,
                                (sizeof(data_in) / sizeof(data_in[0])));
        if (check_output(data_in, (sizeof(data_in) / sizeof(data_in[0])),
                         (.15f - .1f * q)) != 0)
          errors++;
        else {
          puts("ok");
          remove(filename);
        }
      }
      q += .1;
    }
  }
  if (errors)
    exit(1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe6a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe64(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0x2ea2(%rip),%rdi
mov    $0x800,%esi
movsd  0xe05(%rip),%xmm0
call   10a0 <gen_windowed_sine@plt>
movl   $0x1,-0x2c(%rbp)
cmpl   $0x8,-0x2c(%rbp)
jg     13c1 <main+0x211>
movss  0xe07(%rip),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x2c(%rbp),%ecx
lea    0xe35(%rip),%rdx
lea    0xe2d(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movss  -0x30(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdb0(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    13ae <main+0x1fe>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    $0x6,%rax
jae    138b <main+0x1db>
lea    -0x70(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
movss  0xda7(%rip),%xmm0
mulss  -0x30(%rbp),%xmm0
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp,%rax,4),%r8d
mov    $0x40,%esi
lea    0xdc4(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x70(%rbp),%rsi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    0x4dc6(%rip),%rdi
mov    $0x800,%esi
movsd  0xd41(%rip),%xmm0
call   1070 <set_data_in@plt>
lea    -0x70(%rbp),%rdi
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp,%rax,4),%esi
movss  -0x30(%rbp),%xmm0
mov    -0x2c(%rbp),%r8d
lea    0x2d99(%rip),%rdx
mov    $0x800,%ecx
call   10c0 <write_vorbis_data_or_die@plt>
lea    -0x70(%rbp),%rdi
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp,%rax,4),%esi
lea    0x4d7d(%rip),%rdx
mov    $0x800,%ecx
call   1080 <read_vorbis_data_or_die@plt>
movss  -0x30(%rbp),%xmm0
movss  0xcfa(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xcf2(%rip),%xmm1
addss  %xmm1,%xmm0
lea    0x4d4f(%rip),%rdi
mov    $0x800,%esi
call   10b0 <check_output@plt>
cmp    $0x0,%rax
je     1363 <main+0x1b3>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1378 <main+0x1c8>
lea    0xd1e(%rip),%rdi
call   1040 <puts@plt>
lea    -0x70(%rbp),%rdi
call   1030 <remove@plt>
jmp    137d <main+0x1cd>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1269 <main+0xb9>
movss  -0x30(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xc74(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
jmp    1247 <main+0x97>
jmp    13b3 <main+0x203>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1207 <main+0x57>
cmpl   $0x0,-0x28(%rbp)
je     13d5 <main+0x225>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0x2ecb(%rip),%rdi
movsd  0xe33(%rip),%xmm0
mov    $0x800,%esi
call   10a0 <gen_windowed_sine@plt>
mov    $0x1,%ebp
lea    0x20(%rsp),%rbx
lea    0x4ea8(%rip),%r14
xor    %r12d,%r12d
jmp    11fc <main+0x4c>
nopl   (%rax)
add    $0x1,%ebp
cmp    $0x9,%ebp
je     1389 <main+0x1d9>
cmp    $0x1,%ebp
lea    0xe6a(%rip),%rdx
lea    0xe62(%rip),%rax
cmove  %rax,%rdx
lea    0xe40(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0xddf(%rip),%xmm1
movss  0xdef(%rip),%xmm2
jmp    1269 <main+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x18(%rsp),%xmm0
addsd  0xdca(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
movss  0xdcc(%rip),%xmm0
ucomiss %xmm2,%xmm0
jbe    11f0 <main+0x40>
movsd  %xmm1,0x18(%rsp)
movaps %xmm2,%xmm0
mulss  0xdaa(%rip),%xmm0
movss  %xmm0,0x10(%rsp)
movss  %xmm2,0x14(%rsp)
mulss  0xd9a(%rip),%xmm2
addss  0xd96(%rip),%xmm2
movss  %xmm2,0xc(%rsp)
xor    %r13d,%r13d
jmp    12d2 <main+0x122>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xde1(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
add    $0x4,%r13
cmp    $0x18,%r13
je     1240 <main+0x90>
lea    0xd67(%rip),%rax
mov    0x0(%r13,%rax,1),%r15d
mov    %rbx,%rdi
mov    $0x40,%esi
lea    0xd85(%rip),%rdx
mov    %ebp,%ecx
movss  0x10(%rsp),%xmm0
mov    %r15d,%r8d
call   1060 <snprintf@plt>
lea    0xd87(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    %r14,%rdi
mov    $0x800,%esi
movsd  0xce4(%rip),%xmm0
call   1070 <set_data_in@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
movss  0x14(%rsp),%xmm0
lea    0x2d4c(%rip),%rdx
mov    $0x800,%ecx
mov    %ebp,%r8d
call   10c0 <write_vorbis_data_or_die@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
mov    $0x800,%ecx
call   1080 <read_vorbis_data_or_die@plt>
mov    %r14,%rdi
mov    $0x800,%esi
movss  0xc(%rsp),%xmm0
call   10b0 <check_output@plt>
test   %rax,%rax
je     12b0 <main+0x100>
add    $0x1,%r12d
jmp    12c4 <main+0x114>
test   %r12d,%r12d
jne    139f <main+0x1ef>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@main.data_out = internal global [2048 x float] zeroinitializer
@main.data_in = internal global [2048 x float] zeroinitializer
@__const.main.sample_rates = [6 x i32] [i32 44100, i32 48000, i32 32000, i32 22050, i32 16000, i32 96000]
@.str = [24 x i8] c"\0ATesting %d channel%s\0A\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
@.str.3 = [25 x i8] c"vorbis_%dch_q%.1f_%u.ogg\00"
@.str.4 = [13 x i8] c" %-20s : \00"
@stdout = global i32 0
@.str.5 = [3 x i8] c"ok\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
%7 = alloca [64 x i8]
store i32 0, i32* %1
%8 = bitcast [6 x i32]* %2 to i8*
store i32 0, i32* %4
%9 = call i32 @gen_windowed_sine(float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_out, i64 0, i64 0), i32 2048, double 0x3FEE666666666666)
store i32 1, i32* %5
br label %10
10: ; preds = %79, %0
%11 = load i32, i32* %5
%12 = icmp sle i32 %11, 8
br i1 %12, label %13, label %82
13: ; preds = %10
store float 0xBFA99999A0000000, float* %6
%14 = load i32, i32* %5
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 1
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %18)
br label %20
20: ; preds = %73, %13
%21 = load float, float* %6
%22 = fpext float %21 to double
%23 = fcmp olt double %22, 1.000000e+00
br i1 %23, label %24, label %78
24: ; preds = %20
store i32 0, i32* %3
br label %25
25: ; preds = %70, %24
%26 = load i32, i32* %3
%27 = zext i32 %26 to i64
%28 = icmp ult i64 %27, 6
br i1 %28, label %29, label %73
29: ; preds = %25
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%31 = load i32, i32* %5
%32 = load float, float* %6
%33 = fmul float %32, 1.000000e+01
%34 = load i32, i32* %3
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @snprintf(i8* %30, i32 64, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %31, float %33, i32 %37)
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @stdout
%42 = call i32 @fflush(i32 %41)
%43 = call i32 @set_data_in(float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_in, i64 0, i64 0), i32 2048, double 3.141000e+00)
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%45 = load i32, i32* %3
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = load float, float* %6
%50 = load i32, i32* %5
%51 = call i32 @write_vorbis_data_or_die(i8* %44, i32 %48, float %49, float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_out, i64 0, i64 0), i32 2048, i32 %50)
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%53 = load i32, i32* %3
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = call i32 @read_vorbis_data_or_die(i8* %52, i32 %56, float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_in, i64 0, i64 0), i32 2048)
%58 = load float, float* %6
%59 = call float @llvm.fmuladd.f32(float 0xBFB99999A0000000, float %58, float 0x3FC3333340000000)
%60 = call i64 @check_output(float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_in, i64 0, i64 0), i32 2048, float %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %29
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
store i32 %64, i32* %4
br label %69
65: ; preds = %29
%66 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%67 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%68 = call i32 @remove(i8* %67)
br label %69
69: ; preds = %65, %62
br label %70
70: ; preds = %69
%71 = load i32, i32* %3
%72 = add i32 %71, 1
store i32 %72, i32* %3
br label %25
73: ; preds = %25
%74 = load float, float* %6
%75 = fpext float %74 to double
%76 = fadd double %75, 1.000000e-01
%77 = fptrunc double %76 to float
store float %77, float* %6
br label %20
78: ; preds = %20
br label %79
79: ; preds = %78
%80 = load i32, i32* %5
%81 = add nsw i32 %80, 1
store i32 %81, i32* %5
br label %10
82: ; preds = %10
%83 = load i32, i32* %4
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %82
ret i32 0
}

LLVM IR (-O2):
@main.data_out = internal global [2048 x float] zeroinitializer
@main.data_in = internal global [2048 x float] zeroinitializer
@__const.main.sample_rates = [6 x i32] [i32 44100, i32 48000, i32 32000, i32 22050, i32 16000, i32 96000]
@.str = [24 x i8] c"\0ATesting %d channel%s\0A\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
@.str.3 = [25 x i8] c"vorbis_%dch_q%.1f_%u.ogg\00"
@.str.4 = [13 x i8] c" %-20s : \00"
@stdout = global i32 0
@.str.5 = [3 x i8] c"ok\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = tail call i32 @gen_windowed_sine(float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_out, i64 0, i64 0), i32 2048, double 0x3FEE666666666666)
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
br label %4
4: ; preds = %0, %44
%5 = phi i32 [ 1, %0 ], [ %45, %44 ]
%6 = phi i32 [ 0, %0 ], [ %36, %44 ]
%7 = icmp eq i32 %5, 1
%8 = select i1 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %8)
br label %10
10: ; preds = %4, %39
%11 = phi double [ 0xBFA99999A0000000, %4 ], [ %42, %39 ]
%12 = phi float [ 0xBFA99999A0000000, %4 ], [ %41, %39 ]
%13 = phi i32 [ %6, %4 ], [ %36, %39 ]
%14 = fmul float %12, 1.000000e+01
%15 = call float @llvm.fmuladd.f32(float %12, float 0xBFB99999A0000000, float 0x3FC3333340000000)
br label %16
16: ; preds = %10, %35
%17 = phi i64 [ 0, %10 ], [ %37, %35 ]
%18 = phi i32 [ %13, %10 ], [ %36, %35 ]
%19 = getelementptr inbounds [6 x i32], [6 x i32]* @__const.main.sample_rates, i64 0, i64 %17
%20 = load i32, i32* %19
%21 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %5, float %14, i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
%25 = call i32 @set_data_in(float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_in, i64 0, i64 0), i32 2048, double 3.141000e+00)
%26 = call i32 @write_vorbis_data_or_die(i8* %3, i32 %20, float %12, float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_out, i64 0, i64 0), i32 2048, i32 %5)
%27 = call i32 @read_vorbis_data_or_die(i8* %3, i32 %20, float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_in, i64 0, i64 0), i32 2048)
%28 = call i64 @check_output(float* getelementptr inbounds ([2048 x float], [2048 x float]* @main.data_in, i64 0, i64 0), i32 2048, float %15)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %16
%31 = add nsw i32 %18, 1
br label %35
32: ; preds = %16
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @remove(i8* %3)
br label %35
35: ; preds = %32, %30
%36 = phi i32 [ %31, %30 ], [ %18, %32 ]
%37 = add nuw nsw i64 %17, 1
%38 = icmp eq i64 %37, 6
br i1 %38, label %39, label %16
39: ; preds = %35
%40 = fadd double %11, 1.000000e-01
%41 = fptrunc double %40 to float
%42 = fpext float %41 to double
%43 = fcmp olt float %41, 1.000000e+00
br i1 %43, label %10, label %44
44: ; preds = %39
%45 = add nuw nsw i32 %5, 1
%46 = icmp eq i32 %45, 9
br i1 %46, label %47, label %4
47: ; preds = %44
%48 = icmp eq i32 %36, 0
br i1 %48, label %51, label %49
49: ; preds = %47
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %47
ret i32 0
}