// File: luooofan[P]hblzbd_compiler/src/generate_ir.cpp
// Function: ast::VariableDefine::GenerateIR(ir::ContextInfo&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
void VariableDefine::GenerateIR(ir::ContextInfo &ctx, std::vector<ir::IR *> &gIRList) {
  auto &scope = ir::gScopes[ctx.scope_id_];
  auto &symbol_table = scope.symbol_table_;
  // NOTE: 只需在当前作用域查找即可 找到则变量重定义
  const auto &var_iter = symbol_table.find(this->name_.name_);
  if (var_iter == symbol_table.end()) {
    auto tmp = new ir::SymbolTableItem(false, false);
    if (ctx.scope_id_ == 0) {
      tmp->initval_.push_back(0);
    } else {  // GenIR DECLARE
      // gIRList.push_back({IROpKind::ALLOCA, ir::Opn{OpnType::Var, this->name_.name_, ctx.scope_id_},
      //                        ir::Opn{OpnType::Imm, ir::kIntWidth}});
    }
    symbol_table.insert({this->name_.name_, *tmp});
    delete tmp;
  } else {
    ir::SemanticError(this->line_no_, this->name_.name_ + ": variable redefined");
  }
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x140(%rsp)
movq %rsi, 0x138(%rsp)
movq %rdx, 0x130(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x138(%rsp), %rax
movslq (%rax), %rsi
leaq 0x126b3a(%rip), %rdi    # 0x14c628
callq 0x183c0
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x128(%rsp)
movq 0x128(%rsp), %rcx
movq %rcx, 0x120(%rsp)
movq 0x120(%rsp), %rdi
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
callq 0x1f270
movq %rax, 0x110(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x120(%rsp), %rdi
callq 0x109d0
movq 0x48(%rsp), %rdi
movq %rax, 0x108(%rsp)
leaq 0x108(%rsp), %rsi
callq 0x36e80
testb $0x1, %al
jne 0x25b7d
jmp 0x25cc8
movl $0x50, %edi
callq 0x8340
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x38(%rsp)
xorl %edx, %edx
movl %edx, %esi
callq 0x366c0
jmp 0x25b9d
movq 0x38(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x138(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x25c05
movq 0x100(%rsp), %rdi
addq $0x38, %rdi
movl $0x0, 0xf0(%rsp)
leaq 0xf0(%rsp), %rsi
callq 0x36ea0
jmp 0x25c07
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
movl $0x50, %esi
callq 0x8350
jmp 0x25d36
jmp 0x25c07
movq 0x40(%rsp), %rax
movq 0x120(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
movq 0x100(%rsp), %rdx
leaq 0x80(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x36ed0
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x36670
movb %dl, 0x2f(%rsp)
movq %rax, 0x30(%rsp)
jmp 0x25c55
movb 0x2f(%rsp), %al
movq 0x30(%rsp), %rcx
movq %rcx, 0x70(%rsp)
movb %al, 0x78(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x36810
movq 0x100(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x25ca0
movq 0x10(%rsp), %rdi
callq 0x36840
movq 0x10(%rsp), %rdi
movl $0x50, %esi
callq 0x8350
jmp 0x25d2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x36810
jmp 0x25d36
movq 0x40(%rsp), %rax
movl 0x8(%rax), %ecx
movl %ecx, 0x4(%rsp)
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
leaq 0xd4ea7(%rip), %rdx     # 0xfab8a
leaq 0x50(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xc720
movl 0x4(%rsp), %edi
movq 0x8(%rsp), %rsi
callq 0x47ce0
jmp 0x25d02
leaq 0x50(%rsp), %rdi
callq 0x8728
jmp 0x25d2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x8728
jmp 0x25d36
addq $0x148, %rsp            # imm = 0x148
retq
movq 0xf8(%rsp), %rdi
callq 0x8670
nopw %cs:(%rax,%rax)