#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 const M_PI;
double const acos(int);
double const cos(double);
double fabs(double const);
int sqrt(int);
double CalculateSum12NNNDiag(const double d12, const double d34,
                             const double eta) {
  const double t = eta * (cos(6.283185307179586476925 * d12) +
                          cos(6.283185307179586476925 * d34));
  if (fabs(t) < 0.01) {
    const double tsq = t * t;
    return 0.5 + t *
                     (-2.0 + 44.0 * tsq / 3.0 - 1132.0 * tsq * tsq / 5.0 +
                      31096.0 * tsq * tsq * tsq / 7.0) /
                     M_PI;
  } else {
    return acos((sqrt(1 + 32 * t * t) - 1) / (8 * t)) / M_PI;
  }
}


x86 assembly (clang, -O0):
<CalculateSum12NNNDiag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xeaf(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  0xe98(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movaps 0xed0(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe54(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    125d <CalculateSum12NNNDiag+0x12d>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xe8e(%rip),%xmm2
mulsd  -0x30(%rbp),%xmm2
movsd  0xe79(%rip),%xmm0
divsd  %xmm0,%xmm2
movsd  0xe65(%rip),%xmm0
addsd  %xmm2,%xmm0
movsd  0xe51(%rip),%xmm2
mulsd  -0x30(%rbp),%xmm2
mulsd  -0x30(%rbp),%xmm2
movsd  0xe37(%rip),%xmm3
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm0
movsd  0xe1f(%rip),%xmm2
mulsd  -0x30(%rbp),%xmm2
mulsd  -0x30(%rbp),%xmm2
mulsd  -0x30(%rbp),%xmm2
movsd  0xe00(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm1
mov    0x2da5(%rip),%rax
divsd  (%rax),%xmm1
movsd  0xdd9(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b9 <CalculateSum12NNNDiag+0x189>
movsd  0xdbb(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd9d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xd79(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <acos@plt>
mov    0x2d38(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateSum12NNNDiag>:
sub    $0x28,%rsp
movsd  %xmm2,(%rsp)
movsd  %xmm1,0x20(%rsp)
mulsd  0xeb9(%rip),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp),%xmm0
mulsd  0xea0(%rip),%xmm0
call   1040 <cos@plt>
movapd %xmm0,%xmm4
addsd  0x18(%rsp),%xmm4
mulsd  (%rsp),%xmm4
movapd 0xed4(%rip),%xmm0
andpd  %xmm4,%xmm0
movsd  0xe80(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1203 <CalculateSum12NNNDiag+0xd3>
movapd %xmm4,%xmm1
mulsd  %xmm4,%xmm1
movsd  0xe8a(%rip),%xmm2
mulsd  %xmm1,%xmm2
divsd  0xe86(%rip),%xmm2
addsd  0xe86(%rip),%xmm2
movsd  0xe86(%rip),%xmm3
mulsd  %xmm1,%xmm3
unpcklpd %xmm1,%xmm1
movapd 0xe96(%rip),%xmm0
unpcklpd %xmm3,%xmm0
mulpd  %xmm1,%xmm0
mulpd  %xmm1,%xmm0
divpd  0xe92(%rip),%xmm0
subsd  %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm4,%xmm0
xorpd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
addsd  0xe4a(%rip),%xmm0
add    $0x28,%rsp
ret
movsd  0xe05(%rip),%xmm0
mulsd  %xmm4,%xmm0
mulsd  %xmm4,%xmm0
addsd  0xdfd(%rip),%xmm0
cvttsd2si %xmm0,%edi
movapd %xmm4,(%rsp)
call   1050 <sqrt@plt>
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd (%rsp),%xmm1
mulsd  0xde0(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <acos@plt>
xorpd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@M_PI = constant double 0.000000e+00
define double @CalculateSum12NNNDiag(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%10 = load double, double* %7
%11 = load double, double* %5
%12 = fmul double 0x401921FB54442D18, %11
%13 = call double @cos(double %12)
%14 = load double, double* %6
%15 = fmul double 0x401921FB54442D18, %14
%16 = call double @cos(double %15)
%17 = fadd double %13, %16
%18 = fmul double %10, %17
store double %18, double* %8
%19 = load double, double* %8
%20 = call double @llvm.fabs.f64(double %19)
%21 = fcmp olt double %20, 1.000000e-02
br i1 %21, label %22, label %49
22: ; preds = %3
%23 = load double, double* %8
%24 = load double, double* %8
%25 = fmul double %23, %24
store double %25, double* %9
%26 = load double, double* %8
%27 = load double, double* %9
%28 = fmul double 4.400000e+01, %27
%29 = fdiv double %28, 3.000000e+00
%30 = fadd double -2.000000e+00, %29
%31 = load double, double* %9
%32 = fmul double 1.132000e+03, %31
%33 = load double, double* %9
%34 = fmul double %32, %33
%35 = fdiv double %34, 5.000000e+00
%36 = fsub double %30, %35
%37 = load double, double* %9
%38 = fmul double 3.109600e+04, %37
%39 = load double, double* %9
%40 = fmul double %38, %39
%41 = load double, double* %9
%42 = fmul double %40, %41
%43 = fdiv double %42, 7.000000e+00
%44 = fadd double %36, %43
%45 = fmul double %26, %44
%46 = load double, double* @M_PI
%47 = fdiv double %45, %46
%48 = fadd double 5.000000e-01, %47
store double %48, double* %4
br label %65
49: ; preds = %3
%50 = load double, double* %8
%51 = fmul double 3.200000e+01, %50
%52 = load double, double* %8
%53 = call double @llvm.fmuladd.f64(double %51, double %52, double 1.000000e+00)
%54 = fptosi double %53 to i32
%55 = call i32 @sqrt(i32 %54)
%56 = sub nsw i32 %55, 1
%57 = sitofp i32 %56 to double
%58 = load double, double* %8
%59 = fmul double 8.000000e+00, %58
%60 = fdiv double %57, %59
%61 = fptosi double %60 to i32
%62 = call double @acos(i32 %61)
%63 = load double, double* @M_PI
%64 = fdiv double %62, %63
store double %64, double* %4
br label %65
65: ; preds = %49, %22
%66 = load double, double* %4
ret double %66
}

LLVM IR (-O2):
@M_PI = constant double 0.000000e+00
define double @CalculateSum12NNNDiag(double %0, double %1, double %2) {
%4 = fmul double %0, 0x401921FB54442D18
%5 = tail call double @cos(double %4)
%6 = fmul double %1, 0x401921FB54442D18
%7 = tail call double @cos(double %6)
%8 = fadd double %5, %7
%9 = fmul double %8, %2
%10 = tail call double @llvm.fabs.f64(double %9)
%11 = fcmp olt double %10, 1.000000e-02
br i1 %11, label %12, label %31
12: ; preds = %3
%13 = fmul double %9, %9
%14 = fmul double %13, 4.400000e+01
%15 = fdiv double %14, 3.000000e+00
%16 = fadd double %15, -2.000000e+00
%17 = fmul double %13, 3.109600e+04
%18 = insertelement <2 x double> poison, double %13, i64 0
%19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
%20 = insertelement <2 x double> <double 1.132000e+03, double poison>, double %17, i64 1
%21 = fmul <2 x double> %19, %20
%22 = fmul <2 x double> %19, %21
%23 = fdiv <2 x double> %22, <double 5.000000e+00, double 7.000000e+00>
%24 = extractelement <2 x double> %23, i64 0
%25 = fsub double %16, %24
%26 = extractelement <2 x double> %23, i64 1
%27 = fadd double %25, %26
%28 = fmul double %9, %27
%29 = fdiv double %28, 0.000000e+00
%30 = fadd double %29, 5.000000e-01
br label %43
31: ; preds = %3
%32 = fmul double %9, 3.200000e+01
%33 = tail call double @llvm.fmuladd.f64(double %32, double %9, double 1.000000e+00)
%34 = fptosi double %33 to i32
%35 = tail call i32 @sqrt(i32 %34)
%36 = add nsw i32 %35, -1
%37 = sitofp i32 %36 to double
%38 = fmul double %9, 8.000000e+00
%39 = fdiv double %37, %38
%40 = fptosi double %39 to i32
%41 = tail call double @acos(i32 %40)
%42 = fdiv double %41, 0.000000e+00
br label %43
43: ; preds = %31, %12
%44 = phi double [ %30, %12 ], [ %42, %31 ]
ret double %44
}