#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 GCDistance(double, double, double, double);
double Dist3D2_Loc2ssst(double x1, double x2, double y1, double y2, double z1,
                        double z2, int latlon) {
  if (latlon) {
    double hdist = GCDistance(y1, x1, y2, x2);
    double dz = z1 - z2;
    return (hdist * hdist + dz * dz);
  } else {
    double dx, dy, dz;
    dx = x1 - x2;
    dy = y1 - y2;
    dz = z1 - z2;
    return (dx * dx + dy * dy + dz * dz);
  }
}


x86 assembly (clang, -O0):
<Dist3D2_Loc2ssst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
movsd  %xmm5,-0x38(%rbp)
mov    %edi,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1196 <Dist3D2_Loc2ssst+0x86>
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
call   1030 <GCDistance@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f6 <Dist3D2_Loc2ssst+0xe6>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Dist3D2_Loc2ssst>:
movapd %xmm1,%xmm6
movapd %xmm0,%xmm1
test   %edi,%edi
je     1159 <Dist3D2_Loc2ssst+0x49>
sub    $0x18,%rsp
movapd %xmm2,%xmm0
movaps %xmm3,%xmm2
movapd %xmm6,%xmm3
movsd  %xmm4,0x8(%rsp)
movsd  %xmm5,0x10(%rsp)
call   1030 <GCDistance@plt>
movsd  0x8(%rsp),%xmm1
subsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret
subsd  %xmm6,%xmm1
subsd  %xmm3,%xmm2
subsd  %xmm5,%xmm4
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm4,%xmm4
addsd  %xmm1,%xmm4
movapd %xmm4,%xmm0
ret

LLVM IR (-O0):
define double @Dist3D2_Loc2ssst(double %0, double %1, double %2, double %3, double %4, double %5, i32 %6) {
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
store double %0, double* %9
store double %1, double* %10
store double %2, double* %11
store double %3, double* %12
store double %4, double* %13
store double %5, double* %14
store i32 %6, i32* %15
%21 = load i32, i32* %15
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %38
23: ; preds = %7
%24 = load double, double* %11
%25 = load double, double* %9
%26 = load double, double* %12
%27 = load double, double* %10
%28 = call double @GCDistance(double %24, double %25, double %26, double %27)
store double %28, double* %16
%29 = load double, double* %13
%30 = load double, double* %14
%31 = fsub double %29, %30
store double %31, double* %17
%32 = load double, double* %16
%33 = load double, double* %16
%34 = load double, double* %17
%35 = load double, double* %17
%36 = fmul double %34, %35
%37 = call double @llvm.fmuladd.f64(double %32, double %33, double %36)
store double %37, double* %8
br label %57
38: ; preds = %7
%39 = load double, double* %9
%40 = load double, double* %10
%41 = fsub double %39, %40
store double %41, double* %18
%42 = load double, double* %11
%43 = load double, double* %12
%44 = fsub double %42, %43
store double %44, double* %19
%45 = load double, double* %13
%46 = load double, double* %14
%47 = fsub double %45, %46
store double %47, double* %20
%48 = load double, double* %18
%49 = load double, double* %18
%50 = load double, double* %19
%51 = load double, double* %19
%52 = fmul double %50, %51
%53 = call double @llvm.fmuladd.f64(double %48, double %49, double %52)
%54 = load double, double* %20
%55 = load double, double* %20
%56 = call double @llvm.fmuladd.f64(double %54, double %55, double %53)
store double %56, double* %8
br label %57
57: ; preds = %38, %23
%58 = load double, double* %8
ret double %58
}

LLVM IR (-O2):
define double @Dist3D2_Loc2ssst(double %0, double %1, double %2, double %3, double %4, double %5, i32 %6) {
%8 = icmp eq i32 %6, 0
br i1 %8, label %14, label %9
9: ; preds = %7
%10 = tail call double @GCDistance(double %2, double %0, double %3, double %1)
%11 = fsub double %4, %5
%12 = fmul double %11, %11
%13 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %12)
br label %21
14: ; preds = %7
%15 = fsub double %0, %1
%16 = fsub double %2, %3
%17 = fsub double %4, %5
%18 = fmul double %16, %16
%19 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %18)
%20 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %19)
br label %21
21: ; preds = %14, %9
%22 = phi double [ %13, %9 ], [ %20, %14 ]
ret double %22
}