// File: /workspace/github_c_makefile_star2_O1/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 0x15233
callq 0xac81
movq %rax, %r14
leaq 0x14672(%rip), %r12     # 0x29878
movq (%r12), %rax
movq 0x20(%rax), %rdi
callq 0x197d4
movq %rax, %rdi
movq %r14, %rsi
callq 0x9fe1
testq %rax, %rax
je 0x15258
movq %r14, %rdi
movq %rax, %rsi
callq 0xa341
movq %rax, %r14
jmp 0x1527d
leaq 0x167c6(%rip), %rax     # 0x2ba00
movq 0x10(%rax), %rdi
testq %rdi, %rdi
je 0x1531a
leaq 0x1462a(%rip), %rax     # 0x29878
movq (%rax), %rsi
xorl %edx, %edx
jmp 0x15315
movq 0x8(%r14), %r15
movq (%r12), %rax
movq 0x20(%rax), %rdi
callq 0x197d4
leaq 0xb25f(%rip), %rdi      # 0x204cf
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9720
leaq 0x14614(%rip), %r13     # 0x29898
movq (%r13), %rdi
testq %rdi, %rdi
je 0x15330
cmpl $0x2a0, (%r14)          # imm = 0x2A0
jne 0x152bb
movq 0x10(%r14), %r15
cmpl $0xd9, (%r15)
jne 0x152bb
movq 0x18(%r14), %rax
cmpl $0x49, (%rax)
jne 0x152bb
callq 0x9d77
movq %rax, 0x18(%r15)
jmp 0x152db
callq 0x9d77
movq %rax, %rdi
callq 0xab00
movl $0x30, %edi
movq %rax, %rsi
movq %r14, %rdx
callq 0x8c8d
movq %rax, %r15
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3941
leaq 0x16712(%rip), %rax     # 0x2ba00
movq 0x10(%rax), %r14
testq %r14, %r14
je 0x1531a
movq (%r12), %r15
movq (%r13), %rdi
callq 0x9d77
movq %rax, %rdi
callq 0xab00
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x102f8
leaq 0x1ccbf(%rip), %rax     # 0x31fe0
movq (%rax), %rsi
movl $0xf8, %edi
xorl %edx, %edx
jmp 0x15480
leaq 0x166c9(%rip), %r13     # 0x2ba00
cmpq $0x0, 0x10(%r13)
je 0x153a0
movq 0x8(%r14), %rsi
leaq 0x199e7(%rip), %rax     # 0x2ed30
movl (%rax), %edx
movl $0x43, %edi
callq 0x175a8
movq %rax, %r15
movq %rax, %rdi
callq 0x343c
movq %r15, %rdi
movq %r14, %rsi
callq 0x9efb
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3941
movq 0x10(%r13), %r14
movq (%r12), %r12
movq %r15, %rdi
callq 0x9d77
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x102f8
movq %r15, %rdi
callq 0x9d77
movq %rax, %r14
movq 0x8(%r14), %rdi
callq 0xacd9
movq %r14, %rdi
movq %rax, %rsi
callq 0xa341
movq %rax, %r14
movq 0x8(%rax), %rax
cmpl $0xf, (%rax)
jb 0x153c4
movq 0x10(%rax), %rax
cmpl $0x7, (%rax)
jne 0x1542a
movq %r14, %rdi
callq 0x154a3
testq %rax, %rax
je 0x15415
cmpw $0x4, 0x18(%rax)
leaq 0x9393(%rip), %rcx      # 0x1e775
leaq 0xb141(%rip), %rsi      # 0x2052a
cmoveq %rcx, %rsi
testb $0xc, 0x1b(%rax)
je 0x15403
leaq 0xb104(%rip), %rdi      # 0x204fe
xorl %eax, %eax
callq 0x9be3
jmp 0x15415
movq 0x10(%rax), %rdx
leaq 0xb122(%rip), %rdi      # 0x20530
xorl %eax, %eax
callq 0x9be3
leaq 0x1cbbc(%rip), %rax     # 0x31fd8
movq (%rax), %rsi
movq %r14, %rdi
callq 0xa341
movq %rax, %r14
movq 0x8(%r14), %rdi
movl (%rdi), %ecx
movq %rdi, %rax
cmpl $0xf, %ecx
jb 0x1543c
movq 0x10(%rdi), %rax
cmpl $0x3, (%rax)
jb 0x15457
movq %rdi, %rdx
cmpl $0xf, %ecx
jb 0x1544d
movq 0x10(%rdi), %rdx
movl $0xf5, %eax
cmpl $0x7, (%rdx)
jb 0x15477
movq %rdi, %rdx
cmpl $0xf, %ecx
jb 0x15463
movq 0x10(%rdi), %rdx
movl $0xf5, %eax
cmpl $0xd, (%rdx)
je 0x15477
callq 0x1a3e6
addl $0xf0, %eax
movq 0x8(%r14), %rsi
movl %eax, %edi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x17b61
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3941
movl %ebx, %edi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x15554