// File: /workspace/github_cpp_makefile_star2_O1/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, 0xa8(%rsp)
movq 0x30(%rsi), %r14
movq %rsi, 0x70(%rsp)
movq 0x38(%rsi), %rbp
cmpq %rbp, %r14
je 0x420d5
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 0x44722
movq %r12, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x46fac
addq $0x8, %r14
cmpq %rbp, %r14
jne 0x4209a
movq 0x70(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x38(%rax), %rax
movq %rax, 0xb0(%rsp)
cmpq %rax, %rcx
je 0x421e8
leaq 0x50(%rsp), %r15
movq %r15, %r12
movq %rcx, 0x78(%rsp)
movq (%rcx), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rax), %rbp
movq 0x30(%rax), %r14
cmpq %r14, %rbp
je 0x4216a
movq (%rbp), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x47296
movq (%rax), %rbx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x47296
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, %rbp
jmp 0x42110
movq 0x10(%rsp), %rax
movq 0x40(%rax), %rbp
movq 0x48(%rax), %r14
cmpq %r14, %rbp
je 0x421d1
movq (%rbp), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x47296
movq (%rax), %rbx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x47296
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, %rbp
jmp 0x42177
movq 0x78(%rsp), %rcx
addq $0x8, %rcx
cmpq 0xb0(%rsp), %rcx
jne 0x420fb
movq 0x70(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x38(%rax), %rax
movq %rax, 0xb0(%rsp)
cmpq %rax, %rcx
je 0x42339
leaq 0x88(%rsp), %r15
leaq 0x10(%rsp), %rbp
movq %rcx, 0x78(%rsp)
movq (%rcx), %rax
movq %rax, 0x88(%rsp)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x47296
movq (%rax), %rbx
movq 0x88(%rsp), %rsi
movl $0x250, %eax            # imm = 0x250
addq %rax, %rsi
movq 0x8(%rsp), %rdi
callq 0x47296
movq (%rax), %rax
movq %rax, 0x70(%rbx)
movq 0x88(%rsp), %rax
movq 0x258(%rax), %r12
movq 0x260(%rax), %r13
cmpq %r13, %r12
je 0x422a7
movq (%r12), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x47296
movq (%rax), %r14
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x47296
movq (%rax), %rsi
movq %r14, %rdi
callq 0x44878
addq $0x8, %r12
jmp 0x4226a
movq 0x88(%rsp), %rax
movq 0x280(%rax), %r12
testq %r12, %r12
movq %rbp, %rbx
movq %r15, %rbp
leaq 0x50(%rsp), %r13
je 0x4231c
movq 0x8(%r12), %rax
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x47296
movq (%rax), %r14
movl $0x90, %eax
addq %rax, %r14
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x47296
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movq %r14, 0x10(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x3632c
movq (%r12), %r12
testq %r12, %r12
jne 0x422c6
movq 0x78(%rsp), %rcx
addq $0x8, %rcx
cmpq 0xb0(%rsp), %rcx
movq %rbp, %r15
movq %rbx, %rbp
jne 0x42213
movq 0x70(%rsp), %rax
movq 0x30(%rax), %r14
movq 0x38(%rax), %rax
movq %rax, 0x78(%rsp)
cmpq %rax, %r14
je 0x4291c
addq $0x8, 0x70(%rsp)
leaq 0x60(%rsp), %rbp
addq $0xa8, 0xa8(%rsp)
movq (%r14), %rax
movq %rax, 0x80(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x47296
movq (%rax), %r13
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %r15
cmpl $0x7, (%r15)
jne 0x42407
cmpl $0x2, 0x8(%r15)
jne 0x42455
addq $0x10, %r15
leaq 0x8(%r13), %rdi
movq %r15, %rsi
callq 0x81b0
movq 0xa8(%rsp), %rdi
movq %r15, %rsi
callq 0x46a24
testq %rax, %rax
jne 0x4292e
movl $0x50, %edi
callq 0x8290
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x33400
movq 0xa8(%rsp), %rdi
movq %r15, %rsi
callq 0x46b20
movq %r12, (%rax)
jmp 0x428e7
leaq 0x88(%rsp), %r15
movq %r15, %rdi
leaq 0x303af(%rip), %rsi     # 0x727c8
movq 0x70(%rsp), %rdx
callq 0x253b1
movq %r15, %rdi
leaq 0x30398(%rip), %rsi     # 0x727c5
callq 0x8590
movq %rbp, 0x50(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x424aa
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x424b1
leaq 0x88(%rsp), %r15
movq %r15, %rdi
leaq 0x30361(%rip), %rsi     # 0x727c8
movq 0x70(%rsp), %rdx
callq 0x253b1
movq %r15, %rdi
leaq 0x3034a(%rip), %rsi     # 0x727c5
callq 0x8590
movq %rbp, 0x50(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4253f
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x42546
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x80(%rsp), %rdi
callq 0x2b86c
movl %eax, %ebp
movl %eax, %r12d
negl %r12d
cmovsl %eax, %r12d
movl $0x1, %r15d
cmpl $0xa, %r12d
jb 0x425dd
movl $0x4, %r15d
movl %r12d, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x425d4
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x425da
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x425dd
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r15d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x42500
addl $-0x3, %r15d
jmp 0x425dd
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x80(%rsp), %rdi
callq 0x2b86c
movl %eax, %ebp
movl %eax, %r12d
negl %r12d
cmovsl %eax, %r12d
movl $0x1, %r15d
cmpl $0xa, %r12d
jb 0x4276b
movl $0x4, %r15d
movl %r12d, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x42762
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x42768
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x4276b
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r15d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x42595
addl $-0x3, %r15d
jmp 0x4276b
addl $-0x2, %r15d
jmp 0x425dd
decl %r15d
shrl $0x1f, %ebp
leal (%r15,%rbp), %esi
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rdi
movl $0x2d, %edx
callq 0x8350
movl %ebp, %edi
addq 0x30(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0xc65b
movq 0x50(%rsp), %rcx
movl $0xf, %esi
leaq 0x60(%rsp), %rbp
cmpq %rbp, %rcx
je 0x42628
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %r8
movq 0x38(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
leaq 0x20(%rsp), %r12
jbe 0x4265b
movl $0xf, %esi
leaq 0x40(%rsp), %rdi
cmpq %rdi, 0x30(%rsp)
je 0x42656
movq 0x40(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x4266c
movq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x8120
jmp 0x4267a
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x8310
movq %r12, 0x10(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x4269a
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x426a2
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x426db
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x426f2
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x42717
movq 0x98(%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 0x33400
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x4290d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x4290d
addl $-0x2, %r15d
jmp 0x4276b
decl %r15d
shrl $0x1f, %ebp
leal (%r15,%rbp), %esi
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rdi
movl $0x2d, %edx
callq 0x8350
movl %ebp, %edi
addq 0x30(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0xc65b
movq 0x50(%rsp), %rcx
movl $0xf, %esi
leaq 0x60(%rsp), %rbp
cmpq %rbp, %rcx
je 0x427b6
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %r8
movq 0x38(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
leaq 0x20(%rsp), %r12
jbe 0x427e9
movl $0xf, %esi
leaq 0x40(%rsp), %rdi
cmpq %rdi, 0x30(%rsp)
je 0x427e4
movq 0x40(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x427fa
movq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x8120
jmp 0x42808
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x8310
movq %r12, 0x10(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x42828
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x42830
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x42869
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x42880
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x428a5
movq 0x98(%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 0x33400
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x428e7
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x80(%rsp), %r15
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rdx
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0x42908
subq %rsi, %rdx
callq 0x84c0
addq $-0x8, 0x10(%r15)
addq $0x8, %r14
cmpq 0x78(%rsp), %r14
jne 0x4236b
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4d6bb(%rip), %rdi     # 0x8fff0
leaq 0x2c82c(%rip), %rsi     # 0x6f168
callq 0x8280
leaq 0x2fe5c(%rip), %rsi     # 0x727a4
movq %rax, %rdi
callq 0x8280
leaq 0x2da69(%rip), %rsi     # 0x703c0
movq %rax, %rdi
callq 0x8280
movq %rax, %rdi
movl $0xfa, %esi
callq 0x8520
movq %rax, %rdi
callq 0x8180
movl $0xff, %edi
callq 0x8380
jmp 0x429ad
jmp 0x42994
movq %rax, %rbx
movl $0x50, %esi
movq %r12, %rdi
jmp 0x42a35
jmp 0x42999
movq %rax, %rbx
jmp 0x429ef
movq %rax, %rbx
movl $0x50, %esi
movq %r15, %rdi
callq 0x82a0
jmp 0x42a11
jmp 0x429d0
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x429d3
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x429d3
jmp 0x42a0e
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x429ef
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x42a3a
movq 0x98(%rsp), %rsi
jmp 0x42a25
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x42a3a
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0x42a35
movq %rax, %rbx
movl $0xd0, %esi
movq %r13, %rdi
callq 0x82a0
movq %rbx, %rdi
callq 0x8540