// File: lhydave[P]SysYCompilerLab/back/no_alloc.cpp
// Function: no_alloc::gen_func(eeyore_AST::func_entry const&)
void gen_func(const func_entry &func)
{
	auto stk_size = stack_size(func);
	now_func = func;
	var2no.clear();
	tigger_dst << emit_func_begin(func.eeyore_name, func.param_n, stk_size);
	dbg_printf("func %s begin, param: %d, size: %lu\n",
		func.eeyore_name.c_str(), func.param_n, stk_size);
	// initialize mappings
	int posi = 0;
	for (auto i : func.temps)
	{
		var2no[i.second.eeyore_name] = posi;
		dbg_printf(
			"temp var %s mapped to %d\n", i.second.eeyore_name.c_str(), posi);
		if (i.second.is_array)
			posi += i.second.size / int_size;
		else
			posi++;
	}
	for (auto i = 0; i < func.param_n; i++)
	{
		var2no[eeyore_param_prefix + to_string(i)] = posi;
		tigger_dst << emit_store(param_prefix + to_string(i), posi);
		posi++;
	}
	for (auto i : func.funcbody)
		gen_stmt(i);
	tigger_dst << emit_func_end(func.eeyore_name);
	dbg_printf("func %s end\n", func.eeyore_name.c_str());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3f760
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq 0x337f9(%rip), %rdi     # 0x72b30
callq 0x42080
leaq 0x3389d(%rip), %rdi     # 0x72be0
callq 0x420e0
movq -0x8(%rbp), %rsi
movl 0x70(%rsi), %edx
movq -0x10(%rbp), %rcx
leaq -0x30(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0x34b60
movq -0x198(%rbp), %rsi
leaq 0x33147(%rip), %rdi     # 0x724b8
callq 0x52b0
jmp 0x3f378
leaq -0x30(%rbp), %rdi
callq 0x56c0
movl $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x41fc0
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x41ff0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x41dc0
testb $0x1, %al
jne 0x3f3c4
jmp 0x3f481
leaq -0x50(%rbp), %rdi
callq 0x42020
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x41e20
movl -0x40(%rbp), %eax
movl %eax, -0x1a4(%rbp)
leaq -0x80(%rbp), %rsi
leaq 0x337f0(%rip), %rdi     # 0x72be0
callq 0x41ec0
movq %rax, -0x1a0(%rbp)
jmp 0x3f3fe
movq -0x1a0(%rbp), %rax
movl -0x1a4(%rbp), %ecx
movl %ecx, (%rax)
testb $0x1, -0x5c(%rbp)
je 0x3f45e
movslq -0x60(%rbp), %rcx
shrq $0x2, %rcx
movslq -0x40(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x40(%rbp)
jmp 0x3f467
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x56c0
jmp 0x3f755
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x26110
jmp 0x3f755
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x26110
leaq -0x50(%rbp), %rdi
callq 0x42050
jmp 0x3f3ae
movl $0x0, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x70(%rcx), %eax
jge 0x3f64a
movl -0x40(%rbp), %eax
movl %eax, -0x1b4(%rbp)
movl -0xa4(%rbp), %esi
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x13410
movq -0x1b0(%rbp), %rdx
leaq 0x335e2(%rip), %rsi     # 0x72ab0
leaq -0xc8(%rbp), %rdi
callq 0x42130
jmp 0x3f4dc
leaq 0x336fd(%rip), %rdi     # 0x72be0
leaq -0xc8(%rbp), %rsi
callq 0x42100
movq %rax, -0x1c0(%rbp)
jmp 0x3f4f8
movq -0x1c0(%rbp), %rax
movl -0x1b4(%rbp), %ecx
movl %ecx, (%rax)
leaq -0xc8(%rbp), %rdi
callq 0x56c0
leaq -0xe8(%rbp), %rdi
callq 0x56c0
movl -0xa4(%rbp), %esi
leaq -0x148(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x13410
movq -0x1c8(%rbp), %rdx
leaq 0x3354a(%rip), %rsi     # 0x72a90
leaq -0x128(%rbp), %rdi
callq 0x42130
jmp 0x3f554
movl -0x40(%rbp), %edx
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x355b0
jmp 0x3f56c
leaq 0x32f45(%rip), %rdi     # 0x724b8
leaq -0x108(%rbp), %rsi
callq 0x52b0
jmp 0x3f581
leaq -0x108(%rbp), %rdi
callq 0x56c0
leaq -0x128(%rbp), %rdi
callq 0x56c0
leaq -0x148(%rbp), %rdi
callq 0x56c0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x3f48b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3f5e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x56c0
leaq -0xe8(%rbp), %rdi
callq 0x56c0
jmp 0x3f755
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3f639
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3f62d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x56c0
leaq -0x128(%rbp), %rdi
callq 0x56c0
leaq -0x148(%rbp), %rdi
callq 0x56c0
jmp 0x3f755
movq -0x8(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rdi
callq 0x42180
movq %rax, -0x158(%rbp)
movq -0x150(%rbp), %rdi
callq 0x421b0
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x421e0
testb $0x1, %al
jne 0x3f698
jmp 0x3f6fc
leaq -0x158(%rbp), %rdi
callq 0x42220
movq %rax, %rsi
leaq -0x170(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x32480
movq -0x1d0(%rbp), %rdi
callq 0x3f810
jmp 0x3f6c8
leaq -0x170(%rbp), %rdi
callq 0x24f10
leaq -0x158(%rbp), %rdi
callq 0x42240
jmp 0x3f67f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x24f10
jmp 0x3f755
movq -0x8(%rbp), %rsi
leaq -0x190(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x34db0
movq -0x1d8(%rbp), %rsi
leaq 0x32d97(%rip), %rdi     # 0x724b8
callq 0x52b0
jmp 0x3f728
leaq -0x190(%rbp), %rdi
callq 0x56c0
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x56c0
movq -0x38(%rbp), %rdi
callq 0x5610
nop