#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 */
struct Node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ addEnd(struct Node *, double, double, double,
                          int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int);
int /*<<< orphan*/ free(double *);
struct Node *getNext();
double gridArea(struct Node *);
int /*<<< orphan*/ latlon2xyz(int, double const *, double const *, double *,
                              double *, double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ rewindList();
void get_grid_great_circle_area_ug(const int *npts, const double *lon,
                                   const double *lat, double *area) {
  int l, nl, nv;
  int n0, n1, n2, n3;
  double x_in[20], y_in[20], z_in[20];
  struct Node *grid = NULL;
  double *x = NULL, *y = NULL, *z = NULL;
  nl = *npts;
  nv = 4;
  x = (double *)malloc(nl * nv * sizeof(double));
  y = (double *)malloc(nl * nv * sizeof(double));
  z = (double *)malloc(nl * nv * sizeof(double));
  latlon2xyz(nl * nv, lon, lat, x, y, z);
  for (l = 0; l < nv; l++) {
    n0 = l * nv;
    n1 = l * nv + 1;
    n2 = l * nv + 2;
    n3 = l * nv + 3;
    rewindList();
    grid = getNext();
    addEnd(grid, x[n0], y[n0], z[n0], 0, 0, 0, -1);
    addEnd(grid, x[n1], y[n1], z[n1], 0, 0, 0, -1);
    addEnd(grid, x[n2], y[n2], z[n2], 0, 0, 0, -1);
    addEnd(grid, x[n3], y[n3], z[n3], 0, 0, 0, -1);
    area[l] = gridArea(grid);
  }
  free(x);
  free(y);
  free(z);
}


x86 assembly (clang, -O0):
<get_grid_great_circle_area_ug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x228(%rbp)
movq   $0x0,-0x230(%rbp)
movq   $0x0,-0x238(%rbp)
movq   $0x0,-0x240(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movl   $0x4,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
imul   -0x2c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x230(%rbp)
mov    -0x28(%rbp),%eax
imul   -0x2c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x238(%rbp)
mov    -0x28(%rbp),%eax
imul   -0x2c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x240(%rbp)
mov    -0x28(%rbp),%edi
imul   -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x230(%rbp),%rcx
mov    -0x238(%rbp),%r8
mov    -0x240(%rbp),%r9
call   1070 <latlon2xyz@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    13e1 <get_grid_great_circle_area_ug+0x271>
mov    -0x24(%rbp),%eax
imul   -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x2c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1040 <rewindList@plt>
mov    $0x0,%al
call   1080 <getNext@plt>
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
mov    -0x230(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x238(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x240(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <addEnd@plt>
mov    -0x228(%rbp),%rdi
mov    -0x230(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x238(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x240(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <addEnd@plt>
mov    -0x228(%rbp),%rdi
mov    -0x230(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x238(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x240(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <addEnd@plt>
mov    -0x228(%rbp),%rdi
mov    -0x230(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x238(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x240(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <addEnd@plt>
mov    -0x228(%rbp),%rdi
call   1090 <gridArea@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1248 <get_grid_great_circle_area_ug+0xd8>
mov    -0x230(%rbp),%rdi
call   1030 <free@plt>
mov    -0x238(%rbp),%rdi
call   1030 <free@plt>
mov    -0x240(%rbp),%rdi
call   1030 <free@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_grid_great_circle_area_ug>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    (%rdi),%ebx
lea    0x0(,%rbx,4),%ebp
shl    $0x5,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %ebp,%edi
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
mov    %r15,%rcx
mov    %r12,%r8
mov    %rax,%r9
call   1070 <latlon2xyz@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rewindList@plt>
xor    %eax,%eax
call   1080 <getNext@plt>
mov    %rax,%rbx
movsd  (%r15,%rbp,4),%xmm0
movsd  (%r12,%rbp,4),%xmm1
movsd  0x0(%r13,%rbp,4),%xmm2
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
call   1060 <addEnd@plt>
movsd  0x8(%r15,%rbp,4),%xmm0
movsd  0x8(%r12,%rbp,4),%xmm1
movsd  0x8(%r13,%rbp,4),%xmm2
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
call   1060 <addEnd@plt>
movsd  0x10(%r15,%rbp,4),%xmm0
movsd  0x10(%r12,%rbp,4),%xmm1
movsd  0x10(%r13,%rbp,4),%xmm2
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
call   1060 <addEnd@plt>
movsd  0x18(%r15,%rbp,4),%xmm0
movsd  0x18(%r12,%rbp,4),%xmm1
movsd  0x18(%r13,%rbp,4),%xmm2
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
call   1060 <addEnd@plt>
mov    %rbx,%rdi
call   1090 <gridArea@plt>
movsd  %xmm0,(%r14,%rbp,1)
add    $0x8,%rbp
cmp    $0x20,%rbp
jne    11e0 <get_grid_great_circle_area_ug+0x70>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.Node = type { i32 }
define void @get_grid_great_circle_area_ug(i32* %0, double* %1, double* %2, double* %3) {
%5 = alloca i32*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [20 x double]
%17 = alloca [20 x double]
%18 = alloca [20 x double]
%19 = alloca %struct.Node*
%20 = alloca double*
%21 = alloca double*
%22 = alloca double*
store i32* %0, i32** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
store %struct.Node* null, %struct.Node** %19
store double* null, double** %20
store double* null, double** %21
store double* null, double** %22
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
store i32 %24, i32* %10
store i32 4, i32* %11
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = mul nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 8
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to double*
store double* %32, double** %20
%33 = load i32, i32* %10
%34 = load i32, i32* %11
%35 = mul nsw i32 %33, %34
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 8
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to double*
store double* %40, double** %21
%41 = load i32, i32* %10
%42 = load i32, i32* %11
%43 = mul nsw i32 %41, %42
%44 = sext i32 %43 to i64
%45 = mul i64 %44, 8
%46 = trunc i64 %45 to i32
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to double*
store double* %48, double** %22
%49 = load i32, i32* %10
%50 = load i32, i32* %11
%51 = mul nsw i32 %49, %50
%52 = load double*, double** %6
%53 = load double*, double** %7
%54 = load double*, double** %20
%55 = load double*, double** %21
%56 = load double*, double** %22
%57 = call i32 @latlon2xyz(i32 %51, double* %52, double* %53, double* %54, double* %55, double* %56)
store i32 0, i32* %9
br label %58
58: ; preds = %154, %4
%59 = load i32, i32* %9
%60 = load i32, i32* %11
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %157
62: ; preds = %58
%63 = load i32, i32* %9
%64 = load i32, i32* %11
%65 = mul nsw i32 %63, %64
store i32 %65, i32* %12
%66 = load i32, i32* %9
%67 = load i32, i32* %11
%68 = mul nsw i32 %66, %67
%69 = add nsw i32 %68, 1
store i32 %69, i32* %13
%70 = load i32, i32* %9
%71 = load i32, i32* %11
%72 = mul nsw i32 %70, %71
%73 = add nsw i32 %72, 2
store i32 %73, i32* %14
%74 = load i32, i32* %9
%75 = load i32, i32* %11
%76 = mul nsw i32 %74, %75
%77 = add nsw i32 %76, 3
store i32 %77, i32* %15
%78 = call i32 (...) @rewindList()
%79 = call %struct.Node* (...) @getNext()
store %struct.Node* %79, %struct.Node** %19
%80 = load %struct.Node*, %struct.Node** %19
%81 = load double*, double** %20
%82 = load i32, i32* %12
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double, double* %81, i64 %83
%85 = load double, double* %84
%86 = load double*, double** %21
%87 = load i32, i32* %12
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %86, i64 %88
%90 = load double, double* %89
%91 = load double*, double** %22
%92 = load i32, i32* %12
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds double, double* %91, i64 %93
%95 = load double, double* %94
%96 = call i32 @addEnd(%struct.Node* %80, double %85, double %90, double %95, i32 0, i32 0, i32 0, i32 -1)
%97 = load %struct.Node*, %struct.Node** %19
%98 = load double*, double** %20
%99 = load i32, i32* %13
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds double, double* %98, i64 %100
%102 = load double, double* %101
%103 = load double*, double** %21
%104 = load i32, i32* %13
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds double, double* %103, i64 %105
%107 = load double, double* %106
%108 = load double*, double** %22
%109 = load i32, i32* %13
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds double, double* %108, i64 %110
%112 = load double, double* %111
%113 = call i32 @addEnd(%struct.Node* %97, double %102, double %107, double %112, i32 0, i32 0, i32 0, i32 -1)
%114 = load %struct.Node*, %struct.Node** %19
%115 = load double*, double** %20
%116 = load i32, i32* %14
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds double, double* %115, i64 %117
%119 = load double, double* %118
%120 = load double*, double** %21
%121 = load i32, i32* %14
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds double, double* %120, i64 %122
%124 = load double, double* %123
%125 = load double*, double** %22
%126 = load i32, i32* %14
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds double, double* %125, i64 %127
%129 = load double, double* %128
%130 = call i32 @addEnd(%struct.Node* %114, double %119, double %124, double %129, i32 0, i32 0, i32 0, i32 -1)
%131 = load %struct.Node*, %struct.Node** %19
%132 = load double*, double** %20
%133 = load i32, i32* %15
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds double, double* %132, i64 %134
%136 = load double, double* %135
%137 = load double*, double** %21
%138 = load i32, i32* %15
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds double, double* %137, i64 %139
%141 = load double, double* %140
%142 = load double*, double** %22
%143 = load i32, i32* %15
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds double, double* %142, i64 %144
%146 = load double, double* %145
%147 = call i32 @addEnd(%struct.Node* %131, double %136, double %141, double %146, i32 0, i32 0, i32 0, i32 -1)
%148 = load %struct.Node*, %struct.Node** %19
%149 = call double @gridArea(%struct.Node* %148)
%150 = load double*, double** %8
%151 = load i32, i32* %9
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds double, double* %150, i64 %152
store double %149, double* %153
br label %154
154: ; preds = %62
%155 = load i32, i32* %9
%156 = add nsw i32 %155, 1
store i32 %156, i32* %9
br label %58
157: ; preds = %58
%158 = load double*, double** %20
%159 = call i32 @free(double* %158)
%160 = load double*, double** %21
%161 = call i32 @free(double* %160)
%162 = load double*, double** %22
%163 = call i32 @free(double* %162)
ret void
}

LLVM IR (-O2):
%struct.Node = type { i32 }
define void @get_grid_great_circle_area_ug(i32* nocapture %0, double* %1, double* %2, double* nocapture writeonly %3) {
%5 = load i32, i32* %0
%6 = shl nsw i32 %5, 2
%7 = shl i32 %5, 5
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = tail call i64 @malloc(i32 %7)
%11 = inttoptr i64 %10 to double*
%12 = tail call i64 @malloc(i32 %7)
%13 = inttoptr i64 %12 to double*
%14 = tail call i32 @latlon2xyz(i32 %6, double* %1, double* %2, double* %9, double* %11, double* %13)
br label %15
15: ; preds = %4, %15
%16 = phi i64 [ 0, %4 ], [ %53, %15 ]
%17 = shl nuw nsw i64 %16, 2
%18 = or i64 %17, 1
%19 = or i64 %17, 2
%20 = or i64 %17, 3
%21 = tail call i32 (...) @rewindList()
%22 = tail call %struct.Node* (...) @getNext()
%23 = getelementptr inbounds double, double* %9, i64 %17
%24 = load double, double* %23
%25 = getelementptr inbounds double, double* %11, i64 %17
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %13, i64 %17
%28 = load double, double* %27
%29 = tail call i32 @addEnd(%struct.Node* %22, double %24, double %26, double %28, i32 0, i32 0, i32 0, i32 -1)
%30 = getelementptr inbounds double, double* %9, i64 %18
%31 = load double, double* %30
%32 = getelementptr inbounds double, double* %11, i64 %18
%33 = load double, double* %32
%34 = getelementptr inbounds double, double* %13, i64 %18
%35 = load double, double* %34
%36 = tail call i32 @addEnd(%struct.Node* %22, double %31, double %33, double %35, i32 0, i32 0, i32 0, i32 -1)
%37 = getelementptr inbounds double, double* %9, i64 %19
%38 = load double, double* %37
%39 = getelementptr inbounds double, double* %11, i64 %19
%40 = load double, double* %39
%41 = getelementptr inbounds double, double* %13, i64 %19
%42 = load double, double* %41
%43 = tail call i32 @addEnd(%struct.Node* %22, double %38, double %40, double %42, i32 0, i32 0, i32 0, i32 -1)
%44 = getelementptr inbounds double, double* %9, i64 %20
%45 = load double, double* %44
%46 = getelementptr inbounds double, double* %11, i64 %20
%47 = load double, double* %46
%48 = getelementptr inbounds double, double* %13, i64 %20
%49 = load double, double* %48
%50 = tail call i32 @addEnd(%struct.Node* %22, double %45, double %47, double %49, i32 0, i32 0, i32 0, i32 -1)
%51 = tail call double @gridArea(%struct.Node* %22)
%52 = getelementptr inbounds double, double* %3, i64 %16
store double %51, double* %52
%53 = add nuw nsw i64 %16, 1
%54 = icmp eq i64 %53, 4
br i1 %54, label %55, label %15
55: ; preds = %15
%56 = tail call i32 @free(double* %9)
%57 = tail call i32 @free(double* %11)
%58 = tail call i32 @free(double* %13)
ret void
}