// File: /workspace/github_cpp_makefile_star2_O2/lhydave[P]SysYCompilerLab/front/node.cpp
// Function: sysY_AST::vardef_node::set_val(std::vector<int, std::allocator<int>>&, sysY_AST::exp_node*)
vector<exp_node *> vardef_node::set_val(vector<int> &_dim, exp_node *first_val)
{
	vector<exp_node *> ret;
	auto zero_exp = new exp_node(EXP_NUM, "", 0);
	if (dim.empty()) // an expression
	{
		if (first_val->exp_type ==
			EXP_INITVAL) // an expression should not have a child
			yyerror("expected an expression");
		first_val->reduce();
		first_val->new_temp();
		if (is_const && first_val->exp_type != EXP_NUM)
			yyerror("expected a constant expression");
		ret.push_back(first_val);
		return ret;
	}
	// number of entries to fill
	auto to_fill =
		std::accumulate(_dim.begin(), _dim.end(), 1, std::multiplies<int>());
	auto next_size = to_fill / _dim[0];
	// an array
	while (first_val)
	{
		if (first_val->exp_type == EXP_INITVAL) // traverse the child
		{
			if (dim.size() == 1)
			{
				auto msg = "too deep list initializer in '" + name + "'";
				yyerror(msg.c_str());
				first_val = first_val->next;
				continue;
			}
			if (to_fill % next_size != 0)
			{
				auto msg = "unaligned initializer in '" + name + "'";
				yyerror(msg.c_str());
				first_val = first_val->next;
				continue;
			}
			auto down_dim = _dim;
			down_dim.erase(down_dim.begin());
			auto res = set_val(down_dim, first_val->child);
			to_fill -= res.size();
			if (to_fill < 0)
			{
				auto msg =
					"excessive elements in array initializer of '" + name + "'";
				yyerror(msg.c_str());
				to_fill += res.size();
				ret.insert(ret.end(), res.begin(), res.begin() + to_fill);
				return ret;
			}
			ret.insert(ret.end(), res.begin(), res.end());
		}
		else // an expression
		{
			first_val->reduce();
			first_val->new_temp();
			if (is_const && first_val->exp_type != EXP_NUM)
				yyerror("expected a constant expression");
			to_fill--;
			if (to_fill < 0)
			{
				auto msg =
					"excessive elements in array initializer of '" + name + "'";
				yyerror(msg.c_str());
				to_fill++;
				return ret;
			}
			ret.push_back(first_val);
		}
		first_val = first_val->next;
	}
	ret.insert(ret.end(), to_fill, zero_exp); // all zero filled
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq %rcx, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movl $0xa0, %edi
callq 0x5240
movq %rax, %r12
leaq 0x179c3(%rip), %rsi     # 0x1f91c
leaq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x68d2
pushq $0x2
popq %rsi
leaq 0x18(%rsp), %rdx
movq %r12, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xa466
leaq 0x18(%rsp), %rdi
callq 0x5548
movq %r12, 0x90(%rsp)
movq 0x70(%r14), %rax
cmpq 0x78(%r14), %rax
je 0x8226
movq (%r15), %rcx
movq 0x8(%r15), %rax
pushq $0x1
popq %rbp
movq %rcx, %rdx
cmpq %rax, %rdx
je 0x7fbb
imull (%rdx), %ebp
addq $0x4, %rdx
jmp 0x7fad
movl %ebp, %eax
cltd
idivl (%rcx)
movl %eax, 0x3c(%rsp)
leaq 0x48(%r14), %rax
movq %rax, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
leaq 0x40(%rsp), %r13
leaq 0x78(%rsp), %r12
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8292
cmpl $0x5, 0x98(%rdi)
jne 0x809b
movq 0x78(%r14), %rax
subq 0x70(%r14), %rax
cmpq $0x4, %rax
je 0x819e
movl %ebp, %eax
cltd
idivl 0x3c(%rsp)
testl %edx, %edx
jne 0x81c8
movq %r12, %rdi
movq %r15, %rsi
callq 0xc772
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rdx
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x804b
subq %rsi, %rdx
callq 0x5450
movq 0x80(%rsp), %rdx
addq $-0x4, %rdx
movq %rdx, 0x80(%rsp)
movq (%rsp), %rax
movq 0x48(%rax), %rcx
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x7f1c
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq %rcx, %rax
subq %rdx, %rax
shrq $0x3, %rax
subl %eax, %ebp
js 0x80f1
movq 0x8(%rbx), %rsi
movq %rbx, %rdi
callq 0xc7c0
movl %ebp, %r13d
jmp 0x816b
movq (%rdi), %rax
callq *0x18(%rax)
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
cmpb $0x1, 0x68(%r14)
jne 0x80d4
movq (%rsp), %rax
cmpl $0x2, 0x98(%rax)
je 0x80d4
leaq 0x261f2(%rip), %rax     # 0x2e2b8
movl (%rax), %esi
leaq 0x16877(%rip), %rdi     # 0x1e946
callq 0x79c8
testl %ebp, %ebp
jle 0x82ab
movq %rbx, %rdi
movq %rsp, %rsi
callq 0xc754
decl %ebp
movl %ebp, %r13d
jmp 0x8185
movq %r13, %rdi
leaq 0x168a4(%rip), %rsi     # 0x1e99f
movq 0x10(%rsp), %rdx
callq 0xc598
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
leaq 0x168b6(%rip), %rdx     # 0x1e9ca
callq 0xc579
movq %r13, %rdi
callq 0x5548
movq 0x18(%rsp), %rdi
leaq 0x2618b(%rip), %rax     # 0x2e2b8
movl (%rax), %esi
callq 0x79c8
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %r13
subq %rdx, %r13
shrq $0x3, %r13
addl %ebp, %r13d
movq 0x8(%rbx), %rsi
movslq %r13d, %rax
leaq (%rdx,%rax,8), %rcx
movq %rbx, %rdi
callq 0xc7c0
leaq 0x18(%rsp), %rdi
callq 0x5548
movb $0x1, %al
movl %eax, 0xc(%rsp)
leaq 0x60(%rsp), %rdi
callq 0xcbde
movq %r12, %rdi
callq 0xcbaa
testl %ebp, %ebp
js 0x8301
movq (%rsp), %rax
movq 0x40(%rax), %rdi
movq %rdi, (%rsp)
movl %r13d, %ebp
leaq 0x40(%rsp), %r13
jmp 0x7fe3
movq %r13, %rdi
leaq 0x167bd(%rip), %rsi     # 0x1e965
movq 0x10(%rsp), %rdx
callq 0xc598
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
leaq 0x16809(%rip), %rdx     # 0x1e9ca
callq 0xc579
jmp 0x81f0
movq %r13, %rdi
leaq 0x167b2(%rip), %rsi     # 0x1e984
movq 0x10(%rsp), %rdx
callq 0xc598
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
leaq 0x167df(%rip), %rdx     # 0x1e9ca
callq 0xc579
movq %r13, %rdi
callq 0x5548
movq 0x18(%rsp), %rdi
leaq 0x260b4(%rip), %rax     # 0x2e2b8
movl (%rax), %esi
callq 0x79c8
movq (%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, (%rsp)
leaq 0x18(%rsp), %rdi
callq 0x5548
jmp 0x7fdf
movq (%rsp), %rdi
cmpl $0x5, 0x98(%rdi)
jne 0x824c
leaq 0x2607e(%rip), %rax     # 0x2e2b8
movl (%rax), %esi
leaq 0x166ec(%rip), %rdi     # 0x1e92f
callq 0x79c8
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
cmpb $0x1, 0x68(%r14)
jne 0x8285
movq (%rsp), %rax
cmpl $0x2, 0x98(%rax)
je 0x8285
leaq 0x26041(%rip), %rax     # 0x2e2b8
movl (%rax), %esi
leaq 0x166c6(%rip), %rdi     # 0x1e946
callq 0x79c8
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xc754
jmp 0x8310
movq 0x8(%rbx), %rsi
movslq %ebp, %rdx
leaq 0x90(%rsp), %rcx
movq %rbx, %rdi
callq 0xc7e0
jmp 0x8310
leaq 0x166ed(%rip), %rsi     # 0x1e99f
leaq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rdx
callq 0xc598
leaq 0x16702(%rip), %rdx     # 0x1e9ca
leaq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xc579
leaq 0x40(%rsp), %rdi
callq 0x5548
leaq 0x18(%rsp), %r14
movq (%r14), %rdi
leaq 0x25fc8(%rip), %rax     # 0x2e2b8
movl (%rax), %esi
callq 0x79c8
movq %r14, %rdi
callq 0x5548
jmp 0x8310
testb $0x1, 0xc(%rsp)
jne 0x8310
movq %rbx, %rdi
callq 0xcbde
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x832d
jmp 0x839e
jmp 0x832d
jmp 0x839e
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x5548
jmp 0x83a1
jmp 0x839e
jmp 0x839e
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x5548
jmp 0x8352
movq %rax, %r14
movl $0xa0, %esi
movq %r12, %rdi
callq 0x5260
jmp 0x83a1
movq %rax, %r14
leaq 0x18(%rsp), %rdi
jmp 0x8373
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x5548
jmp 0x8381
jmp 0x837e
jmp 0x839e
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0xcbde
jmp 0x8390
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0xcbaa
jmp 0x83a1
jmp 0x839e
movq %rax, %r14
movq %rbx, %rdi
callq 0xcbde
movq %r14, %rdi
callq 0x54c0
nop