#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 */

/* Variables and functions */
float *calloc(int, int);
float crappy_snare(float *, int, int, double, float);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ write_mono_file(char const *, int, int, float *, int);
void generate_file(const char *filename, int format, int len) {
  float *output;
  float maxabs = 0.0;
  output = calloc(len, sizeof(float));
  maxabs = crappy_snare(output, len, 0, 0.95, maxabs);
  maxabs = crappy_snare(output, len, len / 4, 0.85, maxabs);
  maxabs = crappy_snare(output, len, 2 * len / 4, 0.85, maxabs);
  crappy_snare(output, len, 3 * len / 4, 0.85, maxabs);
  write_mono_file(filename, format, 44100, output, len);
  free(output);
}


x86 assembly (clang, -O0):
<generate_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
movss  -0x1c(%rbp),%xmm1
xor    %edx,%edx
movsd  0xe87(%rip),%xmm0
call   1060 <crappy_snare@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
movss  -0x1c(%rbp),%xmm1
movsd  0xe54(%rip),%xmm0
call   1060 <crappy_snare@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
movss  -0x1c(%rbp),%xmm1
movsd  0xe26(%rip),%xmm0
call   1060 <crappy_snare@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
imul   $0x3,-0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
movss  -0x1c(%rbp),%xmm1
movsd  0xdfa(%rip),%xmm0
call   1060 <crappy_snare@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8d
mov    $0xac44,%edx
call   1050 <write_mono_file@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
mov    %edx,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%rbp
movsd  0xe9a(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %rax,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1060 <crappy_snare@plt>
movaps %xmm0,%xmm1
lea    0x3(%rbx),%edx
test   %ebx,%ebx
cmovns %ebx,%edx
sar    $0x2,%edx
movsd  0xe7d(%rip),%xmm0
mov    %rbp,%rdi
mov    %ebx,%esi
call   1060 <crappy_snare@plt>
movaps %xmm0,%xmm1
mov    %ebx,%edx
shr    $0x1f,%edx
add    %ebx,%edx
sar    %edx
mov    %rbp,%rdi
mov    %ebx,%esi
movsd  0xe5a(%rip),%xmm0
call   1060 <crappy_snare@plt>
movaps %xmm0,%xmm1
lea    (%rbx,%rbx,2),%eax
lea    (%rbx,%rbx,2),%edx
add    $0x3,%edx
test   %eax,%eax
cmovns %eax,%edx
sar    $0x2,%edx
mov    %rbp,%rdi
mov    %ebx,%esi
movsd  0xe34(%rip),%xmm0
call   1060 <crappy_snare@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    $0xac44,%edx
mov    %rbp,%rcx
mov    %ebx,%r8d
call   1050 <write_mono_file@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @generate_file(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca float*
%8 = alloca float
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store float 0.000000e+00, float* %8
%9 = load i32, i32* %6
%10 = call float* @calloc(i32 %9, i32 4)
store float* %10, float** %7
%11 = load float*, float** %7
%12 = load i32, i32* %6
%13 = load float, float* %8
%14 = call float @crappy_snare(float* %11, i32 %12, i32 0, double 0x3FEE666666666666, float %13)
store float %14, float* %8
%15 = load float*, float** %7
%16 = load i32, i32* %6
%17 = load i32, i32* %6
%18 = sdiv i32 %17, 4
%19 = load float, float* %8
%20 = call float @crappy_snare(float* %15, i32 %16, i32 %18, double 8.500000e-01, float %19)
store float %20, float* %8
%21 = load float*, float** %7
%22 = load i32, i32* %6
%23 = load i32, i32* %6
%24 = mul nsw i32 2, %23
%25 = sdiv i32 %24, 4
%26 = load float, float* %8
%27 = call float @crappy_snare(float* %21, i32 %22, i32 %25, double 8.500000e-01, float %26)
store float %27, float* %8
%28 = load float*, float** %7
%29 = load i32, i32* %6
%30 = load i32, i32* %6
%31 = mul nsw i32 3, %30
%32 = sdiv i32 %31, 4
%33 = load float, float* %8
%34 = call float @crappy_snare(float* %28, i32 %29, i32 %32, double 8.500000e-01, float %33)
%35 = load i8*, i8** %4
%36 = load i32, i32* %5
%37 = load float*, float** %7
%38 = load i32, i32* %6
%39 = call i32 @write_mono_file(i8* %35, i32 %36, i32 44100, float* %37, i32 %38)
%40 = load float*, float** %7
%41 = call i32 @free(float* %40)
ret void
}

LLVM IR (-O2):
define void @generate_file(i8* %0, i32 %1, i32 %2) {
%4 = tail call float* @calloc(i32 %2, i32 4)
%5 = tail call float @crappy_snare(float* %4, i32 %2, i32 0, double 0x3FEE666666666666, float 0.000000e+00)
%6 = sdiv i32 %2, 4
%7 = tail call float @crappy_snare(float* %4, i32 %2, i32 %6, double 8.500000e-01, float %5)
%8 = sdiv i32 %2, 2
%9 = tail call float @crappy_snare(float* %4, i32 %2, i32 %8, double 8.500000e-01, float %7)
%10 = mul nsw i32 %2, 3
%11 = sdiv i32 %10, 4
%12 = tail call float @crappy_snare(float* %4, i32 %2, i32 %11, double 8.500000e-01, float %9)
%13 = tail call i32 @write_mono_file(i8* %0, i32 %1, i32 44100, float* %4, i32 %2)
%14 = tail call i32 @free(float* %4)
ret void
}