// File: /workspace/github_cpp_makefile_star2_O3/luooofan[P]hblzbd_compiler/src/Pass/loop_invariant_extrapolation.cpp
// Function: walk(IRBasicBlock*, std::set<int, std::less<int>, std::allocator<int>>, std::map<int, IRBasicBlock*, std::less<int>, std::allocator<std::pair<int const, IRBasicBlock*>>>, std::vector<int, std::allocator<int>>, std::map<IRBasicBlock*, int, std::less<IRBasicBlock*>, std::allocator<std::pair<IRBasicBlock* const, int>>>)
vector<IRBasicBlock*> walk(IRBasicBlock* enter, set<int> in_loop, map<int, IRBasicBlock*> id_bb, vector<int> loop,
                           map<IRBasicBlock*, int> bb_id) {
  set<IRBasicBlock*> new_in_loop;
  for (auto it : in_loop) new_in_loop.insert(id_bb[it]);
  vector<IRBasicBlock*> new_loop;
  for (auto bid : loop) new_loop.push_back(id_bb[bid]);
  vector<IRBasicBlock*> res;
  if (enter->ir_list_.size() != 2) return res;
  res.push_back(enter);
  while (true) {
    auto bb = res[res.size() - 1];
    // 下面条件就是要求:后继必须是2个，并且1个指向loop内，1个指向loop外(只要求2个的话，有可能是ifelse)
    if (bb->succ_.size() == 2 && ((new_in_loop.find(bb->succ_[0]) == new_in_loop.end()) +
                                  (new_in_loop.find(bb->succ_[1]) == new_in_loop.end())) == 1) {
      auto nxt = new_in_loop.find(bb->succ_[0]) == new_in_loop.end() ? bb->succ_[1] : bb->succ_[0];
      if (nxt->ir_list_.size() != 1) break;
      res.push_back(nxt);
    } else
      break;
  }
  vector<IRBasicBlock*> res1;
  for (auto bb0 : res) {
    auto op1 = (*(bb0->ir_list_.rbegin()))->opn1_, op2 = (*(bb0->ir_list_.rbegin()))->opn2_;
    if (op1.scope_id_ == 0 || op2.scope_id_ == 0) continue;
    vector<ir::Opn> ops;
    ops.push_back(op1), ops.push_back(op2);
    if (op1.type_ == ir::Opn::Type::Array) ops.push_back(*op1.offset_);
    if (op2.type_ == ir::Opn::Type::Array) ops.push_back(*op2.offset_);
    bool flag = true;
    for (auto bb : new_loop) {
      for (auto ir : bb->ir_list_) {
        for (auto op : ops) {
          if (ir->res_.name_ == op.name_) {
            flag = false;
            break;
          }
        }
      }
    }
    if (flag) res1.push_back(bb0);
  }
  return res1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %r8, %r14
movq %rcx, %rbx
movq %rdx, %r15
movq %rdi, 0x40(%rsp)
movq %rsi, 0x70(%rsp)
leaq 0xf0(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq 0x18(%rdx), %r12
addq $0x8, %r15
cmpq %r15, %r12
je 0x5b1d2
leaq 0x78(%rsp), %r13
leaq 0xe8(%rsp), %rbp
movl 0x20(%r12), %eax
movl %eax, 0x78(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x605dc
movq %rbp, %rdi
movq %rax, %rsi
callq 0x616d4
movq %r12, %rdi
callq 0x8340
movq %rax, %r12
cmpq %r15, %rax
jne 0x5b1a3
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq (%r14), %r12
movq 0x8(%r14), %r13
cmpq %r13, %r12
je 0x5b23a
leaq 0x78(%rsp), %r14
leaq 0x20(%rsp), %r15
movl (%r12), %eax
movl %eax, 0x78(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x605dc
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x5b226
movq (%rax), %rax
movq %rax, (%rsi)
addq $0x8, 0x28(%rsp)
jmp 0x5b231
movq %r15, %rdi
movq %rax, %rdx
callq 0x117de
addq $0x4, %r12
cmpq %r13, %r12
jne 0x5b1f9
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rcx
subq 0x8(%rax), %rcx
cmpq $0x10, %rcx
jne 0x5b6db
movq %rsp, %rdi
leaq 0x70(%rsp), %rdx
xorl %esi, %esi
callq 0x117de
movq 0x40(%rsp), %r13
movq (%rsp), %rbx
movq 0x8(%rsp), %r14
movq -0x8(%r14), %rcx
movq 0x40(%rcx), %rax
movq 0x48(%rcx), %rcx
subq %rax, %rcx
cmpq $0x10, %rcx
jne 0x5b40e
leaq 0x78(%rsp), %r12
movq 0xf8(%rsp), %rdx
testq %rdx, %rdx
je 0x5b40e
movq (%rax), %rcx
movq %rdx, %r8
leaq 0xf0(%rsp), %r9
movq %r9, %rsi
movq %r8, %rdi
movq 0x20(%r8), %r10
xorl %r8d, %r8d
cmpq %rcx, %r10
setb %r8b
movq %rdi, %r9
cmovbq %rsi, %r9
movq 0x10(%rdi,%r8,8), %r8
testq %r8, %r8
jne 0x5b2bb
movq %r14, %rbp
leaq 0xf0(%rsp), %r11
movq %r11, %r8
cmpq %r11, %r9
je 0x5b305
cmpq %rcx, %r10
cmovbq %rsi, %rdi
cmpq 0x20(%rdi), %rcx
cmovbq %r11, %r9
movq %r9, %r8
leaq 0x8(%rax), %rdi
movq 0x8(%rax), %rsi
movq %rdx, %r15
movq %r11, %r14
movq %r14, %r9
movq %r15, %r10
movq 0x20(%r15), %r11
xorl %r15d, %r15d
cmpq %rsi, %r11
setb %r15b
movq %r10, %r14
cmovbq %r9, %r14
movq 0x10(%r10,%r15,8), %r15
testq %r15, %r15
jne 0x5b313
leaq 0xf0(%rsp), %r15
cmpq %r15, %r14
movq %r15, %r14
je 0x5b360
cmpq %r14, %r8
sete %r8b
cmpq %rsi, %r11
cmovbq %r9, %r10
cmpq 0x20(%r10), %rsi
sbbb $0x0, %r8b
jmp 0x5b363
cmpq %r14, %r8
movq %r14, %r11
movq %rbp, %r14
je 0x5b40e
movq %r11, %r8
movq %rdx, %r9
movq 0x20(%rdx), %r10
xorl %edx, %edx
cmpq %rcx, %r10
setb %dl
movq %r9, %r11
cmovbq %r8, %r11
movq 0x10(%r9,%rdx,8), %rdx
testq %rdx, %rdx
jne 0x5b36f
leaq 0xf0(%rsp), %rdx
cmpq %rdx, %r11
je 0x5b3b1
cmpq %rcx, %r10
cmovbq %r8, %r9
cmpq 0x20(%r9), %rcx
cmovbq %rdi, %rax
movq (%rax), %rsi
movq %rsi, 0x78(%rsp)
movq 0x10(%rsi), %rax
subq 0x8(%rsi), %rax
cmpq $0x8, %rax
jne 0x5b40e
cmpq 0x10(%rsp), %r14
je 0x5b3de
movq %rsi, (%r14)
movq 0x8(%rsp), %r14
addq $0x8, %r14
movq %r14, 0x8(%rsp)
jmp 0x5b3f1
movq %rsp, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x117de
movq 0x8(%rsp), %r14
movq (%rsp), %rbx
movq -0x8(%r14), %rcx
movq 0x40(%rcx), %rax
movq 0x48(%rcx), %rcx
subq %rax, %rcx
cmpq $0x10, %rcx
je 0x5b29c
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movq $0x0, 0x10(%r13)
cmpq %r14, %rbx
je 0x5b6c4
movq %r14, 0xb8(%rsp)
movq (%rbx), %rax
movq %rax, 0x48(%rsp)
movq 0x10(%rax), %rax
movq -0x8(%rax), %rsi
addq $0x8, %rsi
leaq 0x78(%rsp), %rdi
callq 0x28816
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rax), %rsi
addq $0x48, %rsi
leaq 0x118(%rsp), %rdi
callq 0x28816
cmpl $0x0, 0xa0(%rsp)
je 0x5b669
cmpl $0x0, 0x140(%rsp)
je 0x5b669
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x60642
leaq 0x50(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x60642
cmpl $0x5, 0x78(%rsp)
jne 0x5b4d2
movq 0xa8(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x60642
cmpl $0x5, 0x118(%rsp)
jne 0x5b4ee
movq 0x148(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x60642
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0xc8(%rsp)
cmpq %rcx, %rax
je 0x5b639
movq %rbx, 0xc0(%rsp)
movb $0x1, %r15b
movq %rax, 0xd0(%rsp)
movq (%rax), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rax
movq %rax, 0xd8(%rsp)
cmpq %rax, %rcx
je 0x5b609
movq 0x50(%rsp), %r12
movq 0x58(%rsp), %rbp
cmpq %rbp, %r12
movq %rcx, 0xe0(%rsp)
je 0x5b5ef
movq (%rcx), %rbx
leaq 0x158(%rsp), %rdi
movq %r12, %rsi
callq 0x28816
movq 0x98(%rbx), %rdx
cmpq 0x168(%rsp), %rdx
jne 0x5b5a4
movq 0x160(%rsp), %r13
testq %rdx, %rdx
je 0x5b5b1
movq 0x90(%rbx), %rdi
movq %r13, %rsi
callq 0x82b0
testl %eax, %eax
sete %r14b
setne %al
andb %r15b, %al
movl %eax, %r15d
jmp 0x5b5b7
movq 0x160(%rsp), %r13
xorl %r14d, %r14d
jmp 0x5b5b7
xorl %r15d, %r15d
movb $0x1, %r14b
leaq 0x170(%rsp), %rax
cmpq %rax, %r13
je 0x5b5d7
movq 0x170(%rsp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x82a0
addq $0x40, %r12
cmpq %rbp, %r12
sete %al
orb %al, %r14b
movq 0x40(%rsp), %r13
je 0x5b556
movq 0xe0(%rsp), %rcx
addq $0x8, %rcx
cmpq 0xd8(%rsp), %rcx
jne 0x5b538
movq 0xd0(%rsp), %rax
addq $0x8, %rax
cmpq 0xc8(%rsp), %rax
jne 0x5b514
testb $0x1, %r15b
movq 0xb8(%rsp), %r14
movq 0xc0(%rsp), %rbx
je 0x5b65f
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x5b652
movq 0x48(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r13)
jmp 0x5b65f
movq %r13, %rdi
leaq 0x48(%rsp), %rdx
callq 0x117de
leaq 0x50(%rsp), %rdi
callq 0x2b81c
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x5b68e
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x5b6b3
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x82a0
addq $0x8, %rbx
cmpq %r14, %rbx
jne 0x5b42f
movq (%rsp), %rbx
testq %rbx, %rbx
je 0x5b6ed
movq 0x10(%rsp), %rsi
subq %rbx, %rsi
movq %rbx, %rdi
callq 0x82a0
jmp 0x5b6ed
movq 0x40(%rsp), %r13
movups %xmm0, (%r13)
movq $0x0, 0x10(%r13)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5b704
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0xe8(%rsp), %rdi
callq 0x60d7a
movq %r13, %rax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5b728
movq %rax, %rbx
jmp 0x5b7ba
jmp 0x5b74e
movq %rax, %rbx
jmp 0x5b7a5
movq %rax, %rbx
jmp 0x5b780
jmp 0x5b74e
movq %rax, %rbx
jmp 0x5b7d0
movq %rax, %rbx
jmp 0x5b7e7
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x2b81c
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x5b780
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x5b7a5
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x82a0
movq (%r13), %rdi
testq %rdi, %rdi
je 0x5b7ba
movq 0x10(%r13), %rsi
subq %rdi, %rsi
callq 0x82a0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5b7d0
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5b7e7
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0xe8(%rsp), %rdi
callq 0x60d7a
movq %rbx, %rdi
callq 0x8540