#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 fabs(double);
double sin(double);
double poly_ctrlat(const double x[], const double y[], int n) {
  double ctrlat = 0.0;
  int i;
  for (i = 0; i < n; i++) {
    int ip = (i + 1) % n;
    double dx = (x[ip] - x[i]);
    double dy, avg_y, hdy;
    double lat1, lat2;
    lat1 = y[ip];
    lat2 = y[i];
    dy = lat2 - lat1;
    hdy = dy * 0.5;
    avg_y = (lat1 + lat2) * 0.5;
    if (dx == 0.0)
      continue;
    if (dx > M_PI)
      dx = dx - 2.0 * M_PI;
    if (dx < -M_PI)
      dx = dx + 2.0 * M_PI;
    if (fabs(hdy) < (1.e-10))
      ctrlat -= dx * (2 * cos(avg_y) + lat2 * sin(avg_y) - cos(lat1));
    else
      ctrlat -= dx * ((sin(hdy) / hdy) * (2 * cos(avg_y) + lat2 * sin(avg_y)) -
                      cos(lat1));
  }
  return (ctrlat * (6371000.) * (6371000.));
}


x86 assembly (clang, -O0):
<poly_ctrlat>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    141f <poly_ctrlat+0x2ff>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe50(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  0xe34(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11fa <poly_ctrlat+0xda>
jp     11fa <poly_ctrlat+0xda>
jmp    1411 <poly_ctrlat+0x2f1>
movsd  -0x30(%rbp),%xmm0
mov    0x2de2(%rip),%rax
ucomisd (%rax),%xmm0
jbe    122d <poly_ctrlat+0x10d>
movsd  -0x30(%rbp),%xmm0
mov    0x2dcc(%rip),%rax
movsd  (%rax),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
mov    0x2daf(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    127b <poly_ctrlat+0x15b>
movsd  -0x30(%rbp),%xmm1
mov    0x2d7e(%rip),%rax
movsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm1
movaps 0xd99(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xd7d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1331 <poly_ctrlat+0x211>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0x78(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x68(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
subsd  %xmm1,%xmm2
movsd  -0x20(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    140c <poly_ctrlat+0x2ec>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <sin@plt>
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0xa0(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0x98(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x90(%rbp),%xmm2
ff
movsd  -0x88(%rbp),%xmm3
ff
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x20(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1411 <poly_ctrlat+0x2f1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1145 <poly_ctrlat+0x25>
movsd  0xbd9(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xbcc(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly_ctrlat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
test   %edx,%edx
jle    1304 <poly_ctrlat+0x1e4>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
neg    %r12
xorpd  %xmm1,%xmm1
mov    $0x1,%ebx
xor    %r13d,%r13d
mov    0x2e93(%rip),%rbp
xorpd  %xmm8,%xmm8
jmp    11f5 <poly_ctrlat+0xd5>
movapd %xmm0,(%rsp)
call   1030 <sin@plt>
divsd  (%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
movsd  0x18(%rsp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x20(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mulsd  0x38(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x28(%rsp),%xmm0
call   1040 <cos@plt>
xorpd  %xmm1,%xmm1
movsd  0x30(%rsp),%xmm8
movsd  (%rsp),%xmm2
subsd  %xmm0,%xmm2
movapd 0x40(%rsp),%xmm0
mulsd  %xmm2,%xmm0
subsd  %xmm0,%xmm8
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     1309 <poly_ctrlat+0x1e9>
mov    %r12,%rax
add    %rbx,%rax
mov    %rbx,%rax
cmove  %r13,%rax
movsd  (%r15,%rax,8),%xmm3
subsd  -0x8(%r15,%rbx,8),%xmm3
ucomisd %xmm1,%xmm3
jne    1217 <poly_ctrlat+0xf7>
jnp    11df <poly_ctrlat+0xbf>
movsd  (%r14,%rax,8),%xmm9
movsd  -0x8(%r14,%rbx,8),%xmm7
movapd %xmm7,%xmm0
subsd  %xmm9,%xmm0
movsd  0xdcb(%rip),%xmm1
mulsd  %xmm1,%xmm0
movapd %xmm9,%xmm6
addsd  %xmm7,%xmm6
mulsd  %xmm1,%xmm6
movsd  0x0(%rbp),%xmm1
movapd %xmm1,%xmm2
addsd  %xmm1,%xmm2
movapd %xmm3,%xmm5
subsd  %xmm2,%xmm5
movapd %xmm1,%xmm4
cmpltsd %xmm3,%xmm4
andpd  %xmm4,%xmm5
andnpd %xmm3,%xmm4
orpd   %xmm5,%xmm4
xorpd  0xda8(%rip),%xmm1
addsd  %xmm4,%xmm2
movapd %xmm4,%xmm3
cmpltsd %xmm1,%xmm3
andpd  %xmm3,%xmm2
andnpd %xmm4,%xmm3
orpd   %xmm2,%xmm3
movapd %xmm0,%xmm2
andpd  0xd93(%rip),%xmm2
movsd  0xd63(%rip),%xmm1
ucomisd %xmm2,%xmm1
movsd  %xmm8,0x30(%rsp)
movapd %xmm3,0x40(%rsp)
movsd  %xmm9,0x28(%rsp)
movsd  %xmm7,0x20(%rsp)
movsd  %xmm6,0x18(%rsp)
jbe    115f <poly_ctrlat+0x3f>
movapd %xmm6,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x20(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
jmp    11ac <poly_ctrlat+0x8c>
xorpd  %xmm8,%xmm8
movsd  0xcff(%rip),%xmm0
mulsd  %xmm0,%xmm8
mulsd  %xmm0,%xmm8
movapd %xmm8,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @poly_ctrlat(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %63
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %60
%8 = phi i64 [ 0, %5 ], [ %10, %60 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %61, %60 ]
%10 = add nuw nsw i64 %8, 1
%11 = icmp eq i64 %10, %6
%12 = and i64 %10, 4294967295
%13 = select i1 %11, i64 0, i64 %12
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %0, i64 %8
%17 = load double, double* %16
%18 = fsub double %15, %17
%19 = getelementptr inbounds double, double* %1, i64 %13
%20 = load double, double* %19
%21 = getelementptr inbounds double, double* %1, i64 %8
%22 = load double, double* %21
%23 = fsub double %22, %20
%24 = fmul double %23, 5.000000e-01
%25 = fadd double %20, %22
%26 = fmul double %25, 5.000000e-01
%27 = fcmp oeq double %18, 0.000000e+00
br i1 %27, label %60, label %28
28: ; preds = %7
%29 = load double, double* @M_PI
%30 = fcmp ogt double %18, %29
%31 = tail call double @llvm.fmuladd.f64(double %29, double -2.000000e+00, double %18)
%32 = select i1 %30, double %31, double %18
%33 = fneg double %29
%34 = fcmp olt double %32, %33
%35 = tail call double @llvm.fmuladd.f64(double %29, double 2.000000e+00, double %32)
%36 = select i1 %34, double %35, double %32
%37 = tail call double @llvm.fabs.f64(double %24)
%38 = fcmp olt double %37, 1.000000e-10
br i1 %38, label %39, label %48
39: ; preds = %28
%40 = tail call double @cos(double %26)
%41 = tail call double @sin(double %26)
%42 = fmul double %22, %41
%43 = tail call double @llvm.fmuladd.f64(double %40, double 2.000000e+00, double %42)
%44 = tail call double @cos(double %20)
%45 = fsub double %43, %44
%46 = fneg double %36
%47 = tail call double @llvm.fmuladd.f64(double %46, double %45, double %9)
br label %60
48: ; preds = %28
%49 = tail call double @sin(double %24)
%50 = fdiv double %49, %24
%51 = tail call double @cos(double %26)
%52 = tail call double @sin(double %26)
%53 = fmul double %22, %52
%54 = tail call double @llvm.fmuladd.f64(double %51, double 2.000000e+00, double %53)
%55 = tail call double @cos(double %20)
%56 = fneg double %55
%57 = tail call double @llvm.fmuladd.f64(double %50, double %54, double %56)
%58 = fneg double %36
%59 = tail call double @llvm.fmuladd.f64(double %58, double %57, double %9)
br label %60
60: ; preds = %39, %48, %7
%61 = phi double [ %9, %7 ], [ %47, %39 ], [ %59, %48 ]
%62 = icmp eq i64 %10, %6
br i1 %62, label %63, label %7
63: ; preds = %60, %3
%64 = phi double [ 0.000000e+00, %3 ], [ %61, %60 ]
%65 = fmul double %64, 6.371000e+06
%66 = fmul double %65, 6.371000e+06
ret double %66
}