#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 asin(float);
float cos(float);
float sin(float);
float sqrt(float);
float CalcLTD(float ev, float az, float rad, float dist) {
  float azp, dlp, l, al;
  azp = asin(cos(ev) * sin(az));
  dlp = sqrt((dist * dist) + (rad * rad) + (2.0f * dist * rad * sin(azp)));
  l = sqrt((dist * dist) - (rad * rad));
  al = (0.5f * 3.14159265358979323846) + azp;
  if (dlp > l)
    dlp = l + (rad * (al - acos(rad / dist)));
  return (dlp / 343.3f);
}


x86 assembly (clang, -O0):
<CalcLTD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
call   1060 <cos@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x8(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
mulss  %xmm1,%xmm0
call   1050 <asin@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  0xe44(%rip),%xmm0
mulss  -0x10(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x14(%rbp),%xmm0
call   1040 <sin@plt>
movss  -0x28(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x24(%rbp),%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1070 <sqrt@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1070 <sqrt@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdc0(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
ucomiss -0x1c(%rbp),%xmm0
jbe    12ac <CalcLTD+0x15c>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0xc(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
call   1030 <acos@plt>
movss  -0x38(%rbp),%xmm2
movss  -0x34(%rbp),%xmm1
movaps %xmm0,%xmm3
movss  -0x30(%rbp),%xmm0
subss  %xmm3,%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  0xd53(%rip),%xmm1
divss  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalcLTD>:
sub    $0x28,%rsp
movss  %xmm3,0x10(%rsp)
movss  %xmm2,0x18(%rsp)
movss  %xmm1,0xc(%rsp)
call   1060 <cos@plt>
movss  %xmm0,0x14(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <sin@plt>
mulss  0x14(%rsp),%xmm0
call   1050 <asin@plt>
movss  0x18(%rsp),%xmm3
movaps %xmm3,%xmm2
mulss  %xmm3,%xmm2
movss  0x10(%rsp),%xmm4
movaps %xmm4,%xmm1
mulss  %xmm4,%xmm1
movss  %xmm1,0xc(%rsp)
movss  %xmm2,0x14(%rsp)
addss  %xmm2,%xmm1
movss  %xmm1,0x24(%rsp)
addss  %xmm4,%xmm4
mulss  %xmm3,%xmm4
movss  %xmm4,0x20(%rsp)
movss  %xmm0,0x1c(%rsp)
call   1040 <sin@plt>
mulss  0x20(%rsp),%xmm0
addss  0x24(%rsp),%xmm0
xorps  %xmm2,%xmm2
ucomiss %xmm2,%xmm0
jb     11ea <CalcLTD+0x9a>
sqrtss %xmm0,%xmm0
jmp    11f2 <CalcLTD+0xa2>
call   1070 <sqrt@plt>
xorps  %xmm2,%xmm2
movss  0xc(%rsp),%xmm1
subss  0x14(%rsp),%xmm1
ucomiss %xmm2,%xmm1
jb     120e <CalcLTD+0xbe>
sqrtss %xmm1,%xmm1
ucomiss %xmm1,%xmm0
ja     122a <CalcLTD+0xda>
jmp    1276 <CalcLTD+0x126>
movss  %xmm0,0xc(%rsp)
movaps %xmm1,%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1276 <CalcLTD+0x126>
movss  0x1c(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xdc4(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x18(%rsp),%xmm0
divss  0x10(%rsp),%xmm0
movss  %xmm1,0x10(%rsp)
call   1030 <acos@plt>
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
movaps %xmm1,%xmm0
mulss  0x18(%rsp),%xmm0
addss  0x10(%rsp),%xmm0
divss  0xd8a(%rip),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define float @CalcLTD(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
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%13 = load float, float* %5
%14 = call float @cos(float %13)
%15 = load float, float* %6
%16 = call float @sin(float %15)
%17 = fmul float %14, %16
%18 = call float @asin(float %17)
store float %18, float* %9
%19 = load float, float* %8
%20 = load float, float* %8
%21 = load float, float* %7
%22 = load float, float* %7
%23 = fmul float %21, %22
%24 = call float @llvm.fmuladd.f32(float %19, float %20, float %23)
%25 = load float, float* %8
%26 = fmul float 2.000000e+00, %25
%27 = load float, float* %7
%28 = fmul float %26, %27
%29 = load float, float* %9
%30 = call float @sin(float %29)
%31 = call float @llvm.fmuladd.f32(float %28, float %30, float %24)
%32 = call float @sqrt(float %31)
store float %32, float* %10
%33 = load float, float* %8
%34 = load float, float* %8
%35 = load float, float* %7
%36 = load float, float* %7
%37 = fmul float %35, %36
%38 = fneg float %37
%39 = call float @llvm.fmuladd.f32(float %33, float %34, float %38)
%40 = call float @sqrt(float %39)
store float %40, float* %11
%41 = load float, float* %9
%42 = fpext float %41 to double
%43 = fadd double 0x3FF921FB54442D18, %42
%44 = fptrunc double %43 to float
store float %44, float* %12
%45 = load float, float* %10
%46 = load float, float* %11
%47 = fcmp ogt float %45, %46
br i1 %47, label %48, label %58
48: ; preds = %4
%49 = load float, float* %11
%50 = load float, float* %7
%51 = load float, float* %12
%52 = load float, float* %7
%53 = load float, float* %8
%54 = fdiv float %52, %53
%55 = call float @acos(float %54)
%56 = fsub float %51, %55
%57 = call float @llvm.fmuladd.f32(float %50, float %56, float %49)
store float %57, float* %10
br label %58
58: ; preds = %48, %4
%59 = load float, float* %10
%60 = fdiv float %59, 0x407574CCC0000000
ret float %60
}

LLVM IR (-O2):
define float @CalcLTD(float %0, float %1, float %2, float %3) {
%5 = tail call float @cos(float %0)
%6 = tail call float @sin(float %1)
%7 = fmul float %5, %6
%8 = tail call float @asin(float %7)
%9 = fmul float %2, %2
%10 = tail call float @llvm.fmuladd.f32(float %3, float %3, float %9)
%11 = fmul float %3, 2.000000e+00
%12 = fmul float %11, %2
%13 = tail call float @sin(float %8)
%14 = tail call float @llvm.fmuladd.f32(float %12, float %13, float %10)
%15 = tail call float @sqrt(float %14)
%16 = fneg float %9
%17 = tail call float @llvm.fmuladd.f32(float %3, float %3, float %16)
%18 = tail call float @sqrt(float %17)
%19 = fcmp ogt float %15, %18
br i1 %19, label %20, label %28
20: ; preds = %4
%21 = fpext float %8 to double
%22 = fadd double %21, 0x3FF921FB54442D18
%23 = fptrunc double %22 to float
%24 = fdiv float %2, %3
%25 = tail call float @acos(float %24)
%26 = fsub float %23, %25
%27 = tail call float @llvm.fmuladd.f32(float %2, float %26, float %18)
br label %28
28: ; preds = %20, %4
%29 = phi float [ %27, %20 ], [ %15, %4 ]
%30 = fdiv float %29, 0x407574CCC0000000
ret float %30
}