#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 absAngle(double const);
double asin(double const);
double atan2(double const, double const);
double const cos(double);
scalar_t__ pow(double const, int);
double const sin(double);
double sqrt(scalar_t__);
double calcCourseGroundSpeed(const double hd, const double wd, const double tas,
                             const double ws, double *gs) {
  double diffAngle = hd - wd;
  *gs = sqrt(pow(ws, 2) + pow(tas, 2) - 2 * ws * tas * cos(diffAngle));
  double wca;
  if (ws < tas)
    wca = asin((ws / (*gs)) * sin(diffAngle));
  else
    wca = atan2(ws * sin(diffAngle), tas - ws * cos(diffAngle));
  return absAngle(hd + wca);
}


x86 assembly (clang, -O0):
<calcCourseGroundSpeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x2,%edi
call   1080 <pow@plt>
mov    %rax,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    $0x2,%edi
call   1080 <pow@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe20(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1070 <cos@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1090 <sqrt@plt>
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1282 <calcCourseGroundSpeed+0x112>
movsd  -0x20(%rbp),%xmm0
mov    -0x28(%rbp),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <asin@plt>
movsd  %xmm0,-0x38(%rbp)
jmp    1300 <calcCourseGroundSpeed+0x190>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1070 <cos@plt>
movsd  -0x70(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x60(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
call   1040 <absAngle@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcCourseGroundSpeed>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
movsd  %xmm3,(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm0,0x20(%rsp)
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movaps %xmm3,%xmm0
mov    $0x2,%edi
call   1080 <pow@plt>
mov    %rax,%rbx
movsd  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1080 <pow@plt>
add    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
movsd  0xe27(%rip),%xmm1
mulsd  (%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x18(%rsp),%xmm1
cvttsd2si %xmm1,%rdi
call   1090 <sqrt@plt>
movsd  %xmm0,(%r14)
movsd  0x10(%rsp),%xmm2
ucomisd (%rsp),%xmm2
jbe    122f <calcCourseGroundSpeed+0xbf>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  (%rsp),%xmm0
call   1060 <asin@plt>
jmp    126a <calcCourseGroundSpeed+0xfa>
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
call   1030 <atan2@plt>
addsd  0x20(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1040 <absAngle@plt>

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

LLVM IR (-O2):
define double @calcCourseGroundSpeed(double %0, double %1, double %2, double %3, double* nocapture writeonly %4) {
%6 = fsub double %0, %1
%7 = tail call i64 @pow(double %3, i32 2)
%8 = tail call i64 @pow(double %2, i32 2)
%9 = add nsw i64 %8, %7
%10 = sitofp i64 %9 to double
%11 = tail call double @cos(double %6)
%12 = fmul double %3, -2.000000e+00
%13 = fmul double %12, %2
%14 = tail call double @llvm.fmuladd.f64(double %13, double %11, double %10)
%15 = fptosi double %14 to i64
%16 = tail call double @sqrt(i64 %15)
store double %16, double* %4
%17 = fcmp olt double %3, %2
br i1 %17, label %18, label %23
18: ; preds = %5
%19 = fdiv double %3, %16
%20 = tail call double @sin(double %6)
%21 = fmul double %19, %20
%22 = tail call double @asin(double %21)
br label %30
23: ; preds = %5
%24 = tail call double @sin(double %6)
%25 = fmul double %24, %3
%26 = tail call double @cos(double %6)
%27 = fneg double %3
%28 = tail call double @llvm.fmuladd.f64(double %27, double %26, double %2)
%29 = tail call double @atan2(double %25, double %28)
br label %30
30: ; preds = %23, %18
%31 = phi double [ %22, %18 ], [ %29, %23 ]
%32 = fadd double %31, %0
%33 = tail call double @absAngle(double %32)
ret double %33
}