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


x86 assembly (clang, -O0):
<calcHeadingGroundSpeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %rdi,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1040 <fabs@plt>
cmp    $0x1,%eax
jle    11ec <calcHeadingGroundSpeed+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ce <calcHeadingGroundSpeed+0x15e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1060 <asin@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
call   1030 <absAngle@plt>
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    $0x2,%edi
call   1080 <pow@plt>
mov    $0x1,%edi
sub    %rax,%rdi
call   1090 <sqrt@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1070 <cos@plt>
movsd  -0x68(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x38(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jbe    12c2 <calcHeadingGroundSpeed+0x152>
movl   $0x0,-0x4(%rbp)
jmp    12ce <calcHeadingGroundSpeed+0x15e>
jmp    12c7 <calcHeadingGroundSpeed+0x157>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcHeadingGroundSpeed>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  %xmm0,0x8(%rsp)
subsd  %xmm0,%xmm1
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x20(%rsp)
divsd  %xmm2,%xmm3
movsd  %xmm3,(%rsp)
movsd  %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
call   1050 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
call   1040 <fabs@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jg     1236 <calcHeadingGroundSpeed+0xc6>
movsd  (%rsp),%xmm0
call   1060 <asin@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rbx)
call   1030 <absAngle@plt>
movsd  %xmm0,(%rbx)
movsd  (%rsp),%xmm0
mov    $0x2,%edi
call   1080 <pow@plt>
mov    $0x1,%edi
sub    %rax,%rdi
call   1090 <sqrt@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1070 <cos@plt>
mulsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mulsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
xorpd  %xmm0,%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
setbe  %al
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @calcHeadingGroundSpeed(double %0, double %1, double %2, double %3, double* nocapture writeonly %4, double* nocapture writeonly %5) {
%7 = fsub double %1, %0
%8 = fdiv double %3, %2
%9 = tail call double @sin(double %7)
%10 = fmul double %8, %9
%11 = tail call i32 @fabs(double %10)
%12 = icmp sgt i32 %11, 1
br i1 %12, label %26, label %13
13: ; preds = %6
%14 = tail call double @asin(double %10)
%15 = fadd double %14, %0
store double %15, double* %4
%16 = tail call double @absAngle(double %15)
store double %16, double* %4
%17 = tail call i64 @pow(double %10, i32 2)
%18 = sub nsw i64 1, %17
%19 = tail call double @sqrt(i64 %18)
%20 = tail call double @cos(double %7)
%21 = fneg double %20
%22 = fmul double %21, %3
%23 = tail call double @llvm.fmuladd.f64(double %2, double %19, double %22)
store double %23, double* %5
%24 = fcmp uge double %23, 0.000000e+00
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %13, %6
%27 = phi i32 [ -1, %6 ], [ %25, %13 ]
ret i32 %27
}