#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 fabs(double);
double ndt_mod(double, int);
double ndt_position_angle_reverse(double);
double ndt_position_bearing_angle(double bearing, double targetb) {
  double brgdiff = ndt_mod(targetb, 360.) - ndt_mod(bearing, 360.);
  if (fabs(brgdiff) > 180.) {
    return ndt_position_angle_reverse(brgdiff);
  }
  return brgdiff == 180. ? -180. : brgdiff;
}


x86 assembly (clang, -O0):
<ndt_position_bearing_angle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    $0x168,%edi
call   1040 <ndt_mod@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    $0x168,%edi
call   1040 <ndt_mod@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe74(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11aa <ndt_position_bearing_angle+0x7a>
movsd  -0x20(%rbp),%xmm0
call   1050 <ndt_position_angle_reverse@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11ed <ndt_position_bearing_angle+0xbd>
movsd  -0x20(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11d9 <ndt_position_bearing_angle+0xa9>
jp     11d9 <ndt_position_bearing_angle+0xa9>
movsd  0xe39(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11e3 <ndt_position_bearing_angle+0xb3>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndt_position_bearing_angle>:
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
movaps %xmm1,%xmm0
mov    $0x168,%edi
call   1040 <ndt_mod@plt>
movaps %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x168,%edi
call   1040 <ndt_mod@plt>
movapd (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   1030 <fabs@plt>
cmp    $0xb5,%eax
jl     1186 <ndt_position_bearing_angle+0x56>
movaps (%rsp),%xmm0
add    $0x18,%rsp
jmp    1050 <ndt_position_angle_reverse@plt>
movsd  0xe72(%rip),%xmm0
movapd (%rsp),%xmm2
cmpeqsd %xmm2,%xmm0
movsd  0xe68(%rip),%xmm1
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @ndt_position_bearing_angle(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %4
store double %1, double* %5
%7 = load double, double* %5
%8 = call double @ndt_mod(double %7, i32 360)
%9 = load double, double* %4
%10 = call double @ndt_mod(double %9, i32 360)
%11 = fsub double %8, %10
store double %11, double* %6
%12 = load double, double* %6
%13 = call i32 @fabs(double %12)
%14 = sitofp i32 %13 to double
%15 = fcmp ogt double %14, 1.800000e+02
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load double, double* %6
%18 = call double @ndt_position_angle_reverse(double %17)
store double %18, double* %3
br label %27
19: ; preds = %2
%20 = load double, double* %6
%21 = fcmp oeq double %20, 1.800000e+02
br i1 %21, label %22, label %23
22: ; preds = %19
br label %25
23: ; preds = %19
%24 = load double, double* %6
br label %25
25: ; preds = %23, %22
%26 = phi double [ -1.800000e+02, %22 ], [ %24, %23 ]
store double %26, double* %3
br label %27
27: ; preds = %25, %16
%28 = load double, double* %3
ret double %28
}

LLVM IR (-O2):
define double @ndt_position_bearing_angle(double %0, double %1) {
%3 = tail call double @ndt_mod(double %1, i32 360)
%4 = tail call double @ndt_mod(double %0, i32 360)
%5 = fsub double %3, %4
%6 = tail call i32 @fabs(double %5)
%7 = icmp sgt i32 %6, 180
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call double @ndt_position_angle_reverse(double %5)
br label %13
10: ; preds = %2
%11 = fcmp oeq double %5, 1.800000e+02
%12 = select i1 %11, double -1.800000e+02, double %5
br label %13
13: ; preds = %10, %8
%14 = phi double [ %9, %8 ], [ %12, %10 ]
ret double %14
}