#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 */
int /*<<< orphan*/ lonlat_to_xyz(double, double, double *);
scalar_t__ mod_tri_area(double *, double *, double *);
double mod_huiliers_area2(int num_corners, double *cell_corner_lon,
                          double *cell_corner_lat, double cell_center_lon,
                          double cell_center_lat) {
  if (num_corners < 3)
    return 0;
  double sum = 0.0;
  double pnt1[3], pnt2[3], pnt3[3];
  lonlat_to_xyz(cell_center_lon, cell_center_lat, pnt1);
  lonlat_to_xyz(cell_corner_lon[0], cell_corner_lat[0], pnt2);
  for (int i = 1; i < num_corners; i++) {
    if ((!(cell_corner_lon[i] < cell_corner_lon[i - 1] ||
           cell_corner_lon[i - 1] < cell_corner_lon[i])) &&
        (!(cell_corner_lat[i] < cell_corner_lat[i - 1] ||
           cell_corner_lat[i - 1] < cell_corner_lat[i])))
      continue;
    lonlat_to_xyz(cell_corner_lon[i], cell_corner_lat[i], pnt3);
    sum += mod_tri_area(pnt1, pnt2, pnt3);
    pnt2[0] = pnt3[0];
    pnt2[1] = pnt3[1];
    pnt2[2] = pnt3[2];
  }
  if (!((!(cell_corner_lon[0] < cell_corner_lon[num_corners - 1] ||
           cell_corner_lon[num_corners - 1] < cell_corner_lon[0])) &&
        (!(cell_corner_lat[0] < cell_corner_lat[num_corners - 1] ||
           cell_corner_lat[num_corners - 1] < cell_corner_lat[0])))) {
    lonlat_to_xyz(cell_corner_lon[0], cell_corner_lat[0], pnt3);
    sum += mod_tri_area(pnt1, pnt2, pnt3);
  }
  return (sum);
}


