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


x86 assembly (clang, -O0):
<poly_area_no_adjust>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12a0 <poly_area_no_adjust+0x180>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x1c(%rbp)
mov    %edx,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11bb <poly_area_no_adjust+0x9b>
jp     11bb <poly_area_no_adjust+0x9b>
jmp    1292 <poly_area_no_adjust+0x172>
movsd  -0x40(%rbp),%xmm1
subsd  -0x48(%rbp),%xmm1
movaps 0xe54(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe30(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    123d <poly_area_no_adjust+0x11d>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm1
addsd  -0x48(%rbp),%xmm1
movsd  0xe12(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%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)
jmp    128d <poly_area_no_adjust+0x16d>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x40(%rbp),%xmm1
subsd  -0x48(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1292 <poly_area_no_adjust+0x172>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1142 <poly_area_no_adjust+0x22>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    12d1 <poly_area_no_adjust+0x1b1>
movsd  0xd4a(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xd3d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ef <poly_area_no_adjust+0x1cf>
movsd  0xd27(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xd1a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly_area_no_adjust>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
test   %edx,%edx
jle    1243 <poly_area_no_adjust+0x123>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
neg    %r12
xorpd  %xmm1,%xmm1
mov    $0x1,%ebx
xor    %r13d,%r13d
xorpd  %xmm2,%xmm2
jmp    11b6 <poly_area_no_adjust+0x96>
movapd %xmm5,0x20(%rsp)
movsd  %xmm6,0x10(%rsp)
call   1040 <cos@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <cos@plt>
xorpd  %xmm1,%xmm1
movsd  0x8(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
subsd  %xmm0,%xmm3
movsd  (%rsp),%xmm0
mulsd  %xmm3,%xmm0
divsd  0x20(%rsp),%xmm0
addsd  %xmm0,%xmm2
nopl   0x0(%rax)
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     1247 <poly_area_no_adjust+0x127>
mov    %r12,%rax
add    %rbx,%rax
mov    %rbx,%rax
cmove  %r13,%rax
movsd  (%r15,%rax,8),%xmm4
subsd  -0x8(%r15,%rbx,8),%xmm4
ucomisd %xmm1,%xmm4
jne    11d8 <poly_area_no_adjust+0xb8>
jnp    11a0 <poly_area_no_adjust+0x80>
movsd  (%r14,%rax,8),%xmm0
movsd  -0x8(%r14,%rbx,8),%xmm6
movapd %xmm0,%xmm5
subsd  %xmm6,%xmm5
movapd %xmm5,%xmm1
andpd  0xe07(%rip),%xmm1
movsd  0xe0f(%rip),%xmm3
ucomisd %xmm1,%xmm3
movsd  %xmm2,0x8(%rsp)
movsd  %xmm4,(%rsp)
jbe    1153 <poly_area_no_adjust+0x33>
addsd  %xmm6,%xmm0
mulsd  0xdf6(%rip),%xmm0
call   1030 <sin@plt>
xorpd  %xmm1,%xmm1
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm3
mulsd  %xmm0,%xmm3
subsd  %xmm3,%xmm2
jmp    11a0 <poly_area_no_adjust+0x80>
xorpd  %xmm2,%xmm2
movsd  0xdd1(%rip),%xmm0
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define double @poly_area_no_adjust(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %44
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %41
%8 = phi i64 [ 0, %5 ], [ %10, %41 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %42, %41 ]
%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 = fcmp oeq double %18, 0.000000e+00
br i1 %23, label %41, label %24
24: ; preds = %7
%25 = fsub double %20, %22
%26 = tail call double @llvm.fabs.f64(double %25)
%27 = fcmp olt double %26, 1.000000e-10
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = fadd double %20, %22
%30 = fmul double %29, 5.000000e-01
%31 = tail call double @sin(double %30)
%32 = fneg double %18
%33 = tail call double @llvm.fmuladd.f64(double %32, double %31, double %9)
br label %41
34: ; preds = %24
%35 = tail call double @cos(double %20)
%36 = tail call double @cos(double %22)
%37 = fsub double %35, %36
%38 = fmul double %18, %37
%39 = fdiv double %38, %25
%40 = fadd double %9, %39
br label %41
41: ; preds = %28, %34, %7
%42 = phi double [ %9, %7 ], [ %33, %28 ], [ %40, %34 ]
%43 = icmp eq i64 %10, %6
br i1 %43, label %44, label %7
44: ; preds = %41, %3
%45 = phi double [ 0.000000e+00, %3 ], [ %42, %41 ]
%46 = fmul double %45, 6.371000e+06
%47 = fmul double %46, 6.371000e+06
ret double %47
}