// File: /workspace/github_cpp_makefile_star2_O2/luooofan[P]hblzbd_compiler/src/Pass/generate_arm_from_ssa.cpp
// Function: GenerateArmFromSSA::GenerateArmBasicBlocks(ArmFunction*, SSAFunction*, std::unordered_map<SSABasicBlock*, ArmBasicBlock*, std::hash<SSABasicBlock*>, std::equal_to<SSABasicBlock*>, std::allocator<std::pair<SSABasicBlock* const, ArmBasicBlock*>>>&)
void GenerateArmFromSSA::GenerateArmBasicBlocks(ArmFunction* armfunc, SSAFunction* func,
                                                std::unordered_map<SSABasicBlock*, ArmBasicBlock*>& bb_map) {
  armfunc->bb_list_.reserve(func->GetBBList().size() + 2);
  // create prologue and epilogue
  prologue = new ArmBasicBlock("." + armfunc->name_ + ".prologue.bb");
  prologue->func_ = armfunc;
  epilogue = new ArmBasicBlock("." + armfunc->name_ + ".epilogue.bb");
  epilogue->func_ = armfunc;
  armfunc->bb_list_.push_back(prologue);

  // create armbb according to irbb
  for (auto bb : func->GetBBList()) {
    // ArmBasicBlock* armbb = new ArmBasicBlock(&(bb->GetLabel()));  // FIXME
    ArmBasicBlock* armbb = new ArmBasicBlock();
    bool set_label = false;
    for (auto use : bb->GetValue()->GetUses()) {
      if (nullptr == dynamic_cast<PhiInst*>(use->GetUser())) set_label = true;
    }
    if (set_label) armbb->label_ = bb->GetLabel();
    bb_map.insert({bb, armbb});
    armfunc->bb_list_.push_back(armbb);
    armbb->func_ = armfunc;
  }

  // maintain pred and succ
  if (armfunc->bb_list_.size() > 1) {
    prologue->succ_.push_back(armfunc->bb_list_[1]);
    armfunc->bb_list_[1]->pred_.push_back(prologue);
  }
  for (auto bb : func->GetBBList()) {
    auto armbb = bb_map[bb];
    for (auto pred : bb->GetPredBB()) {
      armbb->pred_.push_back(bb_map[pred]);
    }
    for (auto succ : bb->GetSuccBB()) {
      armbb->succ_.push_back(bb_map[succ]);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %rbx
movq %rsi, %r15
movq %rdi, %r12
leaq 0x38(%rsi), %rdi
movq %rdx, %r14
movq 0x40(%rdx), %rsi
addq $0x2, %rsi
movq %rdi, 0x10(%rsp)
callq 0x3fe32
movl $0x158, %edi            # imm = 0x158
callq 0x8250
movq %rax, %r13
movq %r15, 0x8(%rsp)
addq $0x8, %r15
leaq 0x1b924(%rip), %rsi     # 0x5972c
leaq 0x28(%rsp), %rdi
movq %r15, %rdx
callq 0x1ae0c
leaq 0x1b9fb(%rip), %rdx     # 0x59817
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xa440
leaq 0x48(%rsp), %rsi
movq %r13, %rdi
callq 0x3fec8
movq %r13, 0x108(%r12)
leaq 0x48(%rsp), %rdi
callq 0x8578
leaq 0x28(%rsp), %rdi
callq 0x8578
movq 0x108(%r12), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x28(%rax)
movl $0x158, %edi            # imm = 0x158
callq 0x8250
movq %rax, %r13
leaq 0x1b8b3(%rip), %rsi     # 0x5972c
leaq 0x28(%rsp), %rdi
movq %r15, %rdx
callq 0x1ae0c
leaq 0x1b997(%rip), %rdx     # 0x59824
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xa440
leaq 0x48(%rsp), %rsi
movq %r13, %rdi
callq 0x3fec8
addq $0x30, %r14
leaq 0x108(%r12), %r15
movq %r13, 0x110(%r12)
leaq 0x48(%rsp), %rdi
callq 0x8578
leaq 0x28(%rsp), %rdi
callq 0x8578
movq 0x110(%r12), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq 0x10(%rsp), %rdi
movq %r15, 0x68(%rsp)
movq %r15, %rsi
callq 0x3fe14
leaq 0x426c5(%rip), %r13     # 0x805c0
leaq 0x4293e(%rip), %rbp     # 0x80840
movq %r14, 0x18(%rsp)
movq (%r14), %r14
cmpq 0x18(%rsp), %r14
je 0x3dfed
movq %r14, 0x80(%rsp)
movq 0x10(%r14), %r14
movl $0x158, %edi            # imm = 0x158
callq 0x8250
movq %rax, %r15
movq %rax, %rdi
callq 0x3ffa2
movq %r15, 0x70(%rsp)
movq %r15, 0x28(%rsp)
movq %r14, 0x78(%rsp)
movq 0xc8(%r14), %r15
addq $0x10, %r15
xorl %r14d, %r14d
movq %r15, %r12
movb %r14b, 0x20(%rsp)
movq (%r12), %r12
cmpq %r15, %r12
je 0x3df89
movq 0x10(%r12), %rax
movq 0x8(%rax), %rdi
movb $0x1, %r14b
testq %rdi, %rdi
je 0x3df56
movq %r13, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x82c0
testq %rax, %rax
jne 0x3df5b
jmp 0x3df56
testb $0x1, 0x20(%rsp)
movq 0x78(%rsp), %r14
movq 0x70(%rsp), %rdi
je 0x3dfac
leaq 0x8(%r14), %rsi
addq $0x8, %rdi
callq 0x81a0
movq 0x28(%rsp), %rdi
movq %r14, 0x48(%rsp)
movq %rdi, 0x50(%rsp)
movq %rbx, %rdi
leaq 0x48(%rsp), %rsi
callq 0x40d7a
movq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3fe14
movq 0x28(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq 0x80(%rsp), %r14
jmp 0x3df07
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
movq 0x40(%rax), %rax
subq %rsi, %rax
cmpq $0x8, %rax
jbe 0x3e030
movq 0x68(%rsp), %r14
movq (%r14), %rdi
addq $0x60, %rdi
addq $0x8, %rsi
callq 0x3fe14
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
addq $0x48, %rdi
movq %r14, %rsi
callq 0x3fe14
leaq 0x28(%rsp), %r12
movq 0x18(%rsp), %rax
movq (%rax), %rax
cmpq 0x18(%rsp), %rax
je 0x3e0e2
movq %rax, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x48(%rsp)
movq %rbx, %rdi
leaq 0x48(%rsp), %rsi
callq 0x410ac
movq (%rax), %r13
movq 0x48(%rsp), %r14
addq $0x40, %r14
leaq 0x48(%r13), %rbp
movq %r14, %r15
movq (%r15), %r15
cmpq %r14, %r15
je 0x3e09f
movq 0x10(%r15), %rax
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x410ac
movq %rbp, %rdi
movq %rax, %rsi
callq 0x3fe14
jmp 0x3e076
movq 0x48(%rsp), %rbp
addq $0x58, %rbp
addq $0x60, %r13
movq %rbp, %r15
movq (%r15), %r15
cmpq %rbp, %r15
je 0x3e0d8
movq 0x10(%r15), %rax
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x410ac
movq %r13, %rdi
movq %rax, %rsi
callq 0x3fe14
jmp 0x3e0af
movq 0x20(%rsp), %rax
jmp 0x3e03a
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3e0fa
jmp 0x3e109
jmp 0x3e118
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x8578
jmp 0x3e10c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x8578
jmp 0x3e11b
movq %rax, %rbx
movl $0x158, %esi            # imm = 0x158
movq %r13, %rdi
callq 0x8260
movq %rbx, %rdi
callq 0x84d0