#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 fabs(double);
double phi_gradient(double in_phi1, double in_phi2, double dphi, double f1,
                    double f2, double grid_lon) {
  double fint, fac;
  double weight;
  double phi1, phi2;
  phi1 = in_phi1 - grid_lon;
  if (phi1 > 3.14159265358979323846)
    phi1 -= (2.0 * 3.14159265358979323846);
  else if (phi1 < -3.14159265358979323846)
    phi1 += (2.0 * 3.14159265358979323846);
  phi2 = in_phi2 - grid_lon;
  if (phi2 > 3.14159265358979323846)
    phi2 -= (2.0 * 3.14159265358979323846);
  else if (phi2 < -3.14159265358979323846)
    phi2 += (2.0 * 3.14159265358979323846);
  if ((phi2 - phi1) < 3.14159265358979323846 &&
      (phi2 - phi1) > -3.14159265358979323846)
    weight = dphi * (phi1 * f1 + phi2 * f2);
  else {
    if (phi1 > 0.0)
      fac = 3.14159265358979323846;
    else
      fac = -3.14159265358979323846;
    fint = f1 + (f2 - f1) * (fac - phi1) / fabs(dphi);
    weight = 0.5 * phi1 * (phi1 - fac) * f1 - 0.5 * phi2 * (phi2 + fac) * f2 +
             0.5 * fac * (phi1 + phi2) * fint;
  }
  return weight;
}


