int MooreIndex(double x, double y) {
  static const int Rank[5][4] = {
      {1, 0, 2, 3}, {2, 3, 1, 0}, {2, 1, 3, 0}, {0, 3, 1, 2}, {0, 1, 3, 2}};
  static const int NextState[5][4] = {
      {2, 2, 3, 3}, {1, 3, 1, 2}, {2, 2, 4, 1}, {4, 1, 3, 3}, {3, 4, 2, 4}};
  int idx = 0, State = 0;
  int i = 4 * sizeof(int);
  while (--i > 0) {
    int ax = x >= 0.5;
    int ay = y >= 0.5;
    int aq = (ax << 1) + ay;
    idx = 4 * idx + Rank[State][aq];
    State = NextState[State][aq];
    x = 2 * x - ax;
    y = 2 * y - ay;
  }
  return idx;
}


x86 assembly (clang, -O0):
<MooreIndex>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x10,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1218 <MooreIndex+0x118>
movsd  -0x8(%rbp),%xmm0
movsd  0xebe(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
movslq -0x18(%rbp),%rdx
lea    0xe86(%rip),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
movslq -0x28(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x14(%rbp)
movslq -0x18(%rbp),%rcx
lea    0xeba(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1123 <MooreIndex+0x23>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<MooreIndex>:
push   %rbx
xor    %eax,%eax
mov    $0x11,%ecx
lea    0xf01(%rip),%r8
movsd  0xee9(%rip),%xmm2
movsd  0xee9(%rip),%xmm3
lea    0xf3a(%rip),%r10
xor    %edx,%edx
jmp    115c <MooreIndex+0x5c>
nopw   0x0(%rax,%rax,1)
mov    %r9b,%dl
mov    %bl,%sil
lea    (%rdx,%rsi,2),%rdx
add    (%r11,%rdx,4),%eax
add    %r10,%rdi
mov    (%rdi,%rdx,4),%edx
addsd  %xmm0,%xmm0
subsd  %xmm5,%xmm0
addsd  %xmm1,%xmm1
subsd  %xmm4,%xmm1
add    $0xffffffff,%ecx
cmp    $0x2,%ecx
jbe    1193 <MooreIndex+0x93>
movslq %edx,%rdi
shl    $0x4,%rdi
xor    %edx,%edx
ucomisd %xmm2,%xmm1
setae  %r9b
movapd %xmm3,%xmm4
jae    1177 <MooreIndex+0x77>
xorpd  %xmm4,%xmm4
shl    $0x2,%eax
lea    (%r8,%rdi,1),%r11
xor    %esi,%esi
ucomisd %xmm2,%xmm0
setae  %bl
movapd %xmm3,%xmm5
jae    1130 <MooreIndex+0x30>
xorpd  %xmm5,%xmm5
jmp    1130 <MooreIndex+0x30>
pop    %rbx
ret

LLVM IR (-O0):
@MooreIndex.Rank = internal constant [5 x [4 x i32]] [[4 x i32] [i32 1, i32 0, i32 2, i32 3], [4 x i32] [i32 2, i32 3, i32 1, i32 0], [4 x i32] [i32 2, i32 1, i32 3, i32 0], [4 x i32] [i32 0, i32 3, i32 1, i32 2], [4 x i32] [i32 0, i32 1, i32 3, i32 2]]
@MooreIndex.NextState = internal constant [5 x [4 x i32]] [[4 x i32] [i32 2, i32 2, i32 3, i32 3], [4 x i32] [i32 1, i32 3, i32 1, i32 2], [4 x i32] [i32 2, i32 2, i32 4, i32 1], [4 x i32] [i32 4, i32 1, i32 3, i32 3], [4 x i32] [i32 3, i32 4, i32 2, i32 4]]
define i32 @MooreIndex(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store double %0, double* %3
store double %1, double* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 16, i32* %7
br label %11
11: ; preds = %15, %2
%12 = load i32, i32* %7
%13 = add nsw i32 %12, -1
store i32 %13, i32* %7
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %53
15: ; preds = %11
%16 = load double, double* %3
%17 = fcmp oge double %16, 5.000000e-01
%18 = zext i1 %17 to i32
store i32 %18, i32* %8
%19 = load double, double* %4
%20 = fcmp oge double %19, 5.000000e-01
%21 = zext i1 %20 to i32
store i32 %21, i32* %9
%22 = load i32, i32* %8
%23 = shl i32 %22, 1
%24 = load i32, i32* %9
%25 = add nsw i32 %23, %24
store i32 %25, i32* %10
%26 = load i32, i32* %5
%27 = mul nsw i32 4, %26
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* @MooreIndex.Rank, i64 0, i64 %29
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %30, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = add nsw i32 %27, %34
store i32 %35, i32* %5
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* @MooreIndex.NextState, i64 0, i64 %37
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [4 x i32], [4 x i32]* %38, i64 0, i64 %40
%42 = load i32, i32* %41
store i32 %42, i32* %6
%43 = load double, double* %3
%44 = load i32, i32* %8
%45 = sitofp i32 %44 to double
%46 = fneg double %45
%47 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %43, double %46)
store double %47, double* %3
%48 = load double, double* %4
%49 = load i32, i32* %9
%50 = sitofp i32 %49 to double
%51 = fneg double %50
%52 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %48, double %51)
store double %52, double* %4
br label %11
53: ; preds = %11
%54 = load i32, i32* %5
ret i32 %54
}

LLVM IR (-O2):
@MooreIndex.Rank = internal unnamed_addr constant [5 x [4 x i32]] [[4 x i32] [i32 1, i32 0, i32 2, i32 3], [4 x i32] [i32 2, i32 3, i32 1, i32 0], [4 x i32] [i32 2, i32 1, i32 3, i32 0], [4 x i32] [i32 0, i32 3, i32 1, i32 2], [4 x i32] [i32 0, i32 1, i32 3, i32 2]]
@MooreIndex.NextState = internal unnamed_addr constant [5 x [4 x i32]] [[4 x i32] [i32 2, i32 2, i32 3, i32 3], [4 x i32] [i32 1, i32 3, i32 1, i32 2], [4 x i32] [i32 2, i32 2, i32 4, i32 1], [4 x i32] [i32 4, i32 1, i32 3, i32 3], [4 x i32] [i32 3, i32 4, i32 2, i32 4]]
define i32 @MooreIndex(double %0, double %1) {
br label %3
3: ; preds = %2, %3
%4 = phi double [ %0, %2 ], [ %24, %3 ]
%5 = phi double [ %1, %2 ], [ %27, %3 ]
%6 = phi i32 [ 0, %2 ], [ %19, %3 ]
%7 = phi i32 [ 16, %2 ], [ %9, %3 ]
%8 = phi i32 [ 0, %2 ], [ %21, %3 ]
%9 = add nsw i32 %7, -1
%10 = fcmp oge double %4, 5.000000e-01
%11 = fcmp oge double %5, 5.000000e-01
%12 = zext i1 %11 to i64
%13 = select i1 %10, i64 2, i64 0
%14 = or i64 %13, %12
%15 = shl nsw i32 %6, 2
%16 = sext i32 %8 to i64
%17 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* @MooreIndex.Rank, i64 0, i64 %16, i64 %14
%18 = load i32, i32* %17
%19 = add nsw i32 %18, %15
%20 = getelementptr inbounds [5 x [4 x i32]], [5 x [4 x i32]]* @MooreIndex.NextState, i64 0, i64 %16, i64 %14
%21 = load i32, i32* %20
%22 = uitofp i1 %10 to double
%23 = fneg double %22
%24 = tail call double @llvm.fmuladd.f64(double %4, double 2.000000e+00, double %23)
%25 = uitofp i1 %11 to double
%26 = fneg double %25
%27 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double %26)
%28 = icmp ugt i32 %7, 2
br i1 %28, label %3, label %29
29: ; preds = %3
ret i32 %19
}