#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 acos(double);
double cos(int /*<<< orphan*/);
int /*<<< orphan*/ deg2rad(double);
double rad2deg(double);
double sin(int /*<<< orphan*/);
double geoDistance(double lat1, double lon1, double lat2, double lon2,
                   char unit) {
  double theta, dist;
  theta = lon1 - lon2;
  dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) +
         cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta));
  dist = acos(dist);
  dist = rad2deg(dist);
  dist = dist * 60 * 1.1515;
  switch (unit) {
  case 'M':
    break;
  case 'K':
    dist = dist * 1.609344;
    break;
  case 'N':
    dist = dist * 0.8684;
    break;
  }
  return (dist);
}


x86 assembly (clang, -O0):
<geoDistance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dil,%al
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %al,-0x21(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1050 <sin@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1050 <sin@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1070 <cos@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1070 <cos@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <acos@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <rad2deg@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xdb8(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsbl -0x21(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x4b,%eax
je     1299 <geoDistance+0x149>
jmp    1272 <geoDistance+0x122>
mov    -0x3c(%rbp),%eax
sub    $0x4d,%eax
je     1294 <geoDistance+0x144>
jmp    1283 <geoDistance+0x133>
mov    -0x3c(%rbp),%eax
sub    $0x4e,%eax
je     12b0 <geoDistance+0x160>
jmp    12c2 <geoDistance+0x172>
jmp    12c2 <geoDistance+0x172>
movsd  0xd77(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12c2 <geoDistance+0x172>
movsd  0xd58(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geoDistance>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
subsd  %xmm3,%xmm1
movsd  %xmm1,0x20(%rsp)
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1050 <sin@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1050 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1070 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1070 <cos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
call   1040 <deg2rad@plt>
mov    %eax,%edi
call   1070 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  0x28(%rsp),%xmm1
addsd  %xmm1,%xmm0
call   1030 <acos@plt>
call   1060 <rad2deg@plt>
mulsd  0xdf9(%rip),%xmm0
mulsd  0xdf9(%rip),%xmm0
cmp    $0x4e,%ebx
je     1223 <geoDistance+0xd3>
cmp    $0x4b,%ebx
jne    122b <geoDistance+0xdb>
mulsd  0xdef(%rip),%xmm0
jmp    122b <geoDistance+0xdb>
mulsd  0xded(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @geoDistance(double %0, double %1, double %2, double %3, i8 signext %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i8
%11 = alloca double
%12 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store i8 %4, i8* %10
%13 = load double, double* %7
%14 = load double, double* %9
%15 = fsub double %13, %14
store double %15, double* %11
%16 = load double, double* %6
%17 = call i32 @deg2rad(double %16)
%18 = call double @sin(i32 %17)
%19 = load double, double* %8
%20 = call i32 @deg2rad(double %19)
%21 = call double @sin(i32 %20)
%22 = load double, double* %6
%23 = call i32 @deg2rad(double %22)
%24 = call double @cos(i32 %23)
%25 = load double, double* %8
%26 = call i32 @deg2rad(double %25)
%27 = call double @cos(i32 %26)
%28 = fmul double %24, %27
%29 = load double, double* %11
%30 = call i32 @deg2rad(double %29)
%31 = call double @cos(i32 %30)
%32 = fmul double %28, %31
%33 = call double @llvm.fmuladd.f64(double %18, double %21, double %32)
store double %33, double* %12
%34 = load double, double* %12
%35 = call double @acos(double %34)
store double %35, double* %12
%36 = load double, double* %12
%37 = call double @rad2deg(double %36)
store double %37, double* %12
%38 = load double, double* %12
%39 = fmul double %38, 6.000000e+01
%40 = fmul double %39, 1.151500e+00
store double %40, double* %12
%41 = load i8, i8* %10
%42 = sext i8 %41 to i32
switch i32 %42, label %50 [
i32 77, label %43
i32 75, label %44
i32 78, label %47
]
43: ; preds = %5
br label %50
44: ; preds = %5
%45 = load double, double* %12
%46 = fmul double %45, 0x3FF9BFDF7E8038A0
store double %46, double* %12
br label %50
47: ; preds = %5
%48 = load double, double* %12
%49 = fmul double %48, 8.684000e-01
store double %49, double* %12
br label %50
50: ; preds = %5, %47, %44, %43
%51 = load double, double* %12
ret double %51
}

LLVM IR (-O2):
define double @geoDistance(double %0, double %1, double %2, double %3, i8 signext %4) {
%6 = fsub double %1, %3
%7 = tail call i32 @deg2rad(double %0)
%8 = tail call double @sin(i32 %7)
%9 = tail call i32 @deg2rad(double %2)
%10 = tail call double @sin(i32 %9)
%11 = tail call i32 @deg2rad(double %0)
%12 = tail call double @cos(i32 %11)
%13 = tail call i32 @deg2rad(double %2)
%14 = tail call double @cos(i32 %13)
%15 = fmul double %12, %14
%16 = tail call i32 @deg2rad(double %6)
%17 = tail call double @cos(i32 %16)
%18 = fmul double %15, %17
%19 = tail call double @llvm.fmuladd.f64(double %8, double %10, double %18)
%20 = tail call double @acos(double %19)
%21 = tail call double @rad2deg(double %20)
%22 = fmul double %21, 6.000000e+01
%23 = fmul double %22, 1.151500e+00
%24 = sext i8 %4 to i32
switch i32 %24, label %29 [
i32 78, label %27
i32 75, label %25
]
25: ; preds = %5
%26 = fmul double %23, 0x3FF9BFDF7E8038A0
br label %29
27: ; preds = %5
%28 = fmul double %23, 8.684000e-01
br label %29
29: ; preds = %5, %27, %25
%30 = phi double [ %23, %5 ], [ %26, %25 ], [ %28, %27 ]
ret double %30
}