x86 assembly (clang, -O0):
<mod_huiliers_area2>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    1157 <mod_huiliers_area2+0x37>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13c5 <mod_huiliers_area2+0x2a5>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    -0x50(%rbp),%rdi
call   1040 <lonlat_to_xyz@plt>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
lea    -0x70(%rbp),%rdi
call   1040 <lonlat_to_xyz@plt>
movl   $0x1,-0x94(%rbp)
mov    -0x94(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ec <mod_huiliers_area2+0x1cc>
mov    -0x18(%rbp),%rax
movslq -0x94(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x94(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
ja     1265 <mod_huiliers_area2+0x145>
mov    -0x18(%rbp),%rax
mov    -0x94(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x94(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
ja     1265 <mod_huiliers_area2+0x145>
mov    -0x20(%rbp),%rax
movslq -0x94(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x94(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
ja     1265 <mod_huiliers_area2+0x145>
mov    -0x20(%rbp),%rax
mov    -0x94(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x94(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
ja     1265 <mod_huiliers_area2+0x145>
jmp    12d8 <mod_huiliers_area2+0x1b8>
mov    -0x18(%rbp),%rax
movslq -0x94(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x94(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    -0x90(%rbp),%rdi
call   1040 <lonlat_to_xyz@plt>
lea    -0x50(%rbp),%rdi
lea    -0x70(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1030 <mod_tri_area@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0x70(%rbp)
movsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x68(%rbp)
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1195 <mod_huiliers_area2+0x75>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
ja     137c <mod_huiliers_area2+0x25c>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
ja     137c <mod_huiliers_area2+0x25c>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
ja     137c <mod_huiliers_area2+0x25c>
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    13bb <mod_huiliers_area2+0x29b>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
lea    -0x90(%rbp),%rdi
call   1040 <lonlat_to_xyz@plt>
lea    -0x50(%rbp),%rdi
lea    -0x70(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1030 <mod_tri_area@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_huiliers_area2>:
xorpd  %xmm2,%xmm2
cmp    $0x3,%edi
jl     1250 <mod_huiliers_area2+0x130>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x50(%rsp),%rdi
call   1040 <lonlat_to_xyz@plt>
movsd  (%rbx),%xmm0
movsd  (%r15),%xmm1
lea    0x30(%rsp),%r13
mov    %r13,%rdi
call   1040 <lonlat_to_xyz@plt>
mov    %rbp,0x8(%rsp)
mov    %ebp,%r14d
xorpd  %xmm2,%xmm2
mov    $0x1,%r12d
lea    0x10(%rsp),%rbp
jmp    11cd <mod_huiliers_area2+0xad>
nopl   0x0(%rax)
mov    %rbp,%rdi
movsd  %xmm2,(%rsp)
call   1040 <lonlat_to_xyz@plt>
lea    0x50(%rsp),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1030 <mod_tri_area@plt>
movsd  (%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm2
movaps 0x10(%rsp),%xmm0
movaps %xmm0,0x30(%rsp)
movsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x40(%rsp)
add    $0x1,%r12
cmp    %r12,%r14
je     11ed <mod_huiliers_area2+0xcd>
movsd  (%rbx,%r12,8),%xmm0
ucomisd -0x8(%rbx,%r12,8),%xmm0
movsd  (%r15,%r12,8),%xmm1
jne    1180 <mod_huiliers_area2+0x60>
ucomisd -0x8(%r15,%r12,8),%xmm1
jne    1180 <mod_huiliers_area2+0x60>
jmp    11c4 <mod_huiliers_area2+0xa4>
movsd  (%rbx),%xmm0
mov    0x8(%rsp),%rax
add    $0xffffffff,%eax
ucomisd (%rbx,%rax,8),%xmm0
movsd  (%r15),%xmm1
jne    120d <mod_huiliers_area2+0xed>
ucomisd (%r15,%rax,8),%xmm1
je     1242 <mod_huiliers_area2+0x122>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
movsd  %xmm2,(%rsp)
call   1040 <lonlat_to_xyz@plt>
lea    0x50(%rsp),%rdi
lea    0x30(%rsp),%rsi
mov    %rbx,%rdx
call   1030 <mod_tri_area@plt>
movsd  (%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm2
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
movapd %xmm2,%xmm0
ret

LLVM IR (-O0):
define double @mod_huiliers_area2(i32 %0, double* %1, double* %2, double %3, double %4) {
%6 = alloca double
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca [3 x double]
%14 = alloca [3 x double]
%15 = alloca [3 x double]
%16 = alloca i32
store i32 %0, i32* %7
store double* %1, double** %8
store double* %2, double** %9
store double %3, double* %10
store double %4, double* %11
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %20
19: ; preds = %5
store double 0.000000e+00, double* %6
br label %184
20: ; preds = %5
store double 0.000000e+00, double* %12
%21 = load double, double* %10
%22 = load double, double* %11
%23 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%24 = call i32 @lonlat_to_xyz(double %21, double %22, double* %23)
%25 = load double*, double** %8
%26 = getelementptr inbounds double, double* %25, i64 0
%27 = load double, double* %26
%28 = load double*, double** %9
%29 = getelementptr inbounds double, double* %28, i64 0
%30 = load double, double* %29
%31 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 0
%32 = call i32 @lonlat_to_xyz(double %27, double %30, double* %31)
store i32 1, i32* %16
br label %33
33: ; preds = %119, %20
%34 = load i32, i32* %16
%35 = load i32, i32* %7
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %122
37: ; preds = %33
%38 = load double*, double** %8
%39 = load i32, i32* %16
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = load double*, double** %8
%44 = load i32, i32* %16
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %43, i64 %46
%48 = load double, double* %47
%49 = fcmp olt double %42, %48
br i1 %49, label %90, label %50
50: ; preds = %37
%51 = load double*, double** %8
%52 = load i32, i32* %16
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %51, i64 %54
%56 = load double, double* %55
%57 = load double*, double** %8
%58 = load i32, i32* %16
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
%61 = load double, double* %60
%62 = fcmp olt double %56, %61
br i1 %62, label %90, label %63
63: ; preds = %50
%64 = load double*, double** %9
%65 = load i32, i32* %16
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
%68 = load double, double* %67
%69 = load double*, double** %9
%70 = load i32, i32* %16
%71 = sub nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %69, i64 %72
%74 = load double, double* %73
%75 = fcmp olt double %68, %74
br i1 %75, label %90, label %76
76: ; preds = %63
%77 = load double*, double** %9
%78 = load i32, i32* %16
%79 = sub nsw i32 %78, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double, double* %77, i64 %80
%82 = load double, double* %81
%83 = load double*, double** %9
%84 = load i32, i32* %16
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %83, i64 %85
%87 = load double, double* %86
%88 = fcmp olt double %82, %87
br i1 %88, label %90, label %89
89: ; preds = %76
br label %119
90: ; preds = %76, %63, %50, %37
%91 = load double*, double** %8
%92 = load i32, i32* %16
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds double, double* %91, i64 %93
%95 = load double, double* %94
%96 = load double*, double** %9
%97 = load i32, i32* %16
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
%100 = load double, double* %99
%101 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%102 = call i32 @lonlat_to_xyz(double %95, double %100, double* %101)
%103 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%104 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 0
%105 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%106 = call i64 @mod_tri_area(double* %103, double* %104, double* %105)
%107 = sitofp i64 %106 to double
%108 = load double, double* %12
%109 = fadd double %108, %107
store double %109, double* %12
%110 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%111 = load double, double* %110
%112 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 0
store double %111, double* %112
%113 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 1
%114 = load double, double* %113
%115 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 1
store double %114, double* %115
%116 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 2
%117 = load double, double* %116
%118 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 2
store double %117, double* %118
br label %119
119: ; preds = %90, %89
%120 = load i32, i32* %16
%121 = add nsw i32 %120, 1
store i32 %121, i32* %16
br label %33
122: ; preds = %33
%123 = load double*, double** %8
%124 = getelementptr inbounds double, double* %123, i64 0
%125 = load double, double* %124
%126 = load double*, double** %8
%127 = load i32, i32* %7
%128 = sub nsw i32 %127, 1
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds double, double* %126, i64 %129
%131 = load double, double* %130
%132 = fcmp olt double %125, %131
br i1 %132, label %166, label %133
133: ; preds = %122
%134 = load double*, double** %8
%135 = load i32, i32* %7
%136 = sub nsw i32 %135, 1
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds double, double* %134, i64 %137
%139 = load double, double* %138
%140 = load double*, double** %8
%141 = getelementptr inbounds double, double* %140, i64 0
%142 = load double, double* %141
%143 = fcmp olt double %139, %142
br i1 %143, label %166, label %144
144: ; preds = %133
%145 = load double*, double** %9
%146 = getelementptr inbounds double, double* %145, i64 0
%147 = load double, double* %146
%148 = load double*, double** %9
%149 = load i32, i32* %7
%150 = sub nsw i32 %149, 1
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds double, double* %148, i64 %151
%153 = load double, double* %152
%154 = fcmp olt double %147, %153
br i1 %154, label %166, label %155
155: ; preds = %144
%156 = load double*, double** %9
%157 = load i32, i32* %7
%158 = sub nsw i32 %157, 1
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds double, double* %156, i64 %159
%161 = load double, double* %160
%162 = load double*, double** %9
%163 = getelementptr inbounds double, double* %162, i64 0
%164 = load double, double* %163
%165 = fcmp olt double %161, %164
br i1 %165, label %166, label %182
166: ; preds = %155, %144, %133, %122
%167 = load double*, double** %8
%168 = getelementptr inbounds double, double* %167, i64 0
%169 = load double, double* %168
%170 = load double*, double** %9
%171 = getelementptr inbounds double, double* %170, i64 0
%172 = load double, double* %171
%173 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%174 = call i32 @lonlat_to_xyz(double %169, double %172, double* %173)
%175 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%176 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 0
%177 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%178 = call i64 @mod_tri_area(double* %175, double* %176, double* %177)
%179 = sitofp i64 %178 to double
%180 = load double, double* %12
%181 = fadd double %180, %179
store double %181, double* %12
br label %182
182: ; preds = %166, %155
%183 = load double, double* %12
store double %183, double* %6
br label %184
184: ; preds = %182, %19
%185 = load double, double* %6
ret double %185
}

LLVM IR (-O2):
define double @mod_huiliers_area2(i32 %0, double* nocapture %1, double* nocapture %2, double %3, double %4) {
%6 = alloca [3 x double]
%7 = alloca [3 x double]
%8 = alloca [3 x double]
%9 = icmp slt i32 %0, 3
br i1 %9, label %72, label %10
10: ; preds = %5
%11 = bitcast [3 x double]* %6 to i8*
%12 = bitcast [3 x double]* %7 to i8*
%13 = bitcast [3 x double]* %8 to i8*
%14 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%15 = call i32 @lonlat_to_xyz(double %3, double %4, double* %14)
%16 = load double, double* %1
%17 = load double, double* %2
%18 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%19 = call i32 @lonlat_to_xyz(double %16, double %17, double* %18)
%20 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%21 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 2
%22 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 2
%23 = zext i32 %0 to i64
%24 = bitcast [3 x double]* %8 to <2 x double>*
%25 = bitcast [3 x double]* %7 to <2 x double>*
br label %34
26: ; preds = %56
%27 = load double, double* %1
%28 = add nsw i32 %0, -1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds double, double* %1, i64 %29
%31 = load double, double* %30
%32 = fcmp ueq double %27, %31
%33 = load double, double* %2
br i1 %32, label %60, label %64
34: ; preds = %10, %56
%35 = phi i64 [ 1, %10 ], [ %58, %56 ]
%36 = phi double [ 0.000000e+00, %10 ], [ %57, %56 ]
%37 = getelementptr inbounds double, double* %1, i64 %35
%38 = load double, double* %37
%39 = add nsw i64 %35, -1
%40 = getelementptr inbounds double, double* %1, i64 %39
%41 = load double, double* %40
%42 = fcmp ueq double %38, %41
%43 = getelementptr inbounds double, double* %2, i64 %35
%44 = load double, double* %43
br i1 %42, label %45, label %49
45: ; preds = %34
%46 = getelementptr inbounds double, double* %2, i64 %39
%47 = load double, double* %46
%48 = fcmp ueq double %44, %47
br i1 %48, label %56, label %49
49: ; preds = %34, %45
%50 = call i32 @lonlat_to_xyz(double %38, double %44, double* %20)
%51 = call i64 @mod_tri_area(double* %14, double* %18, double* %20)
%52 = sitofp i64 %51 to double
%53 = fadd double %36, %52
%54 = load <2 x double>, <2 x double>* %24
store <2 x double> %54, <2 x double>* %25
%55 = load double, double* %21
store double %55, double* %22
br label %56
56: ; preds = %45, %49
%57 = phi double [ %53, %49 ], [ %36, %45 ]
%58 = add nuw nsw i64 %35, 1
%59 = icmp eq i64 %58, %23
br i1 %59, label %26, label %34
60: ; preds = %26
%61 = getelementptr inbounds double, double* %2, i64 %29
%62 = load double, double* %61
%63 = fcmp ueq double %33, %62
br i1 %63, label %70, label %64
64: ; preds = %26, %60
%65 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%66 = call i32 @lonlat_to_xyz(double %27, double %33, double* %65)
%67 = call i64 @mod_tri_area(double* %14, double* %18, double* %65)
%68 = sitofp i64 %67 to double
%69 = fadd double %57, %68
br label %70
70: ; preds = %60, %64
%71 = phi double [ %69, %64 ], [ %57, %60 ]
br label %72
72: ; preds = %5, %70
%73 = phi double [ %71, %70 ], [ 0.000000e+00, %5 ]
ret double %73
}