void geo_to_rectangular(double r[3], double lat, double lon, double Ae2,
                        double Be2) {
  double phi, phig, lam, sin_phig, cos_phig, Re;
  if (90 == lat) {
    r[0] = r[1] = 0;
    r[2] = sqrt(Be2);
    return;
  } else if (-90 == lat) {
    r[0] = r[1] = 0;
    r[2] = -sqrt(Be2);
    return;
  }
  assert(-90 < lat && lat < 90);
  phi = ((lat)*3.141592653589793 / 180.0);
  lam = ((lon)*3.141592653589793 / 180.0);
  phig = atan(Be2 / Ae2 * tan(phi));
  sin_phig = sin(phig);
  cos_phig = cos(phig);
  Re = ellipsoid_radius(sin_phig, cos_phig, Ae2, Be2);
  r[0] = Re * cos_phig * cos(lam);
  r[1] = Re * cos_phig * sin(lam);
  r[2] = Re * sin_phig;
}


x86 assembly (clang, -O0):
<geo_to_rectangular>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  0xe65(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11db <geo_to_rectangular+0x6b>
jp     11db <geo_to_rectangular+0x6b>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
call   1090 <sqrt@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
jmp    1398 <geo_to_rectangular+0x228>
movsd  0xe25(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    123a <geo_to_rectangular+0xca>
jp     123a <geo_to_rectangular+0xca>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
call   1090 <sqrt@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
jmp    1398 <geo_to_rectangular+0x228>
jmp    123f <geo_to_rectangular+0xcf>
movsd  -0x10(%rbp),%xmm0
xor    %eax,%eax
movsd  0xdba(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x59(%rbp)
jbe    126e <geo_to_rectangular+0xfe>
movsd  0xd9d(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
seta   %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <assert@plt>
movsd  0xd93(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xd7e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd75(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xd60(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1070 <tan@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <atan@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1080 <cos@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
mov    $0x4,%al
call   1030 <ellipsoid_radius@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1080 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geo_to_rectangular>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
ucomisd 0xe80(%rip),%xmm0
jne    11a2 <geo_to_rectangular+0x32>
jp     11a2 <geo_to_rectangular+0x32>
xorpd  %xmm0,%xmm0
movupd %xmm0,(%rbx)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jb     11d0 <geo_to_rectangular+0x60>
xorps  %xmm0,%xmm0
sqrtsd %xmm3,%xmm0
jmp    1301 <geo_to_rectangular+0x191>
ucomisd 0xe5e(%rip),%xmm0
jne    11de <geo_to_rectangular+0x6e>
jp     11de <geo_to_rectangular+0x6e>
xorpd  %xmm0,%xmm0
movupd %xmm0,(%rbx)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jb     12f0 <geo_to_rectangular+0x180>
xorps  %xmm0,%xmm0
sqrtsd %xmm3,%xmm0
jmp    12f9 <geo_to_rectangular+0x189>
movapd %xmm3,%xmm0
call   1090 <sqrt@plt>
jmp    1301 <geo_to_rectangular+0x191>
seta   %al
movsd  0xe17(%rip),%xmm4
ucomisd %xmm0,%xmm4
seta   %cl
and    %al,%cl
movzbl %cl,%edi
xor    %eax,%eax
movsd  %xmm3,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,0x18(%rsp)
movsd  %xmm0,(%rsp)
call   1040 <assert@plt>
movsd  0xdf5(%rip),%xmm3
movsd  (%rsp),%xmm0
mulsd  %xmm3,%xmm0
movsd  0xdec(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm2
mulsd  %xmm3,%xmm2
divsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
divsd  0x18(%rsp),%xmm1
movsd  %xmm1,(%rsp)
call   1070 <tan@plt>
mulsd  (%rsp),%xmm0
call   1060 <atan@plt>
movsd  %xmm0,(%rsp)
call   1050 <sin@plt>
movapd %xmm0,0x20(%rsp)
movsd  (%rsp),%xmm0
call   1080 <cos@plt>
movaps %xmm0,%xmm1
movsd  %xmm0,(%rsp)
movaps 0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm2
movsd  0x8(%rsp),%xmm3
mov    $0x4,%al
call   1030 <ellipsoid_radius@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1080 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx)
movsd  0x10(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rbx)
movapd 0x20(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
jmp    1301 <geo_to_rectangular+0x191>
movapd %xmm3,%xmm0
call   1090 <sqrt@plt>
xorpd  0xd1f(%rip),%xmm0
movsd  %xmm0,0x10(%rbx)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @geo_to_rectangular(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 double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = 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
%17 = load double, double* %7
%18 = fcmp oeq double 9.000000e+01, %17
br i1 %18, label %19, label %28
19: ; preds = %5
%20 = load double*, double** %6
%21 = getelementptr inbounds double, double* %20, i64 1
store double 0.000000e+00, double* %21
%22 = load double*, double** %6
%23 = getelementptr inbounds double, double* %22, i64 0
store double 0.000000e+00, double* %23
%24 = load double, double* %10
%25 = call double @sqrt(double %24)
%26 = load double*, double** %6
%27 = getelementptr inbounds double, double* %26, i64 2
store double %25, double* %27
br label %96
28: ; preds = %5
%29 = load double, double* %7
%30 = fcmp oeq double -9.000000e+01, %29
br i1 %30, label %31, label %41
31: ; preds = %28
%32 = load double*, double** %6
%33 = getelementptr inbounds double, double* %32, i64 1
store double 0.000000e+00, double* %33
%34 = load double*, double** %6
%35 = getelementptr inbounds double, double* %34, i64 0
store double 0.000000e+00, double* %35
%36 = load double, double* %10
%37 = call double @sqrt(double %36)
%38 = fneg double %37
%39 = load double*, double** %6
%40 = getelementptr inbounds double, double* %39, i64 2
store double %38, double* %40
br label %96
41: ; preds = %28
br label %42
42: ; preds = %41
%43 = load double, double* %7
%44 = fcmp olt double -9.000000e+01, %43
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load double, double* %7
%47 = fcmp olt double %46, 9.000000e+01
br label %48
48: ; preds = %45, %42
%49 = phi i1 [ false, %42 ], [ %47, %45 ]
%50 = zext i1 %49 to i32
%51 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %50)
%52 = load double, double* %7
%53 = fmul double %52, 0x400921FB54442D18
%54 = fdiv double %53, 1.800000e+02
store double %54, double* %11
%55 = load double, double* %8
%56 = fmul double %55, 0x400921FB54442D18
%57 = fdiv double %56, 1.800000e+02
store double %57, double* %13
%58 = load double, double* %10
%59 = load double, double* %9
%60 = fdiv double %58, %59
%61 = load double, double* %11
%62 = call double @tan(double %61)
%63 = fmul double %60, %62
%64 = call double @atan(double %63)
store double %64, double* %12
%65 = load double, double* %12
%66 = call double @sin(double %65)
store double %66, double* %14
%67 = load double, double* %12
%68 = call double @cos(double %67)
store double %68, double* %15
%69 = load double, double* %14
%70 = load double, double* %15
%71 = load double, double* %9
%72 = load double, double* %10
%73 = call i32 (double, double, double, double, ...) bitcast (i32 (...)* @ellipsoid_radius to i32 (double, double, double, double, ...)*)(double %69, double %70, double %71, double %72)
%74 = sitofp i32 %73 to double
store double %74, double* %16
%75 = load double, double* %16
%76 = load double, double* %15
%77 = fmul double %75, %76
%78 = load double, double* %13
%79 = call double @cos(double %78)
%80 = fmul double %77, %79
%81 = load double*, double** %6
%82 = getelementptr inbounds double, double* %81, i64 0
store double %80, double* %82
%83 = load double, double* %16
%84 = load double, double* %15
%85 = fmul double %83, %84
%86 = load double, double* %13
%87 = call double @sin(double %86)
%88 = fmul double %85, %87
%89 = load double*, double** %6
%90 = getelementptr inbounds double, double* %89, i64 1
store double %88, double* %90
%91 = load double, double* %16
%92 = load double, double* %14
%93 = fmul double %91, %92
%94 = load double*, double** %6
%95 = getelementptr inbounds double, double* %94, i64 2
store double %93, double* %95
br label %96
96: ; preds = %48, %31, %19
ret void
}

LLVM IR (-O2):
define void @geo_to_rectangular(double* nocapture writeonly %0, double %1, double %2, double %3, double %4) {
%6 = fcmp oeq double %1, 9.000000e+01
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = bitcast double* %0 to i8*
%9 = tail call double @sqrt(double %4)
br label %41
10: ; preds = %5
%11 = fcmp oeq double %1, -9.000000e+01
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = bitcast double* %0 to i8*
%14 = tail call double @sqrt(double %4)
%15 = fneg double %14
br label %41
16: ; preds = %10
%17 = fcmp ogt double %1, -9.000000e+01
%18 = fcmp olt double %1, 9.000000e+01
%19 = and i1 %17, %18
%20 = zext i1 %19 to i32
%21 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %20)
%22 = fmul double %1, 0x400921FB54442D18
%23 = fdiv double %22, 1.800000e+02
%24 = fmul double %2, 0x400921FB54442D18
%25 = fdiv double %24, 1.800000e+02
%26 = fdiv double %4, %3
%27 = tail call double @tan(double %23)
%28 = fmul double %26, %27
%29 = tail call double @atan(double %28)
%30 = tail call double @sin(double %29)
%31 = tail call double @cos(double %29)
%32 = tail call i32 (double, double, double, double, ...) bitcast (i32 (...)* @ellipsoid_radius to i32 (double, double, double, double, ...)*)(double %30, double %31, double %3, double %4)
%33 = sitofp i32 %32 to double
%34 = fmul double %31, %33
%35 = tail call double @cos(double %25)
%36 = fmul double %35, %34
store double %36, double* %0
%37 = tail call double @sin(double %25)
%38 = fmul double %34, %37
%39 = getelementptr inbounds double, double* %0, i64 1
store double %38, double* %39
%40 = fmul double %30, %33
br label %41
41: ; preds = %16, %12, %7
%42 = phi double [ %40, %16 ], [ %15, %12 ], [ %9, %7 ]
%43 = getelementptr inbounds double, double* %0, i64 2
store double %42, double* %43
ret void
}