// File: /workspace/github_cpp_makefile_star2_O3/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 0x78973(%rip), %rax     # 0x8f578
shlq $0x6, %r14
addq (%rax), %r14
movq 0x10(%rdi), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x128fa
testq %rax, %rax
je 0x16c83
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 0xc6dc
leaq 0x57fbf(%rip), %rsi     # 0x6ec13
movq %r14, %rdi
callq 0x8590
leaq 0x8(%rsp), %rsi
movl %ebx, %edi
callq 0x2b6aa
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x16da5
movq 0x18(%rsp), %rsi
incq %rsi
jmp 0x16da0
movl $0x50, %edi
callq 0x8290
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x25368
cmpl $0x0, (%r12)
jne 0x16cd6
movl $0x0, 0x8(%rsp)
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x16cc5
movl $0x0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x40(%rbx)
jmp 0x16cd6
movq %rbx, %rdi
addq $0x38, %rdi
leaq 0x8(%rsp), %rdx
callq 0x2740e
movq 0x10(%r15), %rax
movq 0x10(%rax), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rdx
callq 0x257dc
movq %r14, %rdi
movq %r15, %rsi
callq 0x26bbc
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x16d10
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x16d27
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x16d3e
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16d59
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x16d6e
movq 0x48(%rbx), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x16d83
movq 0x30(%rbx), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x16d98
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 0x254bc
jmp 0x16de9
movq %rax, %r14
movl $0x50, %esi
movq %rbx, %rdi
jmp 0x16de4
jmp 0x16dcf
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x16de9
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq %r14, %rdi
callq 0x8540
nop