#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 M_PI;
double cos(double);
double sin(double);
double box_ctrlat(double ll_lon, double ll_lat, double ur_lon, double ur_lat) {
  double dphi = ur_lon - ll_lon;
  double ctrlat;
  if (dphi > M_PI)
    dphi = dphi - 2.0 * M_PI;
  if (dphi < -M_PI)
    dphi = dphi + 2.0 * M_PI;
  ctrlat = dphi * (cos(ur_lat) + ur_lat * sin(ur_lat) -
                   (cos(ll_lat) + ll_lat * sin(ll_lat)));
  return (ctrlat * (6371000.) * (6371000.));
}


x86 assembly (clang, -O0):
<box_ctrlat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    0x2e91(%rip),%rax
ucomisd (%rax),%xmm0
jbe    117e <box_ctrlat+0x5e>
movsd  -0x28(%rbp),%xmm0
mov    0x2e7b(%rip),%rax
movsd  (%rax),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
mov    0x2e5e(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    11cc <box_ctrlat+0xac>
movsd  -0x28(%rbp),%xmm1
mov    0x2e2d(%rip),%rax
movsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0x50(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm3
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm4
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm4,%xmm2
addsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd96(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  0xd89(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<box_ctrlat>:
sub    $0x38,%rsp
movaps %xmm3,%xmm5
movsd  %xmm3,0x8(%rsp)
movsd  %xmm1,0x18(%rsp)
subsd  %xmm0,%xmm2
mov    0x2eaa(%rip),%rax
movsd  (%rax),%xmm0
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm0,%xmm3
cmpltsd %xmm2,%xmm3
movapd %xmm3,%xmm4
andnpd %xmm2,%xmm4
subsd  %xmm1,%xmm2
andpd  %xmm2,%xmm3
orpd   %xmm4,%xmm3
xorpd  0xe91(%rip),%xmm0
addsd  %xmm3,%xmm1
movapd %xmm3,%xmm2
cmpltsd %xmm0,%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm3,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,0x20(%rsp)
movaps %xmm5,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x18(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x20(%rsp),%xmm1
movsd  0xe17(%rip),%xmm0
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @box_ctrlat(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%11 = load double, double* %7
%12 = load double, double* %5
%13 = fsub double %11, %12
store double %13, double* %9
%14 = load double, double* %9
%15 = load double, double* @M_PI
%16 = fcmp ogt double %14, %15
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load double, double* %9
%19 = load double, double* @M_PI
%20 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %19, double %18)
store double %20, double* %9
br label %21
21: ; preds = %17, %4
%22 = load double, double* %9
%23 = load double, double* @M_PI
%24 = fneg double %23
%25 = fcmp olt double %22, %24
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load double, double* %9
%28 = load double, double* @M_PI
%29 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %28, double %27)
store double %29, double* %9
br label %30
30: ; preds = %26, %21
%31 = load double, double* %9
%32 = load double, double* %8
%33 = call double @cos(double %32)
%34 = load double, double* %8
%35 = load double, double* %8
%36 = call double @sin(double %35)
%37 = call double @llvm.fmuladd.f64(double %34, double %36, double %33)
%38 = load double, double* %6
%39 = call double @cos(double %38)
%40 = load double, double* %6
%41 = load double, double* %6
%42 = call double @sin(double %41)
%43 = call double @llvm.fmuladd.f64(double %40, double %42, double %39)
%44 = fsub double %37, %43
%45 = fmul double %31, %44
store double %45, double* %10
%46 = load double, double* %10
%47 = fmul double %46, 6.371000e+06
%48 = fmul double %47, 6.371000e+06
ret double %48
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @box_ctrlat(double %0, double %1, double %2, double %3) {
%5 = fsub double %2, %0
%6 = load double, double* @M_PI
%7 = fcmp ogt double %5, %6
%8 = tail call double @llvm.fmuladd.f64(double %6, double -2.000000e+00, double %5)
%9 = select i1 %7, double %8, double %5
%10 = fneg double %6
%11 = fcmp olt double %9, %10
%12 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double %9)
%13 = select i1 %11, double %12, double %9
%14 = tail call double @cos(double %3)
%15 = tail call double @sin(double %3)
%16 = tail call double @llvm.fmuladd.f64(double %3, double %15, double %14)
%17 = tail call double @cos(double %1)
%18 = tail call double @sin(double %1)
%19 = tail call double @llvm.fmuladd.f64(double %1, double %18, double %17)
%20 = fsub double %16, %19
%21 = fmul double %13, %20
%22 = fmul double %21, 6.371000e+06
%23 = fmul double %22, 6.371000e+06
ret double %23
}