// File: /workspace/github_cpp_makefile_star2_O1/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 $0x188, %rsp            # imm = 0x188
movq %r8, %r15
movq %rcx, %r14
movq %rdx, %r12
movq %rdi, 0x60(%rsp)
movq %rsi, 0x68(%rsp)
leaq 0x120(%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), %r13
addq $0x8, %r12
cmpq %r12, %r13
je 0x5c001
leaq 0x70(%rsp), %rbp
leaq 0x118(%rsp), %rbx
movl 0x20(%r13), %eax
movl %eax, 0x70(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x61372
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6246e
movq %r13, %rdi
callq 0x8340
movq %rax, %r13
cmpq %r12, %rax
jne 0x5bfd3
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq (%r15), %rbx
movq 0x8(%r15), %r13
cmpq %r13, %rbx
je 0x5c067
leaq 0x70(%rsp), %r15
leaq 0x20(%rsp), %r12
movl (%rbx), %eax
movl %eax, 0x70(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x61372
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x5c053
movq (%rax), %rax
movq %rax, (%rsi)
addq $0x8, 0x28(%rsp)
jmp 0x5c05e
movq %r12, %rdi
movq %rax, %rdx
callq 0x11b10
addq $0x4, %rbx
cmpq %r13, %rbx
jne 0x5c028
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rcx
subq 0x8(%rax), %rcx
cmpq $0x10, %rcx
movq 0x60(%rsp), %rbp
jne 0x5c0ae
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x5c0d4
movq %rax, (%rsi)
addq $0x8, 0x8(%rsp)
leaq 0x120(%rsp), %r12
jmp 0x5c0e9
movaps (%rsp), %xmm0
movups %xmm0, (%rbp)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
jmp 0x5c4d4
movq %rsp, %rdi
leaq 0x68(%rsp), %rdx
callq 0x11b10
leaq 0x120(%rsp), %r12
movq %rsp, %r14
leaq 0x70(%rsp), %r15
movq 0x8(%rsp), %rsi
movq -0x8(%rsi), %rcx
movq 0x40(%rcx), %rax
movq 0x48(%rcx), %rcx
subq %rax, %rcx
cmpq $0x10, %rcx
jne 0x5c232
movq 0x128(%rsp), %rcx
movq %r12, %rdi
testq %rcx, %rcx
je 0x5c141
movq (%rax), %rdx
movq %rcx, %r8
movq %r12, %rdi
xorl %r9d, %r9d
cmpq %rdx, 0x20(%r8)
setb %r9b
cmovaeq %r8, %rdi
movq 0x10(%r8,%r9,8), %r8
testq %r8, %r8
jne 0x5c128
movq %r12, %rdx
cmpq %r12, %rdi
je 0x5c157
movq (%rax), %rdx
cmpq 0x20(%rdi), %rdx
cmovbq %r12, %rdi
movq %rdi, %rdx
movq %r12, %rdi
testq %rcx, %rcx
je 0x5c182
movq 0x8(%rax), %r8
movq %rcx, %r9
movq %r12, %rdi
xorl %r10d, %r10d
cmpq %r8, 0x20(%r9)
setb %r10b
cmovaeq %r9, %rdi
movq 0x10(%r9,%r10,8), %r9
testq %r9, %r9
jne 0x5c169
movq %r12, %r8
cmpq %r12, %rdi
je 0x5c199
movq 0x8(%rax), %r8
cmpq 0x20(%rdi), %r8
cmovbq %r12, %rdi
movq %rdi, %r8
cmpq %r12, %rdx
sete %dl
cmpq %r12, %r8
sete %dil
cmpb %dil, %dl
je 0x5c232
movq %r12, %rdx
testq %rcx, %rcx
je 0x5c1d6
movq (%rax), %rdi
movq %r12, %rdx
xorl %r8d, %r8d
cmpq %rdi, 0x20(%rcx)
setb %r8b
cmovaeq %rcx, %rdx
movq 0x10(%rcx,%r8,8), %rcx
testq %rcx, %rcx
jne 0x5c1bd
movq %r12, %rcx
cmpq %r12, %rdx
je 0x5c1ec
movq (%rax), %rcx
cmpq 0x20(%rdx), %rcx
cmovbq %r12, %rdx
movq %rdx, %rcx
xorl %edx, %edx
cmpq %r12, %rcx
sete %dl
movq (%rax,%rdx,8), %rax
movq %rax, 0x70(%rsp)
movq 0x10(%rax), %rbx
subq 0x8(%rax), %rbx
cmpq $0x8, %rbx
jne 0x5c232
cmpq 0x10(%rsp), %rsi
je 0x5c21d
movq %rax, (%rsi)
addq $0x8, 0x8(%rsp)
jmp 0x5c228
movq %r14, %rdi
movq %r15, %rdx
callq 0x11b10
cmpq $0x8, %rbx
je 0x5c0f1
xorps %xmm0, %xmm0
movups %xmm0, (%rbp)
movq $0x0, 0x10(%rbp)
movq (%rsp), %rbx
movq 0x8(%rsp), %r14
cmpq %r14, %rbx
je 0x5c4d4
movq %r14, 0xb0(%rsp)
movq (%rbx), %rax
movq %rax, 0x38(%rsp)
movq 0x10(%rax), %rax
movq -0x8(%rax), %rsi
addq $0x8, %rsi
leaq 0x70(%rsp), %rdi
callq 0x28186
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rax), %rsi
addq $0x48, %rsi
leaq 0xd8(%rsp), %rdi
callq 0x28186
cmpl $0x0, 0x98(%rsp)
je 0x5c480
cmpl $0x0, 0x100(%rsp)
je 0x5c480
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x613d6
leaq 0x40(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x613d6
cmpl $0x5, 0x70(%rsp)
jne 0x5c2fe
movq 0xa0(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x613d6
cmpl $0x5, 0xd8(%rsp)
jne 0x5c31a
movq 0x108(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x613d6
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0xc0(%rsp)
cmpq %rcx, %rax
je 0x5c450
movq %rbx, 0xb8(%rsp)
movb $0x1, %bl
movq %rax, 0xc8(%rsp)
movq (%rax), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rax
movq %rax, 0xd0(%rsp)
cmpq %rax, %r14
je 0x5c421
movq 0x40(%rsp), %r13
movq 0x48(%rsp), %r15
cmpq %r15, %r13
je 0x5c40f
movq (%r14), %r12
leaq 0x148(%rsp), %rdi
movq %r13, %rsi
callq 0x28186
movq 0x98(%r12), %rdx
cmpq 0x158(%rsp), %rdx
jne 0x5c3bd
testq %rdx, %rdx
je 0x5c3c1
movq 0x150(%rsp), %rsi
movq 0x90(%r12), %rdi
callq 0x82b0
testl %eax, %eax
sete %bpl
jmp 0x5c3c4
xorl %ebp, %ebp
jmp 0x5c3c4
movb $0x1, %bpl
movzbl %bl, %ebx
testb %bpl, %bpl
movl $0x0, %eax
cmovnel %eax, %ebx
movq 0x150(%rsp), %rdi
leaq 0x160(%rsp), %rax
cmpq %rax, %rdi
je 0x5c3f7
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x82a0
addq $0x40, %r13
cmpq %r15, %r13
sete %al
orb %al, %bpl
movq 0x60(%rsp), %rbp
je 0x5c379
addq $0x8, %r14
cmpq 0xd0(%rsp), %r14
jne 0x5c363
movq 0xc8(%rsp), %rax
addq $0x8, %rax
cmpq 0xc0(%rsp), %rax
jne 0x5c33f
testb $0x1, %bl
movq 0xb8(%rsp), %rbx
movq 0xb0(%rsp), %r14
je 0x5c476
movq 0x8(%rbp), %rsi
cmpq 0x10(%rbp), %rsi
je 0x5c469
movq 0x38(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbp)
jmp 0x5c476
movq %rbp, %rdi
leaq 0x38(%rsp), %rdx
callq 0x11b10
leaq 0x40(%rsp), %rdi
callq 0x2b2f6
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x5c4a5
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x5c4c7
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x82a0
addq $0x8, %rbx
cmpq %r14, %rbx
jne 0x5c25b
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5c4ea
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5c501
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0x118(%rsp), %rdi
callq 0x61b12
movq %rbp, %rax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5c527
jmp 0x5c54b
movq %rax, %r14
jmp 0x5c5b4
movq %rax, %r14
jmp 0x5c59f
movq %rax, %r14
jmp 0x5c57d
jmp 0x5c54b
movq %rax, %r14
jmp 0x5c5ca
movq %rax, %r14
jmp 0x5c5e1
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x2b2f6
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x5c57d
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x5c59f
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x82a0
movq (%rbp), %rdi
testq %rdi, %rdi
je 0x5c5b4
movq 0x10(%rbp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5c5ca
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5c5e1
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0x118(%rsp), %rdi
callq 0x61b12
movq %r14, %rdi
callq 0x8540