// File: luooofan[P]hblzbd_compiler/src/generate_ir.cpp
// Function: ast::Identifier::GenerateIR(ir::ContextInfo&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
void Identifier::GenerateIR(ir::ContextInfo &ctx, std::vector<ir::IR *> &gIRList) {
  bool is_assigned = ctx.is_assigned_;
  ctx.is_assigned_ = false;
  ir::SymbolTableItem *s = nullptr;
  int scope_id = ir::FindSymbol(ctx.scope_id_, name_, s);
  if (!s) {
    ir::SemanticError(line_no_, name_ + ": undefined variable");
  }

  // NOTE: 常量直接替换为立即数 作用域为当前作用域
  if (!is_assigned && s->is_const_ && !s->is_array_) {
    ctx.opn_ = ir::Opn(OpnType::Imm, s->initval_[0]);
    ctx.shape_.clear();
  } else {
    ctx.shape_ = s->shape_;
    ctx.opn_ = ir::Opn(OpnType::Var, name_, scope_id);
  }
}

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x160(%rsp)
movq %rsi, 0x158(%rsp)
movq %rdx, 0x150(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x158(%rsp), %rcx
movb 0x209(%rcx), %cl
andb $0x1, %cl
movb %cl, 0x14f(%rsp)
movq 0x158(%rsp), %rcx
movb $0x0, 0x209(%rcx)
movq $0x0, 0x140(%rsp)
movq 0x158(%rsp), %rcx
movl (%rcx), %ecx
movl %ecx, 0x34(%rsp)
movq 0x10(%rax), %rsi
leaq 0x118(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x81a0
movl 0x34(%rsp), %edi
movq 0x38(%rsp), %rsi
leaq 0x140(%rsp), %rdx
callq 0x42f30
movl %eax, 0x44(%rsp)
jmp 0x2225f
leaq 0x118(%rsp), %rdi
callq 0x8728
movl 0x44(%rsp), %eax
movl %eax, 0x13c(%rsp)
cmpq $0x0, 0x140(%rsp)
jne 0x2231a
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
movl %ecx, 0x1c(%rsp)
movq 0x10(%rax), %rsi
leaq 0xd86cf(%rip), %rdx     # 0xfa96c
leaq 0xe8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0xc720
movl 0x1c(%rsp), %edi
movq 0x20(%rsp), %rsi
callq 0x47ce0
jmp 0x222bf
leaq 0xe8(%rsp), %rdi
callq 0x8728
jmp 0x2231a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x8728
jmp 0x2249f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x8728
jmp 0x2249f
testb $0x1, 0x14f(%rsp)
jne 0x223da
movq 0x140(%rsp), %rax
testb $0x1, 0x1(%rax)
je 0x223da
movq 0x140(%rsp), %rax
testb $0x1, (%rax)
jne 0x223da
movq 0x140(%rsp), %rdi
addq $0x38, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10a60
movl (%rax), %edx
leaq 0xa8(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movl $0x1, %esi
callq 0x1f160
movq 0x10(%rsp), %rsi
movq 0x158(%rsp), %rdi
addq $0x8, %rdi
callq 0x433c0
jmp 0x22391
leaq 0xa8(%rsp), %rdi
callq 0x1f210
movq 0x158(%rsp), %rdi
addq $0x50, %rdi
callq 0x361a0
jmp 0x22497
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x1f210
jmp 0x2249f
movq 0x140(%rsp), %rsi
addq $0x8, %rsi
movq 0x158(%rsp), %rdi
addq $0x50, %rdi
callq 0x361c0
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rsi
leaq 0x48(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x81a0
movq 0x8(%rsp), %rdx
movl 0x13c(%rsp), %ecx
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
callq 0x36480
jmp 0x22429
movq 0x158(%rsp), %rdi
addq $0x8, %rdi
leaq 0x68(%rsp), %rsi
callq 0x433c0
jmp 0x22441
leaq 0x68(%rsp), %rdi
callq 0x1f210
leaq 0x48(%rsp), %rdi
callq 0x8728
jmp 0x22497
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x2248b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x1f210
leaq 0x48(%rsp), %rdi
callq 0x8728
jmp 0x2249f
addq $0x168, %rsp            # imm = 0x168
retq
movq 0x110(%rsp), %rdi
callq 0x8670
nopl (%rax)