// File: kaityo256[P]minlex/minlex.cpp
// Function: Sudoku::headbox_index(bool)
int headbox_index(bool sort) {
    int min = 16 * 3 + 4 * 3 + 3;
    mbit v = 0;
    for (int i = 0; i < 9; i++) {
      v |= bdata[i];
    }
    for (int i = 0; i < 3; i++) {
      std::vector<int> a(3, 0);
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          if (v & (mbit(1) << (80 - k - (j + i * 3) * 3))) a[j]++;
        }
      }
      if (sort) {
        std::sort(a.begin(), a.end());
      }
      int index = 0;
      for (int i = 0; i < 3; i++) {
        int t = ((1 << a[i]) - 1) << (2 - i) * 3;
        index += t;
      }
      if (index < min) {
        min = index;
      }
    }
    return min;
  }

// Assembly:
subq $0xa8, %rsp
movb %sil, %al
movq %rdi, 0xa0(%rsp)
andb $0x1, %al
movb %al, 0x9f(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x3f, 0x98(%rsp)
movq $0x0, 0x88(%rsp)
movq $0x0, 0x80(%rsp)
movl $0x0, 0x7c(%rsp)
cmpl $0x9, 0x7c(%rsp)
jge 0x3785
movq 0x18(%rsp), %rax
movslq 0x7c(%rsp), %rcx
shlq $0x4, %rcx
movq 0x60(%rax,%rcx), %rsi
movq 0x68(%rax,%rcx), %rdx
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rcx
orq %rsi, %rax
orq %rdx, %rcx
movq %rcx, 0x88(%rsp)
movq %rax, 0x80(%rsp)
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x3733
movl $0x0, 0x78(%rsp)
cmpl $0x3, 0x78(%rsp)
jge 0x399e
movl $0x0, 0x5c(%rsp)
leaq 0x5b(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x5230
movq 0x10(%rsp), %rcx
leaq 0x60(%rsp), %rdi
movl $0x3, %esi
leaq 0x5c(%rsp), %rdx
callq 0x5240
jmp 0x37ca
leaq 0x5b(%rsp), %rdi
callq 0x52c0
movl $0x0, 0x48(%rsp)
cmpl $0x3, 0x48(%rsp)
jge 0x38b2
movl $0x0, 0x44(%rsp)
cmpl $0x3, 0x44(%rsp)
jge 0x38a0
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rcx
movl 0x44(%rsp), %edx
movl 0x48(%rsp), %edi
movl 0x78(%rsp), %r8d
movl %r8d, %esi
leal (%rsi,%rsi,2), %esi
addl %esi, %edi
movl %edi, %esi
leal (%rsi,%rsi,2), %esi
addl %esi, %edx
movb $0x50, %sil
subb %dl, %sil
movb %sil, %dil
movl $0x1, %edx
shlxq %rdi, %rdx, %rdi
xorl %edx, %edx
testb $0x40, %sil
movl %edx, %esi
movq %rdi, %rdx
cmovneq %rsi, %rdx
cmovneq %rdi, %rsi
andq %rsi, %rcx
andq %rdx, %rax
orq %rcx, %rax
je 0x388e
jmp 0x3859
movslq 0x48(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x3b50
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x388e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
leaq 0x5b(%rsp), %rdi
callq 0x52c0
jmp 0x39ad
jmp 0x3890
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x37ef
jmp 0x38a2
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x37dc
testb $0x1, 0x9f(%rsp)
je 0x390f
leaq 0x60(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x3ac0
movq 0x8(%rsp), %rdi
movq %rax, 0x38(%rsp)
callq 0x3af0
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x52d0
jmp 0x38f0
jmp 0x390f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x3d50
jmp 0x39ad
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
cmpl $0x3, 0x28(%rsp)
jge 0x396c
movslq 0x28(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x3b50
movl (%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl $0x2, %ecx
subl 0x28(%rsp), %ecx
imull $0x3, %ecx, %ecx
shll %cl, %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
addl 0x2c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x391f
movl 0x2c(%rsp), %eax
cmpl 0x98(%rsp), %eax
jge 0x3984
movl 0x2c(%rsp), %eax
movl %eax, 0x98(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x3d50
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
jmp 0x378d
movl 0x98(%rsp), %eax
addq $0xa8, %rsp
retq
movq 0x50(%rsp), %rdi
callq 0x2230
nopw (%rax,%rax)