#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*/ arr_init_linspace(double *, double, double, size_t);
double arr_sum(double *, size_t);
size_t arr_util_getstep(double, double, double);
int /*<<< orphan*/ free(double *);
double *malloc(size_t);
int /*<<< orphan*/ printf(char *, size_t);
int /*<<< orphan*/ windowfunction(double *, double *, double *, size_t, size_t,
                                  double, double *, int);
double windowsum(double f0, double low, double high, double rate, double time[],
                 double weight[], size_t N, int useweight, int quiet) {
  double result = 0;
  size_t M = arr_util_getstep(low, high, rate);
  if (quiet == 0)
    printf(" -- INFO: Number of frequencies in the window = %li\n", M);
  double *freq = malloc(M * sizeof(double));
  double *window = malloc(M * sizeof(double));
  arr_init_linspace(freq, low, rate, M);
  windowfunction(time, freq, weight, N, M, f0, window, useweight);
  result = arr_sum(window, M);
  free(freq);
  free(window);
  return result;
}


x86 assembly (clang, -O0):
<windowsum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %ecx,-0x3c(%rbp)
mov    %r8d,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1050 <arr_util_getstep@plt>
mov    %rax,-0x50(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    11d9 <windowsum+0x69>
mov    -0x50(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1060 <printf@plt>
mov    -0x50(%rbp),%rdi
shl    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
shl    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x50(%rbp),%rsi
call   1090 <arr_init_linspace@plt>
mov    -0x28(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x50(%rbp),%r8
movsd  -0x8(%rbp),%xmm0
mov    -0x60(%rbp),%r9
mov    -0x3c(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <windowfunction@plt>
mov    -0x60(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1080 <arr_sum@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <free@plt>
mov    -0x60(%rbp),%rdi
call   1040 <free@plt>
movsd  -0x48(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<windowsum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%ebp
mov    %ecx,%r12d
mov    %rdx,0x10(%rsp)
mov    %rsi,0x30(%rsp)
mov    %rdi,%r13
movsd  %xmm0,0x28(%rsp)
movsd  %xmm1,0x18(%rsp)
movaps %xmm1,%xmm0
movaps %xmm2,%xmm1
movsd  %xmm3,0x20(%rsp)
movaps %xmm3,%xmm2
call   1050 <arr_util_getstep@plt>
mov    %rax,%r15
test   %ebp,%ebp
jne    11c7 <windowsum+0x57>
lea    0xe41(%rip),%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
mov    %r15,%rbx
shl    $0x3,%rbx
mov    %rbx,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rbp,%rdi
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    %r15,%rsi
call   1090 <arr_init_linspace@plt>
mov    %r12d,(%rsp)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    0x30(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    %r15,%r8
movsd  0x28(%rsp),%xmm0
mov    %r14,%r9
call   1030 <windowfunction@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <arr_sum@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
movsd  0x10(%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c" -- INFO: Number of frequencies in the window = %li\0A\00"
define double @windowsum(double %0, double %1, double %2, double %3, double* %4, double* %5, i64 %6, i32 %7, i32 %8) {
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double*
%15 = alloca double*
%16 = alloca i64
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
%20 = alloca i64
%21 = alloca double*
%22 = alloca double*
store double %0, double* %10
store double %1, double* %11
store double %2, double* %12
store double %3, double* %13
store double* %4, double** %14
store double* %5, double** %15
store i64 %6, i64* %16
store i32 %7, i32* %17
store i32 %8, i32* %18
store double 0.000000e+00, double* %19
%23 = load double, double* %11
%24 = load double, double* %12
%25 = load double, double* %13
%26 = call i64 @arr_util_getstep(double %23, double %24, double %25)
store i64 %26, i64* %20
%27 = load i32, i32* %18
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %9
%30 = load i64, i64* %20
%31 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i64 %30)
br label %32
32: ; preds = %29, %9
%33 = load i64, i64* %20
%34 = mul i64 %33, 8
%35 = call double* @malloc(i64 %34)
store double* %35, double** %21
%36 = load i64, i64* %20
%37 = mul i64 %36, 8
%38 = call double* @malloc(i64 %37)
store double* %38, double** %22
%39 = load double*, double** %21
%40 = load double, double* %11
%41 = load double, double* %13
%42 = load i64, i64* %20
%43 = call i32 @arr_init_linspace(double* %39, double %40, double %41, i64 %42)
%44 = load double*, double** %14
%45 = load double*, double** %21
%46 = load double*, double** %15
%47 = load i64, i64* %16
%48 = load i64, i64* %20
%49 = load double, double* %10
%50 = load double*, double** %22
%51 = load i32, i32* %17
%52 = call i32 @windowfunction(double* %44, double* %45, double* %46, i64 %47, i64 %48, double %49, double* %50, i32 %51)
%53 = load double*, double** %22
%54 = load i64, i64* %20
%55 = call double @arr_sum(double* %53, i64 %54)
store double %55, double* %19
%56 = load double*, double** %21
%57 = call i32 @free(double* %56)
%58 = load double*, double** %22
%59 = call i32 @free(double* %58)
%60 = load double, double* %19
ret double %60
}

LLVM IR (-O2):
@.str = [53 x i8] c" -- INFO: Number of frequencies in the window = %li\0A\00"
define double @windowsum(double %0, double %1, double %2, double %3, double* %4, double* %5, i64 %6, i32 %7, i32 %8) {
%10 = tail call i64 @arr_util_getstep(double %1, double %2, double %3)
%11 = icmp eq i32 %8, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %14
14: ; preds = %12, %9
%15 = shl i64 %10, 3
%16 = tail call double* @malloc(i64 %15)
%17 = tail call double* @malloc(i64 %15)
%18 = tail call i32 @arr_init_linspace(double* %16, double %1, double %3, i64 %10)
%19 = tail call i32 @windowfunction(double* %4, double* %16, double* %5, i64 %6, i64 %10, double %0, double* %17, i32 %7)
%20 = tail call double @arr_sum(double* %17, i64 %10)
%21 = tail call i32 @free(double* %16)
%22 = tail call i32 @free(double* %17)
ret double %20
}