#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);
  }
  return area * (6371000.) * (6371000.);
}


x86 assembly (clang, -O0):
<poly_area_no_adjust>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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    12a0 <poly_area_no_adjust+0x180>
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,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%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  -0x38(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movaps 0xe54(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe30(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    123d <poly_area_no_adjust+0x11d>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm1
addsd  -0x40(%rbp),%xmm1
movsd  0xe12(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
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    128d <poly_area_no_adjust+0x16d>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1292 <poly_area_no_adjust+0x172>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1142 <poly_area_no_adjust+0x22>
movsd  0xd58(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xd4b(%rip),%xmm1
mulsd  %xmm1,%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 i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = 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 %13
13: ; preds = %77, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %80
17: ; preds = %13
%18 = load i32, i32* %8
%19 = add nsw i32 %18, 1
%20 = load i32, i32* %6
%21 = srem i32 %19, %20
store i32 %21, i32* %9
%22 = load double*, double** %4
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %4
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = fsub double %26, %31
store double %32, double* %10
%33 = load double*, double** %5
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
store double %37, double* %11
%38 = load double*, double** %5
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
store double %42, double* %12
%43 = load double, double* %10
%44 = fcmp oeq double %43, 0.000000e+00
br i1 %44, label %45, label %46
45: ; preds = %17
br label %77
46: ; preds = %17
%47 = load double, double* %11
%48 = load double, double* %12
%49 = fsub double %47, %48
%50 = call double @llvm.fabs.f64(double %49)
%51 = fcmp olt double %50, 1.000000e-10
br i1 %51, label %52, label %62
52: ; preds = %46
%53 = load double, double* %10
%54 = load double, double* %11
%55 = load double, double* %12
%56 = fadd double %54, %55
%57 = fmul double 5.000000e-01, %56
%58 = call double @sin(double %57)
%59 = load double, double* %7
%60 = fneg double %53
%61 = call double @llvm.fmuladd.f64(double %60, double %58, double %59)
store double %61, double* %7
br label %76
62: ; preds = %46
%63 = load double, double* %10
%64 = load double, double* %11
%65 = call double @cos(double %64)
%66 = load double, double* %12
%67 = call double @cos(double %66)
%68 = fsub double %65, %67
%69 = fmul double %63, %68
%70 = load double, double* %11
%71 = load double, double* %12
%72 = fsub double %70, %71
%73 = fdiv double %69, %72
%74 = load double, double* %7
%75 = fadd double %74, %73
store double %75, double* %7
br label %76
76: ; preds = %62, %52
br label %77
77: ; preds = %76, %45
%78 = load i32, i32* %8
%79 = add nsw i32 %78, 1
store i32 %79, i32* %8
br label %13
80: ; preds = %13
%81 = load double, double* %7
%82 = fmul double %81, 6.371000e+06
%83 = fmul double %82, 6.371000e+06
ret double %83
}

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
}