// File: lhydave[P]SysYCompilerLab/front/node.cpp
// Function: sysY_AST::funcdef_node::gen_code()
void funcdef_node::gen_code()
{
	func_entry query;
	find_func(name, query);
	code = "f_" + name + +" [" + to_string(query.params.size()) + "]\n";
	// declarations
	for (auto i : query.func_var_table)
	{
		dbg_printf("sysy_name:%s eeyore_name:%s\n", i.sysy_name.c_str(),
			i.eeyore_name.c_str());
		code += gen_vardecl(i, true);
	}
	// initial global variables
	if (name == "main")
	{
		for (auto i : var_stack[0])
		{
			auto var = i.second;
			if (var.val.empty())
				continue;
			if (!var.is_array) // a variable
				code += "\t" + var.eeyore_name + " = " + to_string(var.val[0]) +
					"\n";
			else // an array
				for (auto i = 0; i < var.val.size(); i++)
					if (var.val[i])
						code += "\t" + var.eeyore_name + "[" +
							to_string(i * int_size) +
							"] = " + to_string(var.val[i]) + "\n";
		}
	}
	// concatenate the block
	code += blk->code;
	code += "end f_" + name + "\n\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x500, %rsp            # imm = 0x500
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x4e8(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
callq 0x13ac0
movq -0x4e8(%rbp), %rdi
movq -0x4e0(%rbp), %rsi
addq $0x40, %rdi
callq 0x1c5b0
jmp 0xc573
movq -0x4e8(%rbp), %rdx
addq $0x40, %rdx
leaq 0x416b7(%rip), %rsi     # 0x4dc3c
leaq -0xf0(%rbp), %rdi
callq 0x12d60
jmp 0xc593
leaq 0x4214c(%rip), %rdx     # 0x4e6e6
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x12d10
jmp 0xc5af
leaq -0x40(%rbp), %rdi
callq 0x13be0
movq %rax, %rsi
leaq -0x110(%rbp), %rdi
callq 0x13b00
jmp 0xc5c9
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x13340
jmp 0xc5e5
leaq 0x41644(%rip), %rdx     # 0x4dc30
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x12d10
jmp 0xc601
movq -0x4e8(%rbp), %rdi
addq $0x18, %rdi
leaq -0x90(%rbp), %rsi
callq 0x5410
leaq -0x90(%rbp), %rdi
callq 0x56c0
leaq -0xb0(%rbp), %rdi
callq 0x56c0
leaq -0x110(%rbp), %rdi
callq 0x56c0
leaq -0xd0(%rbp), %rdi
callq 0x56c0
leaq -0xf0(%rbp), %rdi
callq 0x56c0
leaq -0x60(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rdi
callq 0x13c10
movq %rax, -0x120(%rbp)
movq -0x118(%rbp), %rdi
callq 0x13c40
movq %rax, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x13c70
testb $0x1, %al
jne 0xc6a5
jmp 0xc7d1
leaq -0x120(%rbp), %rdi
callq 0x13cb0
movq %rax, %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x13cd0
jmp 0xc6c2
leaq -0x1c0(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
movl $0x1, %edx
callq 0xbe50
jmp 0xc6dc
movq -0x4e8(%rbp), %rdi
addq $0x18, %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x5440
jmp 0xc6f5
leaq -0x1c0(%rbp), %rdi
callq 0x56c0
leaq -0x1a0(%rbp), %rdi
callq 0x13530
leaq -0x120(%rbp), %rdi
callq 0x13db0
jmp 0xc689
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xce3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc789
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc77d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc771
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x56c0
leaq -0x110(%rbp), %rdi
callq 0x56c0
leaq -0xd0(%rbp), %rdi
callq 0x56c0
leaq -0xf0(%rbp), %rdi
callq 0x56c0
jmp 0xce3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc7c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x56c0
leaq -0x1a0(%rbp), %rdi
callq 0x13530
jmp 0xce3c
movq -0x4e8(%rbp), %rdi
addq $0x40, %rdi
leaq 0x41450(%rip), %rsi     # 0x4dc33
callq 0x13dd0
movb %al, -0x4e9(%rbp)
jmp 0xc7f0
movb -0x4e9(%rbp), %al
testb $0x1, %al
jne 0xc7ff
jmp 0xcd71
leaq 0x65c22(%rip), %rdi     # 0x72428
xorl %eax, %eax
movl %eax, %esi
callq 0x13e00
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rdi
callq 0x13e20
movq %rax, -0x1d0(%rbp)
movq -0x1c8(%rbp), %rdi
callq 0x13e50
movq %rax, -0x1d8(%rbp)
leaq -0x1d0(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x13e80
testb $0x1, %al
jne 0xc858
jmp 0xcd6f
leaq -0x1d0(%rbp), %rdi
callq 0x13eb0
movq %rax, %rsi
leaq -0x270(%rbp), %rdi
callq 0x13ee0
jmp 0xc875
leaq -0x250(%rbp), %rsi
leaq -0x2e8(%rbp), %rdi
callq 0x13cd0
jmp 0xc88a
leaq -0x2e8(%rbp), %rdi
addq $0x60, %rdi
callq 0x13580
testb $0x1, %al
jne 0xc8a0
jmp 0xc8c0
movl $0x5, -0x2ec(%rbp)
jmp 0xcd03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xcd5e
testb $0x1, -0x2a8(%rbp)
jne 0xca4d
leaq 0x4238b(%rip), %rsi     # 0x4ec5f
leaq -0x370(%rbp), %rdi
leaq -0x2e8(%rbp), %rdx
callq 0x12d60
jmp 0xc8e9
leaq 0x4129f(%rip), %rdx     # 0x4db8f
leaq -0x350(%rbp), %rdi
leaq -0x370(%rbp), %rsi
callq 0x12d10
jmp 0xc905
leaq -0x288(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x136c0
movl (%rax), %esi
leaq -0x390(%rbp), %rdi
callq 0x13410
jmp 0xc925
leaq -0x330(%rbp), %rdi
leaq -0x350(%rbp), %rsi
leaq -0x390(%rbp), %rdx
callq 0x13340
jmp 0xc941
leaq 0x412f8(%rip), %rdx     # 0x4dc40
leaq -0x310(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x12d10
jmp 0xc95d
movq -0x4e8(%rbp), %rdi
addq $0x18, %rdi
leaq -0x310(%rbp), %rsi
callq 0x5440
jmp 0xc976
leaq -0x310(%rbp), %rdi
callq 0x56c0
leaq -0x330(%rbp), %rdi
callq 0x56c0
leaq -0x390(%rbp), %rdi
callq 0x56c0
leaq -0x350(%rbp), %rdi
callq 0x56c0
leaq -0x370(%rbp), %rdi
callq 0x56c0
jmp 0xccf9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xcd52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xca3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xca30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xca24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xca18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x310(%rbp), %rdi
callq 0x56c0
leaq -0x330(%rbp), %rdi
callq 0x56c0
leaq -0x390(%rbp), %rdi
callq 0x56c0
leaq -0x350(%rbp), %rdi
callq 0x56c0
leaq -0x370(%rbp), %rdi
callq 0x56c0
jmp 0xcd52
movl $0x0, -0x394(%rbp)
movslq -0x394(%rbp), %rax
movq %rax, -0x4f8(%rbp)
leaq -0x2e8(%rbp), %rdi
addq $0x60, %rdi
callq 0x12cf0
movq %rax, %rcx
movq -0x4f8(%rbp), %rax
cmpq %rcx, %rax
jae 0xccf7
leaq -0x2e8(%rbp), %rdi
addq $0x60, %rdi
movslq -0x394(%rbp), %rsi
callq 0x136c0
cmpl $0x0, (%rax)
je 0xcce1
leaq 0x421b0(%rip), %rsi     # 0x4ec5f
leaq -0x458(%rbp), %rdi
leaq -0x2e8(%rbp), %rdx
callq 0x12d60
jmp 0xcac4
leaq 0x41c1c(%rip), %rdx     # 0x4e6e7
leaq -0x438(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x12d10
jmp 0xcae0
movl -0x394(%rbp), %esi
shll $0x2, %esi
leaq -0x478(%rbp), %rdi
callq 0x13410
jmp 0xcaf7
leaq -0x418(%rbp), %rdi
leaq -0x438(%rbp), %rsi
leaq -0x478(%rbp), %rdx
callq 0x13340
jmp 0xcb13
leaq 0x41074(%rip), %rdx     # 0x4db8e
leaq -0x3f8(%rbp), %rdi
leaq -0x418(%rbp), %rsi
callq 0x12d10
jmp 0xcb2f
leaq -0x288(%rbp), %rdi
movslq -0x394(%rbp), %rsi
callq 0x136c0
movl (%rax), %esi
leaq -0x498(%rbp), %rdi
callq 0x13410
jmp 0xcb52
leaq -0x3d8(%rbp), %rdi
leaq -0x3f8(%rbp), %rsi
leaq -0x498(%rbp), %rdx
callq 0x13340
jmp 0xcb6e
leaq 0x410cb(%rip), %rdx     # 0x4dc40
leaq -0x3b8(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x12d10
jmp 0xcb8a
movq -0x4e8(%rbp), %rdi
addq $0x18, %rdi
leaq -0x3b8(%rbp), %rsi
callq 0x5440
jmp 0xcba3
leaq -0x3b8(%rbp), %rdi
callq 0x56c0
leaq -0x3d8(%rbp), %rdi
callq 0x56c0
leaq -0x498(%rbp), %rdi
callq 0x56c0
leaq -0x3f8(%rbp), %rdi
callq 0x56c0
leaq -0x418(%rbp), %rdi
callq 0x56c0
leaq -0x478(%rbp), %rdi
callq 0x56c0
leaq -0x438(%rbp), %rdi
callq 0x56c0
leaq -0x458(%rbp), %rdi
callq 0x56c0
jmp 0xcce1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xccd3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xccc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xccbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xccaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xcca3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xcc97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xcc8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x3b8(%rbp), %rdi
callq 0x56c0
leaq -0x3d8(%rbp), %rdi
callq 0x56c0
leaq -0x498(%rbp), %rdi
callq 0x56c0
leaq -0x3f8(%rbp), %rdi
callq 0x56c0
leaq -0x418(%rbp), %rdi
callq 0x56c0
leaq -0x478(%rbp), %rdi
callq 0x56c0
leaq -0x438(%rbp), %rdi
callq 0x56c0
leaq -0x458(%rbp), %rdi
callq 0x56c0
jmp 0xcd52
jmp 0xcce3
movl -0x394(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x394(%rbp)
jmp 0xca57
jmp 0xccf9
movl $0x0, -0x2ec(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x13530
movl -0x2ec(%rbp), %eax
testl %eax, %eax
jne 0xcd25
jmp 0xcd1b
movl $0x0, -0x2ec(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x13f40
movl -0x2ec(%rbp), %eax
testl %eax, %eax
je 0xcd3f
jmp 0xcd3d
jmp 0xcd41
jmp 0xcd41
leaq -0x1d0(%rbp), %rdi
callq 0x13f70
jmp 0xc83c
leaq -0x2e8(%rbp), %rdi
callq 0x13530
leaq -0x270(%rbp), %rdi
callq 0x13f40
jmp 0xce3c
jmp 0xcd71
movq -0x4e8(%rbp), %rdi
movq 0x68(%rdi), %rsi
addq $0x18, %rsi
addq $0x18, %rdi
callq 0x5440
jmp 0xcd8b
movq -0x4e8(%rbp), %rdx
addq $0x40, %rdx
leaq 0x40e9b(%rip), %rsi     # 0x4dc38
leaq -0x4d8(%rbp), %rdi
callq 0x12d60
jmp 0xcdab
leaq 0x40e8d(%rip), %rdx     # 0x4dc3f
leaq -0x4b8(%rbp), %rdi
leaq -0x4d8(%rbp), %rsi
callq 0x12d10
jmp 0xcdc7
movq -0x4e8(%rbp), %rdi
addq $0x18, %rdi
leaq -0x4b8(%rbp), %rsi
callq 0x5440
jmp 0xcde0
leaq -0x4b8(%rbp), %rdi
callq 0x56c0
leaq -0x4d8(%rbp), %rdi
callq 0x56c0
leaq -0x60(%rbp), %rdi
callq 0x13fa0
addq $0x500, %rsp            # imm = 0x500
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xce30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x4b8(%rbp), %rdi
callq 0x56c0
leaq -0x4d8(%rbp), %rdi
callq 0x56c0
leaq -0x60(%rbp), %rdi
callq 0x13fa0
movq -0x68(%rbp), %rdi
callq 0x5610
nop