#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 clamp(double, int /*<<< orphan*/, int);
double normalize_hdg(double hdg) {
  while (hdg < 0.0)
    hdg += 360.0;
  while (hdg >= 360.0)
    hdg -= 360.0;
  if (hdg < 0.0 || hdg > 360.0)
    hdg = clamp(hdg, 0, 360);
  return (hdg);
}


x86 assembly (clang, -O0):
<normalize_hdg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1142 <normalize_hdg+0x32>
movsd  0xecd(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    111d <normalize_hdg+0xd>
jmp    1147 <normalize_hdg+0x37>
movsd  -0x8(%rbp),%xmm0
movsd  0xeac(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1179 <normalize_hdg+0x69>
movsd  -0x8(%rbp),%xmm0
movsd  0xe95(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1147 <normalize_hdg+0x37>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     119e <normalize_hdg+0x8e>
movsd  -0x8(%rbp),%xmm0
movsd  0xe6c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b4 <normalize_hdg+0xa4>
movsd  -0x8(%rbp),%xmm0
xor    %edi,%edi
mov    $0x168,%esi
call   1030 <clamp@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_hdg>:
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    113a <normalize_hdg+0x2a>
movsd  0xede(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addsd  %xmm2,%xmm0
ucomisd %xmm0,%xmm1
ja     1130 <normalize_hdg+0x20>
ucomisd 0xebe(%rip),%xmm0
jb     116a <normalize_hdg+0x5a>
movsd  0xebc(%rip),%xmm1
movsd  0xeac(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jae    1160 <normalize_hdg+0x50>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     117f <normalize_hdg+0x6f>
ucomisd 0xe84(%rip),%xmm0
ja     117f <normalize_hdg+0x6f>
ret
xor    %edi,%edi
mov    $0x168,%esi
jmp    1030 <clamp@plt>

LLVM IR (-O0):
define double @normalize_hdg(double %0) {
%2 = alloca double
store double %0, double* %2
br label %3
3: ; preds = %6, %1
%4 = load double, double* %2
%5 = fcmp olt double %4, 0.000000e+00
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load double, double* %2
%8 = fadd double %7, 3.600000e+02
store double %8, double* %2
br label %3
9: ; preds = %3
br label %10
10: ; preds = %13, %9
%11 = load double, double* %2
%12 = fcmp oge double %11, 3.600000e+02
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load double, double* %2
%15 = fsub double %14, 3.600000e+02
store double %15, double* %2
br label %10
16: ; preds = %10
%17 = load double, double* %2
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load double, double* %2
%21 = fcmp ogt double %20, 3.600000e+02
br i1 %21, label %22, label %25
22: ; preds = %19, %16
%23 = load double, double* %2
%24 = call double @clamp(double %23, i32 0, i32 360)
store double %24, double* %2
br label %25
25: ; preds = %22, %19
%26 = load double, double* %2
ret double %26
}

LLVM IR (-O2):
define double @normalize_hdg(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
br i1 %2, label %6, label %3
3: ; preds = %6, %1
%4 = phi double [ %0, %1 ], [ %8, %6 ]
%5 = fcmp ult double %4, 3.600000e+02
br i1 %5, label %14, label %10
6: ; preds = %1, %6
%7 = phi double [ %8, %6 ], [ %0, %1 ]
%8 = fadd double %7, 3.600000e+02
%9 = fcmp olt double %8, 0.000000e+00
br i1 %9, label %6, label %3
10: ; preds = %3, %10
%11 = phi double [ %12, %10 ], [ %4, %3 ]
%12 = fadd double %11, -3.600000e+02
%13 = fcmp ult double %12, 3.600000e+02
br i1 %13, label %14, label %10
14: ; preds = %10, %3
%15 = phi double [ %4, %3 ], [ %12, %10 ]
%16 = fcmp olt double %15, 0.000000e+00
%17 = fcmp ogt double %15, 3.600000e+02
%18 = or i1 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call double @clamp(double %15, i32 0, i32 360)
br label %21
21: ; preds = %14, %19
%22 = phi double [ %20, %19 ], [ %15, %14 ]
ret double %22
}