void hilpoint(long number, long scale, double qs, double *cx, double *cy) {
  int patterns[4][4] = {{0, 1, 3, 2}, {0, 2, 3, 1}, {3, 1, 0, 2}, {3, 2, 0, 1}};
  int transforms[4][4] = {
      {1, 0, 2, 0}, {0, 3, 1, 1}, {2, 2, 0, 3}, {3, 1, 3, 2}};
  long divisor = scale / 4;
  long tmp = number;
  long pattern = 1;
  (*cx) = (*cy) = 0.0;
  while (divisor > 0) {
    int cell;
    long mantissa;
    mantissa = tmp / divisor;
    tmp = tmp % divisor;
    divisor /= 4;
    cell = patterns[pattern][mantissa];
    pattern = transforms[pattern][cell];
    qs /= 2.0;
    if (cell & 1)
      (*cx) += qs;
    if (cell & 2)
      (*cy) += qs;
  }
}


x86 assembly (clang, -O0):
<hilpoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xed5(%rip),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
lea    -0xb0(%rbp),%rdi
lea    0xefd(%rip),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    $0x4,%ecx
cqto
idiv   %rcx
mov    %rax,-0xb8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xc0(%rbp)
movq   $0x1,-0xc8(%rbp)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
cmpq   $0x0,-0xb8(%rbp)
jle    129c <hilpoint+0x18c>
mov    -0xc0(%rbp),%rax
cqto
idivq  -0xb8(%rbp)
mov    %rax,-0xd8(%rbp)
mov    -0xc0(%rbp),%rax
cqto
idivq  -0xb8(%rbp)
mov    %rdx,-0xc0(%rbp)
mov    -0xb8(%rbp),%rax
mov    $0x4,%ecx
cqto
idiv   %rcx
mov    %rax,-0xb8(%rbp)
mov    -0xc8(%rbp),%rcx
lea    -0x70(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    -0xd8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xcc(%rbp)
mov    -0xc8(%rbp),%rcx
lea    -0xb0(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0xcc(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
mov    %rax,-0xc8(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xdb8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xcc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1274 <hilpoint+0x164>
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0xcc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1297 <hilpoint+0x187>
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    119e <hilpoint+0x8e>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hilpoint>:
push   %rbx
movq   $0x0,(%rcx)
movq   $0x0,(%rdx)
cmp    $0x4,%rsi
jl     11c5 <hilpoint+0xc5>
mov    %rdx,%r8
mov    %rdi,%rax
mov    $0x1,%edi
lea    0xee5(%rip),%r10
lea    0xf1e(%rip),%r11
movsd  0xec6(%rip),%xmm1
jmp    114d <hilpoint+0x4d>
nopl   0x0(%rax)
movslq (%rdi,%rdx,4),%rdi
cmp    $0xf,%rsi
mov    %rbx,%rsi
jle    11c5 <hilpoint+0xc5>
lea    0x3(%rsi),%rbx
test   %rsi,%rsi
cmovns %rsi,%rbx
sar    $0x2,%rbx
mov    %rax,%rdx
or     %rbx,%rdx
shr    $0x20,%rdx
je     1180 <hilpoint+0x80>
cqto
idiv   %rbx
mov    %rax,%r9
mov    %rdx,%rax
jmp    1189 <hilpoint+0x89>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edx,%edx
div    %ebx
mov    %eax,%r9d
mov    %edx,%eax
shl    $0x4,%rdi
lea    (%r10,%rdi,1),%rdx
movslq (%rdx,%r9,4),%rdx
mulsd  %xmm1,%xmm0
test   $0x1,%dl
je     11ac <hilpoint+0xac>
movsd  (%r8),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%r8)
add    %r11,%rdi
test   $0x2,%dl
je     1140 <hilpoint+0x40>
movsd  (%rcx),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rcx)
jmp    1140 <hilpoint+0x40>
pop    %rbx
ret

LLVM IR (-O0):
@__const.hilpoint.patterns = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 3, i32 2], [4 x i32] [i32 0, i32 2, i32 3, i32 1], [4 x i32] [i32 3, i32 1, i32 0, i32 2], [4 x i32] [i32 3, i32 2, i32 0, i32 1]]
@__const.hilpoint.transforms = [4 x [4 x i32]] [[4 x i32] [i32 1, i32 0, i32 2, i32 0], [4 x i32] [i32 0, i32 3, i32 1, i32 1], [4 x i32] [i32 2, i32 2, i32 0, i32 3], [4 x i32] [i32 3, i32 1, i32 3, i32 2]]
define void @hilpoint(i64 %0, i64 %1, double %2, double* %3, double* %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca double
%9 = alloca double*
%10 = alloca double*
%11 = alloca [4 x [4 x i32]]
%12 = alloca [4 x [4 x i32]]
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32
%17 = alloca i64
store i64 %0, i64* %6
store i64 %1, i64* %7
store double %2, double* %8
store double* %3, double** %9
store double* %4, double** %10
%18 = bitcast [4 x [4 x i32]]* %11 to i8*
%19 = bitcast [4 x [4 x i32]]* %12 to i8*
%20 = load i64, i64* %7
%21 = sdiv i64 %20, 4
store i64 %21, i64* %13
%22 = load i64, i64* %6
store i64 %22, i64* %14
store i64 1, i64* %15
%23 = load double*, double** %10
store double 0.000000e+00, double* %23
%24 = load double*, double** %9
store double 0.000000e+00, double* %24
br label %25
25: ; preds = %68, %5
%26 = load i64, i64* %13
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %69
28: ; preds = %25
%29 = load i64, i64* %14
%30 = load i64, i64* %13
%31 = sdiv i64 %29, %30
store i64 %31, i64* %17
%32 = load i64, i64* %14
%33 = load i64, i64* %13
%34 = srem i64 %32, %33
store i64 %34, i64* %14
%35 = load i64, i64* %13
%36 = sdiv i64 %35, 4
store i64 %36, i64* %13
%37 = load i64, i64* %15
%38 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %11, i64 0, i64 %37
%39 = load i64, i64* %17
%40 = getelementptr inbounds [4 x i32], [4 x i32]* %38, i64 0, i64 %39
%41 = load i32, i32* %40
store i32 %41, i32* %16
%42 = load i64, i64* %15
%43 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %12, i64 0, i64 %42
%44 = load i32, i32* %16
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4 x i32], [4 x i32]* %43, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = sext i32 %47 to i64
store i64 %48, i64* %15
%49 = load double, double* %8
%50 = fdiv double %49, 2.000000e+00
store double %50, double* %8
%51 = load i32, i32* %16
%52 = and i32 %51, 1
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %28
%55 = load double, double* %8
%56 = load double*, double** %9
%57 = load double, double* %56
%58 = fadd double %57, %55
store double %58, double* %56
br label %59
59: ; preds = %54, %28
%60 = load i32, i32* %16
%61 = and i32 %60, 2
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %59
%64 = load double, double* %8
%65 = load double*, double** %10
%66 = load double, double* %65
%67 = fadd double %66, %64
store double %67, double* %65
br label %68
68: ; preds = %63, %59
br label %25
69: ; preds = %25
ret void
}

