// File: /workspace/github_cpp_makefile_star2_O2/luooofan[P]hblzbd_compiler/src/Pass/global_value_numbering.cpp
// Function: GlobalValueNumbering::Run()
void GlobalValueNumbering::Run() {
  kCount = 0;
  auto m = dynamic_cast<SSAModule*>(*(this->m_));
  MyAssert(nullptr != m);
  DeadCodeEliminate::FindNoSideEffectFunc(m, no_side_effect_funcs);

#ifdef DEBUG_GVN_PROCESS
  std::cout << "No side effect functions: ";
  for (auto func : no_side_effect_funcs) {
    std::cout << func->GetFuncName() << " ";
  }
  std::cout << std::endl;
#endif

  for (auto func : m->GetFuncList()) {
    // find back-edge
    std::set<std::pair<SSABasicBlock*, SSABasicBlock*>> back_edges;
    for (auto bb : func->GetBasicBlocks()) {
      auto&& dom_set = bb->GetDomSet();
      for (auto succ : bb->GetSuccBB()) {
        if (dom_set.count(succ)) back_edges.insert({bb, succ});
      }
    }
    // find loop and fill bbs_in_loop
    bbs_in_loop.clear();
    std::queue<SSABasicBlock*> q;
    std::unordered_set<SSABasicBlock*> loop;
    for (auto [st, ed] : back_edges) {
      MyAssert(q.empty() && loop.empty());
      loop.insert(ed);
      q.push(st);
      while (!q.empty()) {
        auto front = q.front();
        q.pop();
        if (loop.count(front)) continue;
        loop.insert(front);
        for (auto pred : front->GetPredBB()) q.push(pred);
      }
      bbs_in_loop.insert(loop.begin(), loop.end());
      loop.clear();
    }
    // prepared run for function
    exp_val_vec.clear();
    Run4Func(func);
  }

#ifdef DEBUG_GVN_EFFECT
  std::cout << "GVN Pass works on " << kCount << " insts" << std::endl;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
andl $0x0, 0x3febc(%rip)     # 0x816b4
movq %rdi, 0x20(%rsp)
movq 0x8(%rdi), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x41b22
leaq 0x3de34(%rip), %rsi     # 0x7f648
leaq 0x3f0e5(%rip), %rdx     # 0x80900
xorl %ecx, %ecx
callq 0x82c0
testq %rax, %rax
je 0x41b22
movq 0x20(%rsp), %rbx
leaq 0x38(%rbx), %rsi
movq %rax, %rdi
movq %rax, %r14
callq 0x398be
movq %r14, %rax
addq $0x40, %rax
leaq 0x70(%rbx), %rcx
movq %rcx, 0x28(%rsp)
leaq 0xa8(%rbx), %rcx
movq %rcx, 0x38(%rsp)
leaq 0xc8(%rsp), %rbp
leaq 0x90(%rsp), %r13
leaq 0x8(%rsp), %r12
leaq 0x58(%rsp), %r15
movq %rax, %rcx
movq %rax, 0x30(%rsp)
movq (%rcx), %rcx
cmpq %rax, %rcx
je 0x41ac2
movq %rcx, 0x40(%rsp)
movq 0x10(%rcx), %rcx
andl $0x0, 0x68(%rsp)
andq $0x0, 0x70(%rsp)
leaq 0x68(%rsp), %rax
movq %rax, 0x78(%rsp)
movq %rax, 0x80(%rsp)
andq $0x0, 0x88(%rsp)
movq %rcx, 0x48(%rsp)
leaq 0x30(%rcx), %rax
movq %rax, 0x50(%rsp)
movq %rax, %r14
movq (%r14), %r14
cmpq 0x50(%rsp), %r14
je 0x41949
movq 0x10(%r14), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x284ca
movq %r14, (%rsp)
leaq 0x58(%rbx), %r14
movq %r14, %r12
movq (%r12), %r12
cmpq %r14, %r12
je 0x41936
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x4347c
testq %rax, %rax
je 0x418ed
movq %rbx, 0x90(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x434ae
jmp 0x418ed
movq %rbp, %rdi
callq 0x28c50
leaq 0x8(%rsp), %r12
movq (%rsp), %r14
jmp 0x418c9
movq 0x28(%rsp), %rdi
callq 0x28c6c
movq %rbp, %rdi
callq 0x430fc
leaq 0xc0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq $0x1, 0x98(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, 0xb0(%rsp) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movq 0x78(%rsp), %rcx
leaq 0x68(%rsp), %rax
cmpq %rax, %rcx
je 0x41a80
movq %rcx, (%rsp)
movups 0x20(%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0xf8(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jne 0x41ad4
cmpq $0x0, 0xa8(%rsp)
jne 0x41ad4
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0x28e4c
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x43806
movq 0xd8(%rsp), %rax
cmpq %rax, 0xf8(%rsp)
je 0x41a53
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq %rbp, %rdi
callq 0x43a3a
movq %r13, %rdi
movq %r12, %rsi
callq 0x4347c
testq %rax, %rax
jne 0x419ec
movq %r13, %rdi
movq %r12, %rsi
callq 0x28e4c
movq 0x8(%rsp), %rbx
addq $0x40, %rbx
movq %rbx, %r14
movq (%r14), %r14
cmpq %rbx, %r14
je 0x419ec
movq 0x10(%r14), %rax
movq %rax, 0x58(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x43806
jmp 0x41a35
movq 0xa0(%rsp), %rsi
movq 0x28(%rsp), %rdi
xorl %edx, %edx
callq 0x43a90
movq %r13, %rdi
callq 0x28c6c
movq (%rsp), %rdi
callq 0x82d0
movq %rax, %rcx
jmp 0x41992
movq 0x38(%rsp), %rdi
callq 0x43118
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x41bba
movq %r13, %rdi
callq 0x28c50
movq %rbp, %rdi
callq 0x43126
leaq 0x60(%rsp), %rdi
callq 0x4317e
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rcx
jmp 0x4187d
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3f50d(%rip), %rdi     # 0x80fe8
leaq 0x14606(%rip), %rsi     # 0x560e8
callq 0x8240
leaq 0x17d8d(%rip), %rsi     # 0x5987b
movq %rax, %rdi
callq 0x8240
leaq 0x15823(%rip), %rsi     # 0x57320
movq %rax, %rdi
callq 0x8240
pushq $0x30
popq %rsi
movq %rax, %rdi
callq 0x84b0
movq %rax, %rdi
callq 0x8170
movl $0xff, %edi
callq 0x8300
movq 0x3f4bf(%rip), %rdi     # 0x80fe8
leaq 0x145b8(%rip), %rsi     # 0x560e8
callq 0x8240
leaq 0x17d3f(%rip), %rsi     # 0x5987b
movq %rax, %rdi
callq 0x8240
leaq 0x157d5(%rip), %rsi     # 0x57320
movq %rax, %rdi
callq 0x8240
pushq $0x17
popq %rsi
movq %rax, %rdi
callq 0x84b0
movq %rax, %rdi
callq 0x8170
jmp 0x41b18
jmp 0x41b8b
jmp 0x41b6e
jmp 0x41b8b
movq %rax, %rbx
jmp 0x41ba8
jmp 0x41b8b
jmp 0x41b77
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x28c50
jmp 0x41ba8
jmp 0x41b8b
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x28c50
leaq 0xc8(%rsp), %rdi
callq 0x43126
leaq 0x60(%rsp), %rdi
callq 0x4317e
movq %rbx, %rdi
callq 0x84d0