#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*/ alpbet(double *, double *, size_t, double, double *,
                          double *);
int /*<<< orphan*/ alpbetW(double *, double *, double *, size_t, double, double,
                           double *, double *);
double arr_sum(double *, size_t);
void fourier(double time[], double flux[], double weight[], double freq[],
             size_t N, size_t M, double power[], double alpha[], double beta[],
             int useweight) {
  double alp = 0;
  double bet = 0;
  double ny = 0;
  size_t i;
  if (useweight == 0) {
#pragma omp parallel default(shared) private(alp, bet, ny)
    {
#pragma omp for schedule(static)
      for (i = 0; i < M; ++i) {
        ny = freq[i] * 6.28318530717958647692528676655900576839433879875e-6;
        alpbet(time, flux, N, ny, &alp, &bet);
        alpha[i] = alp;
        beta[i] = bet;
        power[i] = alp * alp + bet * bet;
      }
    }
  } else {
    double sumweights = arr_sum(weight, N);
#pragma omp parallel default(shared) private(alp, bet, ny)
    {
#pragma omp for schedule(static)
      for (i = 0; i < M; ++i) {
        ny = freq[i] * 6.28318530717958647692528676655900576839433879875e-6;
        alpbetW(time, flux, weight, N, ny, sumweights, &alp, &bet);
        alpha[i] = alp;
        beta[i] = bet;
        power[i] = alp * alp + bet * bet;
      }
    }
  }
}


