#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(int, int);
int cos(double);
int sin(double);
void BearCompute(char f_radian, double lat1, double lon1, double lat2,
                 double lon2, double *theta) {
  if ((lat1 == lat2) && (lon1 == lon2)) {
    *theta = 0;
    return;
  }
  lat1 *= 0.017453292519943295769;
  lon1 *= 0.017453292519943295769;
  lat2 *= 0.017453292519943295769;
  lon2 *= 0.017453292519943295769;
  *theta =
      3.14159265358979323846 +
      atan2(cos(lat2) * (cos(lon2) * sin(lon1) - sin(lon2) * cos(lon1)),
            (sin(lat1) * cos(lat2) * cos(lon1 - lon2) - cos(lat1) * sin(lat2)));
  if (*theta > 2 * 3.14159265358979323846) {
    *theta = *theta - 2 * 3.14159265358979323846;
  }
  if (!f_radian) {
    *theta = *theta * 57.295779513082320877;
  }
}


x86 assembly (clang, -O0):
<BearCompute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    1192 <BearCompute+0x62>
jp     1192 <BearCompute+0x62>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    1192 <BearCompute+0x62>
jp     1192 <BearCompute+0x62>
mov    -0x30(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    130d <BearCompute+0x1dd>
movsd  0xe76(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe64(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe52(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe40(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <cos@plt>
mov    %eax,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
mov    %eax,-0x54(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <sin@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4c(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
mov    %eax,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <cos@plt>
mov    -0x50(%rbp),%edx
mov    -0x4c(%rbp),%ecx
mov    %eax,%esi
mov    -0x48(%rbp),%eax
imul   %esi,%edx
sub    %edx,%ecx
imul   %ecx,%eax
mov    %eax,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <sin@plt>
mov    %eax,-0x44(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <cos@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sin@plt>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%edi
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
imul   %ecx,%eax
sub    %eax,%esi
call   1030 <atan2@plt>
movaps %xmm0,%xmm1
movsd  0xd5f(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xd3b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12eb <BearCompute+0x1bb>
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xd21(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
cmpb   $0x0,-0x1(%rbp)
jne    130d <BearCompute+0x1dd>
mov    -0x30(%rbp),%rax
movsd  0xd17(%rip),%xmm0
mulsd  (%rax),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BearCompute>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
ucomisd %xmm2,%xmm0
jne    115a <BearCompute+0x2a>
jp     115a <BearCompute+0x2a>
xorpd  %xmm5,%xmm5
ucomisd %xmm3,%xmm1
jne    115a <BearCompute+0x2a>
jnp    1264 <BearCompute+0x134>
movsd  0xe9e(%rip),%xmm4
mulsd  %xmm4,%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  %xmm4,%xmm1
movsd  %xmm1,(%rsp)
mulsd  %xmm4,%xmm2
movsd  %xmm2,0x18(%rsp)
mulsd  %xmm4,%xmm3
movsd  %xmm3,0x8(%rsp)
movapd %xmm2,%xmm0
call   1050 <cos@plt>
mov    %eax,%r12d
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
mov    %eax,%ebp
movsd  (%rsp),%xmm0
call   1040 <sin@plt>
imul   %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
mov    %eax,%ebx
movsd  (%rsp),%xmm0
call   1050 <cos@plt>
imul   %ebx,%eax
sub    %eax,%ebp
imul   %r12d,%ebp
movsd  0x10(%rsp),%xmm0
call   1040 <sin@plt>
mov    %eax,%ebx
movsd  0x18(%rsp),%xmm0
call   1050 <cos@plt>
imul   %eax,%ebx
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
imul   %eax,%ebx
movsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
mov    %eax,%r12d
movsd  0x18(%rsp),%xmm0
call   1040 <sin@plt>
imul   %r12d,%eax
sub    %eax,%ebx
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <atan2@plt>
addsd  0xddb(%rip),%xmm0
movsd  0xddb(%rip),%xmm2
addsd  %xmm0,%xmm2
movsd  0xdd7(%rip),%xmm5
cmpltsd %xmm0,%xmm5
andpd  %xmm5,%xmm2
andnpd %xmm0,%xmm5
orpd   %xmm2,%xmm5
movlpd %xmm5,(%r15)
test   %r14b,%r14b
jne    1269 <BearCompute+0x139>
mulsd  0xdbc(%rip),%xmm5
movsd  %xmm5,(%r15)
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @BearCompute(i8 signext %0, double %1, double %2, double %3, double %4, double* %5) {
%7 = alloca i8
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double*
store i8 %0, i8* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
store double* %5, double** %12
%13 = load double, double* %8
%14 = load double, double* %10
%15 = fcmp oeq double %13, %14
br i1 %15, label %16, label %22
16: ; preds = %6
%17 = load double, double* %9
%18 = load double, double* %11
%19 = fcmp oeq double %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load double*, double** %12
store double 0.000000e+00, double* %21
br label %80
22: ; preds = %16, %6
%23 = load double, double* %8
%24 = fmul double %23, 0x3F91DF46A2529D39
store double %24, double* %8
%25 = load double, double* %9
%26 = fmul double %25, 0x3F91DF46A2529D39
store double %26, double* %9
%27 = load double, double* %10
%28 = fmul double %27, 0x3F91DF46A2529D39
store double %28, double* %10
%29 = load double, double* %11
%30 = fmul double %29, 0x3F91DF46A2529D39
store double %30, double* %11
%31 = load double, double* %10
%32 = call i32 @cos(double %31)
%33 = load double, double* %11
%34 = call i32 @cos(double %33)
%35 = load double, double* %9
%36 = call i32 @sin(double %35)
%37 = mul nsw i32 %34, %36
%38 = load double, double* %11
%39 = call i32 @sin(double %38)
%40 = load double, double* %9
%41 = call i32 @cos(double %40)
%42 = mul nsw i32 %39, %41
%43 = sub nsw i32 %37, %42
%44 = mul nsw i32 %32, %43
%45 = load double, double* %8
%46 = call i32 @sin(double %45)
%47 = load double, double* %10
%48 = call i32 @cos(double %47)
%49 = mul nsw i32 %46, %48
%50 = load double, double* %9
%51 = load double, double* %11
%52 = fsub double %50, %51
%53 = call i32 @cos(double %52)
%54 = mul nsw i32 %49, %53
%55 = load double, double* %8
%56 = call i32 @cos(double %55)
%57 = load double, double* %10
%58 = call i32 @sin(double %57)
%59 = mul nsw i32 %56, %58
%60 = sub nsw i32 %54, %59
%61 = call double @atan2(i32 %44, i32 %60)
%62 = fadd double 0x400921FB54442D18, %61
%63 = load double*, double** %12
store double %62, double* %63
%64 = load double*, double** %12
%65 = load double, double* %64
%66 = fcmp ogt double %65, 0x401921FB54442D18
br i1 %66, label %67, label %72
67: ; preds = %22
%68 = load double*, double** %12
%69 = load double, double* %68
%70 = fsub double %69, 0x401921FB54442D18
%71 = load double*, double** %12
store double %70, double* %71
br label %72
72: ; preds = %67, %22
%73 = load i8, i8* %7
%74 = icmp ne i8 %73, 0
br i1 %74, label %80, label %75
75: ; preds = %72
%76 = load double*, double** %12
%77 = load double, double* %76
%78 = fmul double %77, 0x404CA5DC1A63C1F8
%79 = load double*, double** %12
store double %78, double* %79
br label %80
80: ; preds = %20, %75, %72
ret void
}

LLVM IR (-O2):
define void @BearCompute(i8 signext %0, double %1, double %2, double %3, double %4, double* nocapture %5) {
%7 = fcmp oeq double %1, %3
%8 = fcmp oeq double %2, %4
%9 = and i1 %7, %8
br i1 %9, label %42, label %10
10: ; preds = %6
%11 = fmul double %1, 0x3F91DF46A2529D39
%12 = fmul double %2, 0x3F91DF46A2529D39
%13 = fmul double %3, 0x3F91DF46A2529D39
%14 = fmul double %4, 0x3F91DF46A2529D39
%15 = tail call i32 @cos(double %13)
%16 = tail call i32 @cos(double %14)
%17 = tail call i32 @sin(double %12)
%18 = mul nsw i32 %17, %16
%19 = tail call i32 @sin(double %14)
%20 = tail call i32 @cos(double %12)
%21 = mul nsw i32 %20, %19
%22 = sub nsw i32 %18, %21
%23 = mul nsw i32 %22, %15
%24 = tail call i32 @sin(double %11)
%25 = tail call i32 @cos(double %13)
%26 = mul nsw i32 %25, %24
%27 = fsub double %12, %14
%28 = tail call i32 @cos(double %27)
%29 = mul nsw i32 %26, %28
%30 = tail call i32 @cos(double %11)
%31 = tail call i32 @sin(double %13)
%32 = mul nsw i32 %31, %30
%33 = sub nsw i32 %29, %32
%34 = tail call double @atan2(i32 %23, i32 %33)
%35 = fadd double %34, 0x400921FB54442D18
%36 = fcmp ogt double %35, 0x401921FB54442D18
%37 = fadd double %35, 0xC01921FB54442D18
%38 = select i1 %36, double %37, double %35
store double %38, double* %5
%39 = icmp eq i8 %0, 0
br i1 %39, label %40, label %44
40: ; preds = %10
%41 = fmul double %38, 0x404CA5DC1A63C1F8
br label %42
42: ; preds = %6, %40
%43 = phi double [ %41, %40 ], [ 0.000000e+00, %6 ]
store double %43, double* %5
br label %44
44: ; preds = %42, %10
ret void
}