#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int calc_stream_moves(unsigned short, int, int);
unsigned short get_back_diag(unsigned long long, unsigned long long, int);
unsigned short get_forward_diag(unsigned long long, unsigned long long, int);
int calc_moves(unsigned long long board_l, unsigned long long board_u,
               int pos) {
  unsigned short stream;
  int row, col, fdiag, bdiag;
  int diag;
  if (pos < 50)
    stream = (board_l >> ((int)pos / 10 % 5) * 10) & 0x3ff;
  else
    stream = (board_u >> ((int)pos / 10 % 5) * 10) & 0x3ff;
  row = calc_stream_moves(stream, pos % 10, 10);
  stream =
      ((((board_l >> pos % 10) & 0x1) | ((board_l >> (pos % 10 + 9)) & 0x2) |
        ((board_l >> (pos % 10 + 18)) & 0x4) |
        ((board_l >> (pos % 10 + 27)) & 0x8) |
        ((board_l >> (pos % 10 + 36)) & 0x10)) |
       ((((board_u >> pos % 10) & 0x1) | ((board_u >> (pos % 10 + 9)) & 0x2) |
         ((board_u >> (pos % 10 + 18)) & 0x4) |
         ((board_u >> (pos % 10 + 27)) & 0x8) |
         ((board_u >> (pos % 10 + 36)) & 0x10))
        << 5));
  col = calc_stream_moves(stream, (int)pos / 10, 10);
  diag =
      (pos % 10 > pos / 10) ? pos - ((pos / 10) * 11) : pos - ((pos % 10) * 11);
  stream = get_forward_diag(board_l, board_u, diag);
  fdiag = calc_stream_moves(stream, (pos % 10 > pos / 10) ? pos / 10 : pos % 10,
                            (diag < 10) ? (10 - diag) : (10 - diag / 10));
  diag = (pos / 10 < (10 - pos % 10)) ? pos - ((pos / 10) * 9)
                                      : pos - ((9 - (pos % 10)) * 9);
  stream = get_back_diag(board_l, board_u, diag);
  bdiag = calc_stream_moves(
      stream, (pos / 10 < (10 - pos % 10)) ? pos / 10 : 9 - pos % 10,
      (diag < 10) ? diag + 1 : (10 - diag / 10));
  return (row + col + fdiag + bdiag);
}


