// File: /workspace/github_cpp_makefile_star2_O3/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, 0x3dc41(%rip)     # 0x8f6e4
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x51fb2
leaq 0x3bb89(%rip), %rsi     # 0x8d648
leaq 0x3ce3a(%rip), %rdx     # 0x8e900
xorl %ecx, %ecx
callq 0x8320
testq %rax, %rax
je 0x51fb2
movq %rax, %r14
movq %rax, %rbx
movq 0x8(%rsp), %rax
leaq 0x38(%rax), %rsi
movq %r14, %rdi
callq 0x48ba6
addq $0x40, %r14
movq 0x40(%rbx), %rcx
cmpq %r14, %rcx
je 0x51f35
leaq 0xf0(%rsp), %r12
movq 0x8(%rsp), %rax
leaq 0x70(%rax), %rdx
movq %rdx, 0x10(%rsp)
addq $0xa8, %rax
movq %rax, 0xd0(%rsp)
leaq 0x20(%rsp), %rbp
movq %rsp, %r13
movq %r14, 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), %r12
movq %rax, 0x70(%rsp)
cmpq %rax, %r12
je 0x51c2a
movq 0x10(%r12), %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x35adc
leaq 0x58(%r14), %rbx
movq 0x58(%r14), %r15
cmpq %rbx, %r15
je 0x51c13
movq 0x10(%r15), %rcx
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq (%rdi,%rdx,8), %rax
testq %rax, %rax
je 0x51c0e
movq %rdx, %rsi
movq (%rax), %r9
cmpq 0x8(%r9), %rcx
je 0x51bef
movq (%r9), %r9
testq %r9, %r9
je 0x51c0e
movq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
cmpq %rsi, %rdx
jne 0x51c0e
cmpq %rdi, %rcx
jne 0x51bd1
movq %r14, 0x78(%rsp)
movq %rcx, 0x80(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x53eda
movq (%r15), %r15
jmp 0x51ba1
movq %rbp, %rdi
callq 0x36424
movq (%r12), %r12
cmpq 0x70(%rsp), %r12
jne 0x51b89
movq 0x10(%rsp), %rdi
callq 0x3644a
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
callq 0x54020
leaq 0xa8(%rsp), %rax
movq %rax, 0x78(%rsp)
movq $0x1, 0x80(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, 0x98(%rsp) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movq 0x100(%rsp), %r14
leaq 0xf0(%rsp), %r12
cmpq %r12, %r14
je 0x51ec5
movups 0x20(%r14), %xmm0
movaps %xmm0, 0xb0(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x30(%rsp), %rax
jne 0x51f47
leaq 0x78(%rsp), %rdi
movq %rdi, (%rsp)
leaq 0xb8(%rsp), %rsi
movq %r13, %rdx
callq 0x36494
movq 0x50(%rsp), %rax
movq 0x60(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x51d06
movq 0xb0(%rsp), %rcx
movq %rcx, (%rax)
movq 0x50(%rsp), %rcx
addq $0x8, %rcx
movq %rcx, 0x50(%rsp)
jmp 0x51d1b
movq %rbp, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x54196
movq 0x50(%rsp), %rcx
movq 0x30(%rsp), %rax
cmpq %rax, %rcx
je 0x51e39
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x40(%rsp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rax
je 0x51d45
addq $0x8, %rax
jmp 0x51d7c
movq 0x38(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x82a0
movq 0x48(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x48(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x40(%rsp)
movq 0x18(%rsp), %rcx
movq %rax, 0x30(%rsp)
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq (%rdi,%rdx,8), %rax
testq %rax, %rax
je 0x51ddb
movq %rdx, %rsi
movq (%rax), %r9
cmpq 0x8(%r9), %rcx
je 0x51dc9
movq (%r9), %r9
testq %r9, %r9
je 0x51ddb
movq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
cmpq %rsi, %rdx
jne 0x51ddb
cmpq %rdi, %rcx
jne 0x51dab
movq 0x30(%rsp), %rax
cmpq %rax, 0x50(%rsp)
jne 0x51d29
jmp 0x51e39
leaq 0x78(%rsp), %rdi
movq %rdi, (%rsp)
leaq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x36494
movq 0x18(%rsp), %rbx
movq 0x40(%rbx), %r15
addq $0x40, %rbx
cmpq %rbx, %r15
je 0x51dc9
movq 0x10(%r15), %rax
movq %rax, (%rsp)
movq 0x50(%rsp), %rcx
movq 0x60(%rsp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
je 0x51e29
movq %rax, (%rcx)
addq $0x8, 0x50(%rsp)
jmp 0x51e34
movq %rbp, %rdi
movq %r13, %rsi
callq 0x54196
movq (%r15), %r15
jmp 0x51dfe
movq 0x88(%rsp), %rbx
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
testq %rbx, %rbx
je 0x51e8a
leaq 0x8(%rbx), %rsi
movq 0x10(%rsp), %rdi
movq %r13, %rdx
callq 0x36494
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x51e4f
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x51e8a
movq (%rdi), %rbx
movl $0x10, %esi
callq 0x82a0
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x51e75
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x81c0
leaq 0xa8(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movq %r14, %rdi
callq 0x8340
movq %rax, %r14
cmpq %r12, %rax
jne 0x51ca2
movq 0xd0(%rsp), %rdi
movq (%rdi), %rsi
callq 0x543f8
movq 0xe0(%rsp), %rax
cmpq $0x0, 0x40(%rax)
je 0x51efa
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rsi
movq 0x8(%rsp), %rdi
callq 0x5205c
leaq 0x78(%rsp), %rdi
callq 0x36424
movq %rbp, %rdi
callq 0x53bb8
leaq 0xe8(%rsp), %rdi
callq 0x53c10
movq 0xd8(%rsp), %rcx
movq (%rcx), %rcx
movq 0xc8(%rsp), %r14
cmpq %r14, %rcx
jne 0x51b32
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3d09a(%rip), %rdi     # 0x8efe8
leaq 0x1c213(%rip), %rsi     # 0x6e168
movl $0x8, %edx
callq 0x8330
movq 0x3d082(%rip), %rdi     # 0x8efe8
leaq 0x1f9ae(%rip), %rsi     # 0x7191b
movl $0x23, %edx
callq 0x8330
movq 0x3d06a(%rip), %rdi     # 0x8efe8
leaq 0x1d43b(%rip), %rsi     # 0x6f3c0
movl $0x1, %edx
callq 0x8330
movq 0x3d052(%rip), %rdi     # 0x8efe8
movl $0x30, %esi
callq 0x8520
movq %rax, %rdi
callq 0x8180
movl $0xff, %edi
callq 0x8380
movq 0x3d02f(%rip), %rdi     # 0x8efe8
leaq 0x1c1a8(%rip), %rsi     # 0x6e168
callq 0x8280
leaq 0x1f94f(%rip), %rsi     # 0x7191b
movq %rax, %rdi
callq 0x8280
leaq 0x1d3e5(%rip), %rsi     # 0x6f3c0
movq %rax, %rdi
callq 0x8280
movq %rax, %rdi
movl $0x17, %esi
callq 0x8520
movq %rax, %rdi
callq 0x8180
jmp 0x51fa8
jmp 0x5201a
jmp 0x52000
jmp 0x5201a
movq %rax, %rbx
jmp 0x52031
jmp 0x5201a
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x36424
jmp 0x52031
jmp 0x5201a
jmp 0x5201a
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x36424
leaq 0x20(%rsp), %rdi
callq 0x53bb8
leaq 0xe8(%rsp), %rdi
callq 0x53c10
movq %rbx, %rdi
callq 0x8540