// File: /workspace/github_c_makefile_star2_O1/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 %r8, 0x98(%rsp)
movl %ecx, 0x34(%rsp)
movq %rsi, %r14
movl %edx, 0xc(%rsp)
movq 0xb8(%rdi), %rcx
movq %rdi, 0x60(%rsp)
movq 0xc0(%rdi), %rax
movq %rax, 0x88(%rsp)
cmpq %rax, %rcx
je 0x14d6b
movq 0x60(%rsp), %rax
addq $0xd0, %rax
movq %rax, 0x68(%rsp)
leaq 0x2b7a(%rip), %rbp      # 0x17331
movq (%rcx), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%rcx), %r13
testq %r13, %r13
je 0x147df
movq 0xc7f9(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x147da
incl 0x8(%r13)
jmp 0x147df
lock
incl 0x8(%r13)
movq %rcx, 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 0x14d3b
cmpl %r12d, %edx
jae 0x1482b
movl 0x34(%rsp), %eax
cmpl %eax, %r12d
cmovael %eax, %r12d
movq 0x60(%rsp), %rdi
movq %r14, %rsi
movl %r12d, %ecx
callq 0x14f02
movl %r12d, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x38(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x14a06
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 0x149ea
movq %r13, 0x70(%rsp)
xorl %ebx, %ebx
movq (%r15), %r13
movq 0x8(%r15), %r12
testq %r12, %r12
je 0x1489e
movq 0xc73c(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x14898
incl 0x8(%r12)
jmp 0x1489e
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 0x1492a
leal 0x1(%rbx), %edx
cmpl $0x6, %ebx
jg 0x14928
movl %edx, %ebx
cmpl %ecx, %eax
leaq 0x35c3(%rip), %rsi      # 0x17e89
leaq 0x35b7(%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 0x14066
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x40(%rsp), %rdi
callq 0x5100
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14926
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x1492a
movl %edx, %ebx
testq %r12, %r12
je 0x14937
movq %r12, %rdi
callq 0x6752
addq $0x10, %r15
cmpq 0xa0(%rsp), %r15
jne 0x14879
testl %ebx, %ebx
movq 0x70(%rsp), %r13
jle 0x149ea
movl 0xc(%rsp), %edx
movl $0x6, %ecx
leaq 0x10(%rsp), %rdi
callq 0x14066
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x5260
movq %rax, %r12
movl $0x2, %edx
movq %rax, %rdi
leaq 0x32b1(%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 0x149ea
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x14a06
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5230
movl 0xc(%rsp), %eax
cmpl 0x34(%rsp), %eax
jae 0x14d28
movq 0x38(%rsp), %rdx
movl 0x4(%rdx), %ecx
addl (%rdx), %ecx
cmpl %ecx, %eax
jae 0x14d28
movq 0x60(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0xa9ae
leaq 0x50(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x68c2
movq 0x48(%rsp), %rdx
testq %rdx, %rdx
je 0x14a94
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 0x14066
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x5260
movl $0x2, %edx
movq %rax, %rdi
leaq 0x3176(%rip), %rsi      # 0x17c3e
callq 0x5260
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14ae9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
movl 0xc(%rsp), %edx
leaq 0xa8(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x13ff0
movq 0x68(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15358
movq (%rax), %rax
cmpw $0x4, 0x22(%rax)
jbe 0x14b31
movl $0xc, %edx
movq %r14, %rdi
leaq 0x3367(%rip), %rsi      # 0x17e8e
callq 0x5260
jmp 0x14c2c
xorl %ebx, %ebx
movq 0xa8(%rsp), %r12
movq 0x68(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15358
movq (%rax), %rax
movzwl 0x22(%rax), %eax
cmpl %eax, %ebx
jae 0x14bf6
movq %r12, %rdi
callq 0x999c
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 0x14b8d
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x5260
movl $0x1, %edx
movq %rax, %rdi
leaq 0x32cf(%rip), %rsi      # 0x17e9d
callq 0x5260
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14bef
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
incl %ebx
jmp 0x14b3b
movq 0x68(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15358
movq (%rax), %rax
movzwl 0x22(%rax), %ebx
cmpl $0x3, %ebx
ja 0x14c2c
addl $-0x4, %ebx
movl $0x3, %edx
movq %r14, %rdi
leaq 0x3278(%rip), %rsi      # 0x17e9b
callq 0x5260
incl %ebx
jne 0x14c14
movq 0x68(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15358
movq (%rax), %rcx
movq %rcx, 0x78(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x80(%rsp)
testq %rax, %rax
je 0x14c69
movq 0xc36d(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x14c65
incl 0x8(%rax)
jmp 0x14c69
lock
incl 0x8(%rax)
movq 0x98(%rsp), %rsi
cmpq $0x0, 0x10(%rsi)
je 0x14d98
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 0x14ce1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x14cf3
callq 0x6752
movq 0x68(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x15358
movq (%rax), %rax
movzwl 0x22(%rax), %eax
addl %eax, 0xc(%rsp)
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x149ea
callq 0x6752
jmp 0x149ea
movq 0x38(%rsp), %rdx
movl 0x4(%rdx), %ecx
addl (%rdx), %ecx
xorl %ebx, %ebx
cmpl %ecx, %eax
setb %bl
addl %ebx, %ebx
testq %r13, %r13
je 0x14d48
movq %r13, %rdi
callq 0x6752
cmpl $0x3, %ebx
movq 0x90(%rsp), %rcx
je 0x14d59
testl %ebx, %ebx
jne 0x14d6b
addq $0x10, %rcx
cmpq 0x88(%rsp), %rcx
jne 0x147b7
movl 0xc(%rsp), %edx
movl 0x34(%rsp), %ecx
cmpl %ecx, %edx
jae 0x14d84
movq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x14f02
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 0x14dfb
jmp 0x14e55
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14dfb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x14dfb
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14dee
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x14dee
jmp 0x14deb
movq %rax, %r14
testq %r12, %r12
je 0x14dfb
movq %r12, %rdi
callq 0x6752
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x14e17
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x70(%rsp), %r13
jmp 0x14eed
jmp 0x14e9b
jmp 0x14e27
jmp 0x14e9b
movq %rax, %r14
jmp 0x14e83
jmp 0x14e5f
jmp 0x14e5f
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14ed1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x14ed1
movq %rax, %r14
jmp 0x14eed
jmp 0x14e9b
movq %rax, %r14
jmp 0x14ed1
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14e83
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x14ebf
callq 0x6752
jmp 0x14ebf
jmp 0x14e9b
jmp 0x14e9b
movq %rax, %r14
jmp 0x14ebf
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x14ebf
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x14ed1
callq 0x6752
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x14eed
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5230
testq %r13, %r13
je 0x14efa
movq %r13, %rdi
callq 0x6752
movq %r14, %rdi
callq 0x53e0