// File: lhydave[P]SysYCompilerLab/front/node.cpp
// Function: sysY_AST::array_exp_node::reduce()
void array_exp_node::reduce()
{
	if (!sysy_name.empty())
		return;
	var_entry query;
	if (!find_var(sysy_array_name, query)) // not defined
	{
		string msg = "identifier '" + sysy_array_name + "' is not defined";
		yyerror(msg.c_str());
		return;
	}
	if (exp_type == EXP_NUM) // a number
		return;
	if (exp_type == EXP_VAR) // a variable
	{
		if (query.is_const) // a constant
		{
			exp_type = EXP_NUM;
			num = query.val[0];
			eeyore_name = to_string(num);
		}
		else
			eeyore_name = query.eeyore_name;
		return;
	}
	// an array
	if (sysy_idx.size() > query.dim.size()) // an error
	{
		yyerror("subscripted value is not an array");
		sysy_name = "?array";
		return;
	}
	else if (sysy_idx.size() == query.dim.size()) // an array
	{
		eeyore_exp = idx_open(sysy_idx, query);
		eeyore_exp = new arith_exp_node(
			MUL, eeyore_exp, new exp_node(EXP_NUM, "", int_size));
		auto array_id = new exp_node(EXP_VAR, sysy_array_name);
		eeyore_exp = new arith_exp_node(MEM, array_id, eeyore_exp);
	}
	else // a pointer
	{
		auto array_id = new exp_node(EXP_VAR, sysy_array_name);
		exp_type = EXP_PTR;
		int steplen = int_size;
		auto start_dim = sysy_idx.size();
		auto dim_size = query.dim.size();
		for (auto i = start_dim; i < dim_size; i++)
			steplen *= query.dim[i];
		eeyore_exp = idx_open(sysy_idx, query);
		eeyore_exp = new arith_exp_node(
			MUL, eeyore_exp, new exp_node(EXP_NUM, "", steplen));
		eeyore_exp = new arith_exp_node(ADD, array_id, eeyore_exp);
	}
	eeyore_exp->reduce();
	code = eeyore_exp->code;
	eeyore_name = eeyore_exp->eeyore_name;
	sysy_name = "?array";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x180(%rbp)
addq $0x50, %rdi
callq 0x55b0
testb $0x1, %al
jne 0xf96c
jmp 0x10258
leaq -0x80(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x13220
movq -0x180(%rbp), %rdi
movq -0x190(%rbp), %rsi
addq $0xc0, %rdi
callq 0x1c4c0
movb %al, -0x181(%rbp)
jmp 0xf99e
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0xfa6b
jmp 0xf9ae
movq -0x180(%rbp), %rdx
addq $0xc0, %rdx
leaq 0x3e325(%rip), %rsi     # 0x4dce8
leaq -0xd0(%rbp), %rdi
callq 0x12d60
jmp 0xf9d1
leaq 0x3e31d(%rip), %rdx     # 0x4dcf5
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x12d10
jmp 0xf9ed
leaq -0xd0(%rbp), %rdi
callq 0x56c0
leaq -0xb0(%rbp), %rdi
callq 0x5160
movq %rax, %rdi
leaq 0x62961(%rip), %rax     # 0x72370
movl (%rax), %esi
callq 0xa6c0
movl $0x1, -0xd4(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x56c0
jmp 0x1024f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x10261
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x56c0
jmp 0x10261
movq -0x180(%rbp), %rax
cmpl $0x2, 0x98(%rax)
jne 0xfa8a
movl $0x1, -0xd4(%rbp)
jmp 0x1024f
movq -0x180(%rbp), %rax
cmpl $0x1, 0x98(%rax)
jne 0xfb34
testb $0x1, -0x3f(%rbp)
je 0xfb0d
movq -0x180(%rbp), %rax
movl $0x2, 0x98(%rax)
leaq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x136c0
movq %rax, %rcx
movq -0x180(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, 0x94(%rax)
movl 0x94(%rax), %esi
leaq -0xf8(%rbp), %rdi
callq 0x13410
jmp 0xfae8
movq -0x180(%rbp), %rdi
addq $0x70, %rdi
leaq -0xf8(%rbp), %rsi
callq 0x5410
leaq -0xf8(%rbp), %rdi
callq 0x56c0
jmp 0xfb25
movq -0x180(%rbp), %rdi
addq $0x70, %rdi
leaq -0x80(%rbp), %rsi
callq 0x5050
jmp 0xfb23
jmp 0xfb25
movl $0x1, -0xd4(%rbp)
jmp 0x1024f
movq -0x180(%rbp), %rdi
addq $0xa0, %rdi
callq 0x13320
movq %rax, -0x198(%rbp)
leaq -0x80(%rbp), %rdi
addq $0x48, %rdi
callq 0x12cf0
movq %rax, %rcx
movq -0x198(%rbp), %rax
cmpq %rcx, %rax
jbe 0xfba7
leaq 0x627ff(%rip), %rax     # 0x72370
movl (%rax), %esi
leaq 0x3e19e(%rip), %rdi     # 0x4dd18
callq 0xa6c0
movq -0x180(%rbp), %rdi
addq $0x50, %rdi
leaq 0x3e1a9(%rip), %rsi     # 0x4dd3a
callq 0x54b0
jmp 0xfb98
movl $0x1, -0xd4(%rbp)
jmp 0x1024f
movq -0x180(%rbp), %rdi
addq $0xa0, %rdi
callq 0x13320
movq %rax, -0x1a0(%rbp)
leaq -0x80(%rbp), %rdi
addq $0x48, %rdi
callq 0x12cf0
movq %rax, %rcx
movq -0x1a0(%rbp), %rax
cmpq %rcx, %rax
jne 0xfe90
movq -0x180(%rbp), %rdi
addq $0xa0, %rdi
leaq -0x80(%rbp), %rsi
callq 0x10280
movq %rax, -0x1a8(%rbp)
jmp 0xfc01
movq -0x180(%rbp), %rax
movq -0x1a8(%rbp), %rcx
movq %rcx, 0xb8(%rax)
movl $0xb0, %edi
callq 0x5300
movq %rax, -0x1b0(%rbp)
jmp 0xfc29
movq -0x180(%rbp), %rax
movb $0x1, -0x11b(%rbp)
movq 0xb8(%rax), %rax
movq %rax, -0x1c0(%rbp)
movl $0xa0, %edi
callq 0x5300
movq %rax, -0x1b8(%rbp)
jmp 0xfc58
movb $0x1, -0x11a(%rbp)
leaq -0x119(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x5620
movq -0x1c8(%rbp), %rdx
leaq 0x3efe0(%rip), %rsi     # 0x4ec60
leaq -0x118(%rbp), %rdi
callq 0x8780
jmp 0xfc8e
movq -0x1b8(%rbp), %rdi
xorl %r8d, %r8d
movl %r8d, %r9d
movl $0x2, %esi
leaq -0x118(%rbp), %rdx
movl $0x4, %ecx
callq 0xef50
jmp 0xfcb3
movq -0x1b8(%rbp), %rcx
movq -0x1c0(%rbp), %rdx
movq -0x1b0(%rbp), %rdi
movb $0x0, -0x11a(%rbp)
movl $0xa, %esi
callq 0x105a0
jmp 0xfcdb
movq -0x180(%rbp), %rax
movq -0x1b0(%rbp), %rcx
movb $0x0, -0x11b(%rbp)
movq %rcx, 0xb8(%rax)
leaq -0x118(%rbp), %rdi
callq 0x56c0
leaq -0x119(%rbp), %rdi
callq 0x5370
movl $0xa0, %edi
callq 0x5300
movq %rax, -0x1d0(%rbp)
jmp 0xfd22
movq -0x1d0(%rbp), %rdi
movq -0x180(%rbp), %rdx
addq $0xc0, %rdx
xorl %r8d, %r8d
movl %r8d, %r9d
movl $0x1, %esi
movl %r8d, %ecx
callq 0xef50
jmp 0xfd4c
movq -0x1d0(%rbp), %rax
movq %rax, -0x128(%rbp)
movl $0xb0, %edi
callq 0x5300
movq %rax, -0x1d8(%rbp)
jmp 0xfd6d
movq -0x1d8(%rbp), %rdi
movq -0x180(%rbp), %rax
movq -0x128(%rbp), %rdx
movq 0xb8(%rax), %rcx
movl $0x10, %esi
callq 0x105a0
jmp 0xfd95
movq -0x180(%rbp), %rax
movq -0x1d8(%rbp), %rcx
movq %rcx, 0xb8(%rax)
jmp 0x101d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xfe1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xfdf5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x56c0
leaq -0x119(%rbp), %rdi
callq 0x5370
testb $0x1, -0x11a(%rbp)
jne 0xfe0c
jmp 0xfe1d
movq -0x1b8(%rbp), %rdi
movl $0xa0, %esi
callq 0x5320
jmp 0xfe1f
testb $0x1, -0x11b(%rbp)
jne 0xfe2a
jmp 0xfe3b
movq -0x1b0(%rbp), %rdi
movl $0xb0, %esi
callq 0x5320
jmp 0x10261
movq -0x1d0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
movl $0xa0, %esi
callq 0x5320
jmp 0x10261
movq -0x1d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
movl $0xb0, %esi
callq 0x5320
jmp 0x10261
movl $0xa0, %edi
callq 0x5300
movq %rax, -0x1e0(%rbp)
jmp 0xfea3
movq -0x1e0(%rbp), %rdi
movq -0x180(%rbp), %rdx
addq $0xc0, %rdx
xorl %r8d, %r8d
movl %r8d, %r9d
movl $0x1, %esi
movl %r8d, %ecx
callq 0xef50
jmp 0xfecd
movq -0x180(%rbp), %rdi
movq -0x1e0(%rbp), %rax
movq %rax, -0x130(%rbp)
movl $0x6, 0x98(%rdi)
movl $0x4, -0x134(%rbp)
addq $0xa0, %rdi
callq 0x13320
movq %rax, -0x140(%rbp)
leaq -0x80(%rbp), %rdi
addq $0x48, %rdi
callq 0x12cf0
movq %rax, -0x148(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rax
cmpq -0x148(%rbp), %rax
jae 0xff9a
leaq -0x80(%rbp), %rdi
addq $0x48, %rdi
movq -0x150(%rbp), %rsi
callq 0x136c0
movl (%rax), %eax
imull -0x134(%rbp), %eax
movl %eax, -0x134(%rbp)
movq -0x150(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x150(%rbp)
jmp 0xff2b
movq -0x1e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
movl $0xa0, %esi
callq 0x5320
jmp 0x10261
movq -0x180(%rbp), %rdi
addq $0xa0, %rdi
leaq -0x80(%rbp), %rsi
callq 0x10280
movq %rax, -0x1e8(%rbp)
jmp 0xffba
movq -0x180(%rbp), %rax
movq -0x1e8(%rbp), %rcx
movq %rcx, 0xb8(%rax)
movl $0xb0, %edi
callq 0x5300
movq %rax, -0x1f0(%rbp)
jmp 0xffe2
movq -0x180(%rbp), %rax
movb $0x1, -0x173(%rbp)
movq 0xb8(%rax), %rax
movq %rax, -0x200(%rbp)
movl $0xa0, %edi
callq 0x5300
movq %rax, -0x1f8(%rbp)
jmp 0x10011
movb $0x1, -0x172(%rbp)
leaq -0x171(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x5620
movq -0x208(%rbp), %rdx
leaq 0x3ec27(%rip), %rsi     # 0x4ec60
leaq -0x170(%rbp), %rdi
callq 0x8780
jmp 0x10047
movq -0x1f8(%rbp), %rdi
movl -0x134(%rbp), %ecx
xorl %r8d, %r8d
movl %r8d, %r9d
movl $0x2, %esi
leaq -0x170(%rbp), %rdx
callq 0xef50
jmp 0x1006d
movq -0x1f8(%rbp), %rcx
movq -0x200(%rbp), %rdx
movq -0x1f0(%rbp), %rdi
movb $0x0, -0x172(%rbp)
movl $0xa, %esi
callq 0x105a0
jmp 0x10095
movq -0x180(%rbp), %rax
movq -0x1f0(%rbp), %rcx
movb $0x0, -0x173(%rbp)
movq %rcx, 0xb8(%rax)
leaq -0x170(%rbp), %rdi
callq 0x56c0
leaq -0x171(%rbp), %rdi
callq 0x5370
movl $0xb0, %edi
callq 0x5300
movq %rax, -0x210(%rbp)
jmp 0x100dc
movq -0x210(%rbp), %rdi
movq -0x180(%rbp), %rax
movq -0x130(%rbp), %rdx
movq 0xb8(%rax), %rcx
movl $0x7, %esi
callq 0x105a0
jmp 0x10104
movq -0x180(%rbp), %rax
movq -0x210(%rbp), %rcx
movq %rcx, 0xb8(%rax)
jmp 0x101d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x1018e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x10164
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x56c0
leaq -0x171(%rbp), %rdi
callq 0x5370
testb $0x1, -0x172(%rbp)
jne 0x1017b
jmp 0x1018c
movq -0x1f8(%rbp), %rdi
movl $0xa0, %esi
callq 0x5320
jmp 0x1018e
testb $0x1, -0x173(%rbp)
jne 0x10199
jmp 0x101aa
movq -0x1f0(%rbp), %rdi
movl $0xb0, %esi
callq 0x5320
jmp 0x10261
movq -0x210(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
movl $0xb0, %esi
callq 0x5320
jmp 0x10261
jmp 0x101d9
movq -0x180(%rbp), %rax
movq 0xb8(%rax), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
jmp 0x101f2
movq -0x180(%rbp), %rdi
movq 0xb8(%rdi), %rsi
addq $0x18, %rsi
addq $0x18, %rdi
callq 0x5050
jmp 0x1020f
movq -0x180(%rbp), %rdi
movq 0xb8(%rdi), %rsi
addq $0x70, %rsi
addq $0x70, %rdi
callq 0x5050
jmp 0x1022c
movq -0x180(%rbp), %rdi
addq $0x50, %rdi
leaq 0x3dafc(%rip), %rsi     # 0x4dd3a
callq 0x54b0
jmp 0x10245
movl $0x0, -0xd4(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x13530
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
leaq -0x80(%rbp), %rdi
callq 0x13530
movq -0x88(%rbp), %rdi
callq 0x5610
nopw %cs:(%rax,%rax)