// File: /workspace/github_cpp_makefile_star2_O1/luooofan[P]hblzbd_compiler/src/Pass/loop_invariant_extrapolation.cpp
// Function: check(ir::Opn, std::vector<int, std::allocator<int>>, std::map<int, IRBasicBlock*, std::less<int>, std::allocator<std::pair<int const, IRBasicBlock*>>>, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>)
bool check(ir::Opn x, vector<int> loop, map<int, IRBasicBlock*> id_bb, vector<pair<int, int> > unchanged) {
  if (x.type_ == ir::Opn::Type::Imm) return true;
  set<pair<int, int> > u;
  for (int i = 0; i < unchanged.size(); i++) u.insert(unchanged[i]);
  for (int i = 0; i < loop.size(); i++) {
    auto bb = id_bb[loop[i]];
    for (int j = 0; j < bb->ir_list_.size(); j++) {
      auto ir = bb->ir_list_[j];
      auto res = ir->res_;
      if (res.name_ == x.name_)  // 如果发现了x的定值
      {
        if (x.type_ == ir::Opn::Type::Array)  // 如果是数组类型，一定返回false
          return false;
        if (u.find(make_pair(loop[i], j)) ==
            u.end())  // 如果是变量类型，则看该x的定值是不是不变的，如果不是则也返回false
        {
          return false;
        }
      } else if (ir->op_ == ir::IR::OpKind::PARAM && ir->opn1_.type_ == ir::Opn::Type::Array &&
                 ir->opn1_.name_ == x.name_)
        return false;
    }
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, 0x8(%rsp)
movb $0x1, %r14b
cmpl $0x1, (%rdi)
je 0x5b7ee
movq %rcx, %rbx
movq %rdx, %rbp
movq %rdi, %r15
leaq 0x70(%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 (%rbx), %rsi
cmpq %rsi, 0x8(%rbx)
je 0x5b658
xorl %r14d, %r14d
leaq 0x68(%rsp), %r12
xorl %r13d, %r13d
addq %r14, %rsi
movq %r12, %rdi
callq 0x621aa
incq %r13
movq (%rbx), %rsi
movq 0x8(%rbx), %rax
subq %rsi, %rax
sarq $0x3, %rax
addq $0x8, %r14
cmpq %r13, %rax
ja 0x5b633
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
sete %r14b
je 0x5b7e4
xorl %edx, %edx
movq %rbp, 0x18(%rsp)
movb %r14b, 0x7(%rsp)
movq %rdx, 0x10(%rsp)
leaq (%rax,%rdx,4), %rsi
movq %rbp, %rdi
callq 0x61372
movq (%rax), %rbp
movq 0x8(%rbp), %rax
cmpq %rax, 0x10(%rbp)
je 0x5b794
xorl %ebx, %ebx
xorl %r14d, %r14d
movq (%rax,%r14,8), %r12
leaq 0x88(%r12), %rsi
leaq 0x28(%rsp), %rdi
callq 0x28186
movq 0x38(%rsp), %rdx
movq 0x10(%r15), %r13
cmpq %r13, %rdx
jne 0x5b6dc
testq %rdx, %rdx
je 0x5b715
movq 0x8(%r15), %rsi
movq 0x30(%rsp), %rdi
callq 0x82b0
testl %eax, %eax
je 0x5b715
cmpl $0x8, (%r12)
jne 0x5b750
cmpl $0x5, 0x8(%r12)
jne 0x5b750
movq 0x18(%r12), %rdx
cmpq %r13, %rdx
jne 0x5b750
testq %rdx, %rdx
je 0x5b7c3
movq 0x8(%r15), %rsi
movq 0x10(%r12), %rdi
callq 0x82b0
testl %eax, %eax
jne 0x5b750
jmp 0x5b7c3
cmpl $0x5, (%r15)
je 0x5b7c3
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %eax
addq %rbx, %rax
movq %rax, 0x20(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3a4ac
leaq 0x70(%rsp), %rcx
cmpq %rcx, %rax
je 0x5b7c3
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x5b76c
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
incq %r14
movq 0x8(%rbp), %rax
movq 0x10(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rdx, %rbx
cmpq %r14, %rcx
ja 0x5b6a1
movq 0x10(%rsp), %rdx
incq %rdx
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
setbe %r14b
movq 0x18(%rsp), %rbp
ja 0x5b675
jmp 0x5b7e4
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x5b7df
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
movb 0x7(%rsp), %r14b
leaq 0x68(%rsp), %rdi
callq 0x3b0d4
andb $0x1, %r14b
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5b82c
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x5b82f
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x5b82f
jmp 0x5b82c
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x3b0d4
movq %r14, %rdi
callq 0x8540