// File: /workspace/github_cpp_makefile_star2_O1/luooofan[P]hblzbd_compiler/src/Pass/dominant.cpp
// Function: ComputeDominance::ComputeIDomInfo(IRFunction*)
void ComputeDominance::ComputeIDomInfo(IRFunction* f) {
  // 构造深度优先生成树 构造完后 保证vertex dfnum有效完整 parent[r]为空
  DFS(nullptr, f->bb_list_.front());
  // std::cout << N << " " << f->bb_list_.size() << std::endl;
  // MyAssert(N == f->bb_list_.size());

  // 基于半必经结点定理计算所有 非根节点 的半必经结点
  for (int i = N - 1; i > 0; --i) {
    BB* n = vertex[i];
    auto p = parent[n];
    MyAssert(nullptr != p);
    auto s = p;  // s即n的半必经结点
    for (auto pred : n->pred_) {
      BB* s_temp = nullptr;
      if (dfnum[pred] <= dfnum[n]) {  // 该前驱在生成树上是n的祖先
        s_temp = pred;                // 则该结点是semi[n]的候选
      } else {                        // 该前驱在生成树上不是n的祖先
        s_temp = semi[AncestorWithLowestSemi(pred)];
        // 则该前驱到其公共祖先的路径上的y:min(dfnum[semi[y]]) semi[y]成为semi[n]候选
      }
      if (dfnum[s_temp] < dfnum[s]) {  // 半必经结点是dfnum最小的
        s = s_temp;
      }
    }
    semi.insert({n, s});  // semi和bucket和ancestor中不会有key为root的pair
    bucket[s].insert(n);
    Link(p, n);  // 把p->n链入到生成树森林

    // 计算 以p为半必经结点的 结点v 的 必经结点 这里可以保证会把semi为root结点的结点的idom都计算到
    for (auto v : bucket[p]) {
      BB* y = AncestorWithLowestSemi(v);  // min(dfnum[semi[y]]) y: from p to v(included). dfnum[v]>dfnum[y].
      if (semi[y] == p /*semi[v]*/) {     // 没有旁路p的分支
        // idom.insert({v, p});
        v->idom_ = p;
        p->doms_.push_back(v);
      } else {
        samedom.insert({v, y});  // fill idom[samedom.key]=idom[samedom.value] later.
      }
    }
    bucket[p].clear();
  }

  // fill idom[samedom.key]=idom[samedom.value]
  for (int i = 1; i < N; ++i) {
    auto n = vertex[i];
    if (samedom.find(n) != samedom.end()) {
      auto idom = samedom[n]->idom_;
      // MyAssert(idom.find(samedom[n]) != idom.end());
      // idom.insert({n, idom[samedom[n]]});
      MyAssert(nullptr != idom);
      n->idom_ = idom;
      idom->doms_.push_back(n);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x30(%rsi), %rax
movq (%rax), %rdx
xorl %esi, %esi
callq 0x4b200
movslq 0x34(%rbx), %r14
cmpq $0x2, %r14
jl 0x4b8d8
leaq 0x88(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x50(%rbx), %r15
leaq 0x130(%rbx), %r12
leaq 0x1a0(%rbx), %rbp
leaq 0xc0(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0xf8(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x168(%rbx), %rax
movq %rax, 0x60(%rsp)
movq %rbp, 0x48(%rsp)
movq 0x38(%rbx), %rax
movq %r14, 0x58(%rsp)
movq -0x8(%rax,%r14,8), %rax
movq %rax, 0x18(%rsp)
movq 0x50(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x4c234
movq (%rax), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x4b9e1
movq %rax, 0x28(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rbp
movq 0x30(%rax), %r14
cmpq %r14, %rbp
je 0x4b780
movq (%rbp), %rax
movq %rax, 0x8(%rsp)
movq $0x0, (%rsp)
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4c2da
movl (%rax), %r13d
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4c2da
cmpl (%rax), %r13d
jle 0x4b745
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4b33a
movq %rax, 0x20(%rsp)
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x4c594
movq (%rax), %rax
jmp 0x4b74a
movq 0x8(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movq %rsp, %rsi
callq 0x4c2da
movl (%rax), %r13d
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x4c2da
cmpl (%rax), %r13d
jge 0x4b777
movq (%rsp), %rax
movq %rax, 0x28(%rsp)
addq $0x8, %rbp
jmp 0x4b6e5
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r12, %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0x4bf4a
movq 0x48(%rsp), %rbp
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
callq 0x4c63a
movq %rax, 0x8(%rsp)
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x4875a
movq 0x30(%rsp), %rax
movq 0x18(%rsp), %r14
movq %r14, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x4bf4a
movq %r14, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq 0x38(%rsp), %rdi
movq %r13, %rsi
callq 0x4bf4a
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x4c63a
movq 0x10(%rax), %r14
testq %r14, %r14
movq 0x58(%rsp), %r13
je 0x4b8b5
movq 0x8(%r14), %rsi
movq %rsi, (%rsp)
movq %rbx, %rdi
callq 0x4b33a
movq %rax, 0x20(%rsp)
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x4c234
movq 0x30(%rsp), %rdi
cmpq %rdi, (%rax)
je 0x4b872
movq (%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x60(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4bf4a
jmp 0x4b8a9
movq (%rsp), %rax
movq %rdi, 0x250(%rax)
movq 0x260(%rdi), %rsi
cmpq 0x268(%rdi), %rsi
je 0x4b89a
movq %rax, (%rsi)
addq $0x8, 0x260(%rdi)
jmp 0x4b8a9
addq $0x258, %rdi            # imm = 0x258
movq %rsp, %rdx
callq 0x11b10
movq (%r14), %r14
testq %r14, %r14
jne 0x4b822
leaq -0x1(%r13), %r14
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x4c63a
movq %rax, %rdi
callq 0x2ba94
cmpq $0x2, %r13
jg 0x4b6a0
cmpl $0x2, 0x34(%rbx)
jl 0x4b9d2
leaq 0x168(%rbx), %r14
movl $0x1, %r12d
leaq 0x8(%rsp), %r15
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rcx
movq %rcx, 0x8(%rsp)
movq 0x168(%rbx), %rdi
movq 0x170(%rbx), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %rsi
movq (%rdi,%rdx,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0x4b961
movq (%rdx), %r9
movq %rdx, %rax
cmpq 0x8(%r9), %rcx
je 0x4b961
movq %r9, %r10
movq (%r9), %r9
testq %r9, %r9
je 0x4b95f
movq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
movl $0x0, %eax
cmpq %rsi, %rdx
jne 0x4b961
movq %r10, %rax
cmpq %rdi, %rcx
jne 0x4b934
jmp 0x4b961
xorl %eax, %eax
testq %rax, %rax
je 0x4b9c2
cmpq $0x0, (%rax)
je 0x4b9c2
movq %r14, %rdi
movq %r15, %rsi
callq 0x4c234
movq (%rax), %rax
movq 0x250(%rax), %rdi
testq %rdi, %rdi
je 0x4ba1c
movq 0x8(%rsp), %rax
movq %rdi, 0x250(%rax)
movq 0x260(%rdi), %rsi
cmpq 0x268(%rdi), %rsi
je 0x4b9b3
movq %rax, (%rsi)
addq $0x8, 0x260(%rdi)
jmp 0x4b9c2
addq $0x258, %rdi            # imm = 0x258
movq %r15, %rdx
callq 0x11b10
incq %r12
movslq 0x34(%rbx), %rax
cmpq %rax, %r12
jl 0x4b8f4
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x44608(%rip), %rdi     # 0x8fff0
leaq 0x23779(%rip), %rsi     # 0x6f168
callq 0x8280
leaq 0x26e27(%rip), %rsi     # 0x72822
movq %rax, %rdi
callq 0x8280
leaq 0x249b6(%rip), %rsi     # 0x703c0
movq %rax, %rdi
callq 0x8280
movq %rax, %rdi
movl $0x42, %esi
jmp 0x4ba55
movq 0x445cd(%rip), %rdi     # 0x8fff0
leaq 0x2373e(%rip), %rsi     # 0x6f168
callq 0x8280
leaq 0x26dec(%rip), %rsi     # 0x72822
movq %rax, %rdi
callq 0x8280
leaq 0x2497b(%rip), %rsi     # 0x703c0
movq %rax, %rdi
callq 0x8280
movq %rax, %rdi
movl $0x69, %esi
callq 0x8520
movq %rax, %rdi
callq 0x8180
movl $0xff, %edi
callq 0x8380