// File: /workspace/github_c_makefile_star2_O3/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 0x150ed
callq 0xac23
movq %rax, %r14
leaq 0x157b8(%rip), %r12     # 0x2a878
movq (%r12), %rax
movq 0x20(%rax), %rdi
callq 0x195c1
movq %rax, %rdi
movq %r14, %rsi
callq 0x9ff1
testq %rax, %rax
je 0x15112
movq %r14, %rdi
movq %rax, %rsi
callq 0xa2f7
movq %rax, %r14
jmp 0x15137
leaq 0x1790c(%rip), %rax     # 0x2ca00
movq 0x10(%rax), %rdi
testq %rdi, %rdi
je 0x151d4
leaq 0x15770(%rip), %rax     # 0x2a878
movq (%rax), %rsi
xorl %edx, %edx
jmp 0x151cf
movq 0x8(%r14), %r15
movq (%r12), %rax
movq 0x20(%rax), %rdi
callq 0x195c1
leaq 0xb425(%rip), %rdi      # 0x2054f
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x974c
leaq 0x1575a(%rip), %r13     # 0x2a898
movq (%r13), %rdi
testq %rdi, %rdi
je 0x151ea
cmpl $0x2a0, (%r14)          # imm = 0x2A0
jne 0x15175
movq 0x10(%r14), %r15
cmpl $0xd9, (%r15)
jne 0x15175
movq 0x18(%r14), %rax
cmpl $0x49, (%rax)
jne 0x15175
callq 0x9d8b
movq %rax, 0x18(%r15)
jmp 0x15195
callq 0x9d8b
movq %rax, %rdi
callq 0xaaaa
movl $0x30, %edi
movq %rax, %rsi
movq %r14, %rdx
callq 0x8cee
movq %rax, %r15
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x394a
leaq 0x17858(%rip), %rax     # 0x2ca00
movq 0x10(%rax), %r14
testq %r14, %r14
je 0x151d4
movq (%r12), %r15
movq (%r13), %rdi
callq 0x9d8b
movq %rax, %rdi
callq 0xaaaa
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1021b
leaq 0x1de05(%rip), %rax     # 0x32fe0
movq (%rax), %rsi
movl $0xf8, %edi
xorl %edx, %edx
jmp 0x15326
leaq 0x1780f(%rip), %r13     # 0x2ca00
cmpq $0x0, 0x10(%r13)
je 0x1525a
movq 0x8(%r14), %rsi
leaq 0x1ab2d(%rip), %rax     # 0x2fd30
movl (%rax), %edx
movl $0x43, %edi
callq 0x17456
movq %rax, %r15
movq %rax, %rdi
callq 0x343c
movq %r15, %rdi
movq %r14, %rsi
callq 0x9f07
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x394a
movq 0x10(%r13), %r14
movq (%r12), %r12
movq %r15, %rdi
callq 0x9d8b
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x1021b
movq %r15, %rdi
callq 0x9d8b
movq %rax, %r14
movq 0x8(%r14), %rdi
callq 0xac7b
movq %r14, %rdi
movq %rax, %rsi
callq 0xa2f7
movq %rax, %r14
movq 0x8(%rax), %rsi
movl (%rsi), %eax
movl %eax, %ecx
cmpl $0xf, %eax
jb 0x15284
movq 0x10(%rsi), %rcx
movl (%rcx), %ecx
cmpl $0x7, %ecx
jne 0x152f0
movq %r14, %rdi
callq 0x15349
testq %rax, %rax
je 0x152d5
cmpw $0x4, 0x18(%rax)
leaq 0x94d3(%rip), %rcx      # 0x1e775
leaq 0xb301(%rip), %rsi      # 0x205aa
cmoveq %rcx, %rsi
testb $0xc, 0x1b(%rax)
je 0x152c3
leaq 0xb2c4(%rip), %rdi      # 0x2057e
xorl %eax, %eax
callq 0x9bfd
jmp 0x152d5
movq 0x10(%rax), %rdx
leaq 0xb2e2(%rip), %rdi      # 0x205b0
xorl %eax, %eax
callq 0x9bfd
leaq 0x1dcfc(%rip), %rax     # 0x32fd8
movq (%rax), %rsi
movq %r14, %rdi
callq 0xa2f7
movq %rax, %r14
movq 0x8(%rax), %rsi
movl (%rsi), %eax
cmpl $0xf, %eax
jb 0x152fb
movq 0x10(%rsi), %rax
movl (%rax), %eax
cmpl $0x2, %eax
jbe 0x1530f
movl $0xf5, %edi
cmpl $0x7, %eax
jb 0x15323
cmpl $0xd, %eax
je 0x15323
movq %rsi, %rdi
callq 0x1a1c9
movl %eax, %edi
addl $0xf0, %edi
movq 0x8(%r14), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x179e5
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x394a
movl %ebx, %edi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x15402