// File: /workspace/github_cpp_makefile_star2_O1/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 0x1af0c
movq 0x10(%r15), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
movq %r14, %rdx
callq *0x10(%rax)
movq 0x50(%rbx), %rax
cmpq 0x58(%rbx), %rax
je 0x1b14d
cmpl $0x4, 0x8(%rbx)
jne 0x1b14d
movl 0x8(%r15), %ebp
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0xca10
leaq 0x5542b(%rip), %rsi     # 0x702f0
movq %r15, %rdi
callq 0x8590
leaq 0x55004(%rip), %rsi     # 0x6fed8
leaq 0x48(%rsp), %rdi
callq 0x8590
leaq 0x78(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1b087
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x1b08e
movq 0x90(%rbx), %rsi
movq 0x98(%rbx), %rax
movq %rax, %rdi
subq %rsi, %rdi
sarq $0x2, %rdi
cmpq %rsi, %rax
je 0x1af50
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 0x1af53
incq %r8
cmpq %r8, %r9
jne 0x1af3d
xorl %r8d, %r8d
movl 0x8c(%rbx), %eax
addl %eax, %r8d
movslq %r8d, %rcx
cmpq %rcx, %rdi
jae 0x1afb5
movl 0x8(%r15), %ebx
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x54b01(%rip), %rsi     # 0x6fa79
leaq 0x54b09(%rip), %rdx     # 0x6fa88
leaq 0x8(%rsp), %rdi
callq 0xcaa0
leaq 0x8(%rsp), %rsi
movl %ebx, %edi
callq 0x2b12a
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x1b28e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1b28e
movl -0x4(%rsi,%rcx,4), %r12d
addl 0x88(%rbx), %r12d
movq 0x18(%r15), %rcx
cmpq 0x20(%r15), %rcx
je 0x1b02a
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 0x1b02a
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 0x1aff9
cmpl %r12d, 0x88(%rbx)
jle 0x1b07b
movl 0x8(%r15), %ebp
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x54a42(%rip), %rsi     # 0x6fa89
leaq 0x54a56(%rip), %rdx     # 0x6faa4
leaq 0x8(%rsp), %rdi
callq 0xcaa0
leaq 0x8(%rsp), %rsi
movl %ebp, %edi
callq 0x2b12a
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x1b07b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movl %r12d, 0x88(%rbx)
jmp 0x1b28e
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x68(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x54ad4(%rip), %rsi     # 0x6fb85
callq 0x8590
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1b0dd
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x1b0e5
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 0x2b12a
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x1b11f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x1b136
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x1b14d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x82a0
cmpl $0x1, 0x8(%rbx)
jne 0x1b15d
cmpl $0x0, 0xc(%rbx)
je 0x1b288
leaq 0x8(%rbx), %r12
movl $0xe0, %edi
callq 0x8290
movq %rax, %r15
leaq 0xc8(%rsp), %rdi
movq %r12, %rsi
callq 0x28186
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0xca10
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 0x12ade
leaq 0x90(%rsp), %rdi
movl $0x5, -0x8(%rdi)
leaq 0xa0(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
callq 0xca10
leaq 0x88(%rsp), %rcx
movl %ebp, 0x28(%rcx)
movq %r12, 0x30(%rcx)
movl $0xffffffff, 0x38(%rcx) # imm = 0xFFFFFFFF
movb $0x1, %bpl
leaq 0xc8(%rsp), %rdx
movq %r15, %rdi
movl $0xc, %esi
callq 0x24e94
leaq 0x8(%rsp), %rsi
movq %r15, (%rsi)
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x114b8
movq 0x90(%rsp), %rdi
cmpq %r13, %rdi
je 0x1b24b
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1b267
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b288
movq 0xe0(%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 0x1b309
jmp 0x1b321
movq %rax, %rbx
movl $0x40, %esi
movq %r12, %rdi
callq 0x82a0
jmp 0x1b369
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x1b388
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x1b2ee
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1b2ee
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x1b3a9
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x1b32c
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1b32c
jmp 0x1b329
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x1b3bb
movq 0x18(%rsp), %rsi
jmp 0x1b33f
movq %rax, %rbx
jmp 0x1b3bb
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x1b3bb
movq 0x58(%rsp), %rsi
incq %rsi
jmp 0x1b3b6
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %r13, %rdi
je 0x1b36c
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1b36c
movq %rax, %rbx
movb $0x1, %bpl
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1b388
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b3a9
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x82a0
testb %bpl, %bpl
je 0x1b3bb
movl $0xe0, %esi
movq %r15, %rdi
callq 0x82a0
movq %rbx, %rdi
callq 0x8540
nop