#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 cos(double);
double sqrt(double);
double dist(double lon1, double lon2, double lat1, double lat2, int sphere_mesh,
            double lat) {
  if (sphere_mesh == 1) {
    double rad = M_PI / 180.;
    double deg2m = 1852 * 60.;
    return sqrt((lon2 - lon1) * (lon2 - lon1) * deg2m * deg2m * cos(rad * lat) *
                    cos(rad * lat) +
                (lat2 - lat1) * (lat2 - lat1) * deg2m * deg2m);
  } else {
    return sqrt((lon2 - lon1) * (lon2 - lon1) + (lat2 - lat1) * (lat2 - lat1));
  }
}


x86 assembly (clang, -O0):
<dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %edi,-0x2c(%rbp)
movsd  %xmm4,-0x38(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    120e <dist+0xee>
mov    0x2e93(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  0xea7(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe8e(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm3
subsd  -0x20(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    124c <dist+0x12c>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm3
subsd  -0x20(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dist>:
cmp    $0x1,%edi
jne    11c8 <dist+0xa8>
sub    $0x28,%rsp
mov    0x2eb4(%rip),%rax
cvtsi2sdl (%rax),%xmm5
divsd  0xec0(%rip),%xmm5
subsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm1
movsd  0xeb8(%rip),%xmm0
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mulsd  %xmm4,%xmm5
movsd  %xmm5,0x10(%rsp)
movapd %xmm5,%xmm0
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x20(%rsp)
call   1030 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <cos@plt>
movapd %xmm0,%xmm1
movsd  0x18(%rsp),%xmm2
subsd  0x20(%rsp),%xmm2
mulsd  %xmm2,%xmm2
movsd  0xe58(%rip),%xmm0
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  0x8(%rsp),%xmm1
addsd  %xmm2,%xmm1
add    $0x28,%rsp
jmp    11dc <dist+0xbc>
subsd  %xmm0,%xmm1
subsd  %xmm2,%xmm3
mulsd  %xmm3,%xmm3
mulsd  %xmm1,%xmm1
addsd  %xmm3,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     11ee <dist+0xce>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
ret
movapd %xmm1,%xmm0
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
@M_PI = global i32 0
define double @dist(double %0, double %1, double %2, double %3, i32 %4, double %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store i32 %4, i32* %12
store double %5, double* %13
%16 = load i32, i32* %12
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %55
18: ; preds = %6
%19 = load i32, i32* @M_PI
%20 = sitofp i32 %19 to double
%21 = fdiv double %20, 1.800000e+02
store double %21, double* %14
store double 1.111200e+05, double* %15
%22 = load double, double* %9
%23 = load double, double* %8
%24 = fsub double %22, %23
%25 = load double, double* %9
%26 = load double, double* %8
%27 = fsub double %25, %26
%28 = fmul double %24, %27
%29 = load double, double* %15
%30 = fmul double %28, %29
%31 = load double, double* %15
%32 = fmul double %30, %31
%33 = load double, double* %14
%34 = load double, double* %13
%35 = fmul double %33, %34
%36 = call double @cos(double %35)
%37 = fmul double %32, %36
%38 = load double, double* %14
%39 = load double, double* %13
%40 = fmul double %38, %39
%41 = call double @cos(double %40)
%42 = load double, double* %11
%43 = load double, double* %10
%44 = fsub double %42, %43
%45 = load double, double* %11
%46 = load double, double* %10
%47 = fsub double %45, %46
%48 = fmul double %44, %47
%49 = load double, double* %15
%50 = fmul double %48, %49
%51 = load double, double* %15
%52 = fmul double %50, %51
%53 = call double @llvm.fmuladd.f64(double %37, double %41, double %52)
%54 = call double @sqrt(double %53)
store double %54, double* %7
br label %71
55: ; preds = %6
%56 = load double, double* %9
%57 = load double, double* %8
%58 = fsub double %56, %57
%59 = load double, double* %9
%60 = load double, double* %8
%61 = fsub double %59, %60
%62 = load double, double* %11
%63 = load double, double* %10
%64 = fsub double %62, %63
%65 = load double, double* %11
%66 = load double, double* %10
%67 = fsub double %65, %66
%68 = fmul double %64, %67
%69 = call double @llvm.fmuladd.f64(double %58, double %61, double %68)
%70 = call double @sqrt(double %69)
store double %70, double* %7
br label %71
71: ; preds = %55, %18
%72 = load double, double* %7
ret double %72
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @dist(double %0, double %1, double %2, double %3, i32 %4, double %5) {
%7 = icmp eq i32 %4, 1
br i1 %7, label %8, label %25
8: ; preds = %6
%9 = load i32, i32* @M_PI
%10 = sitofp i32 %9 to double
%11 = fdiv double %10, 1.800000e+02
%12 = fsub double %1, %0
%13 = fmul double %12, %12
%14 = fmul double %13, 1.111200e+05
%15 = fmul double %14, 1.111200e+05
%16 = fmul double %11, %5
%17 = tail call double @cos(double %16)
%18 = fmul double %15, %17
%19 = tail call double @cos(double %16)
%20 = fsub double %3, %2
%21 = fmul double %20, %20
%22 = fmul double %21, 1.111200e+05
%23 = fmul double %22, 1.111200e+05
%24 = tail call double @llvm.fmuladd.f64(double %18, double %19, double %23)
br label %30
25: ; preds = %6
%26 = fsub double %1, %0
%27 = fsub double %3, %2
%28 = fmul double %27, %27
%29 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %28)
br label %30
30: ; preds = %25, %8
%31 = phi double [ %29, %25 ], [ %24, %8 ]
%32 = tail call double @sqrt(double %31)
ret double %32
}