// File: /workspace/github_c_makefile_star2_O2/Oric4ever[P]lcc65/6502/build/../src/stmt.c
// Function: retcode
void retcode(Tree p, int lab) {
	if (p == 0) {
		if (events.returns)
			apply(events.returns, (Generic)cfunc, (Generic)0);
		p = tree(RET+V, voidtype, 0, 0);
	} else {
		Type ty;
		p = pointer(p);
		ty = assign(freturn(cfunc->type), p);
		if (ty)
			p = cast(p, ty);
		else
			error("illegal return type; found `%t' expected `%t'\n",
				p->type, freturn(cfunc->type));
		if (retv) {
			if (p->op == RIGHT && p->kids[0]->op == CALL+B
			&& p->kids[1]->op == INDIR+B) {
				p = p->kids[0];
				p->kids[1] = idnode(retv);
			} else
				p = asgnnode(ASGN, rvalue(idnode(retv)), p);
			walk(p, 0, 0);
			if (events.returns)
				apply(events.returns, (Generic)cfunc, (Generic)rvalue(idnode(retv)));
			p = tree(RET+V, voidtype, 0, 0);
		} else {
			if (events.returns) {
				Symbol t1 = genident(AUTO, p->type, level);
				addlocal(t1);
				walk(asgn(t1, p), 0, 0);
				apply(events.returns, (Generic)cfunc, (Generic)idnode(t1));
				p = idnode(t1);
			}
			p = cast(p, promote(p->type));
			if (isptr(p->type)) {
				Symbol q = localaddr(p);
				if (q && (q->computed || q->generated))
					warning("pointer to a %s is an illegal return value\n",
						q->scope == PARAM ? "parameter" : "local");
				else if (q)
					warning("pointer to %s `%s' is an illegal return value\n",
						q->scope == PARAM ? "parameter" : "local", q->name);
				p = cast(p, unsignedtype);
			}
			p = tree(RET + widen(p->type), p->type, p, 0);
		}
	}
	walk(p, 0, 0);
	branch(lab);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %esi, %ebx
testq %rdi, %rdi
je 0x13e30
callq 0xa22f
movq %rax, %r14
leaq 0x15a75(%rip), %r12     # 0x29878
movq (%r12), %rax
movq 0x20(%rax), %rdi
callq 0x18021
movq %rax, %rdi
movq %r14, %rsi
callq 0x9610
testq %rax, %rax
je 0x13e55
movq %r14, %rdi
movq %rax, %rsi
callq 0x9912
movq %rax, %r14
jmp 0x13e7a
leaq 0x17bc9(%rip), %rax     # 0x2ba00
movq 0x10(%rax), %rdi
testq %rdi, %rdi
je 0x13f15
leaq 0x15a2d(%rip), %rax     # 0x29878
movq (%rax), %rsi
xorl %edx, %edx
jmp 0x13f10
movq 0x8(%r14), %r15
movq (%r12), %rax
movq 0x20(%rax), %rdi
callq 0x18021
leaq 0xa6ea(%rip), %rdi      # 0x1e557
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8dd4
leaq 0x15a17(%rip), %r13     # 0x29898
movq (%r13), %rdi
testq %rdi, %rdi
je 0x13f2b
cmpl $0x2a0, (%r14)          # imm = 0x2A0
jne 0x13eb8
movq 0x10(%r14), %r15
cmpl $0xd9, (%r15)
jne 0x13eb8
movq 0x18(%r14), %rax
cmpl $0x49, (%rax)
jne 0x13eb8
callq 0x93b4
movq %rax, 0x18(%r15)
jmp 0x13ed6
callq 0x93b4
movq %rax, %rdi
callq 0xa0b9
pushq $0x30
popq %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x8382
movq %rax, %r15
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x376d
leaq 0x17b17(%rip), %rax     # 0x2ba00
movq 0x10(%rax), %r14
testq %r14, %r14
je 0x13f15
movq (%r12), %r15
movq (%r13), %rdi
callq 0x93b4
movq %rax, %rdi
callq 0xa0b9
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0xf206
leaq 0x1e0c4(%rip), %rax     # 0x31fe0
movq (%rax), %rsi
movl $0xf8, %edi
xorl %edx, %edx
jmp 0x14065
leaq 0x17ace(%rip), %r13     # 0x2ba00
cmpq $0x0, 0x10(%r13)
je 0x13f99
movq 0x8(%r14), %rsi
leaq 0x1adec(%rip), %rax     # 0x2ed30
movl (%rax), %edx
pushq $0x43
popq %rdi
callq 0x16090
movq %rax, %r15
movq %rax, %rdi
callq 0x32ac
movq %r15, %rdi
movq %r14, %rsi
callq 0x952e
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x376d
movq 0x10(%r13), %r14
movq (%r12), %r12
movq %r15, %rdi
callq 0x93b4
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xf206
movq %r15, %rdi
callq 0x93b4
movq %rax, %r14
movq 0x8(%r14), %rdi
callq 0xa287
movq %r14, %rdi
movq %rax, %rsi
callq 0x9912
movq %rax, %r14
movq 0x8(%rax), %rsi
movl (%rsi), %eax
movl %eax, %ecx
cmpl $0xf, %eax
jb 0x13fc3
movq 0x10(%rsi), %rcx
movl (%rcx), %ecx
cmpl $0x7, %ecx
jne 0x1402f
movq %r14, %rdi
callq 0x14088
testq %rax, %rax
je 0x14014
cmpw $0x4, 0x18(%rax)
leaq 0x8794(%rip), %rcx      # 0x1c775
leaq 0xa5ca(%rip), %rsi      # 0x1e5b2
cmoveq %rcx, %rsi
testb $0xc, 0x1b(%rax)
je 0x14002
leaq 0xa58d(%rip), %rdi      # 0x1e586
xorl %eax, %eax
callq 0x9239
jmp 0x14014
movq 0x10(%rax), %rdx
leaq 0xa5ab(%rip), %rdi      # 0x1e5b8
xorl %eax, %eax
callq 0x9239
leaq 0x1dfbd(%rip), %rax     # 0x31fd8
movq (%rax), %rsi
movq %r14, %rdi
callq 0x9912
movq %rax, %r14
movq 0x8(%rax), %rsi
movl (%rsi), %eax
cmpl $0xf, %eax
jb 0x1403a
movq 0x10(%rsi), %rax
movl (%rax), %eax
cmpl $0x2, %eax
jbe 0x1404e
movl $0xf5, %edi
cmpl $0x7, %eax
jb 0x14062
cmpl $0xd, %eax
je 0x14062
movq %rsi, %rdi
callq 0x18b82
movl %eax, %edi
addl $0xf0, %edi
movq 0x8(%r14), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x165eb
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x376d
movl %ebx, %edi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x1413f