// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
movq %rsi, %r14
movq %rdi, %r12
movq %rcx, (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0xa0, %edi
callq 0x5220
movq %rax, %r15
leaq 0x20(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x20fe4(%rip), %rdx     # 0x298d9
leaq 0x10(%rsp), %rdi
movq %rdx, %rsi
callq 0x6ef6
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movl $0x2, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe4d0
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8933
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
movq %r15, 0x90(%rsp)
movq 0x70(%r14), %rax
cmpq 0x78(%r14), %rax
je 0x8ce6
movq (%r13), %rcx
movq 0x8(%r13), %rax
movl $0x1, %ebp
cmpq %rax, %rcx
je 0x896a
movq %rcx, %rdx
imull (%rdx), %ebp
addq $0x4, %rdx
cmpq %rax, %rdx
jne 0x895e
movl %ebp, %eax
cltd
idivl (%rcx)
movl %eax, 0x54(%rsp)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8cc9
movq %r13, 0x88(%rsp)
leaq 0x48(%r14), %r13
movl $0x0, 0x50(%rsp)
leaq 0x30(%rsp), %r15
cmpl $0x5, 0x98(%rdi)
jne 0x8aac
movq 0x78(%r14), %rax
subq 0x70(%r14), %rax
cmpq $0x4, %rax
jne 0x89d7
movq %r15, %rdi
leaq 0x1ffa7(%rip), %rsi     # 0x28965
movq %r13, %rdx
callq 0x11eb4
movq %r15, %rdi
leaq 0x1fffa(%rip), %rsi     # 0x289ca
callq 0x5510
jmp 0x8a07
movl %ebp, %eax
cltd
idivl 0x54(%rsp)
testl %edx, %edx
je 0x8b11
movq %r15, %rdi
leaq 0x1ff94(%rip), %rsi     # 0x28984
movq %r13, %rdx
callq 0x11eb4
movq %r15, %rdi
leaq 0x1ffc8(%rip), %rsi     # 0x289ca
callq 0x5510
movq %rbx, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8a2a
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x8a30
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8a64
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5240
movq 0x10(%rsp), %rdi
leaq 0x2c840(%rip), %rax     # 0x352b0
movl (%rax), %esi
callq 0x81dc
movq (%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, (%rsp)
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8a9a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
movq (%rsp), %rdi
testq %rdi, %rdi
jne 0x8999
jmp 0x8cc9
movq (%rdi), %rax
callq *0x18(%rax)
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
cmpb $0x1, 0x68(%r14)
jne 0x8ae5
movq (%rsp), %rax
cmpl $0x2, 0x98(%rax)
je 0x8ae5
leaq 0x2c7d9(%rip), %rax     # 0x352b0
movl (%rax), %esi
leaq 0x1fe66(%rip), %rdi     # 0x28946
callq 0x81dc
testl %ebp, %ebp
jle 0x8d80
decl %ebp
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x8b90
movq (%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x8cb8
leaq 0x70(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq %r12, 0x8(%rsp)
callq 0x11ff6
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rdx
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x8b43
subq %rsi, %rdx
callq 0x5450
addq $-0x4, 0x78(%rsp)
movq (%rsp), %rax
movq 0x48(%rax), %rcx
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
leaq 0x70(%rsp), %rdx
callq 0x88ac
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq %rcx, %rax
subq %rdx, %rax
shrq $0x3, %rax
subl %eax, %ebp
js 0x8ba0
movq 0x8(%r12), %rsi
movq %r12, %rdi
callq 0x12a94
movl %ebp, %r12d
jmp 0x8c77
movq %r12, %rdi
movq %rsp, %rdx
callq 0x12958
jmp 0x8cb8
movq %r15, %rdi
leaq 0x1fdf5(%rip), %rsi     # 0x2899f
movq %r13, %rdx
callq 0x11eb4
movq %r15, %rdi
leaq 0x1fe0e(%rip), %rsi     # 0x289ca
callq 0x5510
movq %rbx, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8be4
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x8bea
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8c1e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5240
movq 0x10(%rsp), %rdi
leaq 0x2c686(%rip), %rax     # 0x352b0
movl (%rax), %esi
callq 0x81dc
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %r12
subq %rdx, %r12
shrq $0x3, %r12
addl %ebp, %r12d
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rsi
movslq %r12d, %rax
leaq (%rdx,%rax,8), %rcx
callq 0x12a94
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8c71
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
movb $0x1, %al
movl %eax, 0x50(%rsp)
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x8c8e
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x5240
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8ca8
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x5240
testl %ebp, %ebp
js 0x8dc8
movl %r12d, %ebp
movq 0x8(%rsp), %r12
movq (%rsp), %rax
movq 0x40(%rax), %rdi
movq %rdi, (%rsp)
jmp 0x8a9e
movq 0x8(%r12), %rsi
movslq %ebp, %rdx
leaq 0x90(%rsp), %rcx
movq %r12, %rdi
callq 0x12c88
jmp 0x8d6b
movq (%rsp), %rax
cmpl $0x5, 0x98(%rax)
jne 0x8d08
leaq 0x2c5b6(%rip), %rax     # 0x352b0
movl (%rax), %esi
leaq 0x1fc2c(%rip), %rdi     # 0x2892f
callq 0x81dc
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
cmpb $0x1, 0x68(%r14)
jne 0x8d45
movq (%rsp), %rax
cmpl $0x2, 0x98(%rax)
je 0x8d45
leaq 0x2c579(%rip), %rax     # 0x352b0
movl (%rax), %esi
leaq 0x1fc06(%rip), %rdi     # 0x28946
callq 0x81dc
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x8d60
movq (%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x8d6b
movq %rsp, %rdx
movq %r12, %rdi
callq 0x12958
movq %r12, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1fc18(%rip), %rsi     # 0x2899f
leaq 0x30(%rsp), %rdi
movq %r13, %rdx
callq 0x11eb4
leaq 0x1fc2f(%rip), %rsi     # 0x289ca
leaq 0x30(%rsp), %rdi
callq 0x5510
movq %rbx, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8de7
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x8ded
testb $0x1, 0x50(%rsp)
movq 0x8(%rsp), %r12
jne 0x8d6b
movq (%r12), %rdi
testq %rdi, %rdi
je 0x8d6b
movq 0x10(%r12), %rsi
subq %rdi, %rsi
jmp 0x8e4a
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8e21
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5240
movq 0x10(%rsp), %rdi
leaq 0x2c483(%rip), %rax     # 0x352b0
movl (%rax), %esi
callq 0x81dc
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8d6b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
jmp 0x8d6b
jmp 0x8f14
jmp 0x8f0a
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8e98
movq 0x20(%rsp), %rsi
jmp 0x8e89
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8e98
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5240
jmp 0x8e98
jmp 0x8e95
movq %rax, %r14
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x8eb4
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x5240
jmp 0x8eb4
movq %rax, %r14
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8f38
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
jmp 0x8f33
jmp 0x8f0f
jmp 0x8f0a
jmp 0x8f0a
movq %r12, 0x8(%rsp)
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8efa
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
jmp 0x8efa
movq %r12, 0x8(%rsp)
movq %rax, %r14
movl $0xa0, %esi
movq %r15, %rdi
jmp 0x8f33
jmp 0x8f0a
jmp 0x8f14
jmp 0x8f0a
movq %r12, 0x8(%rsp)
movq %rax, %r14
jmp 0x8f38
movq %r12, 0x8(%rsp)
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8f38
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5240
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x8f56
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x5240
movq %r14, %rdi
callq 0x54c0