// File: lhydave[P]SysYCompilerLab/front/node.cpp
// Function: sysY_AST::ret_stmt_node::ret_stmt_node(sysY_AST::exp_node*)
ret_stmt_node::ret_stmt_node(exp_node *_ret_val)
{
	dbg_printf("generate a ret_stmt_node... ret_val is null: %d\n",
		_ret_val == nullptr);
	ret_type = (_ret_val != nullptr) ? INT : VOID;
	ret_val = _ret_val;
	if (func_table[now_func_name].ret_type != ret_type)
	{
		string msg;
		switch (func_table[now_func_name].ret_type)
		{
		case INT:
			msg = "non-void function '" + now_func_name +
				"' should return a value";
			break;
		case VOID:
			msg = "void function '" + now_func_name +
				"' should not return a value";
			break;
		default: dbg_printf("there cannot be other type!\n");
		}
		yyerror(msg.c_str());
	}
	if (ret_type == INT)
	{
		ret_val->reduce();
		ret_val->new_temp();
		if (ret_val->exp_type == EXP_PTR)
		{
			string msg =
				"function '" + now_func_name + "' should not return a pointer";
			yyerror(msg.c_str());
		}
	}
	gen_code();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x110(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0xce50
movq -0x110(%rbp), %rax
leaq 0x62983(%rip), %rcx     # 0x714e8
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
testq %rcx, %rcx
setne %cl
movzbl %cl, %ecx
movl %ecx, 0x3c(%rax)
movq -0x10(%rbp), %rcx
movq %rcx, 0x40(%rax)
leaq 0x638b9(%rip), %rdi     # 0x72440
leaq 0x638ea(%rip), %rsi     # 0x72478
callq 0x13a90
movq %rax, -0x108(%rbp)
jmp 0xeb9c
movq -0x110(%rbp), %rcx
movq -0x108(%rbp), %rax
movl 0x50(%rax), %eax
cmpl 0x3c(%rcx), %eax
je 0xed45
leaq -0x40(%rbp), %rdi
callq 0x54c0
leaq 0x6387a(%rip), %rdi     # 0x72440
leaq 0x638ab(%rip), %rsi     # 0x72478
callq 0x13a90
movq %rax, -0x118(%rbp)
jmp 0xebdb
movq -0x118(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x11c(%rbp)
testl %eax, %eax
je 0xec94
jmp 0xebf5
movl -0x11c(%rbp), %eax
subl $0x1, %eax
je 0xec27
jmp 0xed10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xee3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xed37
leaq 0x3f03c(%rip), %rsi     # 0x4dc6a
leaq 0x63843(%rip), %rdx     # 0x72478
leaq -0x80(%rbp), %rdi
callq 0x12d60
jmp 0xec40
leaq 0x3f037(%rip), %rdx     # 0x4dc7e
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x12d10
jmp 0xec56
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x5410
leaq -0x60(%rbp), %rdi
callq 0x56c0
leaq -0x80(%rbp), %rdi
callq 0x56c0
jmp 0xed12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x56c0
jmp 0xed37
leaq 0x3efd3(%rip), %rsi     # 0x4dc6e
leaq 0x637d6(%rip), %rdx     # 0x72478
leaq -0xc0(%rbp), %rdi
callq 0x12d60
jmp 0xecb0
leaq 0x3efdf(%rip), %rdx     # 0x4dc96
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x12d10
jmp 0xeccc
leaq -0x40(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x5410
leaq -0xa0(%rbp), %rdi
callq 0x56c0
leaq -0xc0(%rbp), %rdi
callq 0x56c0
jmp 0xed12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x56c0
jmp 0xed37
jmp 0xed12
leaq -0x40(%rbp), %rdi
callq 0x5160
movq %rax, %rdi
leaq 0x6364b(%rip), %rax     # 0x72370
movl (%rax), %esi
callq 0xa6c0
leaq -0x40(%rbp), %rdi
callq 0x56c0
jmp 0xed45
leaq -0x40(%rbp), %rdi
callq 0x56c0
jmp 0xee3f
movq -0x110(%rbp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0xee25
movq -0x110(%rbp), %rax
movq 0x40(%rax), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
jmp 0xed6c
movq -0x110(%rbp), %rax
movq 0x40(%rax), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0xed82
movq -0x110(%rbp), %rax
movq 0x40(%rax), %rax
cmpl $0x6, 0x98(%rax)
jne 0xee23
leaq 0x3eed2(%rip), %rsi     # 0x4dc73
leaq 0x636d0(%rip), %rdx     # 0x72478
leaq -0x100(%rbp), %rdi
callq 0x12d60
jmp 0xedb6
leaq 0x3eef5(%rip), %rdx     # 0x4dcb2
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x12d10
jmp 0xedd2
leaq -0x100(%rbp), %rdi
callq 0x56c0
leaq -0xe0(%rbp), %rdi
callq 0x5160
movq %rax, %rdi
leaq 0x6357c(%rip), %rax     # 0x72370
movl (%rax), %esi
callq 0xa6c0
leaq -0xe0(%rbp), %rdi
callq 0x56c0
jmp 0xee23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x56c0
jmp 0xee3f
jmp 0xee25
movq -0x110(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
jmp 0xee36
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x110(%rbp), %rdi
callq 0x13fe0
movq -0x18(%rbp), %rdi
callq 0x5610
nopw %cs:(%rax,%rax)