// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r12
movq %rdi, %r15
movslq (%rsi), %r14
leaq 0x796d1(%rip), %rax     # 0x90578
shlq $0x6, %r14
addq (%rax), %r14
movq 0x10(%rdi), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x12c3c
testq %rax, %rax
je 0x16f25
movl 0x8(%r15), %ebx
movq 0x10(%r15), %rax
movq 0x10(%rax), %rax
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xca10
leaq 0x58d1d(%rip), %rsi     # 0x6fc13
movq %r14, %rdi
callq 0x8590
leaq 0x8(%rsp), %rsi
movl %ebx, %edi
callq 0x2b12a
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x17047
movq 0x18(%rsp), %rsi
incq %rsi
jmp 0x17042
movl $0x50, %edi
callq 0x8290
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24c9c
cmpl $0x0, (%r12)
jne 0x16f78
movl $0x0, 0x8(%rsp)
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x16f67
movl $0x0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x40(%rbx)
jmp 0x16f78
movq %rbx, %rdi
addq $0x38, %rdi
leaq 0x8(%rsp), %rdx
callq 0x26d72
movq 0x10(%r15), %rax
movq 0x10(%rax), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rdx
callq 0x25110
movq %r14, %rdi
movq %r15, %rsi
callq 0x26522
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x16fb2
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x16fc9
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x16fe0
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16ffb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x17010
movq 0x48(%rbx), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x17025
movq 0x30(%rbx), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x1703a
movq 0x18(%rbx), %rsi
subq %rdi, %rsi
callq 0x82a0
movl $0x50, %esi
movq %rbx, %rdi
callq 0x82a0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x24df0
jmp 0x1708b
movq %rax, %r14
movl $0x50, %esi
movq %rbx, %rdi
jmp 0x17086
jmp 0x17071
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x1708b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq %r14, %rdi
callq 0x8540
nop