// File: /workspace/github_c_makefile_star2_O0/mrkite[P]regs/src/scanner.cc
// Function: Scanner::trace(Entry const&, std::function<std::shared_ptr<Inst> (std::shared_ptr<TheHandle>, Entry*)>)
bool Scanner::trace(const Entry &start,
                    std::function<std::shared_ptr<Inst>(Handle, Entry*)>
                    decode) {
  std::stack<Entry> workList;

  workList.push(start);
  labels[start.org] = start.org;
  while (!workList.empty()) {
    auto state = workList.top();
    workList.pop();
    std::shared_ptr<Inst> inst = nullptr;
    do {
      auto ptr = getAddress(state.org);
      if (ptr == nullptr) {
        return false;
      }
      auto addr = state.org;
      inst = nullptr;
      int16_t numDB = 0;
      if (fingerprints) {
        auto node = fingerprints->root;
        int8_t len = 0;
        auto fstart = ptr->tell();
        do {
          node = node->map[ptr->r8()];
          len++;
          if (node != nullptr && !node->name.empty()) {
            if (inst == nullptr) {
              inst = std::make_shared<Inst>();
              inst->type = Special;
            }
            inst->name = node->name;
            inst->length = len;
            numDB = node->numDB;
          }
        } while (node != nullptr && !ptr->eof());
        if (inst) {
          fstart += inst->length;
          state.org += inst->length;
        }
        ptr->seek(fstart);
      }
      if (numDB > 0 && inst) {
        inst->name += " {";
        for (int i = 0; i < numDB; i++) {
          if (i) {
            inst->name += ", ";
          }
          inst->name += "$" + hex(ptr->r8(), 2);
        }
        inst->name += "}";
        inst->length += numDB;
        state.org += numDB;
      }
      if (!inst) {
        inst = decode(ptr, &state);
      }
      map[addr] = inst;
      if (inst->type == Jump || inst->type == Branch || inst->type == Call) {
        if (inst->operType == Opr::Abs) {
          if (valid(inst->oper) && labels.find(inst->oper) == labels.end()) {
            workList.push({inst->oper, state.flags});
            labels[inst->oper] = inst->oper;
          }
        }
      }
      if (inst->type == Jump || inst->type == Branch || inst->type == Return) {
        // we want branches included in the block
        branches[state.org] = addr;
      }
      if (inst->type == Invalid) {
        branches[addr] = addr;
      }
    } while (inst->type != Return && inst->type != Jump &&
             inst->type != Invalid);
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdx, -0x1a0(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0x70(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x32fb0
movq -0x190(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x32fe0
jmp 0x305db
movq -0x198(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl (%rsi), %eax
movl %eax, -0x1ac(%rbp)
addq $0x58, %rdi
callq 0x33010
movq %rax, -0x1a8(%rbp)
jmp 0x30600
movq -0x1a8(%rbp), %rax
movl -0x1ac(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x70(%rbp), %rdi
callq 0x330f0
movb %al, -0x1ad(%rbp)
jmp 0x30620
movb -0x1ad(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x30631
jmp 0x30fea
leaq -0x70(%rbp), %rdi
callq 0x33110
movq %rax, -0x1b8(%rbp)
jmp 0x30643
movq -0x1b8(%rbp), %rax
movl 0x8(%rax), %ecx
movl %ecx, -0x80(%rbp)
movq (%rax), %rax
movq %rax, -0x88(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x33130
jmp 0x30665
leaq -0x98(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x33150
movq -0x198(%rbp), %rsi
movl -0x88(%rbp), %edx
leaq -0xa8(%rbp), %rdi
callq 0x31030
jmp 0x30690
leaq -0xa8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x33170
testb $0x1, %al
jne 0x306a6
jmp 0x306db
movb $0x0, -0x1(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0x30f29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x3100f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x30fdc
movl -0x88(%rbp), %eax
movl %eax, -0xb0(%rbp)
leaq -0xc0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x33150
leaq -0x98(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x331a0
leaq -0xc0(%rbp), %rdi
callq 0x1dc40
movq -0x198(%rbp), %rdi
movw $0x0, -0xc2(%rbp)
addq $0x48, %rdi
callq 0x331d0
testb $0x1, %al
jne 0x30738
jmp 0x309ee
movq -0x198(%rbp), %rdi
addq $0x48, %rdi
callq 0x80a0
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x24fb0
movb $0x0, -0xd9(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xd2c0
movq %rax, %rdi
callq 0x11e70
movq %rax, -0x1c0(%rbp)
jmp 0x3077b
movq -0x1c0(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x25070
movq %rax, -0x1d0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xd2c0
movq %rax, %rdi
callq 0x11fc0
movb %al, -0x1c1(%rbp)
jmp 0x307b8
movq -0x1d0(%rbp), %rdi
movb -0x1c1(%rbp), %al
movb %al, -0xe9(%rbp)
leaq -0xe9(%rbp), %rsi
callq 0x331f0
movq %rax, -0x1d8(%rbp)
jmp 0x307e0
movq -0x1d8(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x25270
movb -0xd9(%rbp), %al
addb $0x1, %al
movb %al, -0xd9(%rbp)
leaq -0xd8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x332d0
testb $0x1, %al
jne 0x3081a
jmp 0x3091e
leaq -0xd8(%rbp), %rdi
callq 0x25070
movq %rax, %rdi
addq $0x38, %rdi
callq 0x6510
testb $0x1, %al
jne 0x3091e
leaq -0x98(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x33300
testb $0x1, %al
jne 0x30850
jmp 0x308ae
leaq -0x100(%rbp), %rdi
callq 0x1dbb0
jmp 0x3085e
leaq -0x98(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x331a0
leaq -0x100(%rbp), %rdi
callq 0x1dc40
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movw $0x5, 0x20(%rax)
jmp 0x308ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x9ed0
jmp 0x30fd0
leaq -0xd8(%rbp), %rdi
callq 0x25070
addq $0x38, %rax
movq %rax, -0x1e0(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movq -0x1e0(%rbp), %rsi
movq %rax, %rdi
callq 0x6060
jmp 0x308e2
movsbl -0xd9(%rbp), %eax
movw %ax, -0x1e2(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movw -0x1e2(%rbp), %cx
movw %cx, 0x22(%rax)
leaq -0xd8(%rbp), %rdi
callq 0x25070
movzbl 0x30(%rax), %eax
movw %ax, -0xc2(%rbp)
jmp 0x30920
leaq -0xd8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x332d0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x1e3(%rbp)
jne 0x30941
jmp 0x3096b
leaq -0xa8(%rbp), %rdi
callq 0xd2c0
movq %rax, %rdi
callq 0x11e40
movb %al, -0x1e4(%rbp)
jmp 0x3095d
movb -0x1e4(%rbp), %al
xorb $-0x1, %al
movb %al, -0x1e3(%rbp)
movb -0x1e3(%rbp), %al
testb $0x1, %al
jne 0x30789
leaq -0x98(%rbp), %rdi
callq 0x33330
testb $0x1, %al
jne 0x3098b
jmp 0x309c5
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x22(%rax), %eax
addq -0xe8(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x22(%rax), %eax
addl -0x88(%rbp), %eax
movl %eax, -0x88(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xd2c0
movq %rax, %rdi
movq -0xe8(%rbp), %rsi
callq 0x12210
jmp 0x309e2
leaq -0xd8(%rbp), %rdi
callq 0x9ed0
movswl -0xc2(%rbp), %eax
cmpl $0x0, %eax
jle 0x30bbc
leaq -0x98(%rbp), %rdi
callq 0x33330
testb $0x1, %al
jne 0x30a13
jmp 0x30bbc
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movq %rax, %rdi
leaq 0xa443(%rip), %rsi      # 0x3ae6c
callq 0x62e0
jmp 0x30a30
movl $0x0, -0x104(%rbp)
movl -0x104(%rbp), %eax
movswl -0xc2(%rbp), %ecx
cmpl %ecx, %eax
jge 0x30b63
cmpl $0x0, -0x104(%rbp)
je 0x30a88
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movq %rax, %rdi
leaq 0x9b1b(%rip), %rsi      # 0x3a589
callq 0x62e0
jmp 0x30a75
jmp 0x30a88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x30fd0
leaq -0xa8(%rbp), %rdi
callq 0xd2c0
movq %rax, %rdi
callq 0x11fc0
movb %al, -0x1e5(%rbp)
jmp 0x30aa4
movq -0x198(%rbp), %rsi
movb -0x1e5(%rbp), %al
movzbl %al, %edx
leaq -0x148(%rbp), %rdi
movl $0x2, %ecx
callq 0x31120
jmp 0x30ac7
leaq 0xa133(%rip), %rsi      # 0x3ac01
leaq -0x128(%rbp), %rdi
leaq -0x148(%rbp), %rdx
callq 0x1d8c0
jmp 0x30ae3
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movq %rax, %rdi
leaq -0x128(%rbp), %rsi
callq 0x63c0
jmp 0x30b00
leaq -0x128(%rbp), %rdi
callq 0x61e0
leaq -0x148(%rbp), %rdi
callq 0x61e0
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0x30a3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x30b52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x61e0
leaq -0x148(%rbp), %rdi
callq 0x61e0
jmp 0x30fd0
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movq %rax, %rdi
leaq 0xa064(%rip), %rsi      # 0x3abdd
callq 0x62e0
jmp 0x30b80
movswl -0xc2(%rbp), %eax
movl %eax, -0x1ec(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movl -0x1ec(%rbp), %edx
movzwl 0x22(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x22(%rax)
movswl -0xc2(%rbp), %eax
addl -0x88(%rbp), %eax
movl %eax, -0x88(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x33330
testb $0x1, %al
jne 0x30c57
leaq -0x168(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
leaq -0xa8(%rbp), %rsi
callq 0xb060
movq -0x1a0(%rbp), %rsi
movq -0x1f8(%rbp), %rdx
leaq -0x158(%rbp), %rdi
leaq -0x88(%rbp), %rcx
callq 0x33350
jmp 0x30c0d
leaq -0x98(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x331a0
leaq -0x158(%rbp), %rdi
callq 0x1dc40
leaq -0x168(%rbp), %rdi
callq 0x8b80
jmp 0x30c57
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x8b80
jmp 0x30fd0
movq -0x198(%rbp), %rdi
addq $0xd0, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x333b0
movq %rax, -0x200(%rbp)
jmp 0x30c7a
movq -0x200(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x33490
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0x2, %eax
je 0x30cd0
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0x4, %eax
je 0x30cd0
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0x1, %eax
jne 0x30e4d
leaq -0x98(%rbp), %rdi
callq 0x1dc20
cmpl $0x3, 0x24(%rax)
jne 0x30e4b
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movq -0x198(%rbp), %rdi
movl 0x28(%rax), %esi
callq 0x31390
movb %al, -0x201(%rbp)
jmp 0x30d09
movb -0x201(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x202(%rbp)
jne 0x30d1e
jmp 0x30d96
movq -0x198(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x218(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movq -0x218(%rbp), %rdi
movq %rax, %rsi
addq $0x28, %rsi
callq 0x334f0
movq %rax, -0x210(%rbp)
jmp 0x30d58
movq -0x198(%rbp), %rdi
movq -0x210(%rbp), %rax
movq %rax, -0x170(%rbp)
addq $0x58, %rdi
callq 0x33520
movq %rax, -0x178(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x334c0
movb %al, -0x202(%rbp)
movb -0x202(%rbp), %al
testb $0x1, %al
jne 0x30da5
jmp 0x30e49
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movl 0x28(%rax), %eax
movl %eax, -0x184(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x180(%rbp)
movw $0x0, -0x17c(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x184(%rbp), %rsi
callq 0x33550
jmp 0x30de1
leaq -0x98(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x1dc20
movq -0x238(%rbp), %rdi
movq %rax, %rcx
movq -0x198(%rbp), %rax
movl 0x28(%rcx), %ecx
movl %ecx, -0x22c(%rbp)
addq $0x58, %rax
movq %rax, -0x228(%rbp)
callq 0x1dc20
movq -0x228(%rbp), %rdi
movq %rax, %rsi
addq $0x28, %rsi
callq 0x33010
movq %rax, -0x220(%rbp)
jmp 0x30e3a
movq -0x220(%rbp), %rax
movl -0x22c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x30e4b
jmp 0x30e4d
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0x2, %eax
je 0x30e8c
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0x4, %eax
je 0x30e8c
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0x3, %eax
jne 0x30eca
movq -0x198(%rbp), %rdi
movl -0xb0(%rbp), %eax
movl %eax, -0x244(%rbp)
addq $0x88, %rdi
leaq -0x88(%rbp), %rsi
callq 0x33010
movq %rax, -0x240(%rbp)
jmp 0x30ebb
movq -0x240(%rbp), %rax
movl -0x244(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0xff, %eax
jne 0x30f1f
movq -0x198(%rbp), %rdi
movl -0xb0(%rbp), %eax
movl %eax, -0x254(%rbp)
addq $0x88, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x33010
movq %rax, -0x250(%rbp)
jmp 0x30f10
movq -0x250(%rbp), %rax
movl -0x254(%rbp), %ecx
movl %ecx, (%rax)
movl $0x0, -0xac(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x8b80
movl -0xac(%rbp), %eax
testl %eax, %eax
jne 0x30fb3
jmp 0x30f41
jmp 0x30f43
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %ecx
xorl %eax, %eax
cmpl $0x3, %ecx
movb %al, -0x255(%rbp)
je 0x30f9b
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %ecx
xorl %eax, %eax
cmpl $0x2, %ecx
movb %al, -0x255(%rbp)
je 0x30f9b
leaq -0x98(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0xff, %eax
setne %al
movb %al, -0x255(%rbp)
movb -0x255(%rbp), %al
testb $0x1, %al
jne 0x30675
movl $0x0, -0xac(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1dc40
movl -0xac(%rbp), %eax
testl %eax, %eax
jne 0x30ff8
jmp 0x30fcb
jmp 0x3060f
leaq -0xa8(%rbp), %rdi
callq 0x8b80
leaq -0x98(%rbp), %rdi
callq 0x1dc40
jmp 0x3100f
movb $0x1, -0x1(%rbp)
movl $0x1, -0xac(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x33580
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
leaq -0x70(%rbp), %rdi
callq 0x33580
movq -0x78(%rbp), %rdi
callq 0x6540
nopw %cs:(%rax,%rax)