#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 */
int M_PI;
int atan(double);
double cos(double);
double sin(double);
double trueWindDirection(double boatSpeed, double apparentWindSpeed,
                         double apparentWindDirection) {
  bool convert180 = false;
  if (apparentWindDirection > 180) {
    apparentWindDirection = 360 - apparentWindDirection;
    convert180 = true;
  }
  double apparentWindDirectionRadian = apparentWindDirection * (M_PI / 180);
  double twdRadians =
      (90 * (M_PI / 180)) -
      atan((apparentWindSpeed * cos(apparentWindDirectionRadian) - boatSpeed) /
           (apparentWindSpeed * sin(apparentWindDirectionRadian)));
  double twdDegrees = twdRadians * (180 / M_PI);
  if (convert180) {
    twdDegrees = 360 - twdDegrees;
  }
  return twdDegrees;
}


x86 assembly (clang, -O0):
<trueWindDirection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xea5(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    117e <trueWindDirection+0x4e>
movsd  0xe9b(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
imul   $0x5a,%eax,%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1040 <atan@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    $0xb4,%eax
mov    0x2d9c(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1278 <trueWindDirection+0x148>
movsd  0xd9a(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trueWindDirection>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movapd %xmm2,0x20(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  0xeb0(%rip),%xmm0
subsd  %xmm2,%xmm0
movsd  0xeac(%rip),%xmm1
cmpltsd %xmm2,%xmm1
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm0,%xmm1
mov    0x2e74(%rip),%rbx
movslq (%rbx),%rax
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x7,%ecx
add    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
imul   $0x5a,%ecx,%ebp
call   1050 <cos@plt>
mulsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <atan@plt>
sub    %eax,%ebp
mov    $0xb4,%eax
xor    %edx,%edx
idivl  (%rbx)
movapd 0x20(%rsp),%xmm0
ucomisd 0xe12(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm0
jbe    121a <trueWindDirection+0xea>
movsd  0xdee(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @trueWindDirection(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
store i32 0, i32* %7
%11 = load double, double* %6
%12 = fcmp ogt double %11, 1.800000e+02
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load double, double* %6
%15 = fsub double 3.600000e+02, %14
store double %15, double* %6
store i32 1, i32* %7
br label %16
16: ; preds = %13, %3
%17 = load double, double* %6
%18 = load i32, i32* @M_PI
%19 = sdiv i32 %18, 180
%20 = sitofp i32 %19 to double
%21 = fmul double %17, %20
store double %21, double* %8
%22 = load i32, i32* @M_PI
%23 = sdiv i32 %22, 180
%24 = mul nsw i32 90, %23
%25 = load double, double* %5
%26 = load double, double* %8
%27 = call double @cos(double %26)
%28 = load double, double* %4
%29 = fneg double %28
%30 = call double @llvm.fmuladd.f64(double %25, double %27, double %29)
%31 = load double, double* %5
%32 = load double, double* %8
%33 = call double @sin(double %32)
%34 = fmul double %31, %33
%35 = fdiv double %30, %34
%36 = call i32 @atan(double %35)
%37 = sub nsw i32 %24, %36
%38 = sitofp i32 %37 to double
store double %38, double* %9
%39 = load double, double* %9
%40 = load i32, i32* @M_PI
%41 = sdiv i32 180, %40
%42 = sitofp i32 %41 to double
%43 = fmul double %39, %42
store double %43, double* %10
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %16
%47 = load double, double* %10
%48 = fsub double 3.600000e+02, %47
store double %48, double* %10
br label %49
49: ; preds = %46, %16
%50 = load double, double* %10
ret double %50
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @trueWindDirection(double %0, double %1, double %2) {
%4 = fcmp ogt double %2, 1.800000e+02
%5 = fsub double 3.600000e+02, %2
%6 = select i1 %4, double %5, double %2
%7 = load i32, i32* @M_PI
%8 = sdiv i32 %7, 180
%9 = sitofp i32 %8 to double
%10 = fmul double %6, %9
%11 = mul nsw i32 %8, 90
%12 = tail call double @cos(double %10)
%13 = fneg double %0
%14 = tail call double @llvm.fmuladd.f64(double %1, double %12, double %13)
%15 = tail call double @sin(double %10)
%16 = fmul double %15, %1
%17 = fdiv double %14, %16
%18 = tail call i32 @atan(double %17)
%19 = sub nsw i32 %11, %18
%20 = sitofp i32 %19 to double
%21 = load i32, i32* @M_PI
%22 = sdiv i32 180, %21
%23 = sitofp i32 %22 to double
%24 = fmul double %20, %23
%25 = fsub double 3.600000e+02, %24
%26 = select i1 %4, double %25, double %24
ret double %26
}