MAG_EquivalentLatLon(double lat, double lon, double *repairedLat,
                     double *repairedLon) {
  double colat;
  colat = 90 - lat;
  *repairedLon = lon;
  if (colat < 0)
    colat = -colat;
  while (colat > 360) {
    colat -= 360;
  }
  if (colat > 180) {
    colat -= 180;
    *repairedLon = *repairedLon + 180;
  }
  *repairedLat = 90 - colat;
  if (*repairedLon > 360)
    *repairedLon -= 360;
  if (*repairedLon < -180)
    *repairedLon += 360;
}


x86 assembly (clang, -O0):
<MAG_EquivalentLatLon>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
movsd  0xee2(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1164 <MAG_EquivalentLatLon+0x64>
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1169 <MAG_EquivalentLatLon+0x69>
movsd  -0x30(%rbp),%xmm0
movsd  0xe92(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119b <MAG_EquivalentLatLon+0x9b>
movsd  -0x30(%rbp),%xmm0
movsd  0xe7b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1169 <MAG_EquivalentLatLon+0x69>
movsd  -0x30(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e0 <MAG_EquivalentLatLon+0xe0>
movsd  -0x30(%rbp),%xmm0
movsd  0xe51(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsd  0xe3c(%rip),%xmm0
addsd  (%rax),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xe18(%rip),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe03(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1227 <MAG_EquivalentLatLon+0x127>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xde9(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  0xde5(%rip),%xmm0
ucomisd (%rax),%xmm0
jbe    1251 <MAG_EquivalentLatLon+0x151>
mov    -0x28(%rbp),%rax
movsd  0xdbf(%rip),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<MAG_EquivalentLatLon>:
movsd  0xef8(%rip),%xmm2
movapd %xmm2,%xmm3
subsd  %xmm0,%xmm3
movsd  %xmm1,(%rsi)
movapd 0xf14(%rip),%xmm4
xorpd  %xmm3,%xmm4
xorpd  %xmm5,%xmm5
movapd %xmm3,%xmm0
cmpltsd %xmm5,%xmm0
andpd  %xmm0,%xmm4
andnpd %xmm3,%xmm0
orpd   %xmm4,%xmm0
ucomisd 0xec7(%rip),%xmm0
jbe    116a <MAG_EquivalentLatLon+0x6a>
movsd  0xec5(%rip),%xmm3
movsd  0xeb5(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  %xmm3,%xmm0
ucomisd %xmm4,%xmm0
ja     1160 <MAG_EquivalentLatLon+0x60>
ucomisd 0xea6(%rip),%xmm0
jbe    1188 <MAG_EquivalentLatLon+0x88>
addsd  0xea4(%rip),%xmm0
addsd  0xe94(%rip),%xmm1
movsd  %xmm1,(%rsi)
subsd  %xmm0,%xmm2
movsd  %xmm2,(%rdi)
movsd  (%rsi),%xmm1
movsd  0xe6c(%rip),%xmm0
ucomisd %xmm0,%xmm1
movsd  0xe68(%rip),%xmm2
addsd  %xmm1,%xmm2
cmpltsd %xmm1,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
ja     11ce <MAG_EquivalentLatLon+0xce>
movsd  0xe59(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     11ce <MAG_EquivalentLatLon+0xce>
ret
movsd  0xe32(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
cmpltsd 0xe39(%rip),%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movlpd %xmm2,(%rsi)
ret

LLVM IR (-O0):
define i32 @MAG_EquivalentLatLon(double %0, double %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca double*
%10 = alloca double
store double %0, double* %6
store double %1, double* %7
store double* %2, double** %8
store double* %3, double** %9
%11 = load double, double* %6
%12 = fsub double 9.000000e+01, %11
store double %12, double* %10
%13 = load double, double* %7
%14 = load double*, double** %9
store double %13, double* %14
%15 = load double, double* %10
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = load double, double* %10
%19 = fneg double %18
store double %19, double* %10
br label %20
20: ; preds = %17, %4
br label %21
21: ; preds = %24, %20
%22 = load double, double* %10
%23 = fcmp ogt double %22, 3.600000e+02
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load double, double* %10
%26 = fsub double %25, 3.600000e+02
store double %26, double* %10
br label %21
27: ; preds = %21
%28 = load double, double* %10
%29 = fcmp ogt double %28, 1.800000e+02
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load double, double* %10
%32 = fsub double %31, 1.800000e+02
store double %32, double* %10
%33 = load double*, double** %9
%34 = load double, double* %33
%35 = fadd double %34, 1.800000e+02
%36 = load double*, double** %9
store double %35, double* %36
br label %37
37: ; preds = %30, %27
%38 = load double, double* %10
%39 = fsub double 9.000000e+01, %38
%40 = load double*, double** %8
store double %39, double* %40
%41 = load double*, double** %9
%42 = load double, double* %41
%43 = fcmp ogt double %42, 3.600000e+02
br i1 %43, label %44, label %48
44: ; preds = %37
%45 = load double*, double** %9
%46 = load double, double* %45
%47 = fsub double %46, 3.600000e+02
store double %47, double* %45
br label %48
48: ; preds = %44, %37
%49 = load double*, double** %9
%50 = load double, double* %49
%51 = fcmp olt double %50, -1.800000e+02
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load double*, double** %9
%54 = load double, double* %53
%55 = fadd double %54, 3.600000e+02
store double %55, double* %53
br label %56
56: ; preds = %52, %48
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
define i32 @MAG_EquivalentLatLon(double %0, double %1, double* nocapture writeonly %2, double* nocapture %3) {
%5 = fsub double 9.000000e+01, %0
store double %1, double* %3
%6 = fcmp olt double %5, 0.000000e+00
%7 = fneg double %5
%8 = select i1 %6, double %7, double %5
%9 = fcmp ogt double %8, 3.600000e+02
br i1 %9, label %10, label %14
10: ; preds = %4, %10
%11 = phi double [ %12, %10 ], [ %8, %4 ]
%12 = fadd double %11, -3.600000e+02
%13 = fcmp ogt double %12, 3.600000e+02
br i1 %13, label %10, label %14
14: ; preds = %10, %4
%15 = phi double [ %8, %4 ], [ %12, %10 ]
%16 = fcmp ogt double %15, 1.800000e+02
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = fadd double %15, -1.800000e+02
%19 = fadd double %1, 1.800000e+02
store double %19, double* %3
br label %20
20: ; preds = %17, %14
%21 = phi double [ %18, %17 ], [ %15, %14 ]
%22 = fsub double 9.000000e+01, %21
store double %22, double* %2
%23 = load double, double* %3
%24 = fcmp ogt double %23, 3.600000e+02
%25 = fadd double %23, -3.600000e+02
%26 = select i1 %24, double %25, double %23
%27 = fcmp olt double %26, -1.800000e+02
%28 = or i1 %24, %27
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = fadd double %26, 3.600000e+02
%31 = select i1 %27, double %30, double %26
store double %31, double* %3
br label %32
32: ; preds = %20, %29
ret i32 undef
}