// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r13
leaq 0x38(%rsi), %rdi
movq %rdx, 0x8(%rsp)
movq 0x40(%rdx), %rsi
addq $0x2, %rsi
movq %rdi, 0x58(%rsp)
callq 0x51094
movl $0x158, %edi            # imm = 0x158
callq 0x8290
movq %rax, %rbp
movq %r14, 0x60(%rsp)
leaq 0x8(%r14), %r15
leaq 0x2413b(%rip), %rsi     # 0x727c8
leaq 0x30(%rsp), %rdi
movq %r15, %rdx
callq 0x253b1
leaq 0x24212(%rip), %rsi     # 0x728b3
leaq 0x30(%rsp), %rdi
callq 0x8590
leaq 0x20(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4e6d2
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x4e6d9
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbp, %rdi
callq 0x5112a
movq %rbp, 0x108(%r13)
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4e71b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x108(%r13), %r12
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq 0x60(%rsp), %r14
je 0x4e742
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
movq (%r12), %rax
movq %r14, 0x28(%rax)
movl $0x158, %edi            # imm = 0x158
callq 0x8290
movq %rax, %rbp
leaq 0x2406a(%rip), %rsi     # 0x727c8
leaq 0x30(%rsp), %rdi
movq %r15, %rdx
callq 0x253b1
leaq 0x2414e(%rip), %rsi     # 0x728c0
leaq 0x30(%rsp), %rdi
callq 0x8590
leaq 0x20(%rsp), %r14
movq %r14, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4e7a4
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x4e7ab
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbp, %rdi
callq 0x5112a
movq %rbp, 0x110(%r13)
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4e7ed
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
movq 0x60(%rsp), %rbp
je 0x4e80e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
addq $0x30, 0x8(%rsp)
movq 0x110(%r13), %rax
movq %rbp, 0x28(%rax)
movq 0x40(%rbp), %rsi
cmpq 0x48(%rbp), %rsi
movq %r12, 0x68(%rsp)
je 0x4e83c
movq (%r12), %rax
movq %rax, (%rsi)
addq $0x8, 0x40(%rbp)
jmp 0x4e849
movq 0x58(%rsp), %rdi
movq %r12, %rdx
callq 0x51cf6
movq 0x8(%rsp), %rax
movq (%rax), %r14
cmpq %rax, %r14
je 0x4e95d
movl $0x1, %r12d
movq 0x10(%r14), %r15
movl $0x158, %edi            # imm = 0x158
callq 0x8290
movq %rax, %r13
movq %rax, %rdi
callq 0x5121e
movq %r15, %rax
movq %r13, 0x70(%rsp)
movq %r13, 0x30(%rsp)
movq 0xc8(%r15), %r13
movq 0x10(%r13), %r15
addq $0x10, %r13
cmpq %r13, %r15
je 0x4e902
movq %rax, 0x50(%rsp)
xorl %ebp, %ebp
movq 0x10(%r15), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x4e8d0
leaq 0x40d3b(%rip), %rsi     # 0x8f5f0
leaq 0x40fb4(%rip), %rdx     # 0x8f870
xorl %ecx, %ecx
callq 0x8320
testq %rax, %rax
movzbl %bpl, %ebp
cmovel %r12d, %ebp
jmp 0x4e8d3
movb $0x1, %bpl
movq (%r15), %r15
cmpq %r13, %r15
jne 0x4e8a1
testb $0x1, %bpl
movq 0x60(%rsp), %rbp
movq 0x50(%rsp), %rax
je 0x4e902
leaq 0x8(%rax), %rsi
movq 0x70(%rsp), %rdi
addq $0x8, %rdi
callq 0x81b0
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0x51e32
movq 0x40(%rbp), %rsi
cmpq 0x48(%rbp), %rsi
je 0x4e937
movq 0x30(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x40(%rbp)
jmp 0x4e946
movq 0x58(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x51cf6
movq 0x30(%rsp), %rax
movq %rbp, 0x28(%rax)
movq (%r14), %r14
cmpq 0x8(%rsp), %r14
jne 0x4e860
movq 0x38(%rbp), %rdx
movq 0x40(%rbp), %rax
subq %rdx, %rax
cmpq $0x8, %rax
jbe 0x4e9c9
movq 0x68(%rsp), %r14
movq (%r14), %rdi
addq $0x8, %rdx
movq 0x68(%rdi), %rsi
cmpq 0x70(%rdi), %rsi
je 0x4e991
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x68(%rdi)
jmp 0x4e99a
addq $0x60, %rdi
callq 0x51cf6
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
movq 0x50(%rdi), %rsi
cmpq 0x58(%rdi), %rsi
je 0x4e9bd
movq (%r14), %rax
movq %rax, (%rsi)
addq $0x8, 0x50(%rdi)
jmp 0x4e9c9
addq $0x48, %rdi
movq %r14, %rdx
callq 0x51cf6
movq 0x8(%rsp), %rax
movq (%rax), %rcx
cmpq %rax, %rcx
je 0x4eab8
leaq 0x30(%rsp), %r12
movq %rcx, 0x50(%rsp)
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0x5211c
movq (%rax), %rbp
movq 0x10(%rsp), %r15
movq 0x40(%r15), %r14
addq $0x40, %r15
cmpq %r15, %r14
je 0x4ea51
leaq 0x48(%rbp), %r13
movq 0x10(%r14), %rax
movq %rax, 0x30(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5211c
movq 0x50(%rbp), %rsi
cmpq 0x58(%rbp), %rsi
je 0x4ea3e
movq (%rax), %rax
movq %rax, (%rsi)
addq $0x8, 0x50(%rbp)
jmp 0x4ea49
movq %r13, %rdi
movq %rax, %rdx
callq 0x51cf6
movq (%r14), %r14
cmpq %r15, %r14
jne 0x4ea13
movq 0x10(%rsp), %r15
movq 0x58(%r15), %r14
addq $0x58, %r15
cmpq %r15, %r14
je 0x4eaa5
leaq 0x60(%rbp), %r13
movq 0x10(%r14), %rax
movq %rax, 0x30(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5211c
movq 0x68(%rbp), %rsi
cmpq 0x70(%rbp), %rsi
je 0x4ea92
movq (%rax), %rax
movq %rax, (%rsi)
addq $0x8, 0x68(%rbp)
jmp 0x4ea9d
movq %r13, %rdi
movq %rax, %rdx
callq 0x51cf6
movq (%r14), %r14
cmpq %r15, %r14
jne 0x4ea67
movq 0x50(%rsp), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rsp), %rcx
jne 0x4e9df
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4eae6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x4eae6
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
jmp 0x4eb1c
jmp 0x4eb30
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4eb13
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x4eb13
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4eb33
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x4eb33
movq %rax, %rbx
movl $0x158, %esi            # imm = 0x158
movq %rbp, %rdi
callq 0x82a0
movq %rbx, %rdi
callq 0x8540