unsigned short op(unsigned short x, unsigned short y) {
  unsigned short i = 0, j;
  static const unsigned short p9[5] = {1, 9, 81, 729, 6561};
  static const unsigned short o[9][9] = {
      {4, 3, 3, 1, 0, 0, 1, 0, 0}, {4, 3, 5, 1, 0, 2, 1, 0, 2},
      {5, 5, 4, 2, 2, 1, 2, 2, 1}, {4, 3, 3, 1, 0, 0, 7, 6, 6},
      {4, 3, 5, 1, 0, 2, 7, 6, 8}, {5, 5, 4, 2, 2, 1, 8, 8, 7},
      {7, 6, 6, 7, 6, 6, 4, 3, 3}, {7, 6, 8, 7, 6, 8, 4, 3, 5},
      {8, 8, 7, 8, 8, 7, 5, 5, 4},
  };
  for (j = 0; j < 5; j++)
    i += o[y / p9[j] % 9][x / p9[j] % 9] * p9[j];
  return (i);
}


x86 assembly (clang, -O0):
<op>:
push   %rbp
mov    %rsp,%rbp
mov    %si,%ax
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %ax,-0x4(%rbp)
movw   $0x0,-0x6(%rbp)
movw   $0x0,-0x8(%rbp)
movzwl -0x8(%rbp),%eax
cmp    $0x5,%eax
jge    11ba <op+0xba>
movzwl -0x4(%rbp),%eax
movzwl -0x8(%rbp),%ecx
mov    %ecx,%edx
lea    0xec4(%rip),%rcx
movzwl (%rcx,%rdx,2),%ecx
cltd
idiv   %ecx
mov    $0x9,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xebb(%rip),%rax
imul   $0x12,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movzwl -0x2(%rbp),%eax
movzwl -0x8(%rbp),%ecx
mov    %ecx,%edx
lea    0xe8f(%rip),%rcx
movzwl (%rcx,%rdx,2),%ecx
cltd
idiv   %ecx
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
movslq %edx,%rcx
movzwl (%rax,%rcx,2),%ecx
movzwl -0x8(%rbp),%eax
mov    %eax,%edx
lea    0xe68(%rip),%rax
movzwl (%rax,%rdx,2),%eax
imul   %eax,%ecx
movzwl -0x6(%rbp),%eax
add    %ecx,%eax
mov    %ax,-0x6(%rbp)
mov    -0x8(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x8(%rbp)
jmp    111e <op+0x1e>
movzwl -0x6(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<op>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
imul   $0xe38f,%esi,%r10d
shr    $0x13,%r10d
lea    (%r10,%r10,8),%r8d
imul   $0x6523,%esi,%r14d
imul   $0x6799,%esi,%r11d
mov    %esi,%r9d
imul   $0x4fe9,%esi,%eax
mov    %esi,%ebx
sub    %r8d,%ebx
imul   $0xe38f,%edi,%edx
shr    $0x13,%edx
lea    (%rdx,%rdx,8),%r15d
imul   $0x6523,%edi,%ebp
imul   $0x6799,%edi,%r12d
mov    %edi,%r8d
imul   $0x4fe9,%edi,%esi
sub    %r15d,%edi
imul   $0xe38f,%r10d,%ecx
shr    $0x13,%ecx
lea    (%rcx,%rcx,8),%ecx
sub    %ecx,%r10d
imul   $0xe38f,%edx,%ecx
shr    $0x13,%ecx
lea    (%rcx,%rcx,8),%ecx
sub    %ecx,%edx
lea    0xe82(%rip),%r15
movzwl %r10w,%ecx
movzwl %dx,%edx
lea    (%rcx,%rcx,8),%rcx
lea    (%r15,%rcx,2),%rcx
movzwl (%rcx,%rdx,2),%ecx
movzwl %bx,%edx
movzwl %di,%edi
lea    (%rdx,%rdx,8),%rdx
lea    (%r15,%rdx,2),%rdx
lea    (%rcx,%rcx,8),%ecx
add    (%rdx,%rdi,2),%cx
shr    $0x15,%r14d
imul   $0xe38f,%r14d,%edx
shr    $0x13,%edx
lea    (%rdx,%rdx,8),%edx
sub    %edx,%r14d
shr    $0x15,%ebp
imul   $0xe38f,%ebp,%edx
shr    $0x13,%edx
lea    (%rdx,%rdx,8),%edx
sub    %edx,%ebp
movzwl %r14w,%edx
movzwl %bp,%edi
lea    (%rdx,%rdx,8),%rdx
lea    (%r15,%rdx,2),%rdx
movzwl (%rdx,%rdi,2),%edx
lea    (%rdx,%rdx,8),%edx
lea    (%rdx,%rdx,8),%edx
add    %ecx,%edx
shr    $0x10,%r11d
sub    %r11d,%r9d
movzwl %r9w,%ecx
shr    %ecx
add    %r11d,%ecx
shr    $0x9,%ecx
imul   $0x39,%ecx,%edi
shr    $0x9,%edi
lea    (%rdi,%rdi,8),%edi
sub    %dil,%cl
movzbl %cl,%ecx
shr    $0x10,%r12d
sub    %r12d,%r8d
movzwl %r8w,%edi
shr    %edi
add    %r12d,%edi
shr    $0x9,%edi
imul   $0x39,%edi,%ebp
shr    $0x9,%ebp
lea    0x0(%rbp,%rbp,8),%ebp
sub    %bpl,%dil
movzbl %dil,%edi
lea    (%rcx,%rcx,8),%rcx
lea    (%r15,%rcx,2),%rcx
movzwl (%rcx,%rdi,2),%ecx
imul   $0x2d9,%ecx,%ecx
add    %edx,%ecx
shr    $0x1b,%eax
imul   $0x39,%eax,%edx
shr    $0x9,%edx
lea    (%rdx,%rdx,8),%edx
sub    %dl,%al
movzbl %al,%eax
shr    $0x1b,%esi
imul   $0x39,%esi,%edx
shr    $0x9,%edx
lea    (%rdx,%rdx,8),%edx
sub    %dl,%sil
movzbl %sil,%edx
lea    (%rax,%rax,8),%rax
lea    (%r15,%rax,2),%rax
movzwl (%rax,%rdx,2),%eax
imul   $0x19a1,%eax,%eax
add    %ecx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@op.p9 = internal constant [5 x i16] [i16 1, i16 9, i16 81, i16 729, i16 6561]
@op.o = internal constant [9 x [9 x i16]] [[9 x i16] [i16 4, i16 3, i16 3, i16 1, i16 0, i16 0, i16 1, i16 0, i16 0], [9 x i16] [i16 4, i16 3, i16 5, i16 1, i16 0, i16 2, i16 1, i16 0, i16 2], [9 x i16] [i16 5, i16 5, i16 4, i16 2, i16 2, i16 1, i16 2, i16 2, i16 1], [9 x i16] [i16 4, i16 3, i16 3, i16 1, i16 0, i16 0, i16 7, i16 6, i16 6], [9 x i16] [i16 4, i16 3, i16 5, i16 1, i16 0, i16 2, i16 7, i16 6, i16 8], [9 x i16] [i16 5, i16 5, i16 4, i16 2, i16 2, i16 1, i16 8, i16 8, i16 7], [9 x i16] [i16 7, i16 6, i16 6, i16 7, i16 6, i16 6, i16 4, i16 3, i16 3], [9 x i16] [i16 7, i16 6, i16 8, i16 7, i16 6, i16 8, i16 4, i16 3, i16 5], [9 x i16] [i16 8, i16 8, i16 7, i16 8, i16 8, i16 7, i16 5, i16 5, i16 4]]
define zeroext i16 @op(i16 zeroext %0, i16 zeroext %1) {
%3 = alloca i16
%4 = alloca i16
%5 = alloca i16
%6 = alloca i16
store i16 %0, i16* %3
store i16 %1, i16* %4
store i16 0, i16* %5
store i16 0, i16* %6
br label %7
7: ; preds = %46, %2
%8 = load i16, i16* %6
%9 = zext i16 %8 to i32
%10 = icmp slt i32 %9, 5
br i1 %10, label %11, label %49
11: ; preds = %7
%12 = load i16, i16* %4
%13 = zext i16 %12 to i32
%14 = load i16, i16* %6
%15 = zext i16 %14 to i64
%16 = getelementptr inbounds [5 x i16], [5 x i16]* @op.p9, i64 0, i64 %15
%17 = load i16, i16* %16
%18 = zext i16 %17 to i32
%19 = sdiv i32 %13, %18
%20 = srem i32 %19, 9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [9 x [9 x i16]], [9 x [9 x i16]]* @op.o, i64 0, i64 %21
%23 = load i16, i16* %3
%24 = zext i16 %23 to i32
%25 = load i16, i16* %6
%26 = zext i16 %25 to i64
%27 = getelementptr inbounds [5 x i16], [5 x i16]* @op.p9, i64 0, i64 %26
%28 = load i16, i16* %27
%29 = zext i16 %28 to i32
%30 = sdiv i32 %24, %29
%31 = srem i32 %30, 9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [9 x i16], [9 x i16]* %22, i64 0, i64 %32
%34 = load i16, i16* %33
%35 = zext i16 %34 to i32
%36 = load i16, i16* %6
%37 = zext i16 %36 to i64
%38 = getelementptr inbounds [5 x i16], [5 x i16]* @op.p9, i64 0, i64 %37
%39 = load i16, i16* %38
%40 = zext i16 %39 to i32
%41 = mul nsw i32 %35, %40
%42 = load i16, i16* %5
%43 = zext i16 %42 to i32
%44 = add nsw i32 %43, %41
%45 = trunc i32 %44 to i16
store i16 %45, i16* %5
br label %46
46: ; preds = %11
%47 = load i16, i16* %6
%48 = add i16 %47, 1
store i16 %48, i16* %6
br label %7
49: ; preds = %7
%50 = load i16, i16* %5
ret i16 %50
}

LLVM IR (-O2):
@op.o = internal unnamed_addr constant [9 x [9 x i16]] [[9 x i16] [i16 4, i16 3, i16 3, i16 1, i16 0, i16 0, i16 1, i16 0, i16 0], [9 x i16] [i16 4, i16 3, i16 5, i16 1, i16 0, i16 2, i16 1, i16 0, i16 2], [9 x i16] [i16 5, i16 5, i16 4, i16 2, i16 2, i16 1, i16 2, i16 2, i16 1], [9 x i16] [i16 4, i16 3, i16 3, i16 1, i16 0, i16 0, i16 7, i16 6, i16 6], [9 x i16] [i16 4, i16 3, i16 5, i16 1, i16 0, i16 2, i16 7, i16 6, i16 8], [9 x i16] [i16 5, i16 5, i16 4, i16 2, i16 2, i16 1, i16 8, i16 8, i16 7], [9 x i16] [i16 7, i16 6, i16 6, i16 7, i16 6, i16 6, i16 4, i16 3, i16 3], [9 x i16] [i16 7, i16 6, i16 8, i16 7, i16 6, i16 8, i16 4, i16 3, i16 5], [9 x i16] [i16 8, i16 8, i16 7, i16 8, i16 8, i16 7, i16 5, i16 5, i16 4]]
define zeroext i16 @op(i16 zeroext %0, i16 zeroext %1) {
%3 = urem i16 %1, 9
%4 = zext i16 %3 to i64
%5 = urem i16 %0, 9
%6 = zext i16 %5 to i64
%7 = getelementptr inbounds [9 x [9 x i16]], [9 x [9 x i16]]* @op.o, i64 0, i64 %4, i64 %6
%8 = load i16, i16* %7
%9 = udiv i16 %1, 9
%10 = urem i16 %9, 9
%11 = zext i16 %10 to i64
%12 = udiv i16 %0, 9
%13 = urem i16 %12, 9
%14 = zext i16 %13 to i64
%15 = getelementptr inbounds [9 x [9 x i16]], [9 x [9 x i16]]* @op.o, i64 0, i64 %11, i64 %14
%16 = load i16, i16* %15
%17 = mul i16 %16, 9
%18 = add i16 %17, %8
%19 = udiv i16 %1, 81
%20 = urem i16 %19, 9
%21 = zext i16 %20 to i64
%22 = udiv i16 %0, 81
%23 = urem i16 %22, 9
%24 = zext i16 %23 to i64
%25 = getelementptr inbounds [9 x [9 x i16]], [9 x [9 x i16]]* @op.o, i64 0, i64 %21, i64 %24
%26 = load i16, i16* %25
%27 = mul i16 %26, 81
%28 = add i16 %27, %18
%29 = udiv i16 %1, 729
%30 = trunc i16 %29 to i8
%31 = urem i8 %30, 9
%32 = zext i8 %31 to i64
%33 = udiv i16 %0, 729
%34 = trunc i16 %33 to i8
%35 = urem i8 %34, 9
%36 = zext i8 %35 to i64
%37 = getelementptr inbounds [9 x [9 x i16]], [9 x [9 x i16]]* @op.o, i64 0, i64 %32, i64 %36
%38 = load i16, i16* %37
%39 = mul i16 %38, 729
%40 = add i16 %39, %28
%41 = udiv i16 %1, 6561
%42 = trunc i16 %41 to i8
%43 = urem i8 %42, 9
%44 = zext i8 %43 to i64
%45 = udiv i16 %0, 6561
%46 = trunc i16 %45 to i8
%47 = urem i8 %46, 9
%48 = zext i8 %47 to i64
%49 = getelementptr inbounds [9 x [9 x i16]], [9 x [9 x i16]]* @op.o, i64 0, i64 %44, i64 %48
%50 = load i16, i16* %49
%51 = mul i16 %50, 6561
%52 = add i16 %51, %40
ret i16 %52
}