// File: /workspace/github_c_makefile_star2_O0/mrkite[P]regs/src/scanner.cc
// Function: Scanner::basicBlocks()
bool Scanner::basicBlocks() {
  if (labels.empty()) {  // no blocks
    return true;
  }
  // always start at a label
  auto address = labels.lower_bound(0)->first;
  auto block = getBlock(address);
  auto done = false;
  while (!done) {
    auto label = labels.upper_bound(address);
    auto branch = branches.upper_bound(address);
    if (label != labels.end() && (branch == branches.end() ||
                                  label->second < branch->second)) {
      // label was earliest
      address = label->second;
      block->length = address - block->address;
      auto next = getBlock(address);
      next->preds.push_back(block);
      block->succs.push_back(next);
      block = next;
    } else if (branch != branches.end() && (label == labels.end() ||
                                            branch->second <= label->second)) {
      // branch was earliest (or equal)
      auto b = map[branch->second];
      block->branchLen = b->length;
      block->length = branch->first - block->address;
      if (b->type != Return && b->type != Invalid) {
        // branch has a destination
        if (b->operType == Opr::Abs) {
          if (valid(b->oper)) {
            auto next = getBlock(b->oper);
            next->preds.push_back(block);
            block->succs.push_back(next);
          }
        }
      }
      if (b->type == Jump || b->type == Return || b->type == Invalid) {
        // branch doesn't continue
        auto next = labels.upper_bound(branch->second);
        if (next == labels.end()) {
          done = true;
        } else {
          address = next->second;
          block = getBlock(address);
        }
      } else {
        // branch continues
        auto next = getBlock(branch->first);
        next->preds.push_back(block);
        block->succs.push_back(next);
        block = next;
        address = block->address;
      }
    } else {
      // out of labels and branches
      block->length = map.rbegin()->first + map.rbegin()->second->length -
          block->address;
      done = true;
    }
  }
  std::sort(blocks.begin(), blocks.end(), compareBlocks);
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x108(%rbp)
addq $0x58, %rdi
callq 0x335a0
testb $0x1, %al
jne 0x31459
jmp 0x31462
movb $0x1, -0x1(%rbp)
jmp 0x31c31
movq -0x108(%rbp), %rdi
addq $0x58, %rdi
movl $0x0, -0x24(%rbp)
leaq -0x24(%rbp), %rsi
callq 0x335c0
movq %rax, -0x20(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x335f0
movq -0x108(%rbp), %rsi
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edx
leaq -0x38(%rbp), %rdi
callq 0x31c50
movb $0x0, -0x39(%rbp)
movb -0x39(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x314b4
jmp 0x31bc7
movq -0x108(%rbp), %rdi
addq $0x58, %rdi
leaq -0x14(%rbp), %rsi
callq 0x33610
movq %rax, -0x110(%rbp)
jmp 0x314d1
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rax
movq %rax, -0x48(%rbp)
addq $0x88, %rdi
leaq -0x14(%rbp), %rsi
callq 0x33610
movq %rax, -0x118(%rbp)
jmp 0x314fc
movq -0x108(%rbp), %rdi
movq -0x118(%rbp), %rax
movq %rax, -0x60(%rbp)
addq $0x58, %rdi
callq 0x33520
movq %rax, -0x68(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x33640
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x119(%rbp)
jne 0x31539
jmp 0x315a8
movq -0x108(%rbp), %rdi
addq $0x88, %rdi
callq 0x33520
movq %rax, -0x70(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x334c0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x11a(%rbp)
jne 0x3159c
leaq -0x48(%rbp), %rdi
callq 0x335f0
movl 0x4(%rax), %eax
movl %eax, -0x120(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x335f0
movq %rax, %rcx
movl -0x120(%rbp), %eax
cmpl 0x4(%rcx), %eax
setb %al
movb %al, -0x11a(%rbp)
movb -0x11a(%rbp), %al
movb %al, -0x119(%rbp)
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x315b7
jmp 0x31698
leaq -0x48(%rbp), %rdi
callq 0x335f0
movl 0x4(%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x128(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x33670
movq -0x130(%rbp), %rdi
movq %rax, %rcx
movl -0x128(%rbp), %eax
movl (%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x124(%rbp)
callq 0x33670
movl -0x124(%rbp), %ecx
movq -0x108(%rbp), %rsi
movl %ecx, 0x4(%rax)
movl -0x14(%rbp), %edx
leaq -0x80(%rbp), %rdi
callq 0x31c50
jmp 0x3161c
leaq -0x80(%rbp), %rdi
callq 0x33670
movq %rax, %rdi
addq $0x10, %rdi
leaq -0x38(%rbp), %rsi
callq 0x33690
jmp 0x31637
leaq -0x38(%rbp), %rdi
callq 0x33670
movq %rax, %rdi
addq $0x28, %rdi
leaq -0x80(%rbp), %rsi
callq 0x33690
jmp 0x31652
leaq -0x38(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x33700
leaq -0x80(%rbp), %rdi
callq 0x1ea40
jmp 0x31bc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x31c26
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x1ea40
jmp 0x31c26
movq -0x108(%rbp), %rdi
addq $0x88, %rdi
callq 0x33520
movq %rax, -0x88(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x33640
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x131(%rbp)
jne 0x316d3
jmp 0x31745
movq -0x108(%rbp), %rdi
addq $0x58, %rdi
callq 0x33520
movq %rax, -0x90(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x334c0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x132(%rbp)
jne 0x31739
leaq -0x60(%rbp), %rdi
callq 0x335f0
movl 0x4(%rax), %eax
movl %eax, -0x138(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x335f0
movq %rax, %rcx
movl -0x138(%rbp), %eax
cmpl 0x4(%rcx), %eax
setbe %al
movb %al, -0x132(%rbp)
movb -0x132(%rbp), %al
movb %al, -0x131(%rbp)
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x31754
jmp 0x31af0
movq -0x108(%rbp), %rax
addq $0xd0, %rax
movq %rax, -0x148(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x335f0
movq -0x148(%rbp), %rdi
movq %rax, %rsi
addq $0x4, %rsi
callq 0x333b0
movq %rax, -0x140(%rbp)
jmp 0x3178d
movq -0x140(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x33730
leaq -0xa0(%rbp), %rdi
callq 0x1dc20
movzwl 0x22(%rax), %eax
movl %eax, -0x154(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x33670
movl -0x154(%rbp), %ecx
movl %ecx, 0x8(%rax)
leaq -0x60(%rbp), %rdi
callq 0x335f0
movl (%rax), %eax
movl %eax, -0x150(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x33670
movq %rax, %rcx
movl -0x150(%rbp), %eax
subl (%rcx), %eax
movl %eax, -0x14c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x33670
movl -0x14c(%rbp), %ecx
movl %ecx, 0x4(%rax)
leaq -0xa0(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0x3, %eax
je 0x31921
leaq -0xa0(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0xff, %eax
je 0x31921
leaq -0xa0(%rbp), %rdi
callq 0x1dc20
cmpl $0x3, 0x24(%rax)
jne 0x3191f
leaq -0xa0(%rbp), %rdi
callq 0x1dc20
movq -0x108(%rbp), %rdi
movl 0x28(%rax), %esi
callq 0x31390
movb %al, -0x155(%rbp)
jmp 0x31872
movb -0x155(%rbp), %al
testb $0x1, %al
jne 0x31881
jmp 0x3191d
leaq -0xa0(%rbp), %rdi
callq 0x1dc20
movq -0x108(%rbp), %rsi
movl 0x28(%rax), %edx
leaq -0xb0(%rbp), %rdi
callq 0x31c50
jmp 0x318a5
leaq -0xb0(%rbp), %rdi
callq 0x33670
movq %rax, %rdi
addq $0x10, %rdi
leaq -0x38(%rbp), %rsi
callq 0x33690
jmp 0x318c3
leaq -0x38(%rbp), %rdi
callq 0x33670
movq %rax, %rdi
addq $0x28, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x33690
jmp 0x318e1
leaq -0xb0(%rbp), %rdi
callq 0x1ea40
jmp 0x3191d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x31adf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x1ea40
jmp 0x31adf
jmp 0x3191f
jmp 0x31921
leaq -0xa0(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0x2, %eax
je 0x31966
leaq -0xa0(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0x3, %eax
je 0x31966
leaq -0xa0(%rbp), %rdi
callq 0x1dc20
movzwl 0x20(%rax), %eax
cmpl $0xff, %eax
jne 0x31a2c
movq -0x108(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x168(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x335f0
movq -0x168(%rbp), %rdi
movq %rax, %rsi
addq $0x4, %rsi
callq 0x33610
movq %rax, -0x160(%rbp)
jmp 0x3199d
movq -0x108(%rbp), %rdi
movq -0x160(%rbp), %rax
movq %rax, -0xb8(%rbp)
addq $0x58, %rdi
callq 0x33520
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x334c0
testb $0x1, %al
jne 0x319db
jmp 0x319e1
movb $0x1, -0x39(%rbp)
jmp 0x31a27
leaq -0xb8(%rbp), %rdi
callq 0x335f0
movq -0x108(%rbp), %rsi
movl 0x4(%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edx
leaq -0xd0(%rbp), %rdi
callq 0x31c50
jmp 0x31a0b
leaq -0x38(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x33760
leaq -0xd0(%rbp), %rdi
callq 0x1ea40
jmp 0x31ace
leaq -0x60(%rbp), %rdi
callq 0x335f0
movq -0x108(%rbp), %rsi
movl (%rax), %edx
leaq -0xe0(%rbp), %rdi
callq 0x31c50
jmp 0x31a4c
leaq -0xe0(%rbp), %rdi
callq 0x33670
movq %rax, %rdi
addq $0x10, %rdi
leaq -0x38(%rbp), %rsi
callq 0x33690
jmp 0x31a6a
leaq -0x38(%rbp), %rdi
callq 0x33670
movq %rax, %rdi
addq $0x28, %rdi
leaq -0xe0(%rbp), %rsi
callq 0x33690
jmp 0x31a88
leaq -0x38(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x33700
leaq -0x38(%rbp), %rdi
callq 0x33670
movl (%rax), %eax
movl %eax, -0x14(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x1ea40
jmp 0x31ace
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x1ea40
jmp 0x31adf
leaq -0xa0(%rbp), %rdi
callq 0x1dc40
jmp 0x31bc0
leaq -0xa0(%rbp), %rdi
callq 0x1dc40
jmp 0x31c26
movq -0x108(%rbp), %rsi
addq $0xd0, %rsi
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x33790
movq -0x178(%rbp), %rdi
callq 0x337c0
movq %rax, -0x170(%rbp)
jmp 0x31b26
movq -0x108(%rbp), %rsi
movq -0x170(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18c(%rbp)
addq $0xd0, %rsi
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x33790
movq -0x188(%rbp), %rdi
callq 0x337c0
movq %rax, -0x180(%rbp)
jmp 0x31b6b
movq -0x180(%rbp), %rdi
addq $0x8, %rdi
callq 0x1dc20
movq %rax, %rcx
movl -0x18c(%rbp), %eax
movzwl 0x22(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x194(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x33670
movq %rax, %rcx
movl -0x194(%rbp), %eax
subl (%rcx), %eax
movl %eax, -0x190(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x33670
movl -0x190(%rbp), %ecx
movl %ecx, 0x4(%rax)
movb $0x1, -0x39(%rbp)
jmp 0x31bc2
jmp 0x314a6
movq -0x108(%rbp), %rdi
addq $0xb8, %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x33850
movq -0x1a0(%rbp), %rdi
movq %rax, -0xf8(%rbp)
callq 0x33880
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x100(%rbp), %rsi
leaq 0x170(%rip), %rdx       # 0x31d80
callq 0x33800
jmp 0x31c17
movb $0x1, -0x1(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1ea40
jmp 0x31c31
leaq -0x38(%rbp), %rdi
callq 0x1ea40
jmp 0x31c3f
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x6540
nopl (%rax,%rax)