x86 assembly (clang, -O0):
<phi_gradient>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xec2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1163 <phi_gradient+0x63>
movsd  -0x50(%rbp),%xmm0
movsd  0xebb(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    118d <phi_gradient+0x8d>
movsd  0xe9d(%rip),%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    1188 <phi_gradient+0x88>
movsd  0xe92(%rip),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    118d <phi_gradient+0x8d>
movsd  -0x10(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  0xe57(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ce <phi_gradient+0xce>
movsd  -0x58(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    11f8 <phi_gradient+0xf8>
movsd  0xe32(%rip),%xmm0
ucomisd -0x58(%rbp),%xmm0
jbe    11f3 <phi_gradient+0xf3>
movsd  0xe27(%rip),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    11f8 <phi_gradient+0xf8>
movsd  -0x58(%rbp),%xmm1
subsd  -0x50(%rbp),%xmm1
movsd  0xdf6(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    125f <phi_gradient+0x15f>
movsd  -0x58(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  0xde2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    125f <phi_gradient+0x15f>
movsd  -0x18(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm3
movsd  -0x58(%rbp),%xmm2
mulsd  -0x28(%rbp),%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1356 <phi_gradient+0x256>
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1283 <phi_gradient+0x183>
movsd  0xd87(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1290 <phi_gradient+0x190>
movsd  0xd7d(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
subsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  -0x18(%rbp),%xmm2
movaps 0xd67(%rip),%xmm3
pand   %xmm3,%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xd46(%rip),%xmm1
mulsd  -0x50(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  0xd26(%rip),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm3
addsd  -0x40(%rbp),%xmm3
mulsd  %xmm3,%xmm0
mulsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xce7(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
addsd  -0x58(%rbp),%xmm2
mulsd  %xmm2,%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<phi_gradient>:
subsd  %xmm5,%xmm0
ucomisd 0xef4(%rip),%xmm0
jbe    1118 <phi_gradient+0x18>
addsd  0xf02(%rip),%xmm0
jmp    112e <phi_gradient+0x2e>
movsd  0xee8(%rip),%xmm6
ucomisd %xmm0,%xmm6
jbe    112e <phi_gradient+0x2e>
addsd  0xee2(%rip),%xmm0
subsd  %xmm5,%xmm1
ucomisd 0xec6(%rip),%xmm1
jbe    1146 <phi_gradient+0x46>
addsd  0xed4(%rip),%xmm1
jmp    115c <phi_gradient+0x5c>
movsd  0xeba(%rip),%xmm5
ucomisd %xmm1,%xmm5
jbe    115c <phi_gradient+0x5c>
addsd  0xeb4(%rip),%xmm1
movapd %xmm1,%xmm5
subsd  %xmm0,%xmm5
movsd  0xe94(%rip),%xmm6
ucomisd %xmm5,%xmm6
jbe    118d <phi_gradient+0x8d>
ucomisd 0xe8e(%rip),%xmm5
jbe    118d <phi_gradient+0x8d>
mulsd  %xmm4,%xmm1
mulsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
ret
xorpd  %xmm5,%xmm5
xor    %eax,%eax
ucomisd %xmm5,%xmm0
seta   %al
lea    0xe8f(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm5
movapd %xmm4,%xmm7
subsd  %xmm3,%xmm7
movapd %xmm5,%xmm6
subsd  %xmm0,%xmm6
mulsd  %xmm7,%xmm6
andpd  0xe7e(%rip),%xmm2
divsd  %xmm2,%xmm6
addsd  %xmm3,%xmm6
movsd  0xe4d(%rip),%xmm8
movapd %xmm0,%xmm7
mulsd  %xmm8,%xmm7
movapd %xmm0,%xmm2
subsd  %xmm5,%xmm2
mulsd  %xmm7,%xmm2
movapd %xmm5,%xmm7
addsd  %xmm1,%xmm7
addsd  %xmm1,%xmm0
mulsd  0xe2c(%rip),%xmm1
mulsd  %xmm7,%xmm1
mulsd  %xmm4,%xmm1
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm8,%xmm5
mulsd  %xmm0,%xmm5
mulsd  %xmm6,%xmm5
addsd  %xmm2,%xmm5
movapd %xmm5,%xmm0
ret

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

LLVM IR (-O2):
define double @phi_gradient(double %0, double %1, double %2, double %3, double %4, double %5) {
%7 = fsub double %0, %5
%8 = fcmp ogt double %7, 0x400921FB54442D18
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = fadd double %7, 0xC01921FB54442D18
br label %15
11: ; preds = %6
%12 = fcmp olt double %7, 0xC00921FB54442D18
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = fadd double %7, 0x401921FB54442D18
br label %15
15: ; preds = %11, %13, %9
%16 = phi double [ %10, %9 ], [ %14, %13 ], [ %7, %11 ]
%17 = fsub double %1, %5
%18 = fcmp ogt double %17, 0x400921FB54442D18
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = fadd double %17, 0xC01921FB54442D18
br label %25
21: ; preds = %15
%22 = fcmp olt double %17, 0xC00921FB54442D18
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = fadd double %17, 0x401921FB54442D18
br label %25
25: ; preds = %21, %23, %19
%26 = phi double [ %20, %19 ], [ %24, %23 ], [ %17, %21 ]
%27 = fsub double %26, %16
%28 = fcmp olt double %27, 0x400921FB54442D18
%29 = fcmp ogt double %27, 0xC00921FB54442D18
%30 = and i1 %28, %29
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = fmul double %26, %4
%33 = tail call double @llvm.fmuladd.f64(double %16, double %3, double %32)
%34 = fmul double %33, %2
br label %56
35: ; preds = %25
%36 = fcmp ogt double %16, 0.000000e+00
%37 = select i1 %36, double 0x400921FB54442D18, double 0xC00921FB54442D18
%38 = fsub double %4, %3
%39 = fsub double %37, %16
%40 = fmul double %38, %39
%41 = tail call double @llvm.fabs.f64(double %2)
%42 = fdiv double %40, %41
%43 = fadd double %42, %3
%44 = fmul double %16, 5.000000e-01
%45 = fsub double %16, %37
%46 = fmul double %44, %45
%47 = fadd double %37, %26
%48 = fmul double %26, -5.000000e-01
%49 = fmul double %48, %47
%50 = fmul double %49, %4
%51 = tail call double @llvm.fmuladd.f64(double %46, double %3, double %50)
%52 = fmul double %37, 5.000000e-01
%53 = fadd double %16, %26
%54 = fmul double %52, %53
%55 = tail call double @llvm.fmuladd.f64(double %54, double %43, double %51)
br label %56
56: ; preds = %35, %31
%57 = phi double [ %34, %31 ], [ %55, %35 ]
ret double %57
}