// File: /workspace/github_cpp_makefile_star2_O3/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 0x211be(%rip), %rdx     # 0x29931
leaq 0x10(%rsp), %rdi
movq %rdx, %rsi
callq 0x6d8a
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movl $0x2, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe1ee
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x87b1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
movq %r15, 0x90(%rsp)
movq 0x70(%r14), %rax
cmpq 0x78(%r14), %rax
je 0x8b6c
movq (%r13), %rcx
movq 0x8(%r13), %rax
movl $0x1, %ebp
cmpq %rax, %rcx
je 0x87e8
movq %rcx, %rdx
imull (%rdx), %ebp
addq $0x4, %rdx
cmpq %rax, %rdx
jne 0x87dc
movl %ebp, %eax
cltd
idivl (%rcx)
movl %eax, 0x54(%rsp)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8b4f
movq %r13, 0x88(%rsp)
leaq 0x48(%r14), %r13
movl $0x0, 0x50(%rsp)
leaq 0x30(%rsp), %r15
cmpl $0x5, 0x98(%rdi)
jne 0x892a
movq 0x78(%r14), %rax
subq 0x70(%r14), %rax
cmpq $0x4, %rax
jne 0x8855
movq %r15, %rdi
leaq 0x20160(%rip), %rsi     # 0x2899c
movq %r13, %rdx
callq 0x11c02
movq %r15, %rdi
leaq 0x201b3(%rip), %rsi     # 0x28a01
callq 0x5510
jmp 0x8885
movl %ebp, %eax
cltd
idivl 0x54(%rsp)
testl %edx, %edx
je 0x898f
movq %r15, %rdi
leaq 0x2014d(%rip), %rsi     # 0x289bb
movq %r13, %rdx
callq 0x11c02
movq %r15, %rdi
leaq 0x20181(%rip), %rsi     # 0x28a01
callq 0x5510
movq %rbx, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x88a8
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x88ae
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 0x88e2
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5240
movq 0x10(%rsp), %rdi
leaq 0x2c9c2(%rip), %rax     # 0x352b0
movl (%rax), %esi
callq 0x8030
movq (%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, (%rsp)
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8918
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
movq (%rsp), %rdi
testq %rdi, %rdi
jne 0x8817
jmp 0x8b4f
movq (%rdi), %rax
callq *0x18(%rax)
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
cmpb $0x1, 0x68(%r14)
jne 0x8963
movq (%rsp), %rax
cmpl $0x2, 0x98(%rax)
je 0x8963
leaq 0x2c95b(%rip), %rax     # 0x352b0
movl (%rax), %esi
leaq 0x2001f(%rip), %rdi     # 0x2897d
callq 0x8030
testl %ebp, %ebp
jle 0x8c06
decl %ebp
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x8a16
movq (%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x8b3e
leaq 0x58(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq %r12, 0x8(%rsp)
callq 0x11d44
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rdx
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x89c6
subq %rsi, %rdx
callq 0x5450
movq 0x60(%rsp), %rdx
addq $-0x4, %rdx
movq %rdx, 0x60(%rsp)
movq (%rsp), %rax
movq 0x48(%rax), %rcx
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
leaq 0x58(%rsp), %rdx
callq 0x872a
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
movq %rcx, %rax
subq %rdx, %rax
shrq $0x3, %rax
subl %eax, %ebp
js 0x8a26
movq 0x8(%r12), %rsi
movq %r12, %rdi
callq 0x12b66
movl %ebp, %r12d
jmp 0x8afd
movq %r12, %rdi
movq %rsp, %rdx
callq 0x12a2a
jmp 0x8b3e
movq %r15, %rdi
leaq 0x1ffa6(%rip), %rsi     # 0x289d6
movq %r13, %rdx
callq 0x11c02
movq %r15, %rdi
leaq 0x1ffbf(%rip), %rsi     # 0x28a01
callq 0x5510
movq %rbx, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8a6a
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x8a70
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 0x8aa4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5240
movq 0x10(%rsp), %rdi
leaq 0x2c800(%rip), %rax     # 0x352b0
movl (%rax), %esi
callq 0x8030
movq 0x70(%rsp), %rdx
movq 0x78(%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 0x12b66
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8af7
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
movb $0x1, %al
movl %eax, 0x50(%rsp)
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8b17
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x5240
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x8b2e
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x5240
testl %ebp, %ebp
js 0x8c4e
movl %r12d, %ebp
movq 0x8(%rsp), %r12
movq (%rsp), %rax
movq 0x40(%rax), %rdi
movq %rdi, (%rsp)
jmp 0x891c
movq 0x8(%r12), %rsi
movslq %ebp, %rdx
leaq 0x90(%rsp), %rcx
movq %r12, %rdi
callq 0x12d22
jmp 0x8bf1
movq (%rsp), %rdi
cmpl $0x5, 0x98(%rdi)
jne 0x8b92
leaq 0x2c730(%rip), %rax     # 0x352b0
movl (%rax), %esi
leaq 0x1fddd(%rip), %rdi     # 0x28966
callq 0x8030
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
cmpb $0x1, 0x68(%r14)
jne 0x8bcb
movq (%rsp), %rax
cmpl $0x2, 0x98(%rax)
je 0x8bcb
leaq 0x2c6f3(%rip), %rax     # 0x352b0
movl (%rax), %esi
leaq 0x1fdb7(%rip), %rdi     # 0x2897d
callq 0x8030
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x8be6
movq (%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x8bf1
movq %rsp, %rdx
movq %r12, %rdi
callq 0x12a2a
movq %r12, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1fdc9(%rip), %rsi     # 0x289d6
leaq 0x30(%rsp), %rdi
movq %r13, %rdx
callq 0x11c02
leaq 0x1fde0(%rip), %rsi     # 0x28a01
leaq 0x30(%rsp), %rdi
callq 0x5510
movq %rbx, 0x10(%rsp)
movq (%rax), %rdi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdi
je 0x8c6d
movq %rdi, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x8c76
testb $0x1, 0x50(%rsp)
movq 0x8(%rsp), %r12
jne 0x8bf1
movq (%r12), %rdi
testq %rdi, %rdi
je 0x8bf1
movq 0x10(%r12), %rsi
subq %rdi, %rsi
jmp 0x8cd6
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq %rbx, %rdi
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x30(%rsp), %rax
leaq 0x40(%rsp), %rcx
cmpq %rcx, %rax
je 0x8cb2
movq 0x40(%rsp), %rsi
incq %rsi
movq %rax, %rdi
callq 0x5240
movq 0x10(%rsp), %rdi
leaq 0x2c5f7(%rip), %rax     # 0x352b0
movl (%rax), %esi
callq 0x8030
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8bf1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
jmp 0x8bf1
jmp 0x8da0
jmp 0x8d96
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8d24
movq 0x20(%rsp), %rsi
jmp 0x8d15
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8d24
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5240
jmp 0x8d24
jmp 0x8d21
movq %rax, %r14
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8d43
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x5240
jmp 0x8d43
movq %rax, %r14
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x8dc4
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
jmp 0x8dbf
jmp 0x8d9b
jmp 0x8d96
jmp 0x8d96
movq %r12, 0x8(%rsp)
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8d86
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5240
jmp 0x8d86
movq %r12, 0x8(%rsp)
movq %rax, %r14
movl $0xa0, %esi
movq %r15, %rdi
jmp 0x8dbf
jmp 0x8d96
jmp 0x8da0
jmp 0x8d96
movq %r12, 0x8(%rsp)
movq %rax, %r14
jmp 0x8dc4
movq %r12, 0x8(%rsp)
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8dc4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5240
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x8de2
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x5240
movq %r14, %rdi
callq 0x54c0