// File: /workspace/github_cpp_makefile_star2_O3/luooofan[P]hblzbd_compiler/src/generate_ir.cpp
// Function: ast::VariableDefineWithInit::GenerateIR(ir::ContextInfo&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
void VariableDefineWithInit::GenerateIR(ir::ContextInfo &ctx, std::vector<ir::IR *> &gIRList) {
  auto &scope = ir::gScopes[ctx.scope_id_];
  auto &symbol_table = scope.symbol_table_;
  const auto &var_iter = symbol_table.find(this->name_.name_);
  if (var_iter == symbol_table.end()) {
    if (this->is_const_) {
      symbol_table.insert({this->name_.name_, ir::SymbolTableItem(false, true)});
    } else {
      symbol_table.insert({this->name_.name_, ir::SymbolTableItem(false, false)});
    }
    auto &tmp = symbol_table.find(this->name_.name_)->second;
    // NOTE: 如果是全局量或者常量 需要填写initval 如果是局部变量 生成一条赋值语句
    if (ctx.scope_id_ == 0 || this->is_const_) {
      value_.Evaluate(ctx, gIRList);
      tmp.initval_.push_back(ctx.opn_.imm_num_);
    } else {
      value_.GenerateIR(ctx, gIRList);
      ir::Opn lhs_opn = ir::Opn(OpnType::Var, name_.name_, ctx.scope_id_);
      // GenIR DECLARE
      // gIRList.push_back(new ir::IR(IROpKind::ALLOCA, lhs_opn, ir::Opn{OpnType::Imm, ir::kIntWidth}));
      gIRList.push_back(new ir::IR(IROpKind::ASSIGN, ctx.opn_, lhs_opn));
    }
  } else {
    ir::SemanticError(this->line_no_, this->name_.name_ + ": variable redefined");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movslq (%rsi), %r12
leaq 0x78762(%rip), %rax     # 0x8f578
shlq $0x6, %r12
addq (%rax), %r12
movq 0x10(%rdi), %rax
movq 0x10(%rax), %rsi
movq %r12, %rdi
callq 0x128fa
testq %rax, %rax
je 0x16e99
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 0x57dae(%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 0x17181
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x17181
cmpb $0x1, 0xc(%r15)
jne 0x16edb
movq 0x10(%r15), %rax
movq 0x10(%rax), %r13
leaq 0x78(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x25368
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x25898
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x26bbc
jmp 0x16f11
movq 0x10(%r15), %rax
movq 0x10(%rax), %r13
leaq 0x78(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x25368
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x25898
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x26bbc
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x16f28
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x16f3f
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x16f56
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16f71
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x16f8e
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x16fab
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x16fc8
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x10(%r15), %rax
movq 0x10(%rax), %rsi
movq %r12, %rdi
callq 0x128fa
movq %rax, %r12
cmpl $0x0, (%r14)
je 0x16fe8
cmpb $0x1, 0xc(%r15)
jne 0x1701f
movq 0x18(%r15), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %rbx, %rdx
callq *0x18(%rax)
addq $0xc, %r14
movq 0x68(%r12), %rsi
cmpq 0x70(%r12), %rsi
je 0x17172
movl (%r14), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x68(%r12)
jmp 0x17181
movq 0x18(%r15), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %rbx, %rdx
callq *0x10(%rax)
movq 0x10(%r15), %rax
movq 0x10(%rax), %rax
leaq 0xd8(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
callq 0xc6dc
movl (%r14), %ebp
leaq 0x10(%rsp), %rdi
movl $0x0, -0x8(%rdi)
leaq 0x20(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
callq 0xc6dc
movl %ebp, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movl $0xffffffff, 0x40(%rsp) # imm = 0xFFFFFFFF
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x170b7
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x82a0
movl $0xe0, %edi
callq 0x8290
movq %rax, %r15
addq $0x8, %r14
leaq 0xe8(%rsp), %rdi
movq %r14, %rsi
callq 0x28816
leaq 0x128(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x28816
movb $0x1, %bpl
leaq 0xe8(%rsp), %rdx
leaq 0x128(%rsp), %rcx
movq %r15, %rdi
movl $0xc, %esi
callq 0x25560
leaq 0x78(%rsp), %rsi
movq %r15, (%rsi)
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x11182
leaq 0x140(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1713d
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1715e
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x17181
movq 0x20(%rsp), %rsi
jmp 0x16e8c
addq $0x60, %r12
movq %r12, %rdi
movq %r14, %rdx
callq 0x129f6
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1725b
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1725b
movq %rax, %rbx
jmp 0x1725b
movq %rax, %rbx
jmp 0x17268
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
movq %r13, %r12
cmpq %r13, %rdi
jne 0x17272
jmp 0x17294
jmp 0x171ee
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x254bc
jmp 0x17202
jmp 0x171ff
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2551a
jmp 0x17294
movq %rax, %rbx
leaq 0x140(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17235
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17256
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x82a0
testb %bpl, %bpl
je 0x17268
movl $0xe0, %esi
movq %r15, %rdi
callq 0x82a0
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x17294
movq (%r12), %rsi
jmp 0x1728c
jmp 0x1727a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x17294
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq %rbx, %rdi
callq 0x8540