// File: /workspace/github_cpp_makefile_star2_O3/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, 0x30(%rsp)
movq %rsi, %rbx
movq %rdi, %r13
leaq 0x38(%rsi), %rdi
movq %rdx, (%rsp)
movq 0x40(%rdx), %rsi
addq $0x2, %rsi
movq %rdi, 0x58(%rsp)
callq 0x503a8
movl $0x158, %edi            # imm = 0x158
callq 0x8290
movq %rax, %rbp
leaq 0x8(%rbx), %r15
leaq 0x23dcb(%rip), %rsi     # 0x717cc
leaq 0x38(%rsp), %rdi
movq %r15, %rdx
callq 0x25a7d
leaq 0x23ea2(%rip), %rsi     # 0x718b7
leaq 0x38(%rsp), %rdi
callq 0x8590
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4da46
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x4da4d
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x8(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbp, %rdi
callq 0x50444
movq %rbp, 0x108(%r13)
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x4da8f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x108(%r13), %r12
leaq 0x48(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x4dab1
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x82a0
movq %r12, 0x60(%rsp)
movq (%r12), %rax
movq %rbx, 0x28(%rax)
movl $0x158, %edi            # imm = 0x158
callq 0x8290
movq %rax, %rbp
leaq 0x23cfa(%rip), %rsi     # 0x717cc
leaq 0x38(%rsp), %rdi
movq %r15, %rdx
callq 0x25a7d
leaq 0x23dde(%rip), %rsi     # 0x718c4
leaq 0x38(%rsp), %rdi
callq 0x8590
leaq 0x18(%rsp), %r15
movq %r15, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4db18
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x4db1f
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x8(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbp, %rdi
callq 0x50444
movq %rbp, 0x110(%r13)
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x4db61
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
movq 0x60(%rsp), %r14
je 0x4db7d
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x82a0
addq $0x30, (%rsp)
movq 0x110(%r13), %rax
movq %rbx, 0x28(%rax)
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x4dba4
movq (%r14), %rax
movq %rax, (%rsi)
addq $0x8, 0x40(%rbx)
jmp 0x4dbb1
movq 0x58(%rsp), %rdi
movq %r14, %rdx
callq 0x51066
movq (%rsp), %rax
movq (%rax), %rcx
cmpq %rax, %rcx
je 0x4dccd
leaq 0x409f8(%rip), %r15     # 0x8e5c0
leaq 0x40c71(%rip), %rbp     # 0x8e840
movq %rbx, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
movq 0x10(%rcx), %rbx
movl $0x158, %edi            # imm = 0x158
callq 0x8290
movq %rax, %r13
movq %rax, %rdi
callq 0x50538
movq %r13, 0x38(%rsp)
movq %rbx, 0x28(%rsp)
movq 0xc8(%rbx), %r12
movq 0x10(%r12), %r14
addq $0x10, %r12
cmpq %r12, %r14
je 0x4dc67
xorl %ebx, %ebx
movq 0x10(%r14), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x4dc3c
movq %r15, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x8320
testq %rax, %rax
je 0x4dc3c
movq (%r14), %r14
cmpq %r12, %r14
jne 0x4dc13
jmp 0x4dc48
movq (%r14), %r14
movb $0x1, %bl
cmpq %r12, %r14
jne 0x4dc13
jmp 0x4dc4d
testb $0x1, %bl
je 0x4dc67
movq 0x28(%rsp), %rax
leaq 0x8(%rax), %rsi
addq $0x8, %r13
movq %r13, %rdi
callq 0x81b0
movq 0x38(%rsp), %r13
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r13, 0x10(%rsp)
movq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x511a2
movq 0x68(%rsp), %rbx
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x4dca3
movq 0x38(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x40(%rbx)
jmp 0x4dcb7
movq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x51066
movq 0x38(%rsp), %rax
movq %rbx, 0x28(%rax)
movq 0x70(%rsp), %rcx
movq (%rcx), %rcx
cmpq (%rsp), %rcx
jne 0x4dbd4
movq 0x38(%rbx), %rdx
movq 0x40(%rbx), %rax
subq %rdx, %rax
cmpq $0x8, %rax
jbe 0x4dd39
movq 0x60(%rsp), %rbx
movq (%rbx), %rdi
addq $0x8, %rdx
movq 0x68(%rdi), %rsi
cmpq 0x70(%rdi), %rsi
je 0x4dd01
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x68(%rdi)
jmp 0x4dd0a
addq $0x60, %rdi
callq 0x51066
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
movq 0x50(%rdi), %rsi
cmpq 0x58(%rdi), %rsi
je 0x4dd2d
movq (%rbx), %rax
movq %rax, (%rsi)
addq $0x8, 0x50(%rdi)
jmp 0x4dd39
addq $0x48, %rdi
movq %rbx, %rdx
callq 0x51066
movq (%rsp), %rax
movq (%rax), %rcx
cmpq %rax, %rcx
je 0x4de2c
leaq 0x38(%rsp), %r12
movq %rcx, 0x28(%rsp)
movq 0x10(%rcx), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x51434
movq (%rax), %rbp
movq 0x8(%rsp), %r15
leaq 0x40(%r15), %r14
movq 0x40(%r15), %rbx
cmpq %r14, %rbx
je 0x4ddc9
leaq 0x48(%rbp), %r13
movq 0x10(%rbx), %rax
movq %rax, 0x38(%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x51434
movq 0x50(%rbp), %rsi
cmpq 0x58(%rbp), %rsi
je 0x4ddb1
movq (%rax), %rax
movq %rax, (%rsi)
addq $0x8, 0x50(%rbp)
jmp 0x4ddbc
movq %r13, %rdi
movq %rax, %rdx
callq 0x51066
movq (%rbx), %rbx
cmpq %r14, %rbx
jne 0x4dd84
movq 0x8(%rsp), %r15
movq 0x58(%r15), %r14
addq $0x58, %r15
cmpq %r15, %r14
je 0x4de1a
leaq 0x60(%rbp), %r13
movq 0x10(%r14), %rax
movq %rax, 0x38(%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x51434
movq 0x68(%rbp), %rsi
cmpq 0x70(%rbp), %rsi
je 0x4de07
movq (%rax), %rax
movq %rax, (%rsi)
addq $0x8, 0x68(%rbp)
jmp 0x4de12
movq %r13, %rdi
movq %rax, %rdx
callq 0x51066
movq (%r14), %r14
cmpq %r15, %r14
jne 0x4ddda
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
cmpq (%rsp), %rcx
jne 0x4dd4e
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x4de5a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x4de5a
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
jne 0x4de95
jmp 0x4dea7
jmp 0x4dea4
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x4de87
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x4de87
movq %rax, %rbx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4dea7
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x4dea7
movq %rax, %rbx
movl $0x158, %esi            # imm = 0x158
movq %rbp, %rdi
callq 0x82a0
movq %rbx, %rdi
callq 0x8540