float k2_angle_difference_degreesf(float a, float b) {
  float d = a - b;
  while (d >= 360.0f)
    d -= 360.0f;
  d += 540.0f;
  while (d >= 360.0f)
    d -= 360.0f;
  d -= 180.0f;
  return d;
}


x86 assembly (clang, -O0):
<k2_angle_difference_degreesf>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xed6(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     114e <k2_angle_difference_degreesf+0x4e>
movss  -0xc(%rbp),%xmm0
movss  0xec0(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    111d <k2_angle_difference_degreesf+0x1d>
movss  0xeae(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xe93(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     1191 <k2_angle_difference_degreesf+0x91>
movss  -0xc(%rbp),%xmm0
movss  0xe7d(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1160 <k2_angle_difference_degreesf+0x60>
movss  -0xc(%rbp),%xmm0
movss  0xe6a(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<k2_angle_difference_degreesf>:
subss  %xmm1,%xmm0
ucomiss 0xef5(%rip),%xmm0
jb     1129 <k2_angle_difference_degreesf+0x29>
movss  0xeef(%rip),%xmm1
movss  0xee3(%rip),%xmm2
nopl   (%rax)
addss  %xmm1,%xmm0
ucomiss %xmm2,%xmm0
jae    1120 <k2_angle_difference_degreesf+0x20>
addss  0xed7(%rip),%xmm0
ucomiss 0xec8(%rip),%xmm0
jb     1159 <k2_angle_difference_degreesf+0x59>
movss  0xec2(%rip),%xmm1
movss  0xeb6(%rip),%xmm2
nopw   0x0(%rax,%rax,1)
addss  %xmm1,%xmm0
ucomiss %xmm2,%xmm0
jae    1150 <k2_angle_difference_degreesf+0x50>
addss  0xeab(%rip),%xmm0
ret

LLVM IR (-O0):
define float @k2_angle_difference_degreesf(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
store float %0, float* %3
store float %1, float* %4
%6 = load float, float* %3
%7 = load float, float* %4
%8 = fsub float %6, %7
store float %8, float* %5
br label %9
9: ; preds = %12, %2
%10 = load float, float* %5
%11 = fcmp oge float %10, 3.600000e+02
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load float, float* %5
%14 = fsub float %13, 3.600000e+02
store float %14, float* %5
br label %9
15: ; preds = %9
%16 = load float, float* %5
%17 = fadd float %16, 5.400000e+02
store float %17, float* %5
br label %18
18: ; preds = %21, %15
%19 = load float, float* %5
%20 = fcmp oge float %19, 3.600000e+02
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load float, float* %5
%23 = fsub float %22, 3.600000e+02
store float %23, float* %5
br label %18
24: ; preds = %18
%25 = load float, float* %5
%26 = fsub float %25, 1.800000e+02
store float %26, float* %5
%27 = load float, float* %5
ret float %27
}

LLVM IR (-O2):
define float @k2_angle_difference_degreesf(float %0, float %1) {
%3 = fsub float %0, %1
%4 = fcmp ult float %3, 3.600000e+02
br i1 %4, label %9, label %5
5: ; preds = %2, %5
%6 = phi float [ %7, %5 ], [ %3, %2 ]
%7 = fadd float %6, -3.600000e+02
%8 = fcmp ult float %7, 3.600000e+02
br i1 %8, label %9, label %5
9: ; preds = %5, %2
%10 = phi float [ %3, %2 ], [ %7, %5 ]
%11 = fadd float %10, 5.400000e+02
%12 = fcmp ult float %11, 3.600000e+02
br i1 %12, label %17, label %13
13: ; preds = %9, %13
%14 = phi float [ %15, %13 ], [ %11, %9 ]
%15 = fadd float %14, -3.600000e+02
%16 = fcmp ult float %15, 3.600000e+02
br i1 %16, label %17, label %13
17: ; preds = %13, %9
%18 = phi float [ %11, %9 ], [ %15, %13 ]
%19 = fadd float %18, -1.800000e+02
ret float %19
}