// File: /workspace/github_cpp_makefile_star2_O2/luooofan[P]hblzbd_compiler/src/generate_ir.cpp
// Function: ast::AssignStatement::GenerateIR(ir::ContextInfo&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
void AssignStatement::GenerateIR(ir::ContextInfo &ctx, std::vector<ir::IR *> &gIRList) {
  // 给函数调用赋值过不了语法分析
  this->rhs_.GenerateIR(ctx, gIRList);
  CHECK_OPN_INT("rhs exp");
  ir::Opn rhs_opn = ctx.opn_;

  ctx.is_assigned_ = true;
  this->lhs_.GenerateIR(ctx, gIRList);
  ctx.is_assigned_ = false;
  CHECK_OPN_INT("leftvalue");

  ir::Opn &lhs_opn = ctx.opn_;
  ir::SymbolTableItem *symbol = nullptr;
  ir::FindSymbol(ctx.scope_id_, lhs_opn.name_, symbol);

  // const check
  if (nullptr != symbol && symbol->is_const_) {
    ir::SemanticError(this->line_no_, lhs_opn.name_ + ": constant can't be assigned");
    return;
  }

  // genir(assign,opn1,-,res)
  gIRList.push_back(new ir::IR(IROpKind::ASSIGN, rhs_opn, lhs_opn));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq 0x18(%rdi), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x50(%r14), %rax
cmpq 0x58(%r14), %rax
je 0x138b6
cmpl $0x4, 0x8(%r14)
jne 0x138b6
movl 0x8(%r15), %ebp
leaq 0x10(%r14), %rsi
leaq 0x439fe(%rip), %rdx     # 0x57250
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0xa334
leaq 0x43513(%rip), %rdx     # 0x56d79
movq %rsp, %rdi
movq %r12, %rsi
callq 0xa440
leaq 0x4326d(%rip), %rdx     # 0x56ae5
leaq 0x80(%rsp), %rdi
movq %rsp, %rsi
callq 0xa440
leaq 0x80(%rsp), %rsi
movl %ebp, %edi
callq 0x1f699
leaq 0x80(%rsp), %rdi
callq 0x8578
movq %rsp, %rdi
callq 0x8578
leaq 0x20(%rsp), %rdi
callq 0x8578
leaq 0x8(%r14), %r12
leaq 0x80(%rsp), %rdi
movq %r12, %rsi
callq 0x1da22
movb $0x1, 0x209(%r14)
movq 0x10(%r15), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %rbx, %rdx
callq *0x10(%rax)
movb $0x0, 0x209(%r14)
movq 0x50(%r14), %rax
cmpq 0x58(%r14), %rax
je 0x13964
cmpl $0x4, 0x8(%r14)
jne 0x13964
movl 0x8(%r15), %ebp
leaq 0x10(%r14), %rsi
leaq 0x43946(%rip), %rdx     # 0x57250
leaq 0x60(%rsp), %rdi
callq 0xa334
leaq 0x432d5(%rip), %rdx     # 0x56bf0
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xa440
leaq 0x431b4(%rip), %rdx     # 0x56ae5
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0xa440
movq %rsp, %rsi
movl %ebp, %edi
callq 0x1f699
movq %rsp, %rdi
callq 0x8578
leaq 0x20(%rsp), %rdi
callq 0x8578
leaq 0x60(%rsp), %rdi
callq 0x8578
andq $0x0, 0x20(%rsp)
movl (%r14), %ebp
addq $0x10, %r14
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x8390
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movl %ebp, %edi
callq 0x1d90c
leaq 0x40(%rsp), %rdi
callq 0x8578
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x139ce
cmpb $0x1, 0x1(%rax)
jne 0x139ce
movl 0x8(%r15), %ebx
leaq 0x43246(%rip), %rdx     # 0x56bfa
movq %rsp, %rdi
movq %r14, %rsi
callq 0xa334
movq %rsp, %rsi
movl %ebx, %edi
callq 0x1f699
movq %rsp, %rdi
jmp 0x13a43
movl $0xe0, %edi
callq 0x8250
movq %rax, %r14
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x1da22
leaq 0xc0(%rsp), %rdi
movq %r12, %rsi
callq 0x1da22
movb $0x1, %bpl
pushq $0xc
popq %rsi
leaq 0x100(%rsp), %rdx
leaq 0xc0(%rsp), %rcx
movq %r14, %rdi
callq 0x1aa52
movq %rsp, %rsi
movq %r14, (%rsi)
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0xe358
leaq 0xc8(%rsp), %rdi
callq 0x8578
leaq 0x108(%rsp), %rdi
callq 0x8578
leaq 0x88(%rsp), %rdi
callq 0x8578
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %rsp, %rdi
jmp 0x13ad7
jmp 0x13ae0
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8578
jmp 0x13a7f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x8578
jmp 0x13a8e
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x13ad7
jmp 0x13ae0
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x8578
jmp 0x13aac
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8578
jmp 0x13ab9
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x13b1c
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x13af5
movq %rax, %rbx
jmp 0x13b07
jmp 0x13ae0
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x8578
jmp 0x13b14
jmp 0x13ae0
movq %rax, %rbx
jmp 0x13b14
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x8578
leaq 0x108(%rsp), %rdi
callq 0x8578
testb %bpl, %bpl
je 0x13b14
movl $0xe0, %esi
movq %r14, %rdi
callq 0x8260
leaq 0x88(%rsp), %rdi
callq 0x8578
movq %rbx, %rdi
callq 0x84d0
nop