// File: /workspace/github_c_makefile_star2_O3/mrkite[P]regs/src/scanner.cc
// Function: Scanner::disassemble(std::ostream&, unsigned int, unsigned int, std::function<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> (std::shared_ptr<Inst>)>)
bool Scanner::disassemble(std::ostream &f, uint32_t from, uint32_t to,
                          std::function<std::string(std::shared_ptr<Inst>)>
                          printInst) {
  auto address = from;
  for (auto b : blocks) {
    if (b->address + b->length <= address) {
      continue;
    }
    if (address < b->address) {
      auto last = std::min(to, b->address);
      dumpHex(f, address, last);
      address = last;
    }
    if (address == b->address) {
      auto count = 0;
      std::string preds;
      for (auto pred : b->preds) {
        if (pred->address + pred->length != b->address && count++ < 7) {
          preds += (pred->address < b->address) ? u8"\u25b2 " : u8"\u25bc ";
          preds += hex(pred->address + pred->length - pred->branchLen, 6);
        }
      }
      if (count > 0) {
        f << hex(address, 6) << ": " << preds << std::endl;
      }
    }
    while (address < to && address < b->address + b->length) {
      auto sym = symbols[address];
      if (!sym.empty()) {
        f << sym << std::endl;
      }
      f << hex(address, 6) << ": ";
      auto ptr = getAddress(address);
      if (map[address]->length > 4) {
        f << ".. .. .. .. ";
      } else {
        for (int i = 0; i < map[address]->length; i++) {
          f << hex(ptr->r8(), 2) << " ";
        }
        for (int i = map[address]->length; i < 4; i++) {
          f << "   ";
        }
      }
      f << printInst(map[address]) << std::endl;
      address += map[address]->length;
    }
    if (address < b->address + b->length) {
      break;
    }
  }
  if (address < to) {
    dumpHex(f, address, to);
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movl %edx, 0xc(%rsp)
movq 0xb8(%rdi), %rsi
movq %rdi, 0x68(%rsp)
movq 0xc0(%rdi), %rax
movq %rax, 0x88(%rsp)
cmpq %rax, %rsi
je 0x14b2b
movq %r8, 0x98(%rsp)
movl %ecx, 0x34(%rsp)
movq 0x68(%rsp), %rax
addq $0xd0, %rax
movq %rax, 0x70(%rsp)
leaq 0x2dd2(%rip), %rbp      # 0x17331
movq (%rsi), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%rsi), %r13
testq %r13, %r13
je 0x14587
movq 0xca51(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x14582
incl 0x8(%r13)
jmp 0x14587
lock
incl 0x8(%r13)
movq %rsi, 0x90(%rsp)
movq 0x38(%rsp), %rax
movl (%rax), %r12d
movl 0x4(%rax), %eax
addl %r12d, %eax
movl 0xc(%rsp), %edx
movl $0x3, %ebx
cmpl %edx, %eax
jbe 0x14af3
cmpl %r12d, %edx
jae 0x145dc
movl 0x34(%rsp), %eax
cmpl %eax, %r12d
cmovael %eax, %r12d
movq 0x68(%rsp), %rdi
movq %r14, %rsi
movl %r12d, %ecx
callq 0x14cc8
movl %r12d, 0xc(%rsp)
movq 0x38(%rsp), %rax
movl (%rax), %eax
jmp 0x145e2
movl %r12d, %eax
movl %edx, %r12d
cmpl %eax, %r12d
movq %r13, 0x60(%rsp)
jne 0x147bf
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movb $0x0, 0x50(%rsp)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %r15
movq 0x18(%rax), %rax
movq %rax, 0xa0(%rsp)
cmpq %rax, %r15
je 0x1479e
xorl %ebx, %ebx
movq (%r15), %r13
movq 0x8(%r15), %r12
testq %r12, %r12
je 0x1464d
movq 0xc98d(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x14647
incl 0x8(%r12)
jmp 0x1464d
lock
incl 0x8(%r12)
movl (%r13), %eax
movl 0x4(%r13), %edx
addl %eax, %edx
movq 0x38(%rsp), %rcx
movl (%rcx), %ecx
cmpl %ecx, %edx
je 0x146de
leal 0x1(%rbx), %edx
cmpl $0x6, %ebx
jg 0x146dc
movl %edx, %ebx
cmpl %ecx, %eax
leaq 0x3814(%rip), %rsi      # 0x17e89
leaq 0x3808(%rip), %rax      # 0x17e84
cmovbq %rax, %rsi
leaq 0x40(%rsp), %rdi
callq 0x5430
movl 0x4(%r13), %edx
addl (%r13), %edx
subl 0x8(%r13), %edx
movl $0x6, %ecx
leaq 0x10(%rsp), %rdi
callq 0x13df2
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x40(%rsp), %rdi
movq 0x60(%rsp), %r13
callq 0x5100
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x146da
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x146e3
movl %edx, %ebx
movq 0x60(%rsp), %r13
testq %r12, %r12
je 0x146f0
movq %r12, %rdi
callq 0x671a
addq $0x10, %r15
cmpq 0xa0(%rsp), %r15
jne 0x14628
testl %ebx, %ebx
jle 0x1479e
movl 0xc(%rsp), %edx
movl $0x6, %ecx
leaq 0x10(%rsp), %rdi
callq 0x13df2
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x5260
movq %rax, %r12
movl $0x2, %edx
movq %rax, %rdi
leaq 0x34fd(%rip), %rsi      # 0x17c3e
callq 0x5260
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %r12, %rdi
callq 0x5260
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x5210
movsbl %al, %esi
movq %r12, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5190
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1479e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x147ba
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5230
movl 0xc(%rsp), %r12d
cmpl 0x34(%rsp), %r12d
jae 0x14adf
movq 0x38(%rsp), %rcx
movl 0x4(%rcx), %eax
addl (%rcx), %eax
cmpl %eax, %r12d
jae 0x14adf
movq 0x68(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0xa7a6
leaq 0x50(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x688a
movq 0x48(%rsp), %rdx
testq %rdx, %rdx
je 0x1484b
movq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x5260
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x5210
movsbl %al, %esi
movq %r12, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5190
movl 0xc(%rsp), %edx
movl $0x6, %ecx
leaq 0x10(%rsp), %rdi
callq 0x13df2
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x5260
movl $0x2, %edx
movq %rax, %rdi
leaq 0x33bf(%rip), %rsi      # 0x17c3e
callq 0x5260
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x148a0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
movl 0xc(%rsp), %edx
leaq 0xa8(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x13d80
movq 0x70(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15110
movq (%rax), %rax
cmpw $0x4, 0x22(%rax)
jbe 0x148e8
movl $0xc, %edx
movq %r14, %rdi
leaq 0x35b0(%rip), %rsi      # 0x17e8e
callq 0x5260
jmp 0x149e3
xorl %ebx, %ebx
movq 0xa8(%rsp), %r12
movq 0x70(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15110
movq (%rax), %rax
movzwl 0x22(%rax), %eax
cmpl %eax, %ebx
jae 0x149ad
movq %r12, %rdi
callq 0x9780
movl %eax, %r15d
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0x2, %esi
leaq 0x10(%rsp), %rdi
movl $0x30, %edx
callq 0x5270
movzbl %r15b, %eax
movl $0x4, %ecx
xorl %edx, %edx
movl %eax, %esi
shrl %cl, %esi
andl $0xf, %esi
movb (%rsi,%rbp), %sil
movq 0x10(%rsp), %rdi
movb %sil, (%rdi,%rdx)
incq %rdx
addl $-0x4, %ecx
cmpq $0x2, %rdx
jne 0x14944
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x5260
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3518(%rip), %rsi      # 0x17e9d
callq 0x5260
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x149a6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
incl %ebx
jmp 0x148f2
movq 0x70(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15110
movq (%rax), %rax
movzwl 0x22(%rax), %ebx
cmpl $0x3, %ebx
ja 0x149e3
addl $-0x4, %ebx
movl $0x3, %edx
movq %r14, %rdi
leaq 0x34c1(%rip), %rsi      # 0x17e9b
callq 0x5260
incl %ebx
jne 0x149cb
movq 0x70(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15110
movq (%rax), %rcx
movq %rcx, 0x78(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x80(%rsp)
testq %rax, %rax
je 0x14a20
movq 0xc5b6(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x14a1c
incl 0x8(%rax)
jmp 0x14a20
lock
incl 0x8(%rax)
movq 0x98(%rsp), %rsi
cmpq $0x0, 0x10(%rsi)
je 0x14b50
leaq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq *0x18(%rsi)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x5260
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x5210
movsbl %al, %esi
movq %r12, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5190
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14a98
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x14aaa
callq 0x671a
movq 0x70(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15110
movq (%rax), %rax
movzwl 0x22(%rax), %eax
addl %eax, 0xc(%rsp)
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x1479e
callq 0x671a
jmp 0x1479e
movq 0x38(%rsp), %rcx
movl 0x4(%rcx), %eax
addl (%rcx), %eax
xorl %ebx, %ebx
cmpl %eax, %r12d
setb %bl
addl %ebx, %ebx
testq %r13, %r13
je 0x14b00
movq %r13, %rdi
callq 0x671a
cmpl $0x3, %ebx
movq 0x90(%rsp), %rsi
je 0x14b11
testl %ebx, %ebx
jne 0x14b23
addq $0x10, %rsi
cmpq 0x88(%rsp), %rsi
jne 0x1455f
movl 0xc(%rsp), %edx
movl 0x34(%rsp), %ecx
cmpl %ecx, %edx
jae 0x14b3c
movq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x14cc8
movb $0x1, %al
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5130
movq %rax, %r14
jmp 0x14bb3
jmp 0x14c1b
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14bb3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x14bb3
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14ba6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x14ba6
jmp 0x14ba3
movq %rax, %r14
testq %r12, %r12
je 0x14bb3
movq %r12, %rdi
callq 0x671a
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x14bcf
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x60(%rsp), %r13
jmp 0x14cb3
jmp 0x14c82
movq %rax, %r14
movq 0x60(%rsp), %r13
jmp 0x14c49
movq %rax, %r14
jmp 0x14c49
jmp 0x14c82
jmp 0x14c25
jmp 0x14c25
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14c97
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x14c97
movq %rax, %r14
jmp 0x14cb3
jmp 0x14c82
movq %rax, %r14
jmp 0x14c97
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14c49
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x14c85
callq 0x671a
jmp 0x14c85
jmp 0x14c82
jmp 0x14c82
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14c85
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x14c85
movq %rax, %r14
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x14c97
callq 0x671a
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x14cb3
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5230
testq %r13, %r13
je 0x14cc0
movq %r13, %rdi
callq 0x671a
movq %r14, %rdi
callq 0x53e0