// File: 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:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x48(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x58(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdi, 0x158(%rsp)
movq %rsi, 0x150(%rsp)
movq %rdx, 0x148(%rsp)
movq %rcx, 0x140(%rsp)
cmpl $0x1, (%rdi)
jne 0xcc84d
movb $0x1, 0x167(%rsp)
jmp 0xccbbd
leaq 0x110(%rsp), %rdi
callq 0x6ef00
movl $0x0, 0x10c(%rsp)
movq 0x60(%rsp), %rdi
movslq 0x10c(%rsp), %rax
movq %rax, 0x40(%rsp)
callq 0xd4b70
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
jae 0xcc8fa
movq 0x60(%rsp), %rdi
movslq 0x10c(%rsp), %rsi
callq 0xd4bf0
movq %rax, %rsi
leaq 0x110(%rsp), %rdi
callq 0xd4b90
movb %dl, 0x37(%rsp)
movq %rax, 0x38(%rsp)
jmp 0xcc8b6
movb 0x37(%rsp), %al
movq 0x38(%rsp), %rcx
movq %rcx, 0xe8(%rsp)
movb %al, 0xf0(%rsp)
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0xcc865
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xccbae
movl $0x0, 0xe4(%rsp)
movq 0x50(%rsp), %rdi
movslq 0xe4(%rsp), %rax
movq %rax, 0x28(%rsp)
callq 0x10a40
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
jae 0xccb8c
movq 0x50(%rsp), %rdi
movslq 0xe4(%rsp), %rsi
callq 0x10a60
movq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0xd4c10
movq %rax, 0x20(%rsp)
jmp 0xcc953
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xd8(%rsp)
movl $0x0, 0xd4(%rsp)
movslq 0xd4(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xd8(%rsp), %rdi
addq $0x8, %rdi
callq 0x18440
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0xccb74
movq 0xd8(%rsp), %rdi
addq $0x8, %rdi
movslq 0xd4(%rsp), %rsi
callq 0x18460
movq (%rax), %rax
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rsi
addq $0x88, %rsi
leaq 0x88(%rsp), %rdi
callq 0x43130
jmp 0xcc9df
movq 0x48(%rsp), %rsi
leaq 0x88(%rsp), %rdi
addq $0x8, %rdi
addq $0x8, %rsi
callq 0x1a650
testb $0x1, %al
jne 0xcca02
jmp 0xccae1
movq 0x48(%rsp), %rax
cmpl $0x5, (%rax)
jne 0xcca24
movb $0x0, 0x167(%rsp)
movl $0x1, 0x84(%rsp)
jmp 0xccb42
movq 0x50(%rsp), %rdi
movslq 0xe4(%rsp), %rsi
callq 0x10a60
movq %rax, %rdi
leaq 0xd4(%rsp), %rsi
callq 0xd4d00
movq %rax, 0x10(%rsp)
jmp 0xcca4d
movq 0x10(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x73aa0
movq %rax, 0x8(%rsp)
jmp 0xcca70
movq 0x8(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x73b10
movq %rax, 0x68(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x73a80
testb $0x1, %al
jne 0xccaa1
jmp 0xccadf
movb $0x0, 0x167(%rsp)
movl $0x1, 0x84(%rsp)
jmp 0xccb42
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x1f210
jmp 0xccbae
jmp 0xccb37
movq 0xc8(%rsp), %rax
cmpl $0x8, (%rax)
jne 0xccb35
movq 0xc8(%rsp), %rax
cmpl $0x5, 0x8(%rax)
jne 0xccb35
movq 0x48(%rsp), %rsi
movq 0xc8(%rsp), %rdi
addq $0x8, %rdi
addq $0x8, %rdi
addq $0x8, %rsi
callq 0x1a650
testb $0x1, %al
jne 0xccb20
jmp 0xccb35
movb $0x0, 0x167(%rsp)
movl $0x1, 0x84(%rsp)
jmp 0xccb42
jmp 0xccb37
movl $0x0, 0x84(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x1f210
movl 0x84(%rsp), %eax
testl %eax, %eax
jne 0xccb9f
jmp 0xccb5c
jmp 0xccb5e
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0xcc96e
jmp 0xccb76
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0xcc905
movb $0x1, 0x167(%rsp)
movl $0x1, 0x84(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x6f0b0
jmp 0xccbbd
leaq 0x110(%rsp), %rdi
callq 0x6f0b0
jmp 0xccbce
movb 0x167(%rsp), %al
andb $0x1, %al
addq $0x168, %rsp            # imm = 0x168
retq
movq 0x100(%rsp), %rdi
callq 0x8670
nopl (%rax,%rax)