x86 assembly (clang, -O0):
<fourier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x0,0x28(%rbp)
jne    1232 <fourier+0x102>
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    122d <fourier+0xfd>
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  0xe59(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
movsd  -0x48(%rbp),%xmm0
lea    -0x38(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1040 <alpbet@plt>
movsd  -0x38(%rbp),%xmm0
mov    0x18(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    0x10(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1189 <fourier+0x59>
jmp    12fe <fourier+0x1ce>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <arr_sum@plt>
movsd  %xmm0,-0x58(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    12f9 <fourier+0x1c9>
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  0xd96(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
movsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
lea    -0x38(%rbp),%r8
lea    -0x40(%rbp),%r9
call   1030 <alpbetW@plt>
movsd  -0x38(%rbp),%xmm0
mov    0x18(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    0x10(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    124c <fourier+0x11c>
jmp    12fe <fourier+0x1ce>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fourier>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbx
mov    %rsi,%r14
mov    0x70(%rsp),%r13
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
cmpl   $0x0,0x78(%rsp)
je     1206 <fourier+0xd6>
mov    %rdx,%r12
mov    %rdi,0x20(%rsp)
mov    %rdx,%rdi
mov    %r8,%rsi
mov    %rcx,%rbp
mov    %r8,%r13
call   1050 <arr_sum@plt>
test   %rbx,%rbx
je     1289 <fourier+0x159>
xor    %r15d,%r15d
movsd  %xmm0,0x18(%rsp)
movsd  0x0(%rbp,%r15,8),%xmm0
mulsd  0xe61(%rip),%xmm0
mov    0x20(%rsp),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
movsd  0x18(%rsp),%xmm1
lea    0x8(%rsp),%r8
mov    %rsp,%r9
call   1030 <alpbetW@plt>
movsd  0x8(%rsp),%xmm2
mov    0x68(%rsp),%rax
movsd  %xmm2,(%rax,%r15,8)
movsd  (%rsp),%xmm1
mov    0x70(%rsp),%rax
movsd  %xmm1,(%rax,%r15,8)
mulsd  %xmm1,%xmm1
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
mov    0x60(%rsp),%rax
movsd  %xmm2,(%rax,%r15,8)
add    $0x1,%r15
cmp    %r15,%rbx
jne    1190 <fourier+0x60>
jmp    1289 <fourier+0x159>
test   %rbx,%rbx
je     1289 <fourier+0x159>
mov    %r8,%r12
mov    %rdi,%r15
xor    %ebp,%ebp
mov    %r14,0x10(%rsp)
nopl   0x0(%rax)
movsd  (%rcx,%rbp,8),%xmm0
mulsd  0xdd3(%rip),%xmm0
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %rcx,%r14
lea    0x8(%rsp),%rcx
mov    %rsp,%r8
call   1040 <alpbet@plt>
mov    0x60(%rsp),%rsi
mov    0x68(%rsp),%rdx
mov    %r14,%rcx
mov    0x10(%rsp),%r14
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rdx,%rbp,8)
movsd  (%rsp),%xmm1
movsd  %xmm1,0x0(%r13,%rbp,8)
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsi,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1220 <fourier+0xf0>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fourier(double* %0, double* %1, double* %2, double* %3, i64 %4, i64 %5, double* %6, double* %7, double* %8, i32 %9) {
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i64
%16 = alloca i64
%17 = alloca double*
%18 = alloca double*
%19 = alloca double*
%20 = alloca i32
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca i64
%25 = alloca double
store double* %0, double** %11
store double* %1, double** %12
store double* %2, double** %13
store double* %3, double** %14
store i64 %4, i64* %15
store i64 %5, i64* %16
store double* %6, double** %17
store double* %7, double** %18
store double* %8, double** %19
store i32 %9, i32* %20
store double 0.000000e+00, double* %21
store double 0.000000e+00, double* %22
store double 0.000000e+00, double* %23
%26 = load i32, i32* %20
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %65
28: ; preds = %10
store i64 0, i64* %24
br label %29
29: ; preds = %61, %28
%30 = load i64, i64* %24
%31 = load i64, i64* %16
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %64
33: ; preds = %29
%34 = load double*, double** %14
%35 = load i64, i64* %24
%36 = getelementptr inbounds double, double* %34, i64 %35
%37 = load double, double* %36
%38 = fmul double %37, 0x3EDA5A84D380747E
store double %38, double* %23
%39 = load double*, double** %11
%40 = load double*, double** %12
%41 = load i64, i64* %15
%42 = load double, double* %23
%43 = call i32 @alpbet(double* %39, double* %40, i64 %41, double %42, double* %21, double* %22)
%44 = load double, double* %21
%45 = load double*, double** %18
%46 = load i64, i64* %24
%47 = getelementptr inbounds double, double* %45, i64 %46
store double %44, double* %47
%48 = load double, double* %22
%49 = load double*, double** %19
%50 = load i64, i64* %24
%51 = getelementptr inbounds double, double* %49, i64 %50
store double %48, double* %51
%52 = load double, double* %21
%53 = load double, double* %21
%54 = load double, double* %22
%55 = load double, double* %22
%56 = fmul double %54, %55
%57 = call double @llvm.fmuladd.f64(double %52, double %53, double %56)
%58 = load double*, double** %17
%59 = load i64, i64* %24
%60 = getelementptr inbounds double, double* %58, i64 %59
store double %57, double* %60
br label %61
61: ; preds = %33
%62 = load i64, i64* %24
%63 = add i64 %62, 1
store i64 %63, i64* %24
br label %29
64: ; preds = %29
br label %107
65: ; preds = %10
%66 = load double*, double** %13
%67 = load i64, i64* %15
%68 = call double @arr_sum(double* %66, i64 %67)
store double %68, double* %25
store i64 0, i64* %24
br label %69
69: ; preds = %103, %65
%70 = load i64, i64* %24
%71 = load i64, i64* %16
%72 = icmp ult i64 %70, %71
br i1 %72, label %73, label %106
73: ; preds = %69
%74 = load double*, double** %14
%75 = load i64, i64* %24
%76 = getelementptr inbounds double, double* %74, i64 %75
%77 = load double, double* %76
%78 = fmul double %77, 0x3EDA5A84D380747E
store double %78, double* %23
%79 = load double*, double** %11
%80 = load double*, double** %12
%81 = load double*, double** %13
%82 = load i64, i64* %15
%83 = load double, double* %23
%84 = load double, double* %25
%85 = call i32 @alpbetW(double* %79, double* %80, double* %81, i64 %82, double %83, double %84, double* %21, double* %22)
%86 = load double, double* %21
%87 = load double*, double** %18
%88 = load i64, i64* %24
%89 = getelementptr inbounds double, double* %87, i64 %88
store double %86, double* %89
%90 = load double, double* %22
%91 = load double*, double** %19
%92 = load i64, i64* %24
%93 = getelementptr inbounds double, double* %91, i64 %92
store double %90, double* %93
%94 = load double, double* %21
%95 = load double, double* %21
%96 = load double, double* %22
%97 = load double, double* %22
%98 = fmul double %96, %97
%99 = call double @llvm.fmuladd.f64(double %94, double %95, double %98)
%100 = load double*, double** %17
%101 = load i64, i64* %24
%102 = getelementptr inbounds double, double* %100, i64 %101
store double %99, double* %102
br label %103
103: ; preds = %73
%104 = load i64, i64* %24
%105 = add i64 %104, 1
store i64 %105, i64* %24
br label %69
106: ; preds = %69
br label %107
107: ; preds = %106, %64
ret void
}

LLVM IR (-O2):
define void @fourier(double* %0, double* %1, double* %2, double* nocapture %3, i64 %4, i64 %5, double* nocapture writeonly %6, double* nocapture writeonly %7, double* nocapture writeonly %8, i32 %9) {
%11 = alloca double
%12 = alloca double
%13 = bitcast double* %11 to i8*
store double 0.000000e+00, double* %11
%14 = bitcast double* %12 to i8*
store double 0.000000e+00, double* %12
%15 = icmp eq i32 %9, 0
br i1 %15, label %16, label %33
16: ; preds = %10
%17 = icmp eq i64 %5, 0
br i1 %17, label %51, label %18
18: ; preds = %16, %18
%19 = phi i64 [ %31, %18 ], [ 0, %16 ]
%20 = getelementptr inbounds double, double* %3, i64 %19
%21 = load double, double* %20
%22 = fmul double %21, 0x3EDA5A84D380747E
%23 = call i32 @alpbet(double* %0, double* %1, i64 %4, double %22, double* %11, double* %12)
%24 = load double, double* %11
%25 = getelementptr inbounds double, double* %7, i64 %19
store double %24, double* %25
%26 = load double, double* %12
%27 = getelementptr inbounds double, double* %8, i64 %19
store double %26, double* %27
%28 = fmul double %26, %26
%29 = call double @llvm.fmuladd.f64(double %24, double %24, double %28)
%30 = getelementptr inbounds double, double* %6, i64 %19
store double %29, double* %30
%31 = add nuw i64 %19, 1
%32 = icmp eq i64 %31, %5
br i1 %32, label %51, label %18
33: ; preds = %10
%34 = tail call double @arr_sum(double* %2, i64 %4)
%35 = icmp eq i64 %5, 0
br i1 %35, label %51, label %36
36: ; preds = %33, %36
%37 = phi i64 [ %49, %36 ], [ 0, %33 ]
%38 = getelementptr inbounds double, double* %3, i64 %37
%39 = load double, double* %38
%40 = fmul double %39, 0x3EDA5A84D380747E
%41 = call i32 @alpbetW(double* %0, double* %1, double* %2, i64 %4, double %40, double %34, double* %11, double* %12)
%42 = load double, double* %11
%43 = getelementptr inbounds double, double* %7, i64 %37
store double %42, double* %43
%44 = load double, double* %12
%45 = getelementptr inbounds double, double* %8, i64 %37
store double %44, double* %45
%46 = fmul double %44, %44
%47 = call double @llvm.fmuladd.f64(double %42, double %42, double %46)
%48 = getelementptr inbounds double, double* %6, i64 %37
store double %47, double* %48
%49 = add nuw i64 %37, 1
%50 = icmp eq i64 %49, %5
br i1 %50, label %51, label %36
51: ; preds = %36, %18, %33, %16
ret void
}