// File: /workspace/github_c_makefile_star2_O2/Oric4ever[P]lcc65/6502/build/../src/enode.c
// Function: asgnnode
Tree asgnnode(int op, Tree l, Tree r) {
	Type aty, ty;

	r = pointer(r);
	if ((ty = assign(l->type, r)) == 0) {
		typeerror(ASGN, l, r);
		if (r->type == voidtype)
			r = retype(r, inttype);
		ty = r->type;
	}
	if (l->op != FIELD)
		l = lvalue(l);
	aty = l->type;
	if (isptr(aty))
		aty = unqual(aty)->type;
	if (isconst(aty) || (isstruct(aty) && unqual(aty)->u.sym->u.s.cfields)) {
		if (isaddrop(l->op) && !l->u.sym->computed && !l->u.sym->generated)
			error("assignment to const identifier `%s'\n", l->u.sym->name);
		else
			error("assignment to const location\n");
    }
	r = cast(r, ty);
	if (l->op == FIELD && fieldsize(l->u.field) < 8*l->u.field->type->size) {
		if (isunsigned(l->u.field->type))
			r = bitnode(BAND, r,
				constnode(fieldmask(l->u.field), unsignedtype));
		else {
			int n = 8*l->u.field->type->size - fieldsize(l->u.field);
			/*
			 * The value of assignment is the value of the left
			 * operand (sec. 3.3.16), which for bit fields is the
			 * same as extracting the field. When r is a constant,
			 * the explicit left shift below avoids overflow that
			 * would occur if shnode(LSH, ...) were used. The
			 * subsequent shnode(RSH, ...) will be signed and thus
			 * extend the sign bit correctly.
			 */
			if (r->op == CNST+I)
				r = constnode(r->u.v.i<<n, inttype);
			else
				r = shnode(LSH, r, constnode(n, inttype));
			r = shnode(RSH, r, constnode(n, inttype));
		}
	}
	if (isstruct(ty)) {
		if (r->op == RIGHT && r->kids[0] && r->kids[0]->op == CALL+B
		&& isaddrop(l->op)) {
			/*
			 * When x=f() where f returns a struct and x is a simple
			 * address, release the temporary generated to hold f's
			 * return value and use x in its place. The RIGHT tree
			 * assigned to r below returns x's address, and
			 * rvalue(r) hangs that tree under an INDIR+B,
			 * thus identifying the result as an lvalue.
			 */
			r = r->kids[0];	/* CALL+B node */
			release(r->kids[1]->u.sym);
			r = tree(RIGHT, l->type,
				tree(CALL+B, r->kids[0]->type, r->kids[0], l),
				retype(isarray(l->u.sym->type) ? idnode(l->u.sym) : addrof(idnode(l->u.sym)), l->type));
			return rvalue(r);
		}
		return tree(ASGN+B, ty, l, r);
	}
	return tree(op + (isunsigned(ty) ? I : ttob(ty)), ty, l, r);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %ebp
movq %rdx, %rdi
callq 0xa22f
movq %rax, %r15
movq 0x8(%rbx), %rdi
movq %rax, %rsi
callq 0x9610
testq %rax, %rax
je 0x83b3
movq %rax, %r14
jmp 0x83ea
pushq $0x30
popq %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x86ad
movq 0x8(%r15), %r14
leaq 0x29c14(%rip), %rax     # 0x31fe0
cmpq (%rax), %r14
jne 0x83ea
leaq 0x29bc0(%rip), %rax     # 0x31f98
movq (%rax), %rsi
movq %r15, %rdi
callq 0x16727
movq %rax, %r15
movq 0x8(%rax), %r14
cmpl $0x2b0, (%rbx)          # imm = 0x2B0
je 0x83fd
movq %rbx, %rdi
callq 0xa87d
movq %rax, %rbx
movq 0x8(%rbx), %rax
movl (%rax), %ecx
cmpl $0xf, %ecx
jb 0x8413
movq 0x10(%rax), %rdx
cmpl $0x7, (%rdx)
je 0x841b
jmp 0x8421
movq %rax, %rdx
cmpl $0x7, %ecx
jne 0x8421
movq 0x10(%rdx), %rax
movl (%rax), %ecx
movl %ecx, %edx
orl $0x10, %edx
movabsq $0x100010001, %r13      # imm = 0x100010001
cmpl $0x1f, %edx
jne 0x8461
movl $0xfffffef9, %eax       # imm = 0xFFFFFEF9
addl (%rbx), %eax
cmpl $0x20, %eax
ja 0x8451
btq %rax, %r13
jae 0x8451
movq 0x28(%rbx), %rax
testb $0xc, 0x1b(%rax)
je 0x847a
leaq 0x147bd(%rip), %rdi     # 0x1cc15
xorl %eax, %eax
callq 0x8dd4
jmp 0x84a0
cmpl $0xf, %ecx
jb 0x848e
movq 0x10(%rax), %rcx
movl (%rcx), %ecx
addl $-0x9, %ecx
cmpl $0x2, %ecx
jae 0x84a0
movq 0x10(%rax), %rax
jmp 0x8496
movq 0x10(%rax), %rsi
leaq 0x1476b(%rip), %rdi     # 0x1cbf0
xorl %eax, %eax
callq 0x8dd4
jmp 0x84a0
addl $-0x9, %ecx
cmpl $0x2, %ecx
jae 0x84a0
movq 0x18(%rax), %rax
testb $0x1, 0x48(%rax)
jne 0x8435
movq %r15, %rdi
movq %r14, %rsi
callq 0x9912
movq %rax, %r15
cmpl $0x2b0, (%rbx)          # imm = 0x2B0
jne 0x8588
movq 0x28(%rbx), %rsi
movswl 0x16(%rsi), %edx
movswl 0x14(%rsi), %eax
movl %edx, %ecx
subl %eax, %ecx
movq 0x8(%rsi), %rsi
movl 0x8(%rsi), %r12d
shll $0x3, %r12d
cmpl %r12d, %ecx
jge 0x8588
movl (%rsi), %edi
cmpl $0xf, %edi
jb 0x84ec
movq 0x10(%rsi), %rsi
movl (%rsi), %edi
cmpl $0x6, %edi
jne 0x8519
pushq $-0x1
popq %rdi
shll %cl, %edi
notl %edi
leaq 0x29ad9(%rip), %rax     # 0x31fd8
movq (%rax), %rsi
callq 0x8726
movl $0x180, %edi            # imm = 0x180
movq %r15, %rsi
movq %rax, %rdx
callq 0x7a60
jmp 0x8585
subl %edx, %eax
addl %eax, %r12d
cmpl $0x15, (%r15)
jne 0x853e
movl 0x28(%r15), %edi
movl %r12d, %ecx
shll %cl, %edi
leaq 0x29a64(%rip), %rax     # 0x31f98
movq (%rax), %rsi
callq 0x8726
jmp 0x8560
leaq 0x29a53(%rip), %rax     # 0x31f98
movq (%rax), %rsi
movl %r12d, %edi
callq 0x8726
movl $0x150, %edi            # imm = 0x150
movq %r15, %rsi
movq %rax, %rdx
callq 0x82d7
movq %rax, %r15
leaq 0x29a2e(%rip), %rax     # 0x31f98
movq (%rax), %rsi
movl %r12d, %edi
callq 0x8726
movl $0x170, %edi            # imm = 0x170
movq %r15, %rsi
movq %rax, %rdx
callq 0x82d7
movq %rax, %r15
movl (%r14), %eax
cmpl $0xf, %eax
jb 0x85af
movq 0x10(%r14), %rax
movl (%rax), %eax
leal -0x9(%rax), %ecx
cmpl $0x2, %ecx
jb 0x85b7
cmpl $0x6, %eax
jne 0x8685
pushq $0x5
popq %rdi
jmp 0x868f
leal -0x9(%rax), %ecx
cmpl $0x1, %ecx
ja 0x859e
cmpl $0x2a0, (%r15)          # imm = 0x2A0
jne 0x8680
movq 0x10(%r15), %r12
testq %r12, %r12
je 0x8680
cmpl $0xd9, (%r12)
jne 0x8680
movl $0xfffffef9, %eax       # imm = 0xFFFFFEF9
addl (%rbx), %eax
cmpl $0x20, %eax
ja 0x8680
btq %rax, %r13
jae 0x8680
movq 0x18(%r12), %rax
movq 0x28(%rax), %rdi
callq 0x16370
movq 0x8(%rbx), %r14
movq 0x10(%r12), %rdx
movq 0x8(%rdx), %rsi
movl $0xd9, %edi
movq %rbx, %rcx
callq 0x165eb
movq %rax, %r15
movq 0x28(%rbx), %rdi
movq 0x20(%rdi), %rax
movl (%rax), %ebp
cmpl $0xf, %ebp
jb 0x8639
movq 0x10(%rax), %rax
movl (%rax), %ebp
callq 0x93b4
cmpl $0xc, %ebp
je 0x864b
movq %rax, %rdi
callq 0x92ec
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x16727
movl $0x2a0, %edi            # imm = 0x2A0
movq %r14, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x165eb
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0b9
pushq $0x39
popq %rdi
jmp 0x8691
movq %r14, %rdi
callq 0x18b82
movl %eax, %edi
addl %ebp, %edi
movq %r14, %rsi
movq %rbx, %rdx
movq %r15, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x165eb