// File: /workspace/github_cpp_makefile_star2_O3/luooofan[P]hblzbd_compiler/src/generate_ir.cpp
// Function: ast::ArrayInitVal::GenerateIR(ir::ContextInfo&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
void ArrayInitVal::GenerateIR(ir::ContextInfo &ctx, std::vector<ir::IR *> &gIRList) {
  if (this->is_exp_) {
    this->value_->GenerateIR(ctx, gIRList);
    CHECK_OPN_INT("exp")
    // genir([]=,expvalue,-,arrayname offset)
    if (ctx.opn_.type_ != OpnType::Imm || 0 != ctx.opn_.imm_num_) {
      gIRList.push_back(new ir::IR{
          IROpKind::/*OFFSET_*/ ASSIGN,
          ctx.opn_,
          {OpnType::Array, ctx.array_name_, ctx.scope_id_, new ir::Opn(OpnType::Imm, ctx.array_offset_ * 4)}});
    }
    ctx.array_offset_ += 1;
  } else {
    // 此时该结点表示一对大括号 {}
    int &offset = ctx.array_offset_;
    int &brace_num = ctx.brace_num_;

    // 根据offset和brace_num算出finaloffset
    int temp_level = 0;
    const auto &dim_total_num = ctx.dim_total_num_;
    for (int i = 0; i < dim_total_num.size(); ++i) {
      if (offset % dim_total_num[i] == 0) {
        temp_level = i;
        break;
      }
    }
    temp_level += brace_num;

    if (temp_level > dim_total_num.size()) {  // 语义错误 大括号过多
      ir::SemanticError(this->line_no_, "多余大括号");
    } else {
      int final_offset = offset + dim_total_num[temp_level - 1];
      if (!this->initval_list_.empty()) {
        ++brace_num;
        this->initval_list_[0]->GenerateIR(ctx, gIRList);

        for (int i = 1; i < this->initval_list_.size(); ++i) {
          brace_num = 1;
          this->initval_list_[i]->GenerateIR(ctx, gIRList);
        }
      }
      if (offset > final_offset) {
        ir::SemanticError(this->line_no_, "初始值设定项值太多");
      }
      offset = final_offset;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
cmpb $0x1, 0xc(%rdi)
jne 0x1add1
movq 0x10(%r15), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
movq %r14, %rdx
callq *0x10(%rax)
movq 0x50(%rbx), %rax
cmpq 0x58(%rbx), %rax
setne %cl
leaq 0x8(%rbx), %r12
movl 0x8(%rbx), %eax
cmpl $0x4, %eax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x1b01d
movl 0x8(%r15), %ebp
leaq 0x38(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0xc6dc
leaq 0x54569(%rip), %rsi     # 0x6f2f0
movq %r15, %rdi
callq 0x8590
leaq 0x54142(%rip), %rsi     # 0x6eed8
leaq 0x28(%rsp), %rdi
callq 0x8590
leaq 0x78(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1af4c
movq %rsi, %r15
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x1af55
movq 0x90(%rbx), %rsi
movq 0x98(%rbx), %rax
movq %rax, %rdi
subq %rsi, %rdi
sarq $0x2, %rdi
cmpq %rsi, %rax
je 0x1ae15
movl 0x88(%rbx), %ecx
cmpq $0x1, %rdi
movq %rdi, %r9
adcq $0x0, %r9
xorl %r8d, %r8d
movl %ecx, %eax
cltd
idivl (%rsi,%r8,4)
testl %edx, %edx
je 0x1ae18
incq %r8
cmpq %r8, %r9
jne 0x1ae02
xorl %r8d, %r8d
movl 0x8c(%rbx), %eax
addl %eax, %r8d
movslq %r8d, %rcx
cmpq %rcx, %rdi
jae 0x1ae7a
movl 0x8(%r15), %ebx
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x53c3c(%rip), %rsi     # 0x6ea79
leaq 0x53c44(%rip), %rdx     # 0x6ea88
leaq 0x8(%rsp), %rdi
callq 0xc772
leaq 0x8(%rsp), %rsi
movl %ebx, %edi
callq 0x2b6aa
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x1b159
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1b159
movl -0x4(%rsi,%rcx,4), %r12d
addl 0x88(%rbx), %r12d
movq 0x18(%r15), %rcx
cmpq 0x20(%r15), %rcx
je 0x1aeef
incl %eax
movl %eax, 0x8c(%rbx)
movq (%rcx), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
movq %r14, %rdx
callq *0x10(%rax)
movq 0x18(%r15), %rax
movq 0x20(%r15), %rcx
subq %rax, %rcx
cmpq $0x9, %rcx
jb 0x1aeef
movl $0x1, %r13d
movl $0x1, 0x8c(%rbx)
movq (%rax,%r13,8), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
movq %r14, %rdx
callq *0x10(%rax)
incq %r13
movq 0x18(%r15), %rax
movq 0x20(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
ja 0x1aebe
cmpl %r12d, 0x88(%rbx)
jle 0x1af40
movl 0x8(%r15), %ebp
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x53b7d(%rip), %rsi     # 0x6ea89
leaq 0x53b91(%rip), %rdx     # 0x6eaa4
leaq 0x8(%rsp), %rdi
callq 0xc772
leaq 0x8(%rsp), %rsi
movl %ebp, %edi
callq 0x2b6aa
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x1af40
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movl %r12d, 0x88(%rbx)
jmp 0x1b159
movups (%rcx), %xmm0
movq %rsi, %r15
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x68(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x53c0d(%rip), %rsi     # 0x6eb85
callq 0x8590
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1afa4
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x1afac
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0x8(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl %ebp, %edi
callq 0x2b6aa
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x1afe6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
leaq 0x38(%rsp), %r15
je 0x1b002
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x1b019
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
movl (%r12), %eax
cmpl $0x1, %eax
jne 0x1b02c
cmpl $0x0, 0xc(%rbx)
je 0x1b153
movl $0xe0, %edi
callq 0x8290
movq %rax, %r15
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0x28816
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0xc6dc
movl (%rbx), %ebp
movl $0x40, %edi
callq 0x8290
movq %rax, %r12
movl 0x88(%rbx), %edx
shll $0x2, %edx
movq %rax, %rdi
movl $0x1, %esi
callq 0x1279c
leaq 0xd0(%rsp), %rdi
movl $0x5, -0x8(%rdi)
leaq 0xe0(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
callq 0xc6dc
leaq 0xc8(%rsp), %rcx
movl %ebp, 0x28(%rcx)
movq %r12, 0x30(%rcx)
movl $0xffffffff, 0x38(%rcx) # imm = 0xFFFFFFFF
movb $0x1, %bpl
leaq 0x88(%rsp), %rdx
movq %r15, %rdi
movl $0xc, %esi
callq 0x25560
leaq 0x8(%rsp), %rsi
movq %r15, (%rsi)
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x11182
movq 0xd0(%rsp), %rdi
cmpq %r13, %rdi
je 0x1b116
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x1b132
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b153
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x82a0
incl 0x88(%rbx)
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1b1f7
jmp 0x1b226
movq %rax, %rbx
movl $0x40, %esi
movq %r12, %rdi
callq 0x82a0
jmp 0x1b26e
movq %rax, %rbx
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b2b3
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1b2b3
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x1b1de
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1b1de
movq %rax, %rbx
jmp 0x1b2b3
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x1b212
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1b212
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x1b2c0
movq 0x18(%rsp), %rsi
jmp 0x1b244
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
jne 0x1b23f
jmp 0x1b2c0
movq %rax, %rbx
jmp 0x1b2c0
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x1b2c0
movq 0x38(%rsp), %rsi
incq %rsi
jmp 0x1b2bb
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
cmpq %r13, %rdi
je 0x1b271
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1b271
movq %rax, %rbx
movb $0x1, %bpl
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x1b28d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b2ae
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x82a0
testb %bpl, %bpl
je 0x1b2c0
movl $0xe0, %esi
movq %r15, %rdi
callq 0x82a0
movq %rbx, %rdi
callq 0x8540