// File: /workspace/github_c_makefile_star2_O1/Oric4ever[P]lcc65/6502/build/../src/tree.c
// Function: root
Tree root(p) Tree p; {
	if (p == 0)
		return p;
	switch (generic(p->op)) {
	case COND: {
		Tree q = p->kids[1];
		assert(q && q->op == RIGHT);
		if (p->u.sym && q->kids[0] && generic(q->kids[0]->op) == ASGN)
			q->kids[0] = root(q->kids[0]->kids[1]);
		else
			q->kids[0] = root(q->kids[0]);
		if (p->u.sym && q->kids[1] && generic(q->kids[1]->op) == ASGN)
			q->kids[1] = root(q->kids[1]->kids[1]);
		else
			q->kids[1] = root(q->kids[1]);
		if (p->u.sym)
			release(p->u.sym);
		p->u.sym = 0;
		if (q->kids[0] == 0 && q->kids[1] == 0)
			p = root(p->kids[0]);
		}
		break;
	case AND: case OR:
		if ((p->kids[1] = root(p->kids[1])) == 0)
			p = root(p->kids[0]);
		break;
	case NOT:
		return root(p->kids[0]);
	case RIGHT:
		if (p->kids[1] == 0)
			return root(p->kids[0]);
		if (p->kids[0] && p->kids[0]->op == CALL+B
		&&  p->kids[1] && p->kids[1]->op == INDIR+B)
			/* avoid premature release of the CALL+B temporary */
			return p->kids[0];
		if (p->kids[0] && p->kids[0]->op == RIGHT
		&&  p->kids[1] == p->kids[0]->kids[0])
			/* de-construct e++ construction */
			return p->kids[0]->kids[1];
		/* fall thru */
	case EQ:  case NE:  case GT:   case GE:  case LE:  case LT:
	case ADD: case SUB: case MUL:  case DIV: case MOD:
	case LSH: case RSH: case BAND: case BOR: case BXOR:
		p = tree(RIGHT, p->type, root(p->kids[0]), root(p->kids[1]));
		return p->kids[0] || p->kids[1] ? p : 0;
	case INDIR:
		if (p->type->size == 0)
			warning("reference to `%t' elided\n", p->type);
		if (isptr(p->kids[0]->type) && isvolatile(p->kids[0]->type->type))
			warning("reference to `volatile %t' elided\n", p->type);
		/* fall thru */
	case CVI: case CVF:  case CVD:   case CVU: case CVC: case CVS: case CVP:
	case NEG: case BCOM: case FIELD:
		return root(p->kids[0]);
	case ADDRL:
		if (p->u.sym->temporary)
			release(p->u.sym);
		/* fall thru */
	case ADDRG: case ADDRF: case CNST:
		return 0;
	case ARG: case ASGN: case CALL: case JUMP: case LABEL:
		break;
	default: assert(0);
	}
	return p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x8f53(%rip), %r12      # 0x20c30
leaq 0x91bb(%rip), %r14      # 0x20e9f
leaq 0x91ce(%rip), %r15      # 0x20eb9
testq %rdi, %rdi
je 0x17ec7
movq %rdi, %rbx
movl (%rdi), %eax
addl $-0x10, %eax
shrl $0x4, %eax
cmpl $0x2a, %eax
ja 0x17f00
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq 0x10(%rbx), %rdi
jmp 0x17ceb
movq 0x18(%rbx), %rdi
callq 0x17ccb
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x17d11
jmp 0x17ec9
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x17ceb
jmp 0x17e60
movq 0x18(%rbx), %r13
testq %r13, %r13
je 0x17ee1
cmpl $0x2a0, (%r13)          # imm = 0x2A0
jne 0x17ee1
cmpq $0x0, 0x28(%rbx)
je 0x17dd7
movq 0x10(%r13), %rax
testq %rax, %rax
je 0x17dd7
movl (%rax), %ecx
andl $-0x10, %ecx
cmpl $0x30, %ecx
jne 0x17dd7
leaq 0x10(%r13), %rbp
addq $0x18, %rax
jmp 0x17dde
movq 0x8(%rbx), %rsi
cmpl $0x0, 0x8(%rsi)
jne 0x17d93
movq %r14, %rdi
xorl %eax, %eax
callq 0x9be3
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rax
cmpl $0xf, (%rax)
movq %rax, %rcx
jb 0x17da7
movq 0x10(%rax), %rcx
cmpl $0x7, (%rcx)
jne 0x17d11
movq 0x10(%rax), %rax
movl (%rax), %eax
cmpl $0x1f, %eax
je 0x17dc4
cmpl $0x10, %eax
jne 0x17d11
movq 0x8(%rbx), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x9be3
jmp 0x17d11
leaq 0x10(%r13), %rax
movq %rax, %rbp
movq (%rax), %rdi
callq 0x17ccb
movq %rax, (%rbp)
cmpq $0x0, 0x28(%rbx)
je 0x17e0e
movq 0x18(%r13), %rax
testq %rax, %rax
je 0x17e0e
movl (%rax), %ecx
andl $-0x10, %ecx
cmpl $0x30, %ecx
jne 0x17e0e
leaq 0x18(%r13), %rbp
addq $0x18, %rax
jmp 0x17e15
leaq 0x18(%r13), %rax
movq %rax, %rbp
movq (%rax), %rdi
callq 0x17ccb
movq %rax, (%rbp)
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x17e2f
callq 0x178a9
movq $0x0, 0x28(%rbx)
cmpq $0x0, 0x10(%r13)
jne 0x17ec9
cmpq $0x0, 0x18(%r13)
je 0x17d11
jmp 0x17ec9
movq 0x28(%rbx), %rdi
testb $0x2, 0x1b(%rdi)
je 0x17ec7
callq 0x178a9
jmp 0x17ec7
testq %rdi, %rdi
je 0x17e8a
cmpl $0xd9, (%rdi)
jne 0x17e77
cmpl $0x49, (%rax)
jne 0x17e77
movq %rdi, %rbx
jmp 0x17ec9
testq %rdi, %rdi
je 0x17e8a
cmpl $0x2a0, (%rdi)          # imm = 0x2A0
jne 0x17e8a
cmpq 0x10(%rdi), %rax
je 0x17edb
movq 0x8(%rbx), %r14
movq 0x10(%rbx), %rdi
callq 0x17ccb
movq %rax, %r15
movq 0x18(%rbx), %rdi
callq 0x17ccb
movl $0x2a0, %edi            # imm = 0x2A0
movq %r14, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x17b61
movq %rax, %rbx
cmpq $0x0, 0x10(%rax)
jne 0x17ec9
cmpq $0x0, 0x18(%rbx)
jne 0x17ec9
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rdi), %rbx
jmp 0x17ec9
leaq 0x8f97(%rip), %rdi      # 0x20e7f
leaq 0x8ea6(%rip), %rsi      # 0x20d95
leaq 0x8f9d(%rip), %rcx      # 0x20e93
movl $0x9a, %edx
callq 0x30d0
leaq 0x6294(%rip), %rdi      # 0x1e19b
leaq 0x8e87(%rip), %rsi      # 0x20d95
leaq 0x8f7e(%rip), %rcx      # 0x20e93
movl $0xd2, %edx
callq 0x30d0