#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 atan2(double, double);
int /*<<< orphan*/ sph2rec(double, double, double *);
double sqrt(double);
void sphdist(double lon1, double lat1, double lon2, double lat2,
             double *sdist) {
  double v1[3], v2[3];
  double d, xc, yc, zc, sn;
  sph2rec(lon1, lat1, v1);
  sph2rec(lon2, lat2, v2);
  d = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
  xc = v1[1] * v2[2] - v1[2] * v2[1];
  yc = v1[2] * v2[0] - v1[0] * v2[2];
  zc = v1[0] * v2[1] - v1[1] * v2[0];
  sn = sqrt(xc * xc + yc * yc + zc * zc);
  *sdist = atan2(sn, d);
}


x86 assembly (clang, -O0):
<sphdist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    -0x40(%rbp),%rdi
call   1030 <sph2rec@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    -0x60(%rbp),%rdi
call   1030 <sph2rec@plt>
movsd  -0x40(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x70(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
movsd  -0x78(%rbp),%xmm0
mulsd  -0x78(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
movsd  -0x80(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x68(%rbp),%xmm1
call   1040 <atan2@plt>
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sphdist>:
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
movsd  %xmm3,(%rsp)
movsd  %xmm2,0x8(%rsp)
lea    0x30(%rsp),%rdi
call   1030 <sph2rec@plt>
lea    0x10(%rsp),%rdi
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1030 <sph2rec@plt>
movsd  0x30(%rsp),%xmm0
movsd  0x38(%rsp),%xmm2
movsd  0x10(%rsp),%xmm3
movsd  0x18(%rsp),%xmm8
movapd %xmm0,%xmm4
mulsd  %xmm3,%xmm4
movsd  0x40(%rsp),%xmm5
movapd %xmm5,%xmm1
movapd %xmm8,%xmm6
mulsd  %xmm5,%xmm6
movapd %xmm2,%xmm7
mulsd  %xmm3,%xmm5
mulsd  %xmm2,%xmm3
mulsd  %xmm8,%xmm2
addsd  %xmm2,%xmm4
movsd  0x20(%rsp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm2,%xmm7
subsd  %xmm6,%xmm7
mulsd  %xmm0,%xmm2
subsd  %xmm2,%xmm5
mulsd  %xmm8,%xmm0
subsd  %xmm3,%xmm0
mulsd  %xmm5,%xmm5
mulsd  %xmm7,%xmm7
addsd  %xmm5,%xmm7
mulsd  %xmm0,%xmm0
addsd  %xmm7,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     11f6 <sphdist+0xc6>
sqrtsd %xmm0,%xmm0
jmp    1205 <sphdist+0xd5>
movsd  %xmm1,(%rsp)
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm1
call   1040 <atan2@plt>
movsd  %xmm0,(%rbx)
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @sphdist(double %0, double %1, double %2, double %3, double* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double*
%11 = alloca [3 x double]
%12 = alloca [3 x double]
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double* %4, double** %10
%18 = load double, double* %6
%19 = load double, double* %7
%20 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 0
%21 = call i32 @sph2rec(double %18, double %19, double* %20)
%22 = load double, double* %8
%23 = load double, double* %9
%24 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%25 = call i32 @sph2rec(double %22, double %23, double* %24)
%26 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 0
%27 = load double, double* %26
%28 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%29 = load double, double* %28
%30 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 1
%31 = load double, double* %30
%32 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%33 = load double, double* %32
%34 = fmul double %31, %33
%35 = call double @llvm.fmuladd.f64(double %27, double %29, double %34)
%36 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 2
%37 = load double, double* %36
%38 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%39 = load double, double* %38
%40 = call double @llvm.fmuladd.f64(double %37, double %39, double %35)
store double %40, double* %13
%41 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 1
%42 = load double, double* %41
%43 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%44 = load double, double* %43
%45 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 2
%46 = load double, double* %45
%47 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%48 = load double, double* %47
%49 = fmul double %46, %48
%50 = fneg double %49
%51 = call double @llvm.fmuladd.f64(double %42, double %44, double %50)
store double %51, double* %14
%52 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 2
%53 = load double, double* %52
%54 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%55 = load double, double* %54
%56 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 0
%57 = load double, double* %56
%58 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%59 = load double, double* %58
%60 = fmul double %57, %59
%61 = fneg double %60
%62 = call double @llvm.fmuladd.f64(double %53, double %55, double %61)
store double %62, double* %15
%63 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 0
%64 = load double, double* %63
%65 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%66 = load double, double* %65
%67 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 1
%68 = load double, double* %67
%69 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%70 = load double, double* %69
%71 = fmul double %68, %70
%72 = fneg double %71
%73 = call double @llvm.fmuladd.f64(double %64, double %66, double %72)
store double %73, double* %16
%74 = load double, double* %14
%75 = load double, double* %14
%76 = load double, double* %15
%77 = load double, double* %15
%78 = fmul double %76, %77
%79 = call double @llvm.fmuladd.f64(double %74, double %75, double %78)
%80 = load double, double* %16
%81 = load double, double* %16
%82 = call double @llvm.fmuladd.f64(double %80, double %81, double %79)
%83 = call double @sqrt(double %82)
store double %83, double* %17
%84 = load double, double* %17
%85 = load double, double* %13
%86 = call double @atan2(double %84, double %85)
%87 = load double*, double** %10
store double %86, double* %87
ret void
}

LLVM IR (-O2):
define void @sphdist(double %0, double %1, double %2, double %3, double* nocapture writeonly %4) {
%6 = alloca [3 x double]
%7 = alloca [3 x double]
%8 = bitcast [3 x double]* %6 to i8*
%9 = bitcast [3 x double]* %7 to i8*
%10 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%11 = call i32 @sph2rec(double %0, double %1, double* %10)
%12 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%13 = call i32 @sph2rec(double %2, double %3, double* %12)
%14 = load double, double* %10
%15 = load double, double* %12
%16 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 1
%17 = load double, double* %16
%18 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 1
%19 = load double, double* %18
%20 = fmul double %17, %19
%21 = call double @llvm.fmuladd.f64(double %14, double %15, double %20)
%22 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 2
%23 = load double, double* %22
%24 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 2
%25 = load double, double* %24
%26 = call double @llvm.fmuladd.f64(double %23, double %25, double %21)
%27 = fneg double %23
%28 = fmul double %19, %27
%29 = call double @llvm.fmuladd.f64(double %17, double %25, double %28)
%30 = fneg double %14
%31 = fmul double %25, %30
%32 = call double @llvm.fmuladd.f64(double %23, double %15, double %31)
%33 = fneg double %17
%34 = fmul double %15, %33
%35 = call double @llvm.fmuladd.f64(double %14, double %19, double %34)
%36 = fmul double %32, %32
%37 = call double @llvm.fmuladd.f64(double %29, double %29, double %36)
%38 = call double @llvm.fmuladd.f64(double %35, double %35, double %37)
%39 = call double @sqrt(double %38)
%40 = call double @atan2(double %39, double %26)
store double %40, double* %4
ret void
}