// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x0, 0x3df2d(%rip)     # 0x906e4
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x527e2
leaq 0x3be49(%rip), %rsi     # 0x8e618
leaq 0x3d15a(%rip), %rdx     # 0x8f930
xorl %ecx, %ecx
callq 0x8320
movq %rax, %rbx
jmp 0x527e4
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x52c61
movq 0x8(%rsp), %rax
leaq 0x38(%rax), %rsi
movq %rbx, %rdi
callq 0x49456
movq 0x40(%rbx), %rcx
addq $0x40, %rbx
cmpq %rbx, %rcx
je 0x52be4
leaq 0xf0(%rsp), %r12
movq 0x8(%rsp), %rax
leaq 0x70(%rax), %rdx
movq %rdx, 0x10(%rsp)
addq $0xa8, %rax
movq %rax, 0xd0(%rsp)
leaq 0x40(%rsp), %rbp
movq %rsp, %r13
movq %rbx, 0xc8(%rsp)
movq %rcx, 0xd8(%rsp)
movq 0x10(%rcx), %rcx
movl $0x0, 0xf0(%rsp)
xorl %eax, %eax
movq %rax, 0xf8(%rsp)
movq %r12, 0x100(%rsp)
movq %r12, 0x108(%rsp)
movq %rax, 0x110(%rsp)
leaq 0x30(%rcx), %rax
movq %rcx, 0xe0(%rsp)
movq 0x30(%rcx), %r14
movq %rax, 0x38(%rsp)
cmpq %rax, %r14
je 0x52910
movq 0x10(%r14), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x3597c
leaq 0x58(%r12), %r15
movq 0x58(%r12), %rbx
cmpq %r15, %rbx
je 0x528fe
movq 0x10(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x54bfc
testq %rax, %rax
je 0x528f9
movq %r12, 0x90(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x54c30
movq (%rbx), %rbx
jmp 0x528af
movq %rbp, %rdi
callq 0x362bc
movq (%r14), %r14
cmpq 0x38(%rsp), %r14
jne 0x52896
movq 0x10(%rsp), %rdi
callq 0x362e2
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
callq 0x54d8c
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 0x100(%rsp), %r15
leaq 0xf0(%rsp), %r12
cmpq %r12, %r15
je 0x52b71
movups 0x20(%r15), %xmm0
movaps %xmm0, 0x20(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x50(%rsp), %rax
jne 0x52bf6
cmpq $0x0, 0xa8(%rsp)
jne 0x52bf6
leaq 0x90(%rsp), %rdi
movq %rdi, (%rsp)
leaq 0x28(%rsp), %rsi
movq %r13, %rdx
callq 0x3632c
movq 0x70(%rsp), %rax
movq 0x80(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x529f6
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
addq $0x8, 0x70(%rsp)
jmp 0x52a03
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x54f02
movq 0x50(%rsp), %rax
cmpq %rax, 0x70(%rsp)
je 0x52ae5
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x60(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x52a2f
addq $0x8, %rax
jmp 0x52a61
movq 0x58(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x82a0
movq 0x68(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x68(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x58(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x60(%rsp)
movq %rax, 0x50(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x54bfc
testq %rax, %rax
jne 0x52a03
leaq 0x90(%rsp), %rdi
movq %rdi, (%rsp)
leaq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x3632c
movq 0x18(%rsp), %rbx
movq 0x40(%rbx), %r14
addq $0x40, %rbx
cmpq %rbx, %r14
je 0x52a03
movq 0x10(%r14), %rax
movq %rax, (%rsp)
movq 0x70(%rsp), %rcx
movq 0x80(%rsp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
je 0x52ad5
movq %rax, (%rcx)
addq $0x8, 0x70(%rsp)
jmp 0x52ae0
movq %rbp, %rdi
movq %r13, %rsi
callq 0x54f02
movq (%r14), %r14
jmp 0x52aa3
movq 0xa0(%rsp), %rbx
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
testq %rbx, %rbx
je 0x52b11
leaq 0x8(%rbx), %rsi
movq 0x10(%rsp), %rdi
movq %r13, %rdx
callq 0x3632c
movq (%rbx), %rbx
jmp 0x52af6
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x52b33
movq (%rdi), %rbx
movl $0x10, %esi
callq 0x82a0
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x52b1e
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x81c0
leaq 0xc0(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movq %r15, %rdi
callq 0x8340
movq %rax, %r15
cmpq %r12, %rax
jne 0x5298e
movq 0xd0(%rsp), %rdi
movq (%rdi), %rsi
callq 0x55164
movq 0xe0(%rsp), %rax
cmpq $0x0, 0x40(%rax)
je 0x52ba6
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rsi
movq 0x8(%rsp), %rdi
callq 0x52d10
leaq 0x90(%rsp), %rdi
callq 0x362bc
movq %rbp, %rdi
callq 0x54948
leaq 0xe8(%rsp), %rdi
callq 0x54998
movq 0xd8(%rsp), %rcx
movq (%rcx), %rcx
movq 0xc8(%rsp), %rbx
cmpq %rbx, %rcx
jne 0x52843
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3d3f3(%rip), %rdi     # 0x8fff0
leaq 0x1c564(%rip), %rsi     # 0x6f168
movl $0x8, %edx
callq 0x8330
movq 0x3d3db(%rip), %rdi     # 0x8fff0
leaq 0x1fcfb(%rip), %rsi     # 0x72917
movl $0x23, %edx
callq 0x8330
movq 0x3d3c3(%rip), %rdi     # 0x8fff0
leaq 0x1d78c(%rip), %rsi     # 0x703c0
movl $0x1, %edx
callq 0x8330
movq 0x3d3ab(%rip), %rdi     # 0x8fff0
movl $0x30, %esi
callq 0x8520
movq %rax, %rdi
callq 0x8180
movl $0xff, %edi
callq 0x8380
movq 0x3d388(%rip), %rdi     # 0x8fff0
leaq 0x1c4f9(%rip), %rsi     # 0x6f168
callq 0x8280
leaq 0x1fc9c(%rip), %rsi     # 0x72917
movq %rax, %rdi
callq 0x8280
leaq 0x1d736(%rip), %rsi     # 0x703c0
movq %rax, %rdi
callq 0x8280
movq %rax, %rdi
movl $0x17, %esi
callq 0x8520
movq %rax, %rdi
callq 0x8180
jmp 0x52c57
jmp 0x52ccb
jmp 0x52caf
jmp 0x52ccb
movq %rax, %rbx
jmp 0x52ce5
jmp 0x52ccb
jmp 0x52cba
jmp 0x52ccb
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x362bc
jmp 0x52ce5
jmp 0x52ccb
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x362bc
leaq 0x40(%rsp), %rdi
callq 0x54948
leaq 0xe8(%rsp), %rdi
callq 0x54998
movq %rbx, %rdi
callq 0x8540