// File: /workspace/github_cpp_makefile_star2_O3/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 0x5a9d6
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 0x5a84e
xorl %r14d, %r14d
leaq 0x68(%rsp), %r12
xorl %r13d, %r13d
addq %r14, %rsi
movq %r12, %rdi
callq 0x61412
incq %r13
movq (%rbx), %rsi
movq 0x8(%rbx), %rax
subq %rsi, %rax
sarq $0x3, %rax
addq $0x8, %r14
cmpq %r13, %rax
ja 0x5a829
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movb $0x1, %r14b
cmpq %rax, 0x8(%rcx)
je 0x5a9cc
xorl %edx, %edx
movq %rbp, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
leaq (%rax,%rdx,4), %rsi
movq %rbp, %rdi
callq 0x605dc
movq (%rax), %rbx
movq 0x8(%rbx), %rax
cmpq %rax, 0x10(%rbx)
je 0x5a97f
xorl %r14d, %r14d
xorl %r12d, %r12d
movq (%rax,%r12,8), %rbp
leaq 0x88(%rbp), %rsi
leaq 0x28(%rsp), %rdi
callq 0x28816
movq 0x38(%rsp), %rdx
movq 0x10(%r15), %r13
cmpq %r13, %rdx
jne 0x5a8cc
testq %rdx, %rdx
je 0x5a900
movq 0x8(%r15), %rsi
movq 0x30(%rsp), %rdi
callq 0x82b0
testl %eax, %eax
je 0x5a900
cmpl $0x8, (%rbp)
jne 0x5a93b
cmpl $0x5, 0x8(%rbp)
jne 0x5a93b
cmpq %r13, 0x18(%rbp)
jne 0x5a93b
testq %r13, %r13
je 0x5a9ad
movq 0x8(%r15), %rsi
movq 0x10(%rbp), %rdi
movq %r13, %rdx
callq 0x82b0
testl %eax, %eax
jne 0x5a93b
jmp 0x5a9ad
cmpl $0x5, (%r15)
je 0x5a9ad
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %eax
addq %r14, %rax
movq %rax, 0x20(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3a022
leaq 0x70(%rsp), %rcx
cmpq %rcx, %rax
je 0x5a9ad
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x5a957
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
incq %r12
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rdx, %r14
cmpq %r12, %rcx
ja 0x5a892
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
movq 0x18(%rsp), %rbp
ja 0x5a86a
movb $0x1, %r14b
jmp 0x5a9cc
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x5a9c9
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
xorl %r14d, %r14d
leaq 0x68(%rsp), %rdi
callq 0x3ac5c
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5aa10
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x5aa13
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x5aa13
jmp 0x5aa10
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x3ac5c
movq %r14, %rdi
callq 0x8540