// File: 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:
subq $0x248, %rsp            # imm = 0x248
movq %rdi, 0x240(%rsp)
movq %rsi, 0x238(%rsp)
movq %rdx, 0x230(%rsp)
movq 0x240(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rax), %rdi
movq 0x238(%rsp), %rsi
movq 0x230(%rsp), %rdx
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x238(%rsp), %rdi
addq $0x50, %rdi
callq 0x10a80
testb $0x1, %al
jne 0x28e73
movq 0x238(%rsp), %rax
cmpl $0x4, 0x8(%rax)
jne 0x28e73
movq 0x30(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x238(%rsp), %rsi
addq $0x10, %rsi
leaq 0xd2500(%rip), %rdx     # 0xfb280
leaq 0x1d0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xc720
movq 0x28(%rsp), %rsi
leaq 0xd1ff2(%rip), %rdx     # 0xfad90
leaq 0x1f0(%rsp), %rdi
callq 0xcbd0
jmp 0x28dad
leaq 0xd1d48(%rip), %rdx     # 0xfaafc
leaq 0x210(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0xcbd0
jmp 0x28dcb
movl 0x24(%rsp), %edi
leaq 0x210(%rsp), %rsi
callq 0x47ce0
jmp 0x28dde
leaq 0x210(%rsp), %rdi
callq 0x8728
leaq 0x1f0(%rsp), %rdi
callq 0x8728
leaq 0x1d0(%rsp), %rdi
callq 0x8728
jmp 0x28e73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x28e61
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x28e54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x8728
leaq 0x1f0(%rsp), %rdi
callq 0x8728
leaq 0x1d0(%rsp), %rdi
callq 0x8728
jmp 0x292ab
movq 0x238(%rsp), %rsi
addq $0x8, %rsi
leaq 0x180(%rsp), %rdi
callq 0x43130
movq 0x30(%rsp), %rax
movq 0x238(%rsp), %rcx
movb $0x1, 0x209(%rcx)
movq 0x10(%rax), %rdi
movq 0x238(%rsp), %rsi
movq 0x230(%rsp), %rdx
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0x28ebf
movq 0x238(%rsp), %rax
movb $0x0, 0x209(%rax)
movq 0x238(%rsp), %rdi
addq $0x50, %rdi
callq 0x10a80
testb $0x1, %al
jne 0x29027
movq 0x238(%rsp), %rax
cmpl $0x4, 0x8(%rax)
jne 0x29027
movq 0x30(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x20(%rsp)
movq 0x238(%rsp), %rsi
addq $0x10, %rsi
leaq 0xd2368(%rip), %rdx     # 0xfb280
leaq 0x120(%rsp), %rdi
callq 0xc720
jmp 0x28f27
leaq 0xd1cd9(%rip), %rdx     # 0xfac07
leaq 0x140(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0xcbd0
jmp 0x28f45
leaq 0xd1bb0(%rip), %rdx     # 0xfaafc
leaq 0x160(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0xcbd0
jmp 0x28f63
movl 0x20(%rsp), %edi
leaq 0x160(%rsp), %rsi
callq 0x47ce0
jmp 0x28f76
leaq 0x160(%rsp), %rdi
callq 0x8728
leaq 0x140(%rsp), %rdi
callq 0x8728
leaq 0x120(%rsp), %rdi
callq 0x8728
jmp 0x29027
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x2929e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29015
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29008
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x8728
leaq 0x140(%rsp), %rdi
callq 0x8728
leaq 0x120(%rsp), %rdi
callq 0x8728
jmp 0x2929e
movq 0x238(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x118(%rsp)
movq $0x0, 0x110(%rsp)
movq 0x238(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x118(%rsp), %rsi
addq $0x8, %rsi
leaq 0xf0(%rsp), %rdi
callq 0x81a0
jmp 0x29070
movl 0x1c(%rsp), %edi
leaq 0xf0(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x42f30
jmp 0x2908b
leaq 0xf0(%rsp), %rdi
callq 0x8728
xorl %eax, %eax
cmpq 0x110(%rsp), %rax
je 0x29164
movq 0x110(%rsp), %rax
testb $0x1, 0x1(%rax)
je 0x29164
movq 0x30(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x118(%rsp), %rsi
addq $0x8, %rsi
leaq 0xd1b38(%rip), %rdx     # 0xfac11
leaq 0xd0(%rsp), %rdi
callq 0xc720
jmp 0x290e8
movl 0x18(%rsp), %edi
leaq 0xd0(%rsp), %rsi
callq 0x47ce0
jmp 0x290fb
leaq 0xd0(%rsp), %rdi
callq 0x8728
movl $0x1, 0xcc(%rsp)
jmp 0x29218
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x8728
jmp 0x2929e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x8728
jmp 0x2929e
movq 0x230(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0xe0, %edi
callq 0x8340
movq %rax, 0x10(%rsp)
jmp 0x29182
movb $0x1, 0x3f(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x43130
jmp 0x2919e
movq 0x118(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x43130
jmp 0x291b2
movq 0x10(%rsp), %rdi
movl $0xc, %esi
leaq 0x80(%rsp), %rdx
leaq 0x40(%rsp), %rcx
callq 0x36880
jmp 0x291d0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rax
movb $0x0, 0x3f(%rsp)
movq %rax, 0xc0(%rsp)
leaq 0xc0(%rsp), %rsi
callq 0x185b0
jmp 0x291f6
leaq 0x40(%rsp), %rdi
callq 0x1f210
leaq 0x80(%rsp), %rdi
callq 0x1f210
movl $0x0, 0xcc(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x1f210
addq $0x248, %rsp            # imm = 0x248
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29284
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29277
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x1f210
leaq 0x80(%rsp), %rdi
callq 0x1f210
testb $0x1, 0x3f(%rsp)
jne 0x2928d
jmp 0x2929c
movq 0x10(%rsp), %rdi
movl $0xe0, %esi
callq 0x8350
jmp 0x2929e
leaq 0x180(%rsp), %rdi
callq 0x1f210
movq 0x1c8(%rsp), %rdi
callq 0x8670
nopl (%rax,%rax)