double west_azimuth(double lat1, double lon1, double lat2, double lon2) {
  double phi1, phi2, dlam, sin_A, cos_A, A;
  phi1 = ((lat1)*3.141592653589793 / 180.0);
  phi2 = ((lat2)*3.141592653589793 / 180.0);
  dlam = ((lon1 - lon2) * 3.141592653589793 / 180.0);
  sin_A = cos(phi2) * sin(dlam);
  cos_A = cos(phi1) * sin(phi2) - sin(phi1) * cos(phi2) * cos(dlam);
  A = (cos_A != 0 ? atan2(sin_A, cos_A) : 0);
  return (double)((A)*180.0 / 3.141592653589793);
}


x86 assembly (clang, -O0):
<west_azimuth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  0xeb1(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  0xe9c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe93(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xe6b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe57(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1050 <cos@plt>
movsd  -0x68(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1285 <west_azimuth+0x155>
jp     1285 <west_azimuth+0x155>
jmp    129e <west_azimuth+0x16e>
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x80(%rbp)
jmp    12ab <west_azimuth+0x17b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    12ab <west_azimuth+0x17b>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xd43(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  0xd3e(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<west_azimuth>:
sub    $0x38,%rsp
movapd %xmm2,%xmm4
movsd  0xec0(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xebc(%rip),%xmm5
divsd  %xmm5,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm2,%xmm4
divsd  %xmm5,%xmm4
movsd  %xmm4,(%rsp)
subsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm2
divsd  %xmm5,%xmm2
movsd  %xmm2,0x10(%rsp)
movapd %xmm4,%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x30(%rsp)
movsd  (%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
movsd  0x28(%rsp),%xmm1
movsd  (%rsp),%xmm2
mulsd  0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm2
mulsd  0x30(%rsp),%xmm1
subsd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    120c <west_azimuth+0xdc>
jnp    1225 <west_azimuth+0xf5>
movsd  0x20(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm0
call   1030 <atan2@plt>
mulsd  0xde3(%rip),%xmm0
divsd  0xdd3(%rip),%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @west_azimuth(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%15 = load double, double* %5
%16 = fmul double %15, 0x400921FB54442D18
%17 = fdiv double %16, 1.800000e+02
store double %17, double* %9
%18 = load double, double* %7
%19 = fmul double %18, 0x400921FB54442D18
%20 = fdiv double %19, 1.800000e+02
store double %20, double* %10
%21 = load double, double* %6
%22 = load double, double* %8
%23 = fsub double %21, %22
%24 = fmul double %23, 0x400921FB54442D18
%25 = fdiv double %24, 1.800000e+02
store double %25, double* %11
%26 = load double, double* %10
%27 = call double @cos(double %26)
%28 = load double, double* %11
%29 = call double @sin(double %28)
%30 = fmul double %27, %29
store double %30, double* %12
%31 = load double, double* %9
%32 = call double @cos(double %31)
%33 = load double, double* %10
%34 = call double @sin(double %33)
%35 = load double, double* %9
%36 = call double @sin(double %35)
%37 = load double, double* %10
%38 = call double @cos(double %37)
%39 = fmul double %36, %38
%40 = load double, double* %11
%41 = call double @cos(double %40)
%42 = fmul double %39, %41
%43 = fneg double %42
%44 = call double @llvm.fmuladd.f64(double %32, double %34, double %43)
store double %44, double* %13
%45 = load double, double* %13
%46 = fcmp une double %45, 0.000000e+00
br i1 %46, label %47, label %51
47: ; preds = %4
%48 = load double, double* %12
%49 = load double, double* %13
%50 = call double @atan2(double %48, double %49)
br label %52
51: ; preds = %4
br label %52
52: ; preds = %51, %47
%53 = phi double [ %50, %47 ], [ 0.000000e+00, %51 ]
store double %53, double* %14
%54 = load double, double* %14
%55 = fmul double %54, 1.800000e+02
%56 = fdiv double %55, 0x400921FB54442D18
ret double %56
}

LLVM IR (-O2):
define double @west_azimuth(double %0, double %1, double %2, double %3) {
%5 = fmul double %0, 0x400921FB54442D18
%6 = fdiv double %5, 1.800000e+02
%7 = fmul double %2, 0x400921FB54442D18
%8 = fdiv double %7, 1.800000e+02
%9 = fsub double %1, %3
%10 = fmul double %9, 0x400921FB54442D18
%11 = fdiv double %10, 1.800000e+02
%12 = tail call double @cos(double %8)
%13 = tail call double @sin(double %11)
%14 = tail call double @cos(double %6)
%15 = tail call double @sin(double %8)
%16 = tail call double @sin(double %6)
%17 = tail call double @cos(double %8)
%18 = tail call double @cos(double %11)
%19 = fneg double %16
%20 = fmul double %17, %19
%21 = fmul double %20, %18
%22 = tail call double @llvm.fmuladd.f64(double %14, double %15, double %21)
%23 = fcmp une double %22, 0.000000e+00
br i1 %23, label %24, label %28
24: ; preds = %4
%25 = fmul double %12, %13
%26 = tail call double @atan2(double %25, double %22)
%27 = fmul double %26, 1.800000e+02
br label %28
28: ; preds = %4, %24
%29 = phi double [ %27, %24 ], [ 0.000000e+00, %4 ]
%30 = fdiv double %29, 0x400921FB54442D18
ret double %30
}