#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 atan2(double const, double const);
double const cos(double);
int pow(double const, int);
double const sin(double);
double sqrt(int);
double calcWindDirSpeed(const double crs, const double hd, const double tas,
                        const double gs, double *ws) {
  double diffSpeed = tas - gs;
  double diffAngle = hd - crs;
  *ws = sqrt(pow(diffSpeed, 2) + 4 * tas * gs * pow(sin(diffAngle / 2), 2));
  double wd = crs + atan2(tas * sin(diffAngle), tas * cos(diffAngle) - gs);
  return absAngle(wd);
}


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

x86 assembly (clang, -O2):
<calcWindDirSpeed>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
movapd %xmm0,%xmm4
movsd  %xmm0,0x28(%rsp)
movapd %xmm2,%xmm0
subsd  %xmm3,%xmm0
subsd  %xmm4,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    $0x2,%edi
call   1070 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
movsd  0xe52(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0xe40(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mov    $0x2,%edi
call   1070 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x20(%rsp),%xmm0
addsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1080 <sqrt@plt>
movsd  %xmm0,(%rbx)
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <cos@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
subsd  0x18(%rsp),%xmm1
movsd  (%rsp),%xmm0
call   1030 <atan2@plt>
addsd  0x28(%rsp),%xmm0
add    $0x30,%rsp
pop    %rbx
jmp    1040 <absAngle@plt>

LLVM IR (-O0):
define double @calcWindDirSpeed(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
%13 = 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
%14 = load double, double* %8
%15 = load double, double* %9
%16 = fsub double %14, %15
store double %16, double* %11
%17 = load double, double* %7
%18 = load double, double* %6
%19 = fsub double %17, %18
store double %19, double* %12
%20 = load double, double* %11
%21 = call i32 @pow(double %20, i32 2)
%22 = sitofp i32 %21 to double
%23 = load double, double* %8
%24 = fmul double 4.000000e+00, %23
%25 = load double, double* %9
%26 = fmul double %24, %25
%27 = load double, double* %12
%28 = fdiv double %27, 2.000000e+00
%29 = call double @sin(double %28)
%30 = call i32 @pow(double %29, i32 2)
%31 = sitofp i32 %30 to double
%32 = call double @llvm.fmuladd.f64(double %26, double %31, double %22)
%33 = fptosi double %32 to i32
%34 = call double @sqrt(i32 %33)
%35 = load double*, double** %10
store double %34, double* %35
%36 = load double, double* %6
%37 = load double, double* %8
%38 = load double, double* %12
%39 = call double @sin(double %38)
%40 = fmul double %37, %39
%41 = load double, double* %8
%42 = load double, double* %12
%43 = call double @cos(double %42)
%44 = load double, double* %9
%45 = fneg double %44
%46 = call double @llvm.fmuladd.f64(double %41, double %43, double %45)
%47 = call double @atan2(double %40, double %46)
%48 = fadd double %36, %47
store double %48, double* %13
%49 = load double, double* %13
%50 = call double @absAngle(double %49)
ret double %50
}

LLVM IR (-O2):
define double @calcWindDirSpeed(double %0, double %1, double %2, double %3, double* nocapture writeonly %4) {
%6 = fsub double %2, %3
%7 = fsub double %1, %0
%8 = tail call i32 @pow(double %6, i32 2)
%9 = sitofp i32 %8 to double
%10 = fmul double %2, 4.000000e+00
%11 = fmul double %10, %3
%12 = fmul double %7, 5.000000e-01
%13 = tail call double @sin(double %12)
%14 = tail call i32 @pow(double %13, i32 2)
%15 = sitofp i32 %14 to double
%16 = tail call double @llvm.fmuladd.f64(double %11, double %15, double %9)
%17 = fptosi double %16 to i32
%18 = tail call double @sqrt(i32 %17)
store double %18, double* %4
%19 = tail call double @sin(double %7)
%20 = fmul double %19, %2
%21 = tail call double @cos(double %7)
%22 = fneg double %3
%23 = tail call double @llvm.fmuladd.f64(double %2, double %21, double %22)
%24 = tail call double @atan2(double %20, double %23)
%25 = fadd double %24, %0
%26 = tail call double @absAngle(double %25)
ret double %26
}