#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 */
double cos(double);
double sin(double);
double sqrt(double);
double lpamp(double omega, double a0, double *coef, int M) {
  double wpr, wpi, wr, wi, re, im, temp, lp;
  int i;
  if (a0 == 0.)
    return (0.);
  wpr = cos(omega);
  wpi = sin(omega);
  re = wr = 1.;
  im = wi = 0.;
  for (coef++, i = 1; i <= M; i++, coef++) {
    wr = (temp = wr) * wpr - wi * wpi;
    wi = wi * wpr + temp * wpi;
    re += *coef * wr;
    im += *coef * wi;
  }
  if (re == 0. && im == 0.)
    lp = 0.;
  else
    lp = sqrt(a0 / (re * re + im * im));
  return (lp);
}


x86 assembly (clang, -O0):
<lpamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116e <lpamp+0x3e>
jp     116e <lpamp+0x3e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1301 <lpamp+0x1d1>
movsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe6c(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe5f(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     128b <lpamp+0x15b>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11c9 <lpamp+0x99>
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12c8 <lpamp+0x198>
jp     12c8 <lpamp+0x198>
movsd  -0x58(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12c8 <lpamp+0x198>
jp     12c8 <lpamp+0x198>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    12f7 <lpamp+0x1c7>
movsd  -0x18(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm3
movsd  -0x58(%rbp),%xmm2
mulsd  -0x58(%rbp),%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lpamp>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    114d <lpamp+0x1d>
jp     114d <lpamp+0x1d>
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
mov    %esi,%ebp
mov    %rdi,%rbx
movsd  %xmm1,(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1040 <cos@plt>
movapd %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
xorpd  %xmm1,%xmm1
test   %ebp,%ebp
jle    121e <lpamp+0xee>
unpcklpd %xmm0,%xmm0
movhpd 0xe71(%rip),%xmm1
movapd 0x10(%rsp),%xmm6
unpcklpd %xmm6,%xmm6
mov    %ebp,%eax
xor    %ecx,%ecx
movapd 0xe6b(%rip),%xmm2
movapd %xmm1,%xmm3
movapd %xmm1,%xmm5
nopl   (%rax)
movapd %xmm5,%xmm4
movapd %xmm3,%xmm1
xorpd  %xmm2,%xmm1
movapd %xmm3,%xmm5
shufpd $0x1,%xmm1,%xmm5
mulpd  %xmm0,%xmm5
mulpd  %xmm6,%xmm3
addpd  %xmm5,%xmm3
movsd  0x8(%rbx,%rcx,8),%xmm1
unpcklpd %xmm1,%xmm1
mulpd  %xmm3,%xmm1
movapd %xmm1,%xmm5
addpd  %xmm4,%xmm5
add    $0x1,%rcx
cmp    %ecx,%eax
jne    11b0 <lpamp+0x80>
addpd  %xmm4,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    1226 <lpamp+0xf6>
jp     1226 <lpamp+0xf6>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
movsd  (%rsp),%xmm2
jne    122b <lpamp+0xfb>
jnp    1146 <lpamp+0x16>
jmp    122b <lpamp+0xfb>
movhpd 0xdda(%rip),%xmm1
movsd  (%rsp),%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jb     1259 <lpamp+0x129>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    1146 <lpamp+0x16>
movapd %xmm2,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <sqrt@plt>

LLVM IR (-O0):
define double @lpamp(double %0, double %1, double* %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32
store double %0, double* %6
store double %1, double* %7
store double* %2, double** %8
store i32 %3, i32* %9
%19 = load double, double* %7
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %21, label %22
21: ; preds = %4
store double 0.000000e+00, double* %5
br label %81
22: ; preds = %4
%23 = load double, double* %6
%24 = call double @cos(double %23)
store double %24, double* %10
%25 = load double, double* %6
%26 = call double @sin(double %25)
store double %26, double* %11
store double 1.000000e+00, double* %12
store double 1.000000e+00, double* %14
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %15
%27 = load double*, double** %8
%28 = getelementptr inbounds double, double* %27, i32 1
store double* %28, double** %8
store i32 1, i32* %18
br label %29
29: ; preds = %57, %22
%30 = load i32, i32* %18
%31 = load i32, i32* %9
%32 = icmp sle i32 %30, %31
br i1 %32, label %33, label %62
33: ; preds = %29
%34 = load double, double* %12
store double %34, double* %16
%35 = load double, double* %10
%36 = load double, double* %13
%37 = load double, double* %11
%38 = fmul double %36, %37
%39 = fneg double %38
%40 = call double @llvm.fmuladd.f64(double %34, double %35, double %39)
store double %40, double* %12
%41 = load double, double* %13
%42 = load double, double* %10
%43 = load double, double* %16
%44 = load double, double* %11
%45 = fmul double %43, %44
%46 = call double @llvm.fmuladd.f64(double %41, double %42, double %45)
store double %46, double* %13
%47 = load double*, double** %8
%48 = load double, double* %47
%49 = load double, double* %12
%50 = load double, double* %14
%51 = call double @llvm.fmuladd.f64(double %48, double %49, double %50)
store double %51, double* %14
%52 = load double*, double** %8
%53 = load double, double* %52
%54 = load double, double* %13
%55 = load double, double* %15
%56 = call double @llvm.fmuladd.f64(double %53, double %54, double %55)
store double %56, double* %15
br label %57
57: ; preds = %33
%58 = load i32, i32* %18
%59 = add nsw i32 %58, 1
store i32 %59, i32* %18
%60 = load double*, double** %8
%61 = getelementptr inbounds double, double* %60, i32 1
store double* %61, double** %8
br label %29
62: ; preds = %29
%63 = load double, double* %14
%64 = fcmp oeq double %63, 0.000000e+00
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load double, double* %15
%67 = fcmp oeq double %66, 0.000000e+00
br i1 %67, label %68, label %69
68: ; preds = %65
store double 0.000000e+00, double* %17
br label %79
69: ; preds = %65, %62
%70 = load double, double* %7
%71 = load double, double* %14
%72 = load double, double* %14
%73 = load double, double* %15
%74 = load double, double* %15
%75 = fmul double %73, %74
%76 = call double @llvm.fmuladd.f64(double %71, double %72, double %75)
%77 = fdiv double %70, %76
%78 = call double @sqrt(double %77)
store double %78, double* %17
br label %79
79: ; preds = %69, %68
%80 = load double, double* %17
store double %80, double* %5
br label %81
81: ; preds = %79, %21
%82 = load double, double* %5
ret double %82
}

LLVM IR (-O2):
define double @lpamp(double %0, double %1, double* nocapture %2, i32 %3) {
%5 = fcmp oeq double %1, 0.000000e+00
br i1 %5, label %50, label %6
6: ; preds = %4
%7 = tail call double @cos(double %0)
%8 = tail call double @sin(double %0)
%9 = icmp slt i32 %3, 1
br i1 %9, label %42, label %10
10: ; preds = %6
%11 = insertelement <2 x double> poison, double %8, i64 0
%12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> zeroinitializer
%13 = insertelement <2 x double> poison, double %7, i64 0
%14 = shufflevector <2 x double> %13, <2 x double> poison, <2 x i32> zeroinitializer
br label %15
15: ; preds = %10, %15
%16 = phi double* [ %20, %15 ], [ %2, %10 ]
%17 = phi i32 [ %33, %15 ], [ 1, %10 ]
%18 = phi <2 x double> [ %27, %15 ], [ <double 0.000000e+00, double 1.000000e+00>, %10 ]
%19 = phi <2 x double> [ %32, %15 ], [ <double 0.000000e+00, double 1.000000e+00>, %10 ]
%20 = getelementptr inbounds double, double* %16, i64 1
%21 = extractelement <2 x double> %18, i64 0
%22 = fneg double %21
%23 = extractelement <2 x double> %18, i64 1
%24 = insertelement <2 x double> poison, double %23, i64 0
%25 = insertelement <2 x double> %24, double %22, i64 1
%26 = fmul <2 x double> %12, %25
%27 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %14, <2 x double> %26)
%28 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %14, <2 x double> %26)
%29 = load double, double* %20
%30 = insertelement <2 x double> poison, double %29, i64 0
%31 = shufflevector <2 x double> %30, <2 x double> poison, <2 x i32> zeroinitializer
%32 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %28, <2 x double> %19)
%33 = add nuw i32 %17, 1
%34 = icmp eq i32 %17, %3
br i1 %34, label %35, label %15
35: ; preds = %15
%36 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %28, <2 x double> %19)
%37 = extractelement <2 x double> %36, i64 1
%38 = fcmp oeq double %37, 0.000000e+00
%39 = extractelement <2 x double> %36, i64 0
%40 = fcmp oeq double %39, 0.000000e+00
%41 = select i1 %38, i1 %40, i1 false
br i1 %41, label %50, label %42
42: ; preds = %6, %35
%43 = phi <2 x double> [ %36, %35 ], [ <double 0.000000e+00, double 1.000000e+00>, %6 ]
%44 = fmul <2 x double> %43, %43
%45 = extractelement <2 x double> %44, i64 0
%46 = extractelement <2 x double> %43, i64 1
%47 = tail call double @llvm.fmuladd.f64(double %46, double %46, double %45)
%48 = fdiv double %1, %47
%49 = tail call double @sqrt(double %48)
br label %50
50: ; preds = %42, %35, %4
%51 = phi double [ 0.000000e+00, %4 ], [ %49, %42 ], [ 0.000000e+00, %35 ]
ret double %51
}