// File: /workspace/github_cpp_makefile_star2_O3/luooofan[P]hblzbd_compiler/src/Pass/convert_ssa.cpp
// Function: ConvertSSA::GenerateSSABasicBlocks(IRFunction*, SSAFunction*, std::unordered_map<IRBasicBlock*, SSABasicBlock*, std::hash<IRBasicBlock*>, std::equal_to<IRBasicBlock*>, std::allocator<std::pair<IRBasicBlock* const, SSABasicBlock*>>>&)
void ConvertSSA::GenerateSSABasicBlocks(IRFunction* func, SSAFunction* ssafunc,
                                        std::unordered_map<IRBasicBlock*, SSABasicBlock*>& bb_map) {
  // create armbb according to irbb
  for (auto bb : func->bb_list_) {
    SSABasicBlock* ssabb = new SSABasicBlock(ssafunc);
    bb_map.insert({bb, ssabb});
  }

  // maintain pred and succ
  for (auto bb : func->bb_list_) {
    for (auto pred : bb->pred_) {  // NOTE: it's OK?
      bb_map[bb]->AddPredBB(bb_map[pred]);
      // bb_map[pred]->AddSuccBB(bb_map[bb]);
    }
    for (auto succ : bb->succ_) {
      bb_map[bb]->AddSuccBB(bb_map[succ]);
    }
  }

  // maintain dom info
  for (auto bb : func->bb_list_) {
    bb_map[bb]->SetIDom(bb_map[bb->idom_]);
    for (auto dom : bb->doms_) {
      bb_map[bb]->AddDomBB(bb_map[dom]);
    }
    for (auto df : bb->df_) {
      bb_map[bb]->AddDF(bb_map[df]);
    }
  }

  // 处理所有label语句 给ssabasicblock绑定bbvalue 把bbvalue添加到workmap中
  for (auto bb : func->bb_list_) {
    auto ssabb = bb_map[bb];
    auto first_ir = bb->ir_list_.front();
    if (first_ir->op_ == ir::IR::OpKind::LABEL) {
      if (first_ir->opn1_.type_ == ir::Opn::Type::Label) {  // 如果是label就把label赋给这个bb的label
        auto& label = first_ir->opn1_.name_;
        ssabb->SetLabel(label);
        MyAssert(work_map.find(label) == work_map.end());
        work_map[label] = new BasicBlockValue(label, ssabb);
      }  // 如果是func label不用管 直接删了就行
      else {
        auto label = "." + func->name_ + ".bb." + std::to_string(bb->IndexInFunc());
        ssabb->SetLabel(label);
        new BasicBlockValue(label, ssabb);
      }
      bb->ir_list_.erase(bb->ir_list_.begin());
    } else {
      auto label = "." + func->name_ + ".bb." + std::to_string(bb->IndexInFunc());
      ssabb->SetLabel(label);
      new BasicBlockValue(label, ssabb);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, 0x8(%rsp)
movq %rdi, 0xb0(%rsp)
movq 0x30(%rsi), %r14
movq %rsi, 0x78(%rsp)
movq 0x38(%rsi), %rbp
cmpq %rbp, %r14
je 0x4218e
movq %rdx, %r15
leaq 0x10(%rsp), %rbx
movq (%r14), %r12
movl $0xd0, %edi
callq 0x8290
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
callq 0x43f8e
movq %r12, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x46832
addq $0x8, %r14
cmpq %rbp, %r14
jne 0x418e6
movq 0x78(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x38(%rax), %rbp
cmpq %rbp, %rcx
je 0x41a45
leaq 0x30(%rsp), %r15
movq %r15, %r12
movq %rbp, 0x80(%rsp)
movq %rcx, 0x50(%rsp)
movq (%rcx), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rax), %r14
movq 0x30(%rax), %rbp
cmpq %rbp, %r14
je 0x419bd
movq (%r14), %rax
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x46ac4
movq (%rax), %rbx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x46ac4
movq (%rax), %r15
leaq 0x40(%rbx), %r13
movl $0x18, %edi
callq 0x8290
movq %r15, 0x10(%rax)
movq %r12, %r15
movq %rax, %rdi
movq %r13, %rsi
callq 0x8080
incq 0x50(%rbx)
addq $0x8, %r14
cmpq %rbp, %r14
jne 0x41961
movq 0x10(%rsp), %rax
movq 0x40(%rax), %r14
movq 0x48(%rax), %rbp
cmpq %rbp, %r14
je 0x41a1e
movq (%r14), %rax
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x46ac4
movq (%rax), %rbx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x46ac4
movq (%rax), %r15
leaq 0x58(%rbx), %r13
movl $0x18, %edi
callq 0x8290
movq %r15, 0x10(%rax)
movq %r12, %r15
movq %rax, %rdi
movq %r13, %rsi
callq 0x8080
incq 0x68(%rbx)
addq $0x8, %r14
jmp 0x419c5
movq 0x50(%rsp), %rcx
addq $0x8, %rcx
movq 0x80(%rsp), %rbp
cmpq %rbp, %rcx
jne 0x41947
movq 0x78(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x38(%rax), %rbp
cmpq %rbp, %rcx
je 0x41b99
movq %rbp, 0x80(%rsp)
leaq 0x90(%rsp), %r15
leaq 0x10(%rsp), %rbp
movq %rcx, 0x50(%rsp)
movq (%rcx), %rax
movq %rax, 0x90(%rsp)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x46ac4
movq (%rax), %rbx
movq 0x90(%rsp), %rsi
movl $0x250, %eax            # imm = 0x250
addq %rax, %rsi
movq 0x8(%rsp), %rdi
callq 0x46ac4
movq (%rax), %rax
movq %rax, 0x70(%rbx)
movq 0x90(%rsp), %rax
movq 0x258(%rax), %r12
movq 0x260(%rax), %r13
cmpq %r13, %r12
je 0x41b02
movq (%r12), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x46ac4
movq (%rax), %r14
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x46ac4
movq (%rax), %rsi
movq %r14, %rdi
callq 0x440e4
addq $0x8, %r12
cmpq %r13, %r12
jne 0x41abf
movq 0x90(%rsp), %rax
movq 0x280(%rax), %r12
testq %r12, %r12
movq %rbp, %rbx
movq %r15, %rbp
leaq 0x30(%rsp), %r13
je 0x41b6f
movq 0x8(%r12), %rax
movq %rax, 0x58(%rsp)
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x46ac4
movq (%rax), %r14
movl $0x90, %eax
addq %rax, %r14
movq %r15, %rdi
leaq 0x58(%rsp), %rsi
callq 0x46ac4
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq %r14, 0x10(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x36494
movq (%r12), %r12
testq %r12, %r12
jne 0x41b19
movq 0x50(%rsp), %rcx
addq $0x8, %rcx
cmpq 0x80(%rsp), %rcx
movq %rbp, %r15
movq %rbx, %rbp
jne 0x41a63
movq 0x78(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x38(%rax), %rbp
cmpq %rbp, %rcx
je 0x4218e
addq $0x8, 0x78(%rsp)
leaq 0x40(%rsp), %r12
leaq 0x20(%rsp), %r14
addq $0xa8, 0xb0(%rsp)
movq %rbp, 0x80(%rsp)
movq %rcx, 0x50(%rsp)
movq (%rcx), %rax
movq %rax, 0x88(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x46ac4
movq (%rax), %r13
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %r15
cmpl $0x7, (%r15)
jne 0x41c6c
cmpl $0x2, 0x8(%r15)
jne 0x41cba
addq $0x10, %r15
leaq 0x8(%r13), %rdi
movq %r15, %rsi
callq 0x81b0
movq 0xb0(%rsp), %rdi
movq %r15, %rsi
callq 0x462be
testq %rax, %rax
jne 0x421a0
movl $0x50, %edi
callq 0x8290
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x33554
movq 0xb0(%rsp), %rdi
movq %r15, %rsi
callq 0x463ba
movq %r12, (%rax)
leaq 0x40(%rsp), %r12
jmp 0x4214f
leaq 0x90(%rsp), %r15
movq %r15, %rdi
leaq 0x2fb4e(%rip), %rsi     # 0x717cc
movq 0x78(%rsp), %rdx
callq 0x25a7d
movq %r15, %rdi
leaq 0x2fb37(%rip), %rsi     # 0x717c9
callq 0x8590
movq %r12, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x41d0f
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x41d17
leaq 0x90(%rsp), %r15
movq %r15, %rdi
leaq 0x2fb00(%rip), %rsi     # 0x717cc
movq 0x78(%rsp), %rdx
callq 0x25a7d
movq %r15, %rdi
leaq 0x2fae9(%rip), %rsi     # 0x717c9
callq 0x8590
movq %r12, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x41da5
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x41dad
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x88(%rsp), %rdi
callq 0x2bd9a
movl %eax, %ebp
movl %eax, %r12d
negl %r12d
cmovsl %eax, %r12d
movl $0x1, %r15d
cmpl $0xa, %r12d
jb 0x41e44
movl $0x4, %r15d
movl %r12d, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x41e3b
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x41e41
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x41e44
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r15d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x41d66
addl $-0x3, %r15d
jmp 0x41e44
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x88(%rsp), %rdi
callq 0x2bd9a
movl %eax, %ebp
movl %eax, %r12d
negl %r12d
cmovsl %eax, %r12d
movl $0x1, %r15d
cmpl $0xa, %r12d
jb 0x41fd3
movl $0x4, %r15d
movl %r12d, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x41fca
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x41fd0
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x41fd3
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r15d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x41dfc
addl $-0x3, %r15d
jmp 0x41fd3
addl $-0x2, %r15d
jmp 0x41e44
decl %r15d
shrl $0x1f, %ebp
leal (%r15,%rbp), %esi
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x58(%rsp), %rdi
movl $0x2d, %edx
callq 0x8350
movl %ebp, %edi
addq 0x58(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0xc35d
movq 0x30(%rsp), %rcx
movl $0xf, %edi
leaq 0x40(%rsp), %r12
cmpq %r12, %rcx
je 0x41e8f
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %r8
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
movq 0x80(%rsp), %rbp
jbe 0x41ec8
movl $0xf, %edi
leaq 0x68(%rsp), %r9
cmpq %r9, %rsi
je 0x41ec3
movq 0x68(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x41ed4
leaq 0x30(%rsp), %rdi
callq 0x8120
jmp 0x41ee2
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x8310
movq %r14, 0x10(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x41f02
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x41f09
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x41f42
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x41f59
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x41f7e
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x8(%r13), %rdi
leaq 0x10(%rsp), %rsi
callq 0x81b0
movl $0x50, %edi
callq 0x8290
movq %rax, %r15
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0x33554
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x41fc0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x50(%rsp), %rcx
jmp 0x42181
addl $-0x2, %r15d
jmp 0x41fd3
decl %r15d
shrl $0x1f, %ebp
leal (%r15,%rbp), %esi
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x58(%rsp), %rdi
movl $0x2d, %edx
callq 0x8350
movl %ebp, %edi
addq 0x58(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0xc35d
movq 0x30(%rsp), %rcx
movl $0xf, %edi
leaq 0x40(%rsp), %r12
cmpq %r12, %rcx
je 0x4201e
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %r8
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
movq 0x80(%rsp), %rbp
jbe 0x42057
movl $0xf, %edi
leaq 0x68(%rsp), %r9
cmpq %r9, %rsi
je 0x42052
movq 0x68(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x42063
leaq 0x30(%rsp), %rdi
callq 0x8120
jmp 0x42071
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x8310
movq %r14, 0x10(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x42091
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x42098
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x420d1
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x420e8
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x4210d
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x8(%r13), %rdi
leaq 0x10(%rsp), %rsi
callq 0x81b0
movl $0x50, %edi
callq 0x8290
movq %rax, %r15
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0x33554
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4214f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x88(%rsp), %r15
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rdx
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0x42174
subq %rsi, %rdx
callq 0x84c0
movq 0x10(%r15), %rdx
movq 0x50(%rsp), %rcx
addq $-0x8, %rdx
movq %rdx, 0x10(%r15)
addq $0x8, %rcx
cmpq %rbp, %rcx
jne 0x41bc6
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4ce41(%rip), %rdi     # 0x8efe8
leaq 0x2bfba(%rip), %rsi     # 0x6e168
callq 0x8280
leaq 0x2f5ee(%rip), %rsi     # 0x717a8
movq %rax, %rdi
callq 0x8280
leaq 0x2d1f7(%rip), %rsi     # 0x6f3c0
movq %rax, %rdi
callq 0x8280
movq %rax, %rdi
movl $0xfa, %esi
callq 0x8520
movq %rax, %rdi
callq 0x8180
movl $0xff, %edi
callq 0x8380
jmp 0x4221f
jmp 0x42206
movq %rax, %rbx
movl $0x50, %esi
movq %r12, %rdi
jmp 0x422a2
jmp 0x4220b
movq %rax, %rbx
jmp 0x42261
movq %rax, %rbx
movl $0x50, %esi
movq %r15, %rdi
callq 0x82a0
jmp 0x42283
jmp 0x42242
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x42245
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x42245
jmp 0x42280
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x42261
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x422a7
movq 0xa0(%rsp), %rsi
jmp 0x42292
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x422a7
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0x422a2
movq %rax, %rbx
movl $0xd0, %esi
movq %r13, %rdi
callq 0x82a0
movq %rbx, %rdi
callq 0x8540
nop