// File: /workspace/github_cpp_makefile_star2_O2/luooofan[P]hblzbd_compiler/src/Pass/reach_define.cpp
// Function: ReachDefine::GetGenKill(ir::IR*, IRFunction*)
std::pair<std::unordered_set<ir::IR *>, std::unordered_set<ir::IR *>> ReachDefine::GetGenKill(ir::IR *ir,
                                                                                              IRFunction *func) {
  std::unordered_set<ir::IR *> gen;
  std::unordered_set<ir::IR *> kill;

  if (ir->res_.scope_id_ == 0) return {gen, kill};

  if (ir::IR::OpKind::ADD == ir->op_ || ir::IR::OpKind::SUB == ir->op_ || ir::IR::OpKind::MUL == ir->op_ ||
      ir::IR::OpKind::DIV == ir->op_ || ir::IR::OpKind::MOD == ir->op_) {
    gen.insert(ir);

    std::string res_str = ir->res_.name_ + "_#" + std::to_string(ir->res_.scope_id_);
    for (auto m : func->def_pre_var_[res_str]) {
      if (ir != m) {
        kill.insert(m);
      }
    }
  } else if (ir::IR::OpKind::NOT == ir->op_ || ir::IR::OpKind::NEG == ir->op_) {
    gen.insert(ir);

    std::string res_str = ir->res_.name_ + "_#" + std::to_string(ir->res_.scope_id_);

    for (auto m : func->def_pre_var_[res_str]) {
      if (ir != m) {
        kill.insert(m);
      }
    }
  } else if (ir::IR::OpKind::LABEL == ir->op_) {
    return {gen, kill};
  } else if (ir::IR::OpKind::PARAM == ir->op_) {
    return {gen, kill};
  } else if (ir::IR::OpKind::CALL == ir->op_) {
    return {gen, kill};
  } else if (ir::IR::OpKind::RET == ir->op_) {
    return {gen, kill};
  } else if (ir::IR::OpKind::GOTO == ir->op_) {
    return {gen, kill};
  } else if (ir::IR::OpKind::ASSIGN == ir->op_) {
    gen.insert(ir);
    std::string res_str = ir->res_.name_ + "_#" + std::to_string(ir->res_.scope_id_);

    for (auto m : func->def_pre_var_[res_str]) {
      if (ir != m) {
        kill.insert(m);
      }
    }
  } else if (ir::IR::OpKind::JEQ == ir->op_ || ir::IR::OpKind::JNE == ir->op_ || ir::IR::OpKind::JLT == ir->op_ ||
             ir::IR::OpKind::JLE == ir->op_ || ir::IR::OpKind::JGT == ir->op_ || ir::IR::OpKind::JGE == ir->op_) {
    return {gen, kill};
  } else if (ir::IR::OpKind::VOID == ir->op_) {
    return {gen, kill};
  } else if (ir::IR::OpKind::ASSIGN_OFFSET == ir->op_) {
    gen.insert(ir);
    std::string res_str = ir->res_.name_ + "_#" + std::to_string(ir->res_.scope_id_);

    for (auto m : func->def_pre_var_[res_str]) {
      if (ir != m) {
        kill.insert(m);
      }
    }
  } else if (ir::IR::OpKind::PHI == ir->op_) {
    printf("我就不信我这个pass会有PHI\n");
  } else if (ir::IR::OpKind::ALLOCA == ir->op_) {
    return {gen, kill};
  } else if (ir::IR::OpKind::DECLARE == ir->op_) {
    return {gen, kill};
  } else {
    MyAssert(0);
  }

  return {gen, kill};
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rcx, %r14
movq %rdi, %rbx
movq %rdx, (%rsp)
leaq 0xd0(%rsp), %rax
movq %rax, -0x30(%rax)
pushq $0x1
popq %rcx
movq %rcx, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, %esi       # imm = 0x3F800000
movl %esi, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0x98(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %esi, -0x10(%rax)
movups %xmm0, -0x8(%rax)
cmpl $0x0, 0xb0(%rdx)
je 0x52caa
movl (%rdx), %eax
cmpq $0x17, %rax
ja 0x52cf6
leaq 0x70bd(%rip), %rcx      # 0x59a98
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xa0(%rsp), %rdi
movq %rsp, %rsi
callq 0x532ba
movl $0x90, %esi
addq (%rsp), %rsi
leaq 0x6fc7(%rip), %rdx      # 0x599cb
leaq 0x8(%rsp), %rdi
callq 0xa334
movq (%rsp), %rax
movl 0xb0(%rax), %esi
leaq 0x28(%rsp), %rdi
callq 0xa36c
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xa2cd
leaq 0x28(%rsp), %rdi
callq 0x8578
leaq 0x8(%rsp), %rdi
callq 0x8578
addq $0x60, %r14
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x538ce
movq %rax, %r14
addq $0x10, %r14
leaq 0x68(%rsp), %r15
leaq 0x8(%rsp), %r12
movq (%r14), %r14
testq %r14, %r14
je 0x52ca0
movq 0x8(%r14), %rax
movq %rax, 0x8(%rsp)
cmpq %rax, (%rsp)
je 0x52a6c
movq %r15, %rdi
movq %r12, %rsi
callq 0x532ba
jmp 0x52a6c
leaq 0xa0(%rsp), %rdi
movq %rsp, %rsi
callq 0x532ba
movl $0x90, %esi
addq (%rsp), %rsi
leaq 0x6f17(%rip), %rdx      # 0x599cb
leaq 0x8(%rsp), %rdi
callq 0xa334
movq (%rsp), %rax
movl 0xb0(%rax), %esi
leaq 0x28(%rsp), %rdi
callq 0xa36c
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xa2cd
leaq 0x28(%rsp), %rdi
callq 0x8578
leaq 0x8(%rsp), %rdi
callq 0x8578
addq $0x60, %r14
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x538ce
movq %rax, %r14
addq $0x10, %r14
leaq 0x68(%rsp), %r15
leaq 0x8(%rsp), %r12
movq (%r14), %r14
testq %r14, %r14
je 0x52ca0
movq 0x8(%r14), %rax
movq %rax, 0x8(%rsp)
cmpq %rax, (%rsp)
je 0x52b1c
movq %r15, %rdi
movq %r12, %rsi
callq 0x532ba
jmp 0x52b1c
leaq 0xa0(%rsp), %rdi
movq %rsp, %rsi
callq 0x532ba
movl $0x90, %esi
addq (%rsp), %rsi
leaq 0x6e67(%rip), %rdx      # 0x599cb
leaq 0x8(%rsp), %rdi
callq 0xa334
movq (%rsp), %rax
movl 0xb0(%rax), %esi
leaq 0x28(%rsp), %rdi
callq 0xa36c
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xa2cd
leaq 0x28(%rsp), %rdi
callq 0x8578
leaq 0x8(%rsp), %rdi
callq 0x8578
addq $0x60, %r14
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x538ce
movq %rax, %r14
addq $0x10, %r14
leaq 0x68(%rsp), %r15
leaq 0x8(%rsp), %r12
movq (%r14), %r14
testq %r14, %r14
je 0x52ca0
movq 0x8(%r14), %rax
movq %rax, 0x8(%rsp)
cmpq %rax, (%rsp)
je 0x52bcc
movq %r15, %rdi
movq %r12, %rsi
callq 0x532ba
jmp 0x52bcc
leaq 0xa0(%rsp), %rdi
movq %rsp, %rsi
callq 0x532ba
movl $0x90, %esi
addq (%rsp), %rsi
leaq 0x6db7(%rip), %rdx      # 0x599cb
leaq 0x8(%rsp), %rdi
callq 0xa334
movq (%rsp), %rax
movl 0xb0(%rax), %esi
leaq 0x28(%rsp), %rdi
callq 0xa36c
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xa2cd
leaq 0x28(%rsp), %rdi
callq 0x8578
leaq 0x8(%rsp), %rdi
callq 0x8578
addq $0x60, %r14
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x538ce
movq %rax, %r14
addq $0x10, %r14
leaq 0x68(%rsp), %r15
leaq 0x8(%rsp), %r12
movq (%r14), %r14
testq %r14, %r14
je 0x52ca0
movq 0x8(%r14), %rax
movq %rax, 0x8(%rsp)
cmpq %rax, (%rsp)
je 0x52c7c
movq %r15, %rdi
movq %r12, %rsi
callq 0x532ba
jmp 0x52c7c
leaq 0x48(%rsp), %rdi
callq 0x8578
leaq 0xa0(%rsp), %rsi
leaq 0x68(%rsp), %rdx
movq %rbx, %rdi
callq 0x52e40
leaq 0x68(%rsp), %rdi
callq 0x1fed4
leaq 0xa0(%rsp), %rdi
callq 0x1fed4
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x6e88(%rip), %rdi      # 0x59b77
callq 0x8420
jmp 0x52caa
movq 0x2e2eb(%rip), %rdi     # 0x80fe8
leaq 0x33e4(%rip), %rsi      # 0x560e8
callq 0x8240
leaq 0x6e4d(%rip), %rsi      # 0x59b5d
movq %rax, %rdi
callq 0x8240
leaq 0x4601(%rip), %rsi      # 0x57320
movq %rax, %rdi
callq 0x8240
movq %rax, %rdi
movl $0x15e, %esi            # imm = 0x15E
callq 0x84b0
movq %rax, %rdi
callq 0x8170
movl $0xff, %edi
callq 0x8300
jmp 0x52d86
jmp 0x52d86
jmp 0x52d60
jmp 0x52d60
jmp 0x52d6f
jmp 0x52d6f
jmp 0x52d81
jmp 0x52d81
jmp 0x52d86
jmp 0x52d60
jmp 0x52d6f
jmp 0x52d81
jmp 0x52d86
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x8578
jmp 0x52d72
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x52d8e
jmp 0x52d81
jmp 0x52d86
jmp 0x52d86
jmp 0x52d86
movq %rax, %rbx
jmp 0x52d93
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x8578
leaq 0x68(%rsp), %rdi
callq 0x1fed4
leaq 0xa0(%rsp), %rdi
callq 0x1fed4
movq %rbx, %rdi
callq 0x84d0