// File: /workspace/github_c_makefile_star2_O2/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 $0xa8, %rsp
movq %r8, 0x70(%rsp)
movq %rsi, %r12
leaq 0x4(%rsp), %r14
movl %edx, (%r14)
movq 0xb8(%rdi), %rsi
movq 0xc0(%rdi), %rax
movq %rax, 0x58(%rsp)
movq %rdi, 0x10(%rsp)
leaq 0xd0(%rdi), %rbx
leaq 0x88(%rsp), %r15
movl %ecx, 0x8(%rsp)
cmpq 0x58(%rsp), %rsi
je 0x11ada
leaq 0x28(%rsp), %rdi
movq %rsi, 0x60(%rsp)
callq 0x12042
movq 0x28(%rsp), %rax
movl (%rax), %r13d
movl 0x4(%rax), %ecx
addl %r13d, %ecx
movl 0x4(%rsp), %edx
cmpl %edx, %ecx
jbe 0x11ab0
cmpl %r13d, %edx
jae 0x117b0
movl 0x8(%rsp), %eax
cmpl %eax, %r13d
cmovael %eax, %r13d
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movl %r13d, %ecx
callq 0x11b98
movl %r13d, 0x4(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %ecx
jmp 0x117b6
movl %r13d, %ecx
movl %edx, %r13d
cmpl %ecx, %r13d
movl 0x8(%rsp), %r13d
jne 0x118e6
leaq 0x48(%rsp), %rcx
movq %rcx, 0x38(%rsp)
andq $0x0, 0x40(%rsp)
movb $0x0, 0x48(%rsp)
movq 0x10(%rax), %r13
movq 0x18(%rax), %rax
movq %rax, 0x68(%rsp)
xorl %ebp, %ebp
cmpq 0x68(%rsp), %r13
je 0x1188d
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x12042
movq 0x18(%rsp), %rcx
movl (%rcx), %eax
movl 0x4(%rcx), %edx
addl %eax, %edx
movq 0x28(%rsp), %rcx
movl (%rcx), %ecx
cmpl %ecx, %edx
jne 0x11819
jmp 0x1187a
leal 0x1(%rbp), %edx
movl %edx, 0xc(%rsp)
cmpl $0x6, %ebp
jg 0x11876
cmpl %ecx, %eax
leaq 0x365b(%rip), %rsi      # 0x14e89
leaq 0x364f(%rip), %rax      # 0x14e84
cmovbq %rax, %rsi
leaq 0x38(%rsp), %rdi
callq 0x5410
movq 0x18(%rsp), %rax
movl 0x4(%rax), %edx
addl (%rax), %edx
subl 0x8(%rax), %edx
movq %r15, %rdi
pushq $0x6
popq %rcx
callq 0x11136
movl 0xc(%rsp), %ebp
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x5440
movq %r15, %rdi
callq 0x5140
jmp 0x1187a
movl 0xc(%rsp), %ebp
leaq 0x20(%rsp), %rdi
callq 0x61e4
addq $0x10, %r13
jmp 0x117e8
testl %ebp, %ebp
movl 0x8(%rsp), %r13d
jle 0x118dc
movl 0x4(%rsp), %edx
movq %r15, %rdi
pushq $0x6
popq %rcx
callq 0x11136
movq %r12, %rdi
movq %r15, %rsi
callq 0x51f0
movq %rax, %rdi
leaq 0x3384(%rip), %rsi      # 0x14c3e
callq 0x5200
movq %rax, %rdi
leaq 0x38(%rsp), %rsi
callq 0x51f0
movq %rax, %rdi
callq 0x5150
movq %r15, %rdi
callq 0x5140
leaq 0x38(%rsp), %rdi
callq 0x5140
movl 0x4(%rsp), %eax
movq 0x28(%rsp), %rdx
movl 0x4(%rdx), %ecx
addl (%rdx), %ecx
cmpl %r13d, %eax
jae 0x11aac
cmpl %ecx, %eax
jae 0x11aac
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x95ac
leaq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x52c0
cmpq $0x0, 0x40(%rsp)
je 0x1193c
movq %r12, %rdi
leaq 0x38(%rsp), %rsi
callq 0x51f0
movq %rax, %rdi
callq 0x5150
movl 0x4(%rsp), %edx
movq %r15, %rdi
pushq $0x6
popq %rcx
callq 0x11136
movq %r12, %rdi
movq %r15, %rsi
callq 0x51f0
movq %rax, %rdi
leaq 0x32de(%rip), %rsi      # 0x14c3e
callq 0x5200
movq %r15, %rdi
callq 0x5140
movl 0x4(%rsp), %edx
leaq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x110dc
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11eee
movq (%rax), %rax
cmpw $0x4, 0x22(%rax)
jbe 0x11a20
movq %r12, %rdi
leaq 0x34eb(%rip), %rsi      # 0x14e8e
callq 0x5200
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11eee
leaq 0x78(%rsp), %rbp
movq %rbp, %rdi
movq %rax, %rsi
callq 0x1202e
movq %r15, %rdi
movq 0x70(%rsp), %rsi
movq %rbp, %rdx
callq 0x11f68
movq %r12, %rdi
movq %r15, %rsi
callq 0x51f0
movq %rax, %rdi
callq 0x5150
movq %r15, %rdi
callq 0x5140
leaq 0x80(%rsp), %rdi
callq 0x61e4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11eee
movq (%rax), %rax
movzwl 0x22(%rax), %eax
addl %eax, 0x4(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x61e4
jmp 0x118dc
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11eee
movq (%rax), %rax
movzwl 0x22(%rax), %eax
cmpl %eax, %r13d
jae 0x11a79
movq 0x18(%rsp), %rdi
callq 0x8966
movzbl %al, %edx
movq %r15, %rdi
pushq $0x2
popq %rcx
callq 0x11136
movq %r12, %rdi
movq %r15, %rsi
callq 0x51f0
movq %rax, %rdi
leaq 0x3436(%rip), %rsi      # 0x14e9d
callq 0x5200
movq %r15, %rdi
callq 0x5140
incl %r13d
jmp 0x11a23
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11eee
movq (%rax), %rax
movzwl 0x22(%rax), %ebp
movl 0x8(%rsp), %r13d
cmpl $0x4, %ebp
jae 0x119a8
movq %r12, %rdi
leaq 0x33f8(%rip), %rsi      # 0x14e9b
callq 0x5200
incl %ebp
jmp 0x11a90
cmpl %ecx, %eax
jb 0x11acc
leaq 0x30(%rsp), %rdi
callq 0x61e4
movq 0x60(%rsp), %rsi
addq $0x10, %rsi
movl 0x8(%rsp), %ecx
jmp 0x1174e
leaq 0x30(%rsp), %rdi
callq 0x61e4
movl 0x8(%rsp), %ecx
movl 0x4(%rsp), %edx
cmpl %ecx, %edx
jae 0x11aef
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x11b98
movb $0x1, %al
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11b1c
jmp 0x11b52
jmp 0x11b40
jmp 0x11b62
jmp 0x11b5d
jmp 0x11b5d
jmp 0x11b5d
movq %rax, %rbx
jmp 0x11b31
jmp 0x11b5d
jmp 0x11b1c
jmp 0x11b1c
movq %rax, %rbx
jmp 0x11b7c
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x5140
leaq 0x80(%rsp), %rdi
callq 0x61e4
jmp 0x11b72
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x5140
jmp 0x11b7c
movq %rax, %rbx
jmp 0x11b86
jmp 0x11b5d
jmp 0x11b5d
jmp 0x11b5d
movq %rax, %rbx
jmp 0x11b72
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x5140
leaq 0x20(%rsp), %rdi
callq 0x61e4
leaq 0x38(%rsp), %rdi
callq 0x5140
leaq 0x30(%rsp), %rdi
callq 0x61e4
movq %rbx, %rdi
callq 0x53c0