x86 assembly (clang, -O0):
<calc_moves>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x32,-0x14(%rbp)
jge    1186 <calc_moves+0x56>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
imul   $0xa,%edx,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
and    $0x3ff,%rax
mov    %ax,-0x16(%rbp)
jmp    11b7 <calc_moves+0x87>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    -0x40(%rbp),%rax
imul   $0xa,%edx,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
and    $0x3ff,%rax
mov    %ax,-0x16(%rbp)
mov    -0x16(%rbp),%ax
mov    %ax,-0xe2(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0xe2(%rbp),%ax
mov    %edx,%esi
mov    $0xa,%edx
movzwl %ax,%edi
call   1040 <calc_stream_moves@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0xe0(%rbp),%rax
mov    %edx,%ecx
shr    %cl,%rax
and    $0x1,%rax
mov    %rax,-0xd8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0xd8(%rbp),%rax
mov    %edx,%ecx
mov    -0xd0(%rbp),%rdx
add    $0x9,%ecx
mov    %ecx,%ecx
shr    %cl,%rdx
mov    %rdx,%rcx
and    $0x2,%rcx
or     %rcx,%rax
mov    %rax,-0xc8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0xc8(%rbp),%rax
mov    %edx,%ecx
mov    -0xc0(%rbp),%rdx
add    $0x12,%ecx
mov    %ecx,%ecx
shr    %cl,%rdx
mov    %rdx,%rcx
and    $0x4,%rcx
or     %rcx,%rax
mov    %rax,-0xb8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0xb8(%rbp),%rax
mov    %edx,%ecx
mov    -0xb0(%rbp),%rdx
add    $0x1b,%ecx
mov    %ecx,%ecx
shr    %cl,%rdx
mov    %rdx,%rcx
and    $0x8,%rcx
or     %rcx,%rax
mov    %rax,-0xa8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0xa8(%rbp),%rax
mov    %edx,%ecx
mov    -0xa0(%rbp),%rdx
add    $0x24,%ecx
mov    %ecx,%ecx
shr    %cl,%rdx
mov    %rdx,%rcx
and    $0x10,%rcx
or     %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x98(%rbp),%rax
mov    %edx,%ecx
shr    %cl,%rax
and    $0x1,%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x90(%rbp),%rax
mov    %edx,%ecx
mov    -0x88(%rbp),%rdx
add    $0x9,%ecx
mov    %ecx,%ecx
shr    %cl,%rdx
mov    %rdx,%rcx
and    $0x2,%rcx
or     %rcx,%rax
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x80(%rbp),%rax
mov    %edx,%ecx
mov    -0x78(%rbp),%rdx
add    $0x12,%ecx
mov    %ecx,%ecx
shr    %cl,%rdx
mov    %rdx,%rcx
and    $0x4,%rcx
or     %rcx,%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x70(%rbp),%rax
mov    %edx,%ecx
mov    -0x68(%rbp),%rdx
add    $0x1b,%ecx
mov    %ecx,%ecx
shr    %cl,%rdx
mov    %rdx,%rcx
and    $0x8,%rcx
or     %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x60(%rbp),%rax
mov    %edx,%ecx
mov    -0x58(%rbp),%rdx
add    $0x24,%ecx
mov    %ecx,%ecx
shr    %cl,%rdx
mov    -0x50(%rbp),%rcx
and    $0x10,%rdx
or     %rdx,%rcx
shl    $0x5,%rcx
or     %rcx,%rax
mov    %ax,-0x16(%rbp)
mov    -0x16(%rbp),%ax
mov    %ax,-0x46(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x46(%rbp),%ax
mov    $0xa,%edx
movzwl %ax,%edi
call   1040 <calc_stream_moves@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x44(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x44(%rbp),%edx
cmp    %eax,%edx
jle    148f <calc_moves+0x35f>
mov    -0x14(%rbp),%eax
mov    %eax,-0xec(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xec(%rbp),%eax
imul   $0xb,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0xe8(%rbp)
jmp    14b4 <calc_moves+0x384>
mov    -0x14(%rbp),%eax
mov    %eax,-0xf0(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0xf0(%rbp),%eax
imul   $0xb,%edx,%ecx
sub    %ecx,%eax
mov    %eax,-0xe8(%rbp)
mov    -0xe8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <get_forward_diag@plt>
mov    %ax,-0x16(%rbp)
mov    -0x16(%rbp),%ax
mov    %ax,-0xf6(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xf4(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0xf4(%rbp),%edx
cmp    %eax,%edx
jle    151e <calc_moves+0x3ee>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    %edx,-0xfc(%rbp)
jmp    152f <calc_moves+0x3ff>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xfc(%rbp)
mov    -0xfc(%rbp),%eax
mov    %eax,-0x100(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    1558 <calc_moves+0x428>
mov    $0xa,%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x104(%rbp)
jmp    1572 <calc_moves+0x442>
mov    -0x2c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0xa,%eax
sub    %ecx,%eax
mov    %eax,-0x104(%rbp)
mov    -0x100(%rbp),%esi
mov    -0xf6(%rbp),%ax
mov    -0x104(%rbp),%edx
movzwl %ax,%edi
call   1040 <calc_stream_moves@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x108(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x108(%rbp),%eax
mov    $0xa,%ecx
sub    %edx,%ecx
cmp    %ecx,%eax
jge    15ed <calc_moves+0x4bd>
mov    -0x14(%rbp),%eax
mov    %eax,-0x110(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x110(%rbp),%eax
imul   $0x9,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0x10c(%rbp)
jmp    1619 <calc_moves+0x4e9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x114(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x114(%rbp),%eax
mov    $0x9,%ecx
sub    %edx,%ecx
imul   $0x9,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0x10c(%rbp)
mov    -0x10c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <get_back_diag@plt>
mov    %ax,-0x16(%rbp)
mov    -0x16(%rbp),%ax
mov    %ax,-0x11a(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x118(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x118(%rbp),%eax
mov    $0xa,%ecx
sub    %edx,%ecx
cmp    %ecx,%eax
jge    1688 <calc_moves+0x558>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x120(%rbp)
jmp    16a0 <calc_moves+0x570>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    $0x9,%eax
sub    %edx,%eax
mov    %eax,-0x120(%rbp)
mov    -0x120(%rbp),%eax
mov    %eax,-0x124(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    16c7 <calc_moves+0x597>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
jmp    16e1 <calc_moves+0x5b1>
mov    -0x2c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0xa,%eax
sub    %ecx,%eax
mov    %eax,-0x128(%rbp)
mov    -0x124(%rbp),%esi
mov    -0x11a(%rbp),%ax
mov    -0x128(%rbp),%edx
movzwl %ax,%edi
call   1040 <calc_stream_moves@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_moves>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,%r14
movslq %edx,%rax
cmp    $0x31,%edx
jg     1189 <calc_moves+0x59>
imul   $0x66666667,%rax,%r15
mov    %r15,%rcx
shr    $0x3f,%rcx
sar    $0x22,%r15
add    %ecx,%r15d
movslq %r15d,%rcx
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x21,%rdx
add    %esi,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %r14,%rdi
jmp    11b4 <calc_moves+0x84>
mov    %ebx,%r15d
mov    $0xcccccccd,%ecx
imul   %rcx,%r15
shr    $0x23,%r15
mov    %r15,%rdx
imul   %rcx,%rdx
shr    $0x22,%rdx
lea    (%rdx,%rdx,4),%ecx
mov    %r15d,%edx
sub    %ecx,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%ecx
mov    %r12,%rdi
shr    %cl,%rdi
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %ebx,%r13d
sub    %eax,%r13d
and    $0x3ff,%edi
mov    %r13d,%esi
mov    $0xa,%edx
call   1040 <calc_stream_moves@plt>
mov    %eax,0x4(%rsp)
mov    %r14,%rdx
mov    %r13d,%ecx
shr    %cl,%rdx
lea    0x9(%r13),%r8d
mov    %r14,%rdi
mov    %r8d,%ecx
shr    %cl,%rdi
and    $0x1,%edx
and    $0x2,%edi
or     %edx,%edi
lea    0x12(%r13),%r9d
mov    %r14,%rbp
mov    %r9d,%ecx
shr    %cl,%rbp
and    $0x4,%ebp
lea    0x1b(%r13),%esi
mov    %ebx,(%rsp)
mov    %r14,%rbx
mov    %esi,%ecx
shr    %cl,%rbx
or     %edi,%ebp
and    $0x8,%ebx
or     %ebp,%ebx
lea    0x24(%r13),%edi
mov    %r14,%rbp
mov    %edi,%ecx
shr    %cl,%rbp
and    $0x10,%ebp
or     %ebx,%ebp
mov    %r12,%rbx
mov    %r13d,%ecx
shr    %cl,%rbx
and    $0x1,%ebx
mov    %r12,%rax
mov    %r8d,%ecx
shr    %cl,%rax
and    $0x2,%eax
mov    %r12,%rdx
mov    %r9d,%ecx
shr    %cl,%rdx
or     %ebx,%eax
mov    %r12,%rbx
mov    %esi,%ecx
shr    %cl,%rbx
and    $0x4,%edx
or     %eax,%edx
and    $0x8,%ebx
or     %edx,%ebx
mov    %r12,%rax
mov    %edi,%ecx
shr    %cl,%rax
and    $0x10,%eax
or     %ebx,%eax
shl    $0x5,%eax
or     %ebp,%eax
movzwl %ax,%edi
mov    %r15d,%esi
mov    $0xa,%edx
call   1040 <calc_stream_moves@plt>
mov    %r12,%rsi
mov    %eax,%r12d
cmp    %r15d,%r13d
mov    %r13d,%ebx
cmovg  %r15d,%ebx
imul   $0xfffffff5,%ebx,%ebp
add    (%rsp),%ebp
mov    %r14,0x8(%rsp)
mov    %r14,%rdi
mov    %rsi,0x10(%rsp)
mov    %ebp,%edx
call   1050 <get_forward_diag@plt>
cmp    $0xa,%ebp
jl     12d7 <calc_moves+0x1a7>
mov    %ebp,%ecx
mov    $0xcccccccd,%ebp
imul   %rcx,%rbp
shr    $0x23,%rbp
mov    $0xa,%edx
sub    %ebp,%edx
movzwl %ax,%edi
mov    %ebx,%esi
call   1040 <calc_stream_moves@plt>
mov    %eax,%ebp
mov    $0xa,%eax
sub    %r13d,%eax
mov    $0x9,%r14d
sub    %r13d,%r14d
cmp    %eax,%r15d
cmovl  %r15d,%r14d
lea    (%r14,%r14,8),%eax
mov    (%rsp),%ebx
sub    %eax,%ebx
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    %ebx,%edx
call   1030 <get_back_diag@plt>
cmp    $0x9,%ebx
jg     1326 <calc_moves+0x1f6>
add    $0x1,%ebx
jmp    133c <calc_moves+0x20c>
mov    %ebx,%ecx
mov    $0xcccccccd,%edx
imul   %rcx,%rdx
shr    $0x23,%rdx
mov    $0xa,%ebx
sub    %edx,%ebx
movzwl %ax,%edi
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <calc_stream_moves@plt>
add    0x4(%rsp),%r12d
add    %ebp,%r12d
add    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calc_moves(i64 %0, i64 %1, i32 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i16
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i64 %0, i64* %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 50
br i1 %14, label %15, label %25
15: ; preds = %3
%16 = load i64, i64* %4
%17 = load i32, i32* %6
%18 = sdiv i32 %17, 10
%19 = srem i32 %18, 5
%20 = mul nsw i32 %19, 10
%21 = zext i32 %20 to i64
%22 = lshr i64 %16, %21
%23 = and i64 %22, 1023
%24 = trunc i64 %23 to i16
store i16 %24, i16* %7
br label %35
25: ; preds = %3
%26 = load i64, i64* %5
%27 = load i32, i32* %6
%28 = sdiv i32 %27, 10
%29 = srem i32 %28, 5
%30 = mul nsw i32 %29, 10
%31 = zext i32 %30 to i64
%32 = lshr i64 %26, %31
%33 = and i64 %32, 1023
%34 = trunc i64 %33 to i16
store i16 %34, i16* %7
br label %35
35: ; preds = %25, %15
%36 = load i16, i16* %7
%37 = load i32, i32* %6
%38 = srem i32 %37, 10
%39 = call i32 @calc_stream_moves(i16 zeroext %36, i32 %38, i32 10)
store i32 %39, i32* %8
%40 = load i64, i64* %4
%41 = load i32, i32* %6
%42 = srem i32 %41, 10
%43 = zext i32 %42 to i64
%44 = lshr i64 %40, %43
%45 = and i64 %44, 1
%46 = load i64, i64* %4
%47 = load i32, i32* %6
%48 = srem i32 %47, 10
%49 = add nsw i32 %48, 9
%50 = zext i32 %49 to i64
%51 = lshr i64 %46, %50
%52 = and i64 %51, 2
%53 = or i64 %45, %52
%54 = load i64, i64* %4
%55 = load i32, i32* %6
%56 = srem i32 %55, 10
%57 = add nsw i32 %56, 18
%58 = zext i32 %57 to i64
%59 = lshr i64 %54, %58
%60 = and i64 %59, 4
%61 = or i64 %53, %60
%62 = load i64, i64* %4
%63 = load i32, i32* %6
%64 = srem i32 %63, 10
%65 = add nsw i32 %64, 27
%66 = zext i32 %65 to i64
%67 = lshr i64 %62, %66
%68 = and i64 %67, 8
%69 = or i64 %61, %68
%70 = load i64, i64* %4
%71 = load i32, i32* %6
%72 = srem i32 %71, 10
%73 = add nsw i32 %72, 36
%74 = zext i32 %73 to i64
%75 = lshr i64 %70, %74
%76 = and i64 %75, 16
%77 = or i64 %69, %76
%78 = load i64, i64* %5
%79 = load i32, i32* %6
%80 = srem i32 %79, 10
%81 = zext i32 %80 to i64
%82 = lshr i64 %78, %81
%83 = and i64 %82, 1
%84 = load i64, i64* %5
%85 = load i32, i32* %6
%86 = srem i32 %85, 10
%87 = add nsw i32 %86, 9
%88 = zext i32 %87 to i64
%89 = lshr i64 %84, %88
%90 = and i64 %89, 2
%91 = or i64 %83, %90
%92 = load i64, i64* %5
%93 = load i32, i32* %6
%94 = srem i32 %93, 10
%95 = add nsw i32 %94, 18
%96 = zext i32 %95 to i64
%97 = lshr i64 %92, %96
%98 = and i64 %97, 4
%99 = or i64 %91, %98
%100 = load i64, i64* %5
%101 = load i32, i32* %6
%102 = srem i32 %101, 10
%103 = add nsw i32 %102, 27
%104 = zext i32 %103 to i64
%105 = lshr i64 %100, %104
%106 = and i64 %105, 8
%107 = or i64 %99, %106
%108 = load i64, i64* %5
%109 = load i32, i32* %6
%110 = srem i32 %109, 10
%111 = add nsw i32 %110, 36
%112 = zext i32 %111 to i64
%113 = lshr i64 %108, %112
%114 = and i64 %113, 16
%115 = or i64 %107, %114
%116 = shl i64 %115, 5
%117 = or i64 %77, %116
%118 = trunc i64 %117 to i16
store i16 %118, i16* %7
%119 = load i16, i16* %7
%120 = load i32, i32* %6
%121 = sdiv i32 %120, 10
%122 = call i32 @calc_stream_moves(i16 zeroext %119, i32 %121, i32 10)
store i32 %122, i32* %9
%123 = load i32, i32* %6
%124 = srem i32 %123, 10
%125 = load i32, i32* %6
%126 = sdiv i32 %125, 10
%127 = icmp sgt i32 %124, %126
br i1 %127, label %128, label %134
128: ; preds = %35
%129 = load i32, i32* %6
%130 = load i32, i32* %6
%131 = sdiv i32 %130, 10
%132 = mul nsw i32 %131, 11
%133 = sub nsw i32 %129, %132
br label %140
134: ; preds = %35
%135 = load i32, i32* %6
%136 = load i32, i32* %6
%137 = srem i32 %136, 10
%138 = mul nsw i32 %137, 11
%139 = sub nsw i32 %135, %138
br label %140
140: ; preds = %134, %128
%141 = phi i32 [ %133, %128 ], [ %139, %134 ]
store i32 %141, i32* %12
%142 = load i64, i64* %4
%143 = load i64, i64* %5
%144 = load i32, i32* %12
%145 = call zeroext i16 @get_forward_diag(i64 %142, i64 %143, i32 %144)
store i16 %145, i16* %7
%146 = load i16, i16* %7
%147 = load i32, i32* %6
%148 = srem i32 %147, 10
%149 = load i32, i32* %6
%150 = sdiv i32 %149, 10
%151 = icmp sgt i32 %148, %150
br i1 %151, label %152, label %155
152: ; preds = %140
%153 = load i32, i32* %6
%154 = sdiv i32 %153, 10
br label %158
155: ; preds = %140
%156 = load i32, i32* %6
%157 = srem i32 %156, 10
br label %158
158: ; preds = %155, %152
%159 = phi i32 [ %154, %152 ], [ %157, %155 ]
%160 = load i32, i32* %12
%161 = icmp slt i32 %160, 10
br i1 %161, label %162, label %165
162: ; preds = %158
%163 = load i32, i32* %12
%164 = sub nsw i32 10, %163
br label %169
165: ; preds = %158
%166 = load i32, i32* %12
%167 = sdiv i32 %166, 10
%168 = sub nsw i32 10, %167
br label %169
169: ; preds = %165, %162
%170 = phi i32 [ %164, %162 ], [ %168, %165 ]
%171 = call i32 @calc_stream_moves(i16 zeroext %146, i32 %159, i32 %170)
store i32 %171, i32* %10
%172 = load i32, i32* %6
%173 = sdiv i32 %172, 10
%174 = load i32, i32* %6
%175 = srem i32 %174, 10
%176 = sub nsw i32 10, %175
%177 = icmp slt i32 %173, %176
br i1 %177, label %178, label %184
178: ; preds = %169
%179 = load i32, i32* %6
%180 = load i32, i32* %6
%181 = sdiv i32 %180, 10
%182 = mul nsw i32 %181, 9
%183 = sub nsw i32 %179, %182
br label %191
184: ; preds = %169
%185 = load i32, i32* %6
%186 = load i32, i32* %6
%187 = srem i32 %186, 10
%188 = sub nsw i32 9, %187
%189 = mul nsw i32 %188, 9
%190 = sub nsw i32 %185, %189
br label %191
191: ; preds = %184, %178
%192 = phi i32 [ %183, %178 ], [ %190, %184 ]
store i32 %192, i32* %12
%193 = load i64, i64* %4
%194 = load i64, i64* %5
%195 = load i32, i32* %12
%196 = call zeroext i16 @get_back_diag(i64 %193, i64 %194, i32 %195)
store i16 %196, i16* %7
%197 = load i16, i16* %7
%198 = load i32, i32* %6
%199 = sdiv i32 %198, 10
%200 = load i32, i32* %6
%201 = srem i32 %200, 10
%202 = sub nsw i32 10, %201
%203 = icmp slt i32 %199, %202
br i1 %203, label %204, label %207
204: ; preds = %191
%205 = load i32, i32* %6
%206 = sdiv i32 %205, 10
br label %211
207: ; preds = %191
%208 = load i32, i32* %6
%209 = srem i32 %208, 10
%210 = sub nsw i32 9, %209
br label %211
211: ; preds = %207, %204
%212 = phi i32 [ %206, %204 ], [ %210, %207 ]
%213 = load i32, i32* %12
%214 = icmp slt i32 %213, 10
br i1 %214, label %215, label %218
215: ; preds = %211
%216 = load i32, i32* %12
%217 = add nsw i32 %216, 1
br label %222
218: ; preds = %211
%219 = load i32, i32* %12
%220 = sdiv i32 %219, 10
%221 = sub nsw i32 10, %220
br label %222
222: ; preds = %218, %215
%223 = phi i32 [ %217, %215 ], [ %221, %218 ]
%224 = call i32 @calc_stream_moves(i16 zeroext %197, i32 %212, i32 %223)
store i32 %224, i32* %11
%225 = load i32, i32* %8
%226 = load i32, i32* %9
%227 = add nsw i32 %225, %226
%228 = load i32, i32* %10
%229 = add nsw i32 %227, %228
%230 = load i32, i32* %11
%231 = add nsw i32 %229, %230
ret i32 %231
}

LLVM IR (-O2):
define i32 @calc_moves(i64 %0, i64 %1, i32 %2) {
%4 = icmp slt i32 %2, 50
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = sdiv i32 %2, 10
%7 = srem i32 %6, 5
%8 = mul nsw i32 %7, 10
%9 = zext i32 %8 to i64
%10 = lshr i64 %0, %9
br label %18
11: ; preds = %3
%12 = udiv i32 %2, 10
%13 = urem i32 %12, 5
%14 = mul nuw nsw i32 %13, 10
%15 = zext i32 %14 to i64
%16 = lshr i64 %1, %15
%17 = udiv i32 %2, 10
br label %18
18: ; preds = %11, %5
%19 = phi i32 [ %17, %11 ], [ %6, %5 ]
%20 = phi i64 [ %16, %11 ], [ %10, %5 ]
%21 = trunc i64 %20 to i16
%22 = and i16 %21, 1023
%23 = srem i32 %2, 10
%24 = tail call i32 @calc_stream_moves(i16 zeroext %22, i32 %23, i32 10)
%25 = zext i32 %23 to i64
%26 = lshr i64 %0, %25
%27 = and i64 %26, 1
%28 = add nsw i32 %23, 9
%29 = zext i32 %28 to i64
%30 = lshr i64 %0, %29
%31 = and i64 %30, 2
%32 = add nsw i32 %23, 18
%33 = zext i32 %32 to i64
%34 = lshr i64 %0, %33
%35 = and i64 %34, 4
%36 = add nsw i32 %23, 27
%37 = zext i32 %36 to i64
%38 = lshr i64 %0, %37
%39 = and i64 %38, 8
%40 = add nsw i32 %23, 36
%41 = zext i32 %40 to i64
%42 = lshr i64 %0, %41
%43 = and i64 %42, 16
%44 = lshr i64 %1, %25
%45 = and i64 %44, 1
%46 = lshr i64 %1, %29
%47 = and i64 %46, 2
%48 = lshr i64 %1, %33
%49 = and i64 %48, 4
%50 = lshr i64 %1, %37
%51 = and i64 %50, 8
%52 = lshr i64 %1, %41
%53 = and i64 %52, 16
%54 = or i64 %47, %45
%55 = or i64 %54, %49
%56 = or i64 %55, %51
%57 = or i64 %56, %53
%58 = shl nuw nsw i64 %57, 5
%59 = or i64 %31, %27
%60 = or i64 %59, %35
%61 = or i64 %60, %39
%62 = or i64 %61, %43
%63 = or i64 %62, %58
%64 = trunc i64 %63 to i16
%65 = tail call i32 @calc_stream_moves(i16 zeroext %64, i32 %19, i32 10)
%66 = icmp sgt i32 %23, %19
%67 = select i1 %66, i32 %19, i32 %23
%68 = mul i32 %67, -11
%69 = add i32 %68, %2
%70 = tail call zeroext i16 @get_forward_diag(i64 %0, i64 %1, i32 %69)
%71 = icmp slt i32 %69, 10
%72 = udiv i32 %69, 10
%73 = select i1 %71, i32 %69, i32 %72
%74 = sub nsw i32 10, %73
%75 = tail call i32 @calc_stream_moves(i16 zeroext %70, i32 %67, i32 %74)
%76 = sub nsw i32 10, %23
%77 = icmp slt i32 %19, %76
%78 = sub nsw i32 9, %23
%79 = select i1 %77, i32 %19, i32 %78
%80 = mul nsw i32 %79, -9
%81 = add i32 %80, %2
%82 = tail call zeroext i16 @get_back_diag(i64 %0, i64 %1, i32 %81)
%83 = icmp slt i32 %81, 10
br i1 %83, label %84, label %86
84: ; preds = %18
%85 = add nsw i32 %81, 1
br label %89
86: ; preds = %18
%87 = udiv i32 %81, 10
%88 = sub nsw i32 10, %87
br label %89
89: ; preds = %86, %84
%90 = phi i32 [ %85, %84 ], [ %88, %86 ]
%91 = tail call i32 @calc_stream_moves(i16 zeroext %82, i32 %79, i32 %90)
%92 = add nsw i32 %65, %24
%93 = add nsw i32 %92, %75
%94 = add nsw i32 %93, %91
ret i32 %94
}