// File: luooofan[P]hblzbd_compiler/src/Pass/dead_function_eliminate.cpp
// Function: isLiveness(IRBasicBlock*, ir::IR*, ir::Opn)
bool isLiveness(IRBasicBlock *bb, ir::IR *end_ir, ir::Opn opn) {
  std::unordered_set<std::string> keepalive = bb->liveout_;
  auto it = find(bb->ir_list_.begin(), bb->ir_list_.end(), end_ir);
  std::string opn_str = opn.name_ + "." + std::to_string(opn.scope_id_);

  for (auto iter = it + 1; iter != bb->ir_list_.end(); ++iter) {
    auto ir = *iter;

    auto [def, use] = GetDefUse(ir);

    if (find(def.begin(), def.end(), opn_str) != def.end()) {
      return false;
    }

    if (find(use.begin(), use.end(), opn_str) != use.end()) {
      return true;
    }
  }

  if (keepalive.find(opn_str) != keepalive.end()) {
    return true;
  } else {
    return false;
  }
}

// Assembly:
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdx, 0x28(%rsp)
movq %rdi, 0x1b8(%rsp)
movq %rsi, 0x1b0(%rsp)
movq %rdx, 0x1a8(%rsp)
movq 0x1b8(%rsp), %rsi
addq $0x100, %rsi            # imm = 0x100
leaq 0x170(%rsp), %rdi
callq 0xa3d90
movq 0x1b8(%rsp), %rdi
addq $0x8, %rdi
callq 0x1b070
movq %rax, 0x160(%rsp)
movq 0x1b8(%rsp), %rdi
addq $0x8, %rdi
callq 0x1aeb0
movq %rax, 0x158(%rsp)
movq 0x160(%rsp), %rdi
movq 0x158(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
callq 0xa3dc0
movq %rax, 0x30(%rsp)
jmp 0xa3206
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rax
movq %rax, 0x168(%rsp)
addq $0x8, %rsi
leaq 0x5a6a6(%rip), %rdx     # 0xfd8c9
leaq 0x108(%rsp), %rdi
callq 0xc720
jmp 0xa3232
movq 0x28(%rsp), %rax
movl 0x28(%rax), %esi
leaq 0xe8(%rsp), %rdi
callq 0xc7b0
jmp 0xa3249
leaq 0x128(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0xc630
jmp 0xa3268
leaq 0xe8(%rsp), %rdi
callq 0x8728
leaq 0x108(%rsp), %rdi
callq 0x8728
leaq 0x168(%rsp), %rdi
movl $0x1, %esi
callq 0x976a0
movq %rax, 0xe0(%rsp)
movq 0x1b8(%rsp), %rdi
addq $0x8, %rdi
callq 0x1aeb0
movq %rax, 0xd8(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x493c0
testb $0x1, %al
jne 0xa32d3
jmp 0xa3527
leaq 0xe0(%rsp), %rdi
callq 0x1b4d0
movq (%rax), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
movl $0x1, %edx
callq 0xc83e0
jmp 0xa3307
leaq 0xa0(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x8f320
movq 0x18(%rsp), %rdi
movq %rax, 0x98(%rsp)
callq 0x8f330
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rdi
callq 0xa3ec0
movq %rax, 0x80(%rsp)
movq 0x98(%rsp), %rdi
callq 0xa3ef0
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
leaq 0x128(%rsp), %rdx
callq 0xa3e60
movq %rax, 0x20(%rsp)
jmp 0xa337b
movq 0x20(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x98(%rsp), %rdi
callq 0xa3ef0
movq %rax, 0x70(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xa3e20
testb $0x1, %al
jne 0xa33b5
jmp 0xa346b
movb $0x0, 0x1c7(%rsp)
movl $0x1, 0x6c(%rsp)
jmp 0xa34f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xa35ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xa341a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x8728
leaq 0x108(%rsp), %rdi
callq 0x8728
jmp 0xa35ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xa35c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x8f530
jmp 0xa35c1
movq 0x90(%rsp), %rdi
callq 0xa3ec0
movq %rax, 0x58(%rsp)
movq 0x90(%rsp), %rdi
callq 0xa3ef0
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
leaq 0x128(%rsp), %rdx
callq 0xa3e60
movq %rax, 0x10(%rsp)
jmp 0xa34ad
movq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x90(%rsp), %rdi
callq 0xa3ef0
movq %rax, 0x48(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0xa3e20
testb $0x1, %al
jne 0xa34de
jmp 0xa34f0
movb $0x1, 0x1c7(%rsp)
movl $0x1, 0x6c(%rsp)
jmp 0xa34f8
movl $0x0, 0x6c(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x8f530
movl 0x6c(%rsp), %eax
testl %eax, %eax
jne 0xa3596
jmp 0xa3513
jmp 0xa3515
leaq 0xe0(%rsp), %rdi
callq 0x49460
jmp 0xa329c
leaq 0x170(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x8f940
movq %rax, 0x8(%rsp)
jmp 0xa3543
movq 0x8(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x8f6e0
movq %rax, 0x38(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x8f710
testb $0x1, %al
jne 0xa3574
jmp 0xa3586
movb $0x1, 0x1c7(%rsp)
movl $0x1, 0x6c(%rsp)
jmp 0xa3596
movb $0x0, 0x1c7(%rsp)
movl $0x1, 0x6c(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x8728
leaq 0x170(%rsp), %rdi
callq 0x35900
movb 0x1c7(%rsp), %al
andb $0x1, %al
addq $0x1c8, %rsp            # imm = 0x1C8
retq
leaq 0x128(%rsp), %rdi
callq 0x8728
leaq 0x170(%rsp), %rdi
callq 0x35900
movq 0x150(%rsp), %rdi
callq 0x8670
nopl (%rax,%rax)