#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 */
int M_PI;
double acos(double);
double cos(double);
double fabs(double);
double fmod(double, int);
double sin(double);
double ortho_initial_angle(double latitude, double longitude,
                           double wp_latitude, double wp_longitude) {
  double g, d, a, den;
  g = fmod(wp_longitude - longitude, M_PI * 2);
  if (fabs(g) < 0.0000001) {
    den = wp_latitude - latitude;
    return (den > 0) ? 0 : M_PI;
  }
  if (g <= -M_PI) {
    g += M_PI * 2;
  } else if (g > M_PI) {
    g -= M_PI * 2;
  }
  d = acos(sin(wp_latitude) * sin(latitude) +
           cos(wp_latitude) * cos(latitude) * cos(g));
  den = cos(latitude) * sin(d);
  a = (sin(wp_latitude) - sin(latitude) * cos(d)) / den;
  if ((a > 1.0) || (a < -1.0)) {
    return (wp_latitude > latitude) ? 0 : M_PI;
  }
  if (g < 0) {
    return M_PI * 2 - acos(a);
  } else {
    return acos(a);
  }
}


x86 assembly (clang, -O0):
<ortho_initial_angle>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
shl    $0x1,%edi
call   1030 <fmod@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movaps 0xe95(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe69(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e9 <ortho_initial_angle+0xa9>
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11cc <ortho_initial_angle+0x8c>
xor    %eax,%eax
mov    %eax,-0x4c(%rbp)
jmp    11d8 <ortho_initial_angle+0x98>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    142d <ortho_initial_angle+0x2ed>
movsd  -0x30(%rbp),%xmm1
xor    %eax,%eax
mov    0x2df1(%rip),%rcx
sub    (%rcx),%eax
cvtsi2sd %eax,%xmm0
ucomisd %xmm1,%xmm0
jb     1226 <ortho_initial_angle+0xe6>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1263 <ortho_initial_angle+0x123>
movsd  -0x30(%rbp),%xmm0
mov    0x2db6(%rip),%rax
cvtsi2sdl (%rax),%xmm1
ucomisd %xmm1,%xmm0
jbe    125e <ortho_initial_angle+0x11e>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1263 <ortho_initial_angle+0x123>
movsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x10(%rbp),%xmm0
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <cos@plt>
movsd  -0x80(%rbp),%xmm1
movsd  -0x78(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <acos@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <cos@plt>
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xc90(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1395 <ortho_initial_angle+0x255>
movsd  0xc86(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    13d5 <ortho_initial_angle+0x295>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    13b2 <ortho_initial_angle+0x272>
xor    %eax,%eax
mov    %eax,-0x8c(%rbp)
jmp    13c1 <ortho_initial_angle+0x281>
mov    0x2c2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    142d <ortho_initial_angle+0x2ed>
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    141e <ortho_initial_angle+0x2de>
mov    0x2bfe(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
call   1040 <acos@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    142d <ortho_initial_angle+0x2ed>
movsd  -0x40(%rbp),%xmm0
call   1040 <acos@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ortho_initial_angle>:
push   %rbx
sub    $0x50,%rsp
movsd  %xmm2,(%rsp)
movaps %xmm0,0x20(%rsp)
subsd  %xmm1,%xmm3
mov    0x2e8e(%rip),%rbx
mov    (%rbx),%edi
add    %edi,%edi
movapd %xmm3,%xmm0
call   1030 <fmod@plt>
movapd %xmm0,%xmm2
movapd 0xe8d(%rip),%xmm0
andpd  %xmm2,%xmm0
movsd  0xe91(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11a5 <ortho_initial_angle+0x65>
xorps  %xmm0,%xmm0
cvtsi2sdl (%rbx),%xmm0
movsd  (%rsp),%xmm2
subsd  0x20(%rsp),%xmm2
xorpd  %xmm1,%xmm1
cmpltsd %xmm2,%xmm1
jmp    1324 <ortho_initial_angle+0x1e4>
mov    (%rbx),%eax
mov    %eax,%ecx
neg    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
ucomisd %xmm2,%xmm0
jae    11d9 <ortho_initial_angle+0x99>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd %xmm0,%xmm2
movsd  (%rsp),%xmm0
jbe    11eb <ortho_initial_angle+0xab>
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm2
jmp    11eb <ortho_initial_angle+0xab>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm2
movsd  (%rsp),%xmm0
movapd %xmm2,0x40(%rsp)
call   1050 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movaps 0x20(%rsp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movapd 0x20(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x40(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
addsd  %xmm1,%xmm0
call   1040 <acos@plt>
movsd  %xmm0,0x18(%rsp)
movaps 0x20(%rsp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movaps 0x20(%rsp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x38(%rsp)
movsd  0x18(%rsp),%xmm0
call   1060 <cos@plt>
movsd  0x8(%rsp),%xmm1
mulsd  0x38(%rsp),%xmm0
subsd  %xmm0,%xmm1
divsd  0x10(%rsp),%xmm1
ucomisd 0xd49(%rip),%xmm1
ja     1311 <ortho_initial_angle+0x1d1>
movsd  0xd47(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1311 <ortho_initial_angle+0x1d1>
xorpd  %xmm0,%xmm0
ucomisd 0x40(%rsp),%xmm0
jbe    1332 <ortho_initial_angle+0x1f2>
mov    (%rbx),%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd %xmm0,0x20(%rsp)
movapd %xmm1,%xmm0
call   1040 <acos@plt>
movapd 0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
jmp    1328 <ortho_initial_angle+0x1e8>
xorps  %xmm0,%xmm0
cvtsi2sdl (%rbx),%xmm0
movapd 0x20(%rsp),%xmm1
cmpltsd (%rsp),%xmm1
andnpd %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbx
ret
movapd %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbx
jmp    1040 <acos@plt>

LLVM IR (-O0):
@M_PI = global i32 0
define double @ortho_initial_angle(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
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%14 = load double, double* %9
%15 = load double, double* %7
%16 = fsub double %14, %15
%17 = load i32, i32* @M_PI
%18 = mul nsw i32 %17, 2
%19 = call double @fmod(double %16, i32 %18)
store double %19, double* %10
%20 = load double, double* %10
%21 = call double @llvm.fabs.f64(double %20)
%22 = fcmp olt double %21, 0x3E7AD7F29ABCAF48
br i1 %22, label %23, label %35
23: ; preds = %4
%24 = load double, double* %8
%25 = load double, double* %6
%26 = fsub double %24, %25
store double %26, double* %13
%27 = load double, double* %13
%28 = fcmp ogt double %27, 0.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %23
br label %32
30: ; preds = %23
%31 = load i32, i32* @M_PI
br label %32
32: ; preds = %30, %29
%33 = phi i32 [ 0, %29 ], [ %31, %30 ]
%34 = sitofp i32 %33 to double
store double %34, double* %5
br label %117
35: ; preds = %4
%36 = load double, double* %10
%37 = load i32, i32* @M_PI
%38 = sub nsw i32 0, %37
%39 = sitofp i32 %38 to double
%40 = fcmp ole double %36, %39
br i1 %40, label %41, label %47
41: ; preds = %35
%42 = load i32, i32* @M_PI
%43 = mul nsw i32 %42, 2
%44 = sitofp i32 %43 to double
%45 = load double, double* %10
%46 = fadd double %45, %44
store double %46, double* %10
br label %59
47: ; preds = %35
%48 = load double, double* %10
%49 = load i32, i32* @M_PI
%50 = sitofp i32 %49 to double
%51 = fcmp ogt double %48, %50
br i1 %51, label %52, label %58
52: ; preds = %47
%53 = load i32, i32* @M_PI
%54 = mul nsw i32 %53, 2
%55 = sitofp i32 %54 to double
%56 = load double, double* %10
%57 = fsub double %56, %55
store double %57, double* %10
br label %58
58: ; preds = %52, %47
br label %59
59: ; preds = %58, %41
%60 = load double, double* %8
%61 = call double @sin(double %60)
%62 = load double, double* %6
%63 = call double @sin(double %62)
%64 = load double, double* %8
%65 = call double @cos(double %64)
%66 = load double, double* %6
%67 = call double @cos(double %66)
%68 = fmul double %65, %67
%69 = load double, double* %10
%70 = call double @cos(double %69)
%71 = fmul double %68, %70
%72 = call double @llvm.fmuladd.f64(double %61, double %63, double %71)
%73 = call double @acos(double %72)
store double %73, double* %11
%74 = load double, double* %6
%75 = call double @cos(double %74)
%76 = load double, double* %11
%77 = call double @sin(double %76)
%78 = fmul double %75, %77
store double %78, double* %13
%79 = load double, double* %8
%80 = call double @sin(double %79)
%81 = load double, double* %6
%82 = call double @sin(double %81)
%83 = load double, double* %11
%84 = call double @cos(double %83)
%85 = fneg double %82
%86 = call double @llvm.fmuladd.f64(double %85, double %84, double %80)
%87 = load double, double* %13
%88 = fdiv double %86, %87
store double %88, double* %12
%89 = load double, double* %12
%90 = fcmp ogt double %89, 1.000000e+00
br i1 %90, label %94, label %91
91: ; preds = %59
%92 = load double, double* %12
%93 = fcmp olt double %92, -1.000000e+00
br i1 %93, label %94, label %104
94: ; preds = %91, %59
%95 = load double, double* %8
%96 = load double, double* %6
%97 = fcmp ogt double %95, %96
br i1 %97, label %98, label %99
98: ; preds = %94
br label %101
99: ; preds = %94
%100 = load i32, i32* @M_PI
br label %101
101: ; preds = %99, %98
%102 = phi i32 [ 0, %98 ], [ %100, %99 ]
%103 = sitofp i32 %102 to double
store double %103, double* %5
br label %117
104: ; preds = %91
%105 = load double, double* %10
%106 = fcmp olt double %105, 0.000000e+00
br i1 %106, label %107, label %114
107: ; preds = %104
%108 = load i32, i32* @M_PI
%109 = mul nsw i32 %108, 2
%110 = sitofp i32 %109 to double
%111 = load double, double* %12
%112 = call double @acos(double %111)
%113 = fsub double %110, %112
store double %113, double* %5
br label %117
114: ; preds = %104
%115 = load double, double* %12
%116 = call double @acos(double %115)
store double %116, double* %5
br label %117
117: ; preds = %114, %107, %101, %32
%118 = load double, double* %5
ret double %118
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @ortho_initial_angle(double %0, double %1, double %2, double %3) {
%5 = fsub double %3, %1
%6 = load i32, i32* @M_PI
%7 = shl nsw i32 %6, 1
%8 = tail call double @fmod(double %5, i32 %7)
%9 = tail call double @llvm.fabs.f64(double %8)
%10 = fcmp olt double %9, 0x3E7AD7F29ABCAF48
br i1 %10, label %11, label %17
11: ; preds = %4
%12 = fsub double %2, %0
%13 = fcmp ogt double %12, 0.000000e+00
%14 = load i32, i32* @M_PI
%15 = sitofp i32 %14 to double
%16 = select i1 %13, double 0.000000e+00, double %15
br label %71
17: ; preds = %4
%18 = load i32, i32* @M_PI
%19 = sub nsw i32 0, %18
%20 = sitofp i32 %19 to double
%21 = fcmp ugt double %8, %20
br i1 %21, label %26, label %22
22: ; preds = %17
%23 = shl nsw i32 %18, 1
%24 = sitofp i32 %23 to double
%25 = fadd double %8, %24
br label %33
26: ; preds = %17
%27 = sitofp i32 %18 to double
%28 = fcmp ogt double %8, %27
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = shl nsw i32 %18, 1
%31 = sitofp i32 %30 to double
%32 = fsub double %8, %31
br label %33
33: ; preds = %26, %29, %22
%34 = phi double [ %25, %22 ], [ %32, %29 ], [ %8, %26 ]
%35 = tail call double @sin(double %2)
%36 = tail call double @sin(double %0)
%37 = tail call double @cos(double %2)
%38 = tail call double @cos(double %0)
%39 = fmul double %37, %38
%40 = tail call double @cos(double %34)
%41 = fmul double %39, %40
%42 = tail call double @llvm.fmuladd.f64(double %35, double %36, double %41)
%43 = tail call double @acos(double %42)
%44 = tail call double @cos(double %0)
%45 = tail call double @sin(double %43)
%46 = fmul double %44, %45
%47 = tail call double @sin(double %2)
%48 = tail call double @sin(double %0)
%49 = tail call double @cos(double %43)
%50 = fneg double %48
%51 = tail call double @llvm.fmuladd.f64(double %50, double %49, double %47)
%52 = fdiv double %51, %46
%53 = fcmp ogt double %52, 1.000000e+00
%54 = fcmp olt double %52, -1.000000e+00
%55 = or i1 %53, %54
br i1 %55, label %56, label %61
56: ; preds = %33
%57 = fcmp ogt double %2, %0
%58 = load i32, i32* @M_PI
%59 = sitofp i32 %58 to double
%60 = select i1 %57, double 0.000000e+00, double %59
br label %71
61: ; preds = %33
%62 = fcmp olt double %34, 0.000000e+00
br i1 %62, label %63, label %69
63: ; preds = %61
%64 = load i32, i32* @M_PI
%65 = shl nsw i32 %64, 1
%66 = sitofp i32 %65 to double
%67 = tail call double @acos(double %52)
%68 = fsub double %66, %67
br label %71
69: ; preds = %61
%70 = tail call double @acos(double %52)
br label %71
71: ; preds = %69, %63, %56, %11
%72 = phi double [ %16, %11 ], [ %60, %56 ], [ %68, %63 ], [ %70, %69 ]
ret double %72
}