// File: luooofan[P]hblzbd_compiler/src/Pass/ir_liveness_analysis.cpp
// Function: GetDefUse[abi:cxx11](ir::IR*, bool)
std::pair<std::vector<std::string>, std::vector<std::string>> GetDefUse(IR *ir, bool consider) {
  std::vector<std::string> def;
  std::vector<std::string> use;

  auto process_opn = [&use, &consider](Opn *op) {
    if (nullptr == op) return;
    if (op->type_ == Opn::Type::Imm || op->type_ == Opn::Type::Label || op->type_ == Opn::Type::Func ||
        op->type_ == Opn::Type::Null)
      return;
    if (op->type_ == Opn::Type::Array) {
      if (consider) use.push_back(op->name_ + "." + std::to_string(op->scope_id_));
      if (op->offset_->type_ == Opn::Type::Var)
        if (consider || 0 != op->offset_->scope_id_)
          use.push_back(op->offset_->name_ + "." + std::to_string(op->offset_->scope_id_));
    } else {  // var
      if (!consider && 0 == op->scope_id_) return;
      use.push_back(op->name_ + "." + std::to_string(op->scope_id_));
    }
  };

  auto process_res = [&def, &use, &consider](Opn *res) {
    if (nullptr == res) return;
    if (res->type_ == Opn::Type::Label || res->type_ == Opn::Type::Func || res->type_ == Opn::Type::Null) return;
    if (res->type_ == Opn::Type::Array) {
      if (consider) def.push_back(res->name_ + "." + std::to_string(res->scope_id_));
      if (res->offset_->type_ == Opn::Type::Var)
        if (consider || 0 != res->offset_->scope_id_)
          use.push_back(res->offset_->name_ + "." + std::to_string(res->offset_->scope_id_));
    } else {
      if (!consider && 0 == res->scope_id_) return;
      def.push_back(res->name_ + "." + std::to_string(res->scope_id_));
    }
  };

  if (ir->op_ == IR::OpKind::ADD || ir->op_ == IR::OpKind::SUB || ir->op_ == IR::OpKind::MUL ||
      ir->op_ == IR::OpKind::DIV || ir->op_ == IR::OpKind::MOD) {
    process_opn(&(ir->opn1_));
    process_opn(&(ir->opn2_));
    process_res(&(ir->res_));
  } else if (ir->op_ == IR::OpKind::NOT || ir->op_ == IR::OpKind::NEG) {
    process_opn(&(ir->opn1_));
    process_res(&(ir->res_));
  } else if (ir->op_ == IR::OpKind::LABEL) {
    return {def, use};
  } else if (ir->op_ == IR::OpKind::PARAM) {
    process_opn(&(ir->opn1_));
  } else if (ir->op_ == IR::OpKind::CALL) {
    process_res(&(ir->res_));
  } else if (ir->op_ == IR::OpKind::RET) {
    process_opn(&(ir->opn1_));
  } else if (ir->op_ == IR::OpKind::GOTO) {
    return {def, use};
  } else if (ir->op_ == IR::OpKind::ASSIGN) {
    process_opn(&(ir->opn1_));
    process_res(&(ir->res_));
  } else if (ir->op_ == IR::OpKind::JEQ || ir->op_ == IR::OpKind::JNE || ir->op_ == IR::OpKind::JLT ||
             ir->op_ == IR::OpKind::JLE || ir->op_ == IR::OpKind::JGT || ir->op_ == IR::OpKind::JGE) {
    process_opn(&(ir->opn1_));
    process_opn(&(ir->opn2_));
  } else if (ir->op_ == IR::OpKind::VOID) {
    return {def, use};
  } else if (ir->op_ == IR::OpKind::ASSIGN_OFFSET) {
    process_opn(&(ir->opn1_));
    process_res(&(ir->res_));
  } else if (ir->op_ == IR::OpKind::PHI) {
    for (auto &arg : ir->phi_args_) {
      process_opn(&(arg));
    }
    process_res(&(ir->res_));
  } else if (ir->op_ == IR::OpKind::ALLOCA) {
    process_res(&(ir->opn1_));
  } else if (ir->op_ == IR::OpKind::DECLARE) {
    process_res(&(ir->opn1_));
  } else {
    MyAssert(0);
  }

  return {def, use};
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0x28(%rsp)
movb %dl, %al
movq %rdi, %rcx
movq %rcx, 0x30(%rsp)
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
andb $0x1, %al
movb %al, 0xc7(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xc9f30
leaq 0x90(%rsp), %rdi
callq 0xc9f30
leaq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0xc7(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0xa8(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0xc7(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0xc8(%rsp), %rax
cmpl $0x0, (%rax)
je 0xc84b5
movq 0xc8(%rsp), %rax
cmpl $0x1, (%rax)
je 0xc84b5
movq 0xc8(%rsp), %rax
cmpl $0x2, (%rax)
je 0xc84b5
movq 0xc8(%rsp), %rax
cmpl $0x3, (%rax)
je 0xc84b5
movq 0xc8(%rsp), %rax
cmpl $0x4, (%rax)
jne 0xc8538
movq 0xc8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc84d0
movq 0xc8(%rsp), %rsi
addq $0x48, %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc84eb
movq 0xc8(%rsp), %rsi
addq $0x88, %rsi
leaq 0x68(%rsp), %rdi
callq 0xc8de0
jmp 0xc8506
jmp 0xc895f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x92970
leaq 0xa8(%rsp), %rdi
callq 0x92970
jmp 0xc89aa
movq 0xc8(%rsp), %rax
cmpl $0x5, (%rax)
je 0xc8552
movq 0xc8(%rsp), %rax
cmpl $0x6, (%rax)
jne 0xc858d
movq 0xc8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc856d
movq 0xc8(%rsp), %rsi
addq $0x88, %rsi
leaq 0x68(%rsp), %rdi
callq 0xc8de0
jmp 0xc8588
jmp 0xc895d
movq 0xc8(%rsp), %rax
cmpl $0x7, (%rax)
jne 0xc85c3
movq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xc9f40
jmp 0xc85b6
movl $0x1, 0x58(%rsp)
jmp 0xc8983
movq 0xc8(%rsp), %rax
cmpl $0x8, (%rax)
jne 0xc85f0
movq 0xc8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc85eb
jmp 0xc8959
movq 0xc8(%rsp), %rax
cmpl $0x9, (%rax)
jne 0xc861d
movq 0xc8(%rsp), %rsi
addq $0x88, %rsi
leaq 0x68(%rsp), %rdi
callq 0xc8de0
jmp 0xc8618
jmp 0xc8957
movq 0xc8(%rsp), %rax
cmpl $0xa, (%rax)
jne 0xc864a
movq 0xc8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc8645
jmp 0xc8955
movq 0xc8(%rsp), %rax
cmpl $0xb, (%rax)
jne 0xc8680
movq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xc9f40
jmp 0xc8673
movl $0x1, 0x58(%rsp)
jmp 0xc8983
movq 0xc8(%rsp), %rax
cmpl $0xc, (%rax)
jne 0xc86c8
movq 0xc8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc86a8
movq 0xc8(%rsp), %rsi
addq $0x88, %rsi
leaq 0x68(%rsp), %rdi
callq 0xc8de0
jmp 0xc86c3
jmp 0xc8951
movq 0xc8(%rsp), %rax
cmpl $0xd, (%rax)
je 0xc8716
movq 0xc8(%rsp), %rax
cmpl $0xe, (%rax)
je 0xc8716
movq 0xc8(%rsp), %rax
cmpl $0xf, (%rax)
je 0xc8716
movq 0xc8(%rsp), %rax
cmpl $0x10, (%rax)
je 0xc8716
movq 0xc8(%rsp), %rax
cmpl $0x11, (%rax)
je 0xc8716
movq 0xc8(%rsp), %rax
cmpl $0x12, (%rax)
jne 0xc8751
movq 0xc8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc8731
movq 0xc8(%rsp), %rsi
addq $0x48, %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc874c
jmp 0xc894f
movq 0xc8(%rsp), %rax
cmpl $0x13, (%rax)
jne 0xc8787
movq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xc9f40
jmp 0xc877a
movl $0x1, 0x58(%rsp)
jmp 0xc8983
movq 0xc8(%rsp), %rax
cmpl $0x14, (%rax)
jne 0xc87cf
movq 0xc8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc87af
movq 0xc8(%rsp), %rsi
addq $0x88, %rsi
leaq 0x68(%rsp), %rdi
callq 0xc8de0
jmp 0xc87ca
jmp 0xc894b
movq 0xc8(%rsp), %rax
cmpl $0x15, (%rax)
jne 0xc8877
movq 0xc8(%rsp), %rax
addq $0xc8, %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
callq 0x47fb0
movq %rax, 0x48(%rsp)
movq 0x50(%rsp), %rdi
callq 0x47fe0
movq %rax, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x48010
testb $0x1, %al
jne 0xc8826
jmp 0xc8857
leaq 0x48(%rsp), %rdi
callq 0x48050
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0xc89c0
jmp 0xc8849
jmp 0xc884b
leaq 0x48(%rsp), %rdi
callq 0x48060
jmp 0xc8811
movq 0xc8(%rsp), %rsi
addq $0x88, %rsi
leaq 0x68(%rsp), %rdi
callq 0xc8de0
jmp 0xc8872
jmp 0xc8949
movq 0xc8(%rsp), %rax
cmpl $0x16, (%rax)
jne 0xc88a1
movq 0xc8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x68(%rsp), %rdi
callq 0xc8de0
jmp 0xc889c
jmp 0xc8947
movq 0xc8(%rsp), %rax
cmpl $0x17, (%rax)
jne 0xc88c8
movq 0xc8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x68(%rsp), %rdi
callq 0xc8de0
jmp 0xc88c6
jmp 0xc8945
movq 0x83719(%rip), %rdi     # 0x14bfe8
leaq 0x31822(%rip), %rsi     # 0xfa0f8
callq 0x8330
movq %rax, 0x20(%rsp)
jmp 0xc88e2
movq 0x20(%rsp), %rdi
leaq 0x351bd(%rip), %rsi     # 0xfdaab
callq 0x8330
movq %rax, 0x18(%rsp)
jmp 0xc88fa
movq 0x18(%rsp), %rdi
leaq 0x32ae4(%rip), %rsi     # 0xfb3ea
callq 0x8330
movq %rax, 0x10(%rsp)
jmp 0xc8912
movq 0x10(%rsp), %rdi
movl $0x9e, %esi
callq 0x8650
movq %rax, 0x8(%rsp)
jmp 0xc8928
movq 0x8(%rsp), %rdi
movq 0x8364c(%rip), %rsi     # 0x14bf80
callq 0x8380
jmp 0xc893b
movl $0xff, %edi
callq 0x8460
jmp 0xc8947
jmp 0xc8949
jmp 0xc894b
jmp 0xc894d
jmp 0xc894f
jmp 0xc8951
jmp 0xc8953
jmp 0xc8955
jmp 0xc8957
jmp 0xc8959
jmp 0xc895b
jmp 0xc895d
jmp 0xc895f
movq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xc9f40
jmp 0xc897b
movl $0x1, 0x58(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x92970
leaq 0xa8(%rsp), %rdi
callq 0x92970
movq 0x30(%rsp), %rax
addq $0xd8, %rsp
retq
movq 0x60(%rsp), %rdi
callq 0x8670
nopw %cs:(%rax,%rax)