// File: /workspace/github_cpp_makefile_star2_O1/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 0x794c0(%rip), %rax     # 0x90578
shlq $0x6, %r12
addq (%rax), %r12
movq 0x10(%rdi), %rax
movq 0x10(%rax), %rsi
movq %r12, %rdi
callq 0x12c3c
testq %rax, %rax
je 0x1713b
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 0x58b0c(%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 0x17423
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x17423
cmpb $0x1, 0xc(%r15)
jne 0x1717d
movq 0x10(%r15), %rax
movq 0x10(%rax), %r13
leaq 0x78(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x24c9c
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x251cc
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x26522
jmp 0x171b3
movq 0x10(%r15), %rax
movq 0x10(%rax), %r13
leaq 0x78(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24c9c
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x251cc
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x26522
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x171ca
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x171e1
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x171f8
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17213
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x17230
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x1724d
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1726a
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x10(%r15), %rax
movq 0x10(%rax), %rsi
movq %r12, %rdi
callq 0x12c3c
movq %rax, %r12
cmpl $0x0, (%r14)
je 0x1728a
cmpb $0x1, 0xc(%r15)
jne 0x172c1
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 0x17414
movl (%r14), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x68(%r12)
jmp 0x17423
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 0xca10
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 0xca10
movl %ebp, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movl $0xffffffff, 0x40(%rsp) # imm = 0xFFFFFFFF
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x17359
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x82a0
movl $0xe0, %edi
callq 0x8290
movq %rax, %r15
addq $0x8, %r14
leaq 0x128(%rsp), %rdi
movq %r14, %rsi
callq 0x28186
leaq 0xe8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x28186
movb $0x1, %bpl
leaq 0x128(%rsp), %rdx
leaq 0xe8(%rsp), %rcx
movq %r15, %rdi
movl $0xc, %esi
callq 0x24e94
leaq 0x78(%rsp), %rsi
movq %r15, (%rsi)
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x114b8
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x173df
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x140(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17400
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x17423
movq 0x20(%rsp), %rsi
jmp 0x1712e
addq $0x60, %r12
movq %r12, %rdi
movq %r14, %rdx
callq 0x12d38
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x174b5
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x174d6
movq %rax, %rbx
jmp 0x174e8
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
movq %r13, %r12
cmpq %r13, %rdi
jne 0x174f2
jmp 0x17514
jmp 0x1746e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x24df0
jmp 0x17482
jmp 0x1747f
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x24e4e
jmp 0x17514
movq %rax, %rbx
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x174b5
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x140(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x174d6
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x82a0
testb %bpl, %bpl
je 0x174e8
movl $0xe0, %esi
movq %r15, %rdi
callq 0x82a0
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x17514
movq (%r12), %rsi
jmp 0x1750c
jmp 0x174fa
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x17514
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq %rbx, %rdi
callq 0x8540