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


x86 assembly (clang, -O0):
<mod_huiliers_area>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    114d <mod_huiliers_area+0x2d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1240 <mod_huiliers_area+0x120>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
lea    -0x40(%rbp),%rdi
call   1040 <lonlat_to_xyz@plt>
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm1
lea    -0x60(%rbp),%rdi
call   1040 <lonlat_to_xyz@plt>
movl   $0x2,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1236 <mod_huiliers_area+0x116>
mov    -0x18(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    -0x80(%rbp),%rdi
call   1040 <lonlat_to_xyz@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1030 <mod_tri_area@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x84(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    121d <mod_huiliers_area+0xfd>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1222 <mod_huiliers_area+0x102>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1193 <mod_huiliers_area+0x73>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_huiliers_area>:
xorpd  %xmm0,%xmm0
cmp    $0x3,%edi
jl     1207 <mod_huiliers_area+0xe7>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %edi,%ebx
movsd  (%rsi),%xmm0
movsd  (%rdx),%xmm1
lea    0x50(%rsp),%rdi
call   1040 <lonlat_to_xyz@plt>
movsd  0x8(%r13),%xmm0
movsd  0x8(%r14),%xmm1
lea    0x10(%rsp),%rdi
call   1040 <lonlat_to_xyz@plt>
lea    -0x1(%rbx),%ebp
mov    %ebx,%r15d
xorpd  %xmm0,%xmm0
mov    $0x2,%r12d
lea    0x30(%rsp),%rbx
jmp    11af <mod_huiliers_area+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x1,%r12
cmp    %r12,%r15
je     11f9 <mod_huiliers_area+0xd9>
movsd  %xmm0,0x8(%rsp)
movsd  0x0(%r13,%r12,8),%xmm0
movsd  (%r14,%r12,8),%xmm1
mov    %rbx,%rdi
call   1040 <lonlat_to_xyz@plt>
lea    0x50(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1030 <mod_tri_area@plt>
cmp    %rbp,%r12
jae    1190 <mod_huiliers_area+0x70>
movaps 0x30(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
movsd  0x40(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
jmp    1190 <mod_huiliers_area+0x70>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @mod_huiliers_area(i32 %0, double* nocapture %1, double* nocapture %2) {
%4 = alloca [3 x double]
%5 = alloca [3 x double]
%6 = alloca [3 x double]
%7 = icmp slt i32 %0, 3
br i1 %7, label %49, label %8
8: ; preds = %3
%9 = bitcast [3 x double]* %4 to i8*
%10 = bitcast [3 x double]* %5 to i8*
%11 = bitcast [3 x double]* %6 to i8*
%12 = load double, double* %1
%13 = load double, double* %2
%14 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%15 = call i32 @lonlat_to_xyz(double %12, double %13, double* %14)
%16 = getelementptr inbounds double, double* %1, i64 1
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %2, i64 1
%19 = load double, double* %18
%20 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%21 = call i32 @lonlat_to_xyz(double %17, double %19, double* %20)
%22 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%23 = add nsw i32 %0, -1
%24 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 2
%25 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 2
%26 = zext i32 %23 to i64
%27 = zext i32 %0 to i64
%28 = bitcast [3 x double]* %6 to <2 x double>*
%29 = bitcast [3 x double]* %5 to <2 x double>*
br label %31
30: ; preds = %46
br label %49
31: ; preds = %8, %46
%32 = phi i64 [ 2, %8 ], [ %47, %46 ]
%33 = phi double [ 0.000000e+00, %8 ], [ %41, %46 ]
%34 = getelementptr inbounds double, double* %1, i64 %32
%35 = load double, double* %34
%36 = getelementptr inbounds double, double* %2, i64 %32
%37 = load double, double* %36
%38 = call i32 @lonlat_to_xyz(double %35, double %37, double* %22)
%39 = call i64 @mod_tri_area(double* %14, double* %20, double* %22)
%40 = sitofp i64 %39 to double
%41 = fadd double %33, %40
%42 = icmp ult i64 %32, %26
br i1 %42, label %43, label %46
43: ; preds = %31
%44 = load <2 x double>, <2 x double>* %28
store <2 x double> %44, <2 x double>* %29
%45 = load double, double* %24
store double %45, double* %25
br label %46
46: ; preds = %31, %43
%47 = add nuw nsw i64 %32, 1
%48 = icmp eq i64 %47, %27
br i1 %48, label %30, label %31
49: ; preds = %3, %30
%50 = phi double [ %41, %30 ], [ 0.000000e+00, %3 ]
ret double %50
}