int gcode_math_angle_within_arc(double start_angle, double sweep_angle,
                                double test_angle) {
  double begin, end;
  if (sweep_angle < 0.0) {
    begin = start_angle + sweep_angle;
    end = start_angle;
  } else {
    begin = start_angle;
    end = start_angle + sweep_angle;
  }
  if (begin < 0.0) {
    begin += 360.0;
    end += 360.0;
  }
  if ((test_angle >= begin - 0.001) && (test_angle <= end + 0.001))
    return (0);
  if ((test_angle - 360.0 >= begin - 0.001) &&
      (test_angle - 360.0 <= end + 0.001))
    return (0);
  if ((test_angle + 360.0 >= begin - 0.001) &&
      (test_angle + 360.0 <= end + 0.001))
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<gcode_math_angle_within_arc>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    113f <gcode_math_angle_within_arc+0x3f>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1158 <gcode_math_angle_within_arc+0x58>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    118a <gcode_math_angle_within_arc+0x8a>
movsd  0xe92(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe80(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe6c(%rip),%xmm2
subsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jb     11d2 <gcode_math_angle_within_arc+0xd2>
movsd  -0x20(%rbp),%xmm1
movsd  0xe51(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11d2 <gcode_math_angle_within_arc+0xd2>
movl   $0x0,-0x4(%rbp)
jmp    1291 <gcode_math_angle_within_arc+0x191>
movsd  -0x20(%rbp),%xmm0
movsd  0xe21(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe18(%rip),%xmm2
subsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jb     1232 <gcode_math_angle_within_arc+0x132>
movsd  -0x20(%rbp),%xmm1
movsd  0xdf5(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xdf1(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1232 <gcode_math_angle_within_arc+0x132>
movl   $0x0,-0x4(%rbp)
jmp    1291 <gcode_math_angle_within_arc+0x191>
movsd  0xdc6(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xdbc(%rip),%xmm2
subsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jb     128a <gcode_math_angle_within_arc+0x18a>
movsd  0xd9e(%rip),%xmm1
addsd  -0x20(%rbp),%xmm1
movsd  0xd99(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     128a <gcode_math_angle_within_arc+0x18a>
movl   $0x0,-0x4(%rbp)
jmp    1291 <gcode_math_angle_within_arc+0x191>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<gcode_math_angle_within_arc>:
xorpd  %xmm4,%xmm4
ucomisd %xmm1,%xmm4
movapd %xmm0,%xmm5
addsd  %xmm1,%xmm5
movapd %xmm5,%xmm3
ja     111a <gcode_math_angle_within_arc+0x1a>
movapd %xmm0,%xmm3
cmpltsd %xmm4,%xmm1
movapd %xmm1,%xmm6
andnpd %xmm5,%xmm6
andpd  %xmm0,%xmm1
orpd   %xmm6,%xmm1
ucomisd %xmm3,%xmm4
movsd  0xec5(%rip),%xmm0
movapd %xmm1,%xmm5
addsd  %xmm0,%xmm5
ja     114b <gcode_math_angle_within_arc+0x4b>
movapd %xmm3,%xmm0
jmp    114f <gcode_math_angle_within_arc+0x4f>
addsd  %xmm3,%xmm0
cmpltsd %xmm4,%xmm3
movapd %xmm3,%xmm4
andnpd %xmm1,%xmm4
andpd  %xmm5,%xmm3
orpd   %xmm4,%xmm3
addsd  0xe9c(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm0,%xmm2
addsd  0xe96(%rip),%xmm3
jb     1183 <gcode_math_angle_within_arc+0x83>
ucomisd %xmm2,%xmm3
jb     1183 <gcode_math_angle_within_arc+0x83>
ret
movsd  0xe8d(%rip),%xmm1
addsd  %xmm2,%xmm1
ucomisd %xmm0,%xmm1
jb     119b <gcode_math_angle_within_arc+0x9b>
ucomisd %xmm1,%xmm3
jae    1182 <gcode_math_angle_within_arc+0x82>
addsd  0xe5d(%rip),%xmm2
ucomisd %xmm0,%xmm2
setb   %al
ucomisd %xmm2,%xmm3
setb   %cl
or     %al,%cl
movzbl %cl,%eax
ret

LLVM IR (-O0):
define i32 @gcode_math_angle_within_arc(double %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%10 = load double, double* %6
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load double, double* %5
%14 = load double, double* %6
%15 = fadd double %13, %14
store double %15, double* %8
%16 = load double, double* %5
store double %16, double* %9
br label %22
17: ; preds = %3
%18 = load double, double* %5
store double %18, double* %8
%19 = load double, double* %5
%20 = load double, double* %6
%21 = fadd double %19, %20
store double %21, double* %9
br label %22
22: ; preds = %17, %12
%23 = load double, double* %8
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load double, double* %8
%27 = fadd double %26, 3.600000e+02
store double %27, double* %8
%28 = load double, double* %9
%29 = fadd double %28, 3.600000e+02
store double %29, double* %9
br label %30
30: ; preds = %25, %22
%31 = load double, double* %7
%32 = load double, double* %8
%33 = fsub double %32, 1.000000e-03
%34 = fcmp oge double %31, %33
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load double, double* %7
%37 = load double, double* %9
%38 = fadd double %37, 1.000000e-03
%39 = fcmp ole double %36, %38
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 0, i32* %4
br label %68
41: ; preds = %35, %30
%42 = load double, double* %7
%43 = fsub double %42, 3.600000e+02
%44 = load double, double* %8
%45 = fsub double %44, 1.000000e-03
%46 = fcmp oge double %43, %45
br i1 %46, label %47, label %54
47: ; preds = %41
%48 = load double, double* %7
%49 = fsub double %48, 3.600000e+02
%50 = load double, double* %9
%51 = fadd double %50, 1.000000e-03
%52 = fcmp ole double %49, %51
br i1 %52, label %53, label %54
53: ; preds = %47
store i32 0, i32* %4
br label %68
54: ; preds = %47, %41
%55 = load double, double* %7
%56 = fadd double %55, 3.600000e+02
%57 = load double, double* %8
%58 = fsub double %57, 1.000000e-03
%59 = fcmp oge double %56, %58
br i1 %59, label %60, label %67
60: ; preds = %54
%61 = load double, double* %7
%62 = fadd double %61, 3.600000e+02
%63 = load double, double* %9
%64 = fadd double %63, 1.000000e-03
%65 = fcmp ole double %62, %64
br i1 %65, label %66, label %67
66: ; preds = %60
store i32 0, i32* %4
br label %68
67: ; preds = %60, %54
store i32 1, i32* %4
br label %68
68: ; preds = %67, %66, %53, %40
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
define i32 @gcode_math_angle_within_arc(double %0, double %1, double %2) {
%4 = fcmp olt double %1, 0.000000e+00
%5 = fadd double %0, %1
%6 = select i1 %4, double %5, double %0
%7 = select i1 %4, double %0, double %5
%8 = fcmp olt double %6, 0.000000e+00
%9 = fadd double %6, 3.600000e+02
%10 = fadd double %7, 3.600000e+02
%11 = select i1 %8, double %9, double %6
%12 = select i1 %8, double %10, double %7
%13 = fadd double %11, -1.000000e-03
%14 = fcmp ugt double %13, %2
%15 = fadd double %12, 1.000000e-03
%16 = fcmp ult double %15, %2
%17 = or i1 %14, %16
br i1 %17, label %18, label %29
18: ; preds = %3
%19 = fadd double %2, -3.600000e+02
%20 = fcmp ult double %19, %13
%21 = fcmp ugt double %19, %15
%22 = or i1 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = fadd double %2, 3.600000e+02
%25 = fcmp ult double %24, %13
%26 = fcmp ugt double %24, %15
%27 = or i1 %25, %26
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %23, %18, %3
%30 = phi i32 [ 0, %3 ], [ 0, %18 ], [ %28, %23 ]
ret i32 %30
}