int AngleInRange(x, y, start, extent)
double x, y;
double start;
double extent;
{
  double diff;
  diff = -atan2(y, x);
  diff = diff * (180.0 / 3.14159265358979323846) - start;
  while (diff > 360.0) {
    diff -= 360.0;
  }
  while (diff < 0.0) {
    diff += 360.0;
  }
  if (extent >= 0) {
    return diff <= extent;
  }
  return (diff - 360.0) >= extent;
}


x86 assembly (clang, -O0):
<AngleInRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <atan2@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe80(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11bf <AngleInRange+0xaf>
movsd  -0x30(%rbp),%xmm0
movsd  0xe57(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    118d <AngleInRange+0x7d>
jmp    11c4 <AngleInRange+0xb4>
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11e9 <AngleInRange+0xd9>
movsd  0xe2e(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11c4 <AngleInRange+0xb4>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1219 <AngleInRange+0x109>
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    123a <AngleInRange+0x12a>
movsd  -0x30(%rbp),%xmm0
movsd  0xde2(%rip),%xmm1
subsd  %xmm1,%xmm0
ucomisd -0x28(%rbp),%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AngleInRange>:
sub    $0x18,%rsp
movsd  %xmm3,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
movapd %xmm0,%xmm2
movapd %xmm1,%xmm0
movapd %xmm2,%xmm1
call   1030 <atan2@plt>
mulsd  0xec7(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
ucomisd 0xec1(%rip),%xmm0
jbe    116a <AngleInRange+0x5a>
movsd  0xebf(%rip),%xmm1
movsd  0xeaf(%rip),%xmm2
nopl   0x0(%rax)
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
ja     1160 <AngleInRange+0x50>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    118a <AngleInRange+0x7a>
movsd  0xe8c(%rip),%xmm2
nopl   0x0(%rax)
addsd  %xmm2,%xmm0
ucomisd %xmm0,%xmm1
ja     1180 <AngleInRange+0x70>
xor    %eax,%eax
movsd  0x10(%rsp),%xmm2
ucomisd %xmm0,%xmm2
addsd  0xe72(%rip),%xmm0
setae  %al
xor    %ecx,%ecx
ucomisd %xmm2,%xmm0
setae  %cl
ucomisd %xmm1,%xmm2
cmovae %eax,%ecx
movzbl %cl,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @AngleInRange(double %0, double %1, double %2, double %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%11 = load double, double* %7
%12 = load double, double* %6
%13 = call double @atan2(double %11, double %12)
%14 = fneg double %13
store double %14, double* %10
%15 = load double, double* %10
%16 = load double, double* %8
%17 = fneg double %16
%18 = call double @llvm.fmuladd.f64(double %15, double 0x404CA5DC1A63C1F8, double %17)
store double %18, double* %10
br label %19
19: ; preds = %22, %4
%20 = load double, double* %10
%21 = fcmp ogt double %20, 3.600000e+02
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load double, double* %10
%24 = fsub double %23, 3.600000e+02
store double %24, double* %10
br label %19
25: ; preds = %19
br label %26
26: ; preds = %29, %25
%27 = load double, double* %10
%28 = fcmp olt double %27, 0.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load double, double* %10
%31 = fadd double %30, 3.600000e+02
store double %31, double* %10
br label %26
32: ; preds = %26
%33 = load double, double* %9
%34 = fcmp oge double %33, 0.000000e+00
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load double, double* %10
%37 = load double, double* %9
%38 = fcmp ole double %36, %37
%39 = zext i1 %38 to i32
store i32 %39, i32* %5
br label %46
40: ; preds = %32
%41 = load double, double* %10
%42 = fsub double %41, 3.600000e+02
%43 = load double, double* %9
%44 = fcmp oge double %42, %43
%45 = zext i1 %44 to i32
store i32 %45, i32* %5
br label %46
46: ; preds = %40, %35
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
define i32 @AngleInRange(double %0, double %1, double %2, double %3) {
%5 = tail call double @atan2(double %1, double %0)
%6 = fneg double %5
%7 = fneg double %2
%8 = tail call double @llvm.fmuladd.f64(double %6, double 0x404CA5DC1A63C1F8, double %7)
%9 = fcmp ogt double %8, 3.600000e+02
br i1 %9, label %13, label %10
10: ; preds = %13, %4
%11 = phi double [ %8, %4 ], [ %15, %13 ]
%12 = fcmp olt double %11, 0.000000e+00
br i1 %12, label %17, label %21
13: ; preds = %4, %13
%14 = phi double [ %15, %13 ], [ %8, %4 ]
%15 = fadd double %14, -3.600000e+02
%16 = fcmp ogt double %15, 3.600000e+02
br i1 %16, label %13, label %10
17: ; preds = %10, %17
%18 = phi double [ %19, %17 ], [ %11, %10 ]
%19 = fadd double %18, 3.600000e+02
%20 = fcmp olt double %19, 0.000000e+00
br i1 %20, label %17, label %21
21: ; preds = %17, %10
%22 = phi double [ %11, %10 ], [ %19, %17 ]
%23 = fcmp ult double %3, 0.000000e+00
%24 = fcmp ole double %22, %3
%25 = fadd double %22, -3.600000e+02
%26 = fcmp oge double %25, %3
%27 = select i1 %23, i1 %26, i1 %24
%28 = zext i1 %27 to i32
ret i32 %28
}