#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(float);
float cos(float);
float sin(float);
float getdist(float lat1, float long1, float lat2, float long2) {
  float theta1, theta2, phi1, phi2, temp;
  float term1, term2, term3;
  theta1 = 2.0 * 3.141593 / 360.0 * long1;
  phi1 = 2.0 * 3.141593 / 360.0 * lat1;
  theta2 = 2.0 * 3.141593 / 360.0 * long2;
  phi2 = 2.0 * 3.141593 / 360.0 * lat2;
  term1 = cos(phi1) * cos(theta1) * cos(phi2) * cos(theta2);
  term2 = cos(phi1) * sin(theta1) * cos(phi2) * sin(theta2);
  term3 = sin(phi1) * sin(phi2);
  temp = term1 + term2 + term3;
  temp = temp > 1.0 ? 1.0 : temp;
  return 6378.0 * acos(temp);
}


x86 assembly (clang, -O0):
<getdist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xeab(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe8d(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe6f(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe51(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x4c(%rbp)
movss  -0x14(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x4c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x20(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x48(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x18(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x44(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x40(%rbp)
movss  -0x14(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x40(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x20(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x3c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x18(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x38(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x20(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x34(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x28(%rbp),%xmm0
addss  -0x2c(%rbp),%xmm0
addss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd2d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ef <getdist+0x1bf>
movsd  0xd1b(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    12fd <getdist+0x1cd>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <acos@plt>
movaps %xmm0,%xmm1
movsd  0xcf0(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdist>:
sub    $0x68,%rsp
cvtss2sd %xmm1,%xmm1
movsd  0xec0(%rip),%xmm4
mulsd  %xmm4,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x4(%rsp)
cvtss2sd %xmm0,%xmm0
mulsd  %xmm4,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
mulsd  %xmm4,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
mulsd  %xmm4,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,(%rsp)
call   1050 <cos@plt>
movaps %xmm0,0x50(%rsp)
movss  0x4(%rsp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,0x20(%rsp)
movss  (%rsp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,0x10(%rsp)
movss  0x8(%rsp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,0x30(%rsp)
movss  0xc(%rsp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,0x40(%rsp)
movss  0x4(%rsp),%xmm0
call   1040 <sin@plt>
movaps 0x50(%rsp),%xmm2
unpcklps 0x40(%rsp),%xmm2
movaps 0x20(%rsp),%xmm1
unpcklps %xmm0,%xmm1
mulps  %xmm2,%xmm1
movaps %xmm1,0x20(%rsp)
movss  (%rsp),%xmm0
call   1050 <cos@plt>
movaps 0x10(%rsp),%xmm1
unpcklps %xmm0,%xmm1
mulps  0x20(%rsp),%xmm1
movaps %xmm1,0x10(%rsp)
movss  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movaps 0x30(%rsp),%xmm1
unpcklps %xmm0,%xmm1
mulps  0x10(%rsp),%xmm1
movaps %xmm1,0x30(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,0x10(%rsp)
movss  (%rsp),%xmm0
call   1040 <sin@plt>
mulss  0x10(%rsp),%xmm0
movaps 0x30(%rsp),%xmm2
movaps %xmm2,%xmm1
shufps $0x55,%xmm2,%xmm1
addss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  0xda3(%rip),%xmm0
minss  %xmm1,%xmm0
call   1030 <acos@plt>
mulsd  0xd8a(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x68,%rsp
ret

LLVM IR (-O0):
define float @getdist(float %0, float %1, float %2, float %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca float
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%17 = load float, float* %6
%18 = fpext float %17 to double
%19 = fmul double 0x3F91DF46C362A8E3, %18
%20 = fptrunc double %19 to float
store float %20, float* %9
%21 = load float, float* %5
%22 = fpext float %21 to double
%23 = fmul double 0x3F91DF46C362A8E3, %22
%24 = fptrunc double %23 to float
store float %24, float* %11
%25 = load float, float* %8
%26 = fpext float %25 to double
%27 = fmul double 0x3F91DF46C362A8E3, %26
%28 = fptrunc double %27 to float
store float %28, float* %10
%29 = load float, float* %7
%30 = fpext float %29 to double
%31 = fmul double 0x3F91DF46C362A8E3, %30
%32 = fptrunc double %31 to float
store float %32, float* %12
%33 = load float, float* %11
%34 = call float @cos(float %33)
%35 = load float, float* %9
%36 = call float @cos(float %35)
%37 = fmul float %34, %36
%38 = load float, float* %12
%39 = call float @cos(float %38)
%40 = fmul float %37, %39
%41 = load float, float* %10
%42 = call float @cos(float %41)
%43 = fmul float %40, %42
store float %43, float* %14
%44 = load float, float* %11
%45 = call float @cos(float %44)
%46 = load float, float* %9
%47 = call float @sin(float %46)
%48 = fmul float %45, %47
%49 = load float, float* %12
%50 = call float @cos(float %49)
%51 = fmul float %48, %50
%52 = load float, float* %10
%53 = call float @sin(float %52)
%54 = fmul float %51, %53
store float %54, float* %15
%55 = load float, float* %11
%56 = call float @sin(float %55)
%57 = load float, float* %12
%58 = call float @sin(float %57)
%59 = fmul float %56, %58
store float %59, float* %16
%60 = load float, float* %14
%61 = load float, float* %15
%62 = fadd float %60, %61
%63 = load float, float* %16
%64 = fadd float %62, %63
store float %64, float* %13
%65 = load float, float* %13
%66 = fpext float %65 to double
%67 = fcmp ogt double %66, 1.000000e+00
br i1 %67, label %68, label %69
68: ; preds = %4
br label %72
69: ; preds = %4
%70 = load float, float* %13
%71 = fpext float %70 to double
br label %72
72: ; preds = %69, %68
%73 = phi double [ 1.000000e+00, %68 ], [ %71, %69 ]
%74 = fptrunc double %73 to float
store float %74, float* %13
%75 = load float, float* %13
%76 = call double @acos(float %75)
%77 = fmul double 6.378000e+03, %76
%78 = fptrunc double %77 to float
ret float %78
}

LLVM IR (-O2):
define float @getdist(float %0, float %1, float %2, float %3) {
%5 = fpext float %1 to double
%6 = fmul double %5, 0x3F91DF46C362A8E3
%7 = fptrunc double %6 to float
%8 = fpext float %0 to double
%9 = fmul double %8, 0x3F91DF46C362A8E3
%10 = fptrunc double %9 to float
%11 = fpext float %3 to double
%12 = fmul double %11, 0x3F91DF46C362A8E3
%13 = fptrunc double %12 to float
%14 = fpext float %2 to double
%15 = fmul double %14, 0x3F91DF46C362A8E3
%16 = fptrunc double %15 to float
%17 = tail call float @cos(float %10)
%18 = tail call float @cos(float %7)
%19 = tail call float @cos(float %16)
%20 = tail call float @cos(float %13)
%21 = tail call float @cos(float %10)
%22 = tail call float @sin(float %7)
%23 = insertelement <2 x float> poison, float %17, i64 0
%24 = insertelement <2 x float> %23, float %21, i64 1
%25 = insertelement <2 x float> poison, float %18, i64 0
%26 = insertelement <2 x float> %25, float %22, i64 1
%27 = fmul <2 x float> %24, %26
%28 = tail call float @cos(float %16)
%29 = insertelement <2 x float> poison, float %19, i64 0
%30 = insertelement <2 x float> %29, float %28, i64 1
%31 = fmul <2 x float> %27, %30
%32 = tail call float @sin(float %13)
%33 = insertelement <2 x float> poison, float %20, i64 0
%34 = insertelement <2 x float> %33, float %32, i64 1
%35 = fmul <2 x float> %31, %34
%36 = tail call float @sin(float %10)
%37 = tail call float @sin(float %16)
%38 = fmul float %36, %37
%39 = shufflevector <2 x float> %35, <2 x float> poison, <2 x i32> <i32 1, i32 undef>
%40 = fadd <2 x float> %35, %39
%41 = extractelement <2 x float> %40, i64 0
%42 = fadd float %41, %38
%43 = fcmp ogt float %42, 1.000000e+00
%44 = select i1 %43, float 1.000000e+00, float %42
%45 = tail call double @acos(float %44)
%46 = fmul double %45, 6.378000e+03
%47 = fptrunc double %46 to float
ret float %47
}