// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movb $0x1, %bpl
movq %rdi, 0x18(%rsp)
cmpl $0x1, (%rdi)
je 0x479d9
movq %rcx, %rbx
leaq 0x40(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorl %r14d, %r14d
leaq 0x38(%rsp), %r12
xorl %r15d, %r15d
movq (%rbx), %rsi
movq 0x8(%rbx), %rax
subq %rsi, %rax
sarq $0x3, %rax
cmpq %r15, %rax
jbe 0x478b0
addq %r14, %rsi
movq %r12, %rdi
callq 0x4c0ec
incq %r15
addq $0x8, %r14
jmp 0x47889
leaq 0x70(%rsp), %r12
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %r13
xorl %edx, %edx
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
setbe %bpl
jbe 0x479cf
movb %bpl, 0xf(%rsp)
movq %rdx, 0x10(%rsp)
leaq (%rax,%rdx,4), %rsi
movq 0x28(%rsp), %rdi
callq 0x4b3d6
movq (%rax), %r14
xorl %ebx, %ebx
xorl %r15d, %r15d
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
jbe 0x479b5
movq (%rax,%r15,8), %rbp
leaq 0x88(%rbp), %rsi
leaq 0x68(%rsp), %rdi
callq 0x1da22
movq %r12, %rdi
movq %r13, %rsi
callq 0xe1ca
testb %al, %al
je 0x47979
movq 0x18(%rsp), %rax
cmpl $0x5, (%rax)
je 0x479c2
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %eax
addq %rbx, %rax
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2cafc
leaq 0x40(%rsp), %rcx
cmpq %rcx, %rax
jne 0x47998
jmp 0x479c2
cmpl $0x8, (%rbp)
jne 0x47998
cmpl $0x5, 0x8(%rbp)
jne 0x47998
addq $0x10, %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0xe1ca
testb %al, %al
jne 0x479c2
movq %r12, %rdi
callq 0x8578
incq %r15
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rbx
jmp 0x47900
movq 0x10(%rsp), %rdx
incq %rdx
jmp 0x478c0
movq %r12, %rdi
callq 0x8578
movb 0xf(%rsp), %bpl
leaq 0x38(%rsp), %rdi
callq 0x2da5c
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x479fe
movq %rax, %rbx
movq %r12, %rdi
callq 0x8578
jmp 0x47a01
jmp 0x479fe
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2da5c
movq %rbx, %rdi
callq 0x84d0