LLVM IR (-O2):
@__const.hilpoint.patterns = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 3, i32 2], [4 x i32] [i32 0, i32 2, i32 3, i32 1], [4 x i32] [i32 3, i32 1, i32 0, i32 2], [4 x i32] [i32 3, i32 2, i32 0, i32 1]]
@__const.hilpoint.transforms = [4 x [4 x i32]] [[4 x i32] [i32 1, i32 0, i32 2, i32 0], [4 x i32] [i32 0, i32 3, i32 1, i32 1], [4 x i32] [i32 2, i32 2, i32 0, i32 3], [4 x i32] [i32 3, i32 1, i32 3, i32 2]]
define void @hilpoint(i64 %0, i64 %1, double %2, double* nocapture %3, double* nocapture %4) {
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %3
%6 = icmp sgt i64 %1, 3
br i1 %6, label %7, label %35
7: ; preds = %5, %33
%8 = phi i64 [ %12, %33 ], [ %1, %5 ]
%9 = phi double [ %21, %33 ], [ %2, %5 ]
%10 = phi i64 [ %20, %33 ], [ 1, %5 ]
%11 = phi i64 [ %14, %33 ], [ %0, %5 ]
%12 = sdiv i64 %8, 4
%13 = sdiv i64 %11, %12
%14 = srem i64 %11, %12
%15 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* @__const.hilpoint.patterns, i64 0, i64 %10, i64 %13
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* @__const.hilpoint.transforms, i64 0, i64 %10, i64 %17
%19 = load i32, i32* %18
%20 = sext i32 %19 to i64
%21 = fmul double %9, 5.000000e-01
%22 = and i32 %16, 1
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %7
%25 = load double, double* %3
%26 = fadd double %21, %25
store double %26, double* %3
br label %27
27: ; preds = %24, %7
%28 = and i32 %16, 2
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load double, double* %4
%32 = fadd double %21, %31
store double %32, double* %4
br label %33
33: ; preds = %30, %27
%34 = icmp sgt i64 %8, 15
br i1 %34, label %7, label %35
35: ; preds = %33, %5
ret void
}