#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 pow(double, int);
double paraCryst_an(double ww, double qval, double davg, int Nlayers) {
  double an;
  an = 4.0 * ww * ww - 2.0 * (ww * ww * ww + ww) * cos(qval * davg);
  an -= 4.0 * pow(ww, (Nlayers + 2)) * cos((double)Nlayers * qval * davg);
  an += 2.0 * pow(ww, (Nlayers + 3)) * cos((double)(Nlayers - 1) * qval * davg);
  an += 2.0 * pow(ww, (Nlayers + 1)) * cos((double)(Nlayers + 1) * qval * davg);
  return an;
}


x86 assembly (clang, -O0):
<paraCryst_an>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  0xec6(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe86(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1030 <cos@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
add    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe21(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
add    $0x3,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xdb0(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xd59(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paraCryst_an>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
movsd  %xmm2,0x28(%rsp)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x18(%rsp)
movsd  0xebf(%rip),%xmm3
mulsd  %xmm0,%xmm3
movsd  %xmm3,0x8(%rsp)
movapd %xmm0,%xmm3
mulsd  %xmm0,%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm0,%xmm3
movsd  %xmm3,0x10(%rsp)
movapd %xmm1,%xmm0
mulsd  %xmm2,%xmm0
call   1030 <cos@plt>
movapd %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  0xe88(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0x2(%rbx),%edi
call   1040 <pow@plt>
movsd  %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x20(%rsp),%xmm0
mulsd  0x28(%rsp),%xmm0
call   1030 <cos@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0xe3e(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x3(%rbx),%edi
movsd  0x18(%rsp),%xmm0
call   1040 <pow@plt>
addsd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    -0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x20(%rsp),%xmm0
mulsd  0x28(%rsp),%xmm0
call   1030 <cos@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebx
movsd  0x18(%rsp),%xmm0
mov    %ebx,%edi
call   1040 <pow@plt>
addsd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x20(%rsp),%xmm0
mulsd  0x28(%rsp),%xmm0
call   1030 <cos@plt>
mulsd  0x18(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @paraCryst_an(double %0, double %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
%10 = load double, double* %5
%11 = fmul double 4.000000e+00, %10
%12 = load double, double* %5
%13 = load double, double* %5
%14 = load double, double* %5
%15 = fmul double %13, %14
%16 = load double, double* %5
%17 = load double, double* %5
%18 = call double @llvm.fmuladd.f64(double %15, double %16, double %17)
%19 = fmul double 2.000000e+00, %18
%20 = load double, double* %6
%21 = load double, double* %7
%22 = fmul double %20, %21
%23 = call double @cos(double %22)
%24 = fmul double %19, %23
%25 = fneg double %24
%26 = call double @llvm.fmuladd.f64(double %11, double %12, double %25)
store double %26, double* %9
%27 = load double, double* %5
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 2
%30 = call double @pow(double %27, i32 %29)
%31 = fmul double 4.000000e+00, %30
%32 = load i32, i32* %8
%33 = sitofp i32 %32 to double
%34 = load double, double* %6
%35 = fmul double %33, %34
%36 = load double, double* %7
%37 = fmul double %35, %36
%38 = call double @cos(double %37)
%39 = load double, double* %9
%40 = fneg double %31
%41 = call double @llvm.fmuladd.f64(double %40, double %38, double %39)
store double %41, double* %9
%42 = load double, double* %5
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 3
%45 = call double @pow(double %42, i32 %44)
%46 = fmul double 2.000000e+00, %45
%47 = load i32, i32* %8
%48 = sub nsw i32 %47, 1
%49 = sitofp i32 %48 to double
%50 = load double, double* %6
%51 = fmul double %49, %50
%52 = load double, double* %7
%53 = fmul double %51, %52
%54 = call double @cos(double %53)
%55 = load double, double* %9
%56 = call double @llvm.fmuladd.f64(double %46, double %54, double %55)
store double %56, double* %9
%57 = load double, double* %5
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
%60 = call double @pow(double %57, i32 %59)
%61 = fmul double 2.000000e+00, %60
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
%64 = sitofp i32 %63 to double
%65 = load double, double* %6
%66 = fmul double %64, %65
%67 = load double, double* %7
%68 = fmul double %66, %67
%69 = call double @cos(double %68)
%70 = load double, double* %9
%71 = call double @llvm.fmuladd.f64(double %61, double %69, double %70)
store double %71, double* %9
%72 = load double, double* %9
ret double %72
}

LLVM IR (-O2):
define double @paraCryst_an(double %0, double %1, double %2, i32 %3) {
%5 = fmul double %0, 4.000000e+00
%6 = fmul double %0, %0
%7 = tail call double @llvm.fmuladd.f64(double %6, double %0, double %0)
%8 = fmul double %1, %2
%9 = tail call double @cos(double %8)
%10 = fmul double %7, -2.000000e+00
%11 = fmul double %10, %9
%12 = tail call double @llvm.fmuladd.f64(double %5, double %0, double %11)
%13 = add nsw i32 %3, 2
%14 = tail call double @pow(double %0, i32 %13)
%15 = sitofp i32 %3 to double
%16 = fmul double %15, %1
%17 = fmul double %16, %2
%18 = tail call double @cos(double %17)
%19 = fmul double %14, -4.000000e+00
%20 = tail call double @llvm.fmuladd.f64(double %19, double %18, double %12)
%21 = add nsw i32 %3, 3
%22 = tail call double @pow(double %0, i32 %21)
%23 = fmul double %22, 2.000000e+00
%24 = add nsw i32 %3, -1
%25 = sitofp i32 %24 to double
%26 = fmul double %25, %1
%27 = fmul double %26, %2
%28 = tail call double @cos(double %27)
%29 = tail call double @llvm.fmuladd.f64(double %23, double %28, double %20)
%30 = add nsw i32 %3, 1
%31 = tail call double @pow(double %0, i32 %30)
%32 = fmul double %31, 2.000000e+00
%33 = sitofp i32 %30 to double
%34 = fmul double %33, %1
%35 = fmul double %34, %2
%36 = tail call double @cos(double %35)
%37 = tail call double @llvm.fmuladd.f64(double %32, double %36, double %29)
ret double %37
}