#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 */
float acos(float);
float cos(float);
float sin(float);
float calc_distance(float latcell, float loncell, float latstat,
                    float lonstat) {
  float lat1, long1, lat2, long2;
  float pi = 3.141593;
  float radius = 6378.0;
  float dtor = 2.0 * pi / 360.0;
  float theta1, theta2, phi1, phi2, temp;
  float term1, term2, term3;
  lat1 = latcell;
  long1 = loncell;
  lat2 = latstat;
  long2 = lonstat;
  theta1 = dtor * long1;
  phi1 = dtor * lat1;
  theta2 = dtor * long2;
  phi2 = dtor * 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;
  if (temp < 1.0)
    temp = temp;
  if (temp > 1.0)
    temp = 1.0;
  return (radius * acos(temp));
}


x86 assembly (clang, -O0):
<calc_distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  0xec8(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  0xeb7(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe99(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe85(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x2c(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x2c(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x2c(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x2c(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x38(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x68(%rbp)
movss  -0x30(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x68(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x64(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x64(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x60(%rbp)
movss  -0x34(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x60(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x38(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x5c(%rbp)
movss  -0x30(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x5c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x58(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x58(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x34(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x54(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x38(%rbp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,-0x50(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x50(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x44(%rbp),%xmm0
addss  -0x48(%rbp),%xmm0
addss  -0x4c(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x40(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xcfd(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1317 <calc_distance+0x1e7>
movss  -0x40(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x40(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xcd8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    133f <calc_distance+0x20f>
movss  0xce6(%rip),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x6c(%rbp)
movss  -0x40(%rbp),%xmm0
call   1030 <acos@plt>
movaps %xmm0,%xmm1
movss  -0x6c(%rbp),%xmm0
mulss  %xmm1,%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_distance>:
sub    $0x68,%rsp
movss  0xec4(%rip),%xmm4
mulss  %xmm4,%xmm1
movss  %xmm1,0x4(%rsp)
mulss  %xmm4,%xmm0
movss  %xmm0,0xc(%rsp)
mulss  %xmm4,%xmm3
movss  %xmm3,0x8(%rsp)
mulss  %xmm2,%xmm4
movss  %xmm4,(%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  0xdbd(%rip),%xmm0
minss  %xmm1,%xmm0
call   1030 <acos@plt>
mulss  0xdb0(%rip),%xmm0
add    $0x68,%rsp
ret

LLVM IR (-O0):
define float @calc_distance(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
%17 = alloca float
%18 = alloca float
%19 = alloca float
%20 = alloca float
%21 = alloca float
%22 = alloca float
%23 = alloca float
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
store float 0x400921FB80000000, float* %13
store float 6.378000e+03, float* %14
%24 = load float, float* %13
%25 = fpext float %24 to double
%26 = fmul double 2.000000e+00, %25
%27 = fdiv double %26, 3.600000e+02
%28 = fptrunc double %27 to float
store float %28, float* %15
%29 = load float, float* %5
store float %29, float* %9
%30 = load float, float* %6
store float %30, float* %10
%31 = load float, float* %7
store float %31, float* %11
%32 = load float, float* %8
store float %32, float* %12
%33 = load float, float* %15
%34 = load float, float* %10
%35 = fmul float %33, %34
store float %35, float* %16
%36 = load float, float* %15
%37 = load float, float* %9
%38 = fmul float %36, %37
store float %38, float* %18
%39 = load float, float* %15
%40 = load float, float* %12
%41 = fmul float %39, %40
store float %41, float* %17
%42 = load float, float* %15
%43 = load float, float* %11
%44 = fmul float %42, %43
store float %44, float* %19
%45 = load float, float* %18
%46 = call float @cos(float %45)
%47 = load float, float* %16
%48 = call float @cos(float %47)
%49 = fmul float %46, %48
%50 = load float, float* %19
%51 = call float @cos(float %50)
%52 = fmul float %49, %51
%53 = load float, float* %17
%54 = call float @cos(float %53)
%55 = fmul float %52, %54
store float %55, float* %21
%56 = load float, float* %18
%57 = call float @cos(float %56)
%58 = load float, float* %16
%59 = call float @sin(float %58)
%60 = fmul float %57, %59
%61 = load float, float* %19
%62 = call float @cos(float %61)
%63 = fmul float %60, %62
%64 = load float, float* %17
%65 = call float @sin(float %64)
%66 = fmul float %63, %65
store float %66, float* %22
%67 = load float, float* %18
%68 = call float @sin(float %67)
%69 = load float, float* %19
%70 = call float @sin(float %69)
%71 = fmul float %68, %70
store float %71, float* %23
%72 = load float, float* %21
%73 = load float, float* %22
%74 = fadd float %72, %73
%75 = load float, float* %23
%76 = fadd float %74, %75
store float %76, float* %20
%77 = load float, float* %20
%78 = fpext float %77 to double
%79 = fcmp olt double %78, 1.000000e+00
br i1 %79, label %80, label %82
80: ; preds = %4
%81 = load float, float* %20
store float %81, float* %20
br label %82
82: ; preds = %80, %4
%83 = load float, float* %20
%84 = fpext float %83 to double
%85 = fcmp ogt double %84, 1.000000e+00
br i1 %85, label %86, label %87
86: ; preds = %82
store float 1.000000e+00, float* %20
br label %87
87: ; preds = %86, %82
%88 = load float, float* %14
%89 = load float, float* %20
%90 = call float @acos(float %89)
%91 = fmul float %88, %90
ret float %91
}

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