#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
double *malloc(int);
int /*<<< orphan*/ printf(char *);
int sin(int);
double *createLowPassFilter(int length, double sampleRate, double cutoffFreq) {
  double *filter = malloc(length);
  if (filter == NULL) {
    printf("Memory allocation failed. Fatal Error.");
    exit(EXIT_FAILURE);
  }
  int mid = (length - 1) / 2;
  double lam = cutoffFreq * 3.1415926535897931 / sampleRate;
  int i;
  for (i = 0; i < mid; i++) {
    filter[i] = sin((i - mid) * lam) / ((i - mid) * 3.1415926535897931);
    filter[length - 1 - i] = filter[i];
  }
  return filter;
}


x86 assembly (clang, -O0):
<createLowPassFilter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <createLowPassFilter+0x46>
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
movsd  0xe61(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1234 <createLowPassFilter+0xf4>
mov    -0x34(%rbp),%eax
sub    -0x24(%rbp),%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sin@plt>
cvtsi2sd %eax,%xmm0
mov    -0x34(%rbp),%eax
sub    -0x24(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe11(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b5 <createLowPassFilter+0x75>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createLowPassFilter>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %edi,%r14d
call   1050 <malloc@plt>
test   %rax,%rax
je     1226 <createLowPassFilter+0xe6>
mov    %rax,%r15
cmp    $0x3,%r14d
movsd  (%rsp),%xmm0
jl     1215 <createLowPassFilter+0xd5>
mov    %r14d,%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
shr    $0x1f,%eax
add    %eax,%r14d
add    $0xffffffff,%r14d
sar    %r14d
mulsd  0xe68(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rsp)
cmp    $0x2,%r14d
mov    $0x1,%r12d
cmovge %r14d,%r12d
neg    %r14d
lea    (%r15,%rcx,8),%r13
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    (%r14,%rbx,1),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0xe08(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r15,%rbx,8)
movsd  %xmm0,0x0(%r13)
add    $0x1,%rbx
add    $0xfffffffffffffff8,%r13
cmp    %rbx,%r12
jne    11c0 <createLowPassFilter+0x80>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xddb(%rip),%rdi
call   1030 <printf@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"Memory allocation failed. Fatal Error.\00"
@EXIT_FAILURE = global i32 0
define double* @createLowPassFilter(i32 %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store i32 %0, i32* %4
store double %1, double* %5
store double %2, double* %6
%11 = load i32, i32* %4
%12 = call double* @malloc(i32 %11)
store double* %12, double** %7
%13 = load double*, double** %7
%14 = icmp eq double* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %3
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
%22 = sdiv i32 %21, 2
store i32 %22, i32* %8
%23 = load double, double* %6
%24 = fmul double %23, 0x400921FB54442D18
%25 = load double, double* %5
%26 = fdiv double %24, %25
store double %26, double* %9
store i32 0, i32* %10
br label %27
27: ; preds = %63, %19
%28 = load i32, i32* %10
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %66
31: ; preds = %27
%32 = load i32, i32* %10
%33 = load i32, i32* %8
%34 = sub nsw i32 %32, %33
%35 = sitofp i32 %34 to double
%36 = load double, double* %9
%37 = fmul double %35, %36
%38 = fptosi double %37 to i32
%39 = call i32 @sin(i32 %38)
%40 = sitofp i32 %39 to double
%41 = load i32, i32* %10
%42 = load i32, i32* %8
%43 = sub nsw i32 %41, %42
%44 = sitofp i32 %43 to double
%45 = fmul double %44, 0x400921FB54442D18
%46 = fdiv double %40, %45
%47 = load double*, double** %7
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
store double %46, double* %50
%51 = load double*, double** %7
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
%55 = load double, double* %54
%56 = load double*, double** %7
%57 = load i32, i32* %4
%58 = sub nsw i32 %57, 1
%59 = load i32, i32* %10
%60 = sub nsw i32 %58, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %56, i64 %61
store double %55, double* %62
br label %63
63: ; preds = %31
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %27
66: ; preds = %27
%67 = load double*, double** %7
ret double* %67
}

LLVM IR (-O2):
@.str = [39 x i8] c"Memory allocation failed. Fatal Error.\00"
@EXIT_FAILURE = global i32 0
define noalias double* @createLowPassFilter(i32 %0, double %1, double %2) {
%4 = tail call double* @malloc(i32 %0)
%5 = icmp eq double* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %3
%11 = add nsw i32 %0, -1
%12 = sdiv i32 %11, 2
%13 = fmul double %2, 0x400921FB54442D18
%14 = fdiv double %13, %1
%15 = icmp sgt i32 %0, 2
br i1 %15, label %16, label %36
16: ; preds = %10
%17 = zext i32 %11 to i64
%18 = call i32 @llvm.smax.i32(i32 %12, i32 1)
%19 = zext i32 %18 to i64
br label %20
20: ; preds = %16, %20
%21 = phi i64 [ 0, %16 ], [ %34, %20 ]
%22 = trunc i64 %21 to i32
%23 = sub i32 %22, %12
%24 = sitofp i32 %23 to double
%25 = fmul double %14, %24
%26 = fptosi double %25 to i32
%27 = tail call i32 @sin(i32 %26)
%28 = sitofp i32 %27 to double
%29 = fmul double %24, 0x400921FB54442D18
%30 = fdiv double %28, %29
%31 = getelementptr inbounds double, double* %4, i64 %21
store double %30, double* %31
%32 = sub nsw i64 %17, %21
%33 = getelementptr inbounds double, double* %4, i64 %32
store double %30, double* %33
%34 = add nuw nsw i64 %21, 1
%35 = icmp eq i64 %34, %19
br i1 %35, label %36, label %20
36: ; preds = %20, %10
ret double* %4
}