// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]cproc/expr.c
// Function: mkbinaryexpr
static struct expr *
mkbinaryexpr(struct location *loc, enum tokenkind op, struct expr *l, struct expr *r)
{
	struct expr *e;
	struct type *t = NULL;
	enum typeprop lp, rp;

	lp = l->type->prop;
	rp = r->type->prop;
	switch (op) {
	case TLOR:
	case TLAND:
		if (!(lp & PROPSCALAR))
			error(loc, "left operand of '%s' operator must be scalar", tokstr[op]);
		if (!(rp & PROPSCALAR))
			error(loc, "right operand of '%s' operator must be scalar", tokstr[op]);
		t = &typeint;
		break;
	case TEQL:
	case TNEQ:
		t = &typeint;
		if (lp & PROPARITH && rp & PROPARITH) {
			commonreal(&l, &r);
			break;
		}
		if (l->type->kind != TYPEPOINTER)
			e = l, l = r, r = e;
		if (l->type->kind != TYPEPOINTER)
			error(loc, "invalid operands to '%s' operator", tokstr[op]);
		if (nullpointer(eval(r))) {
			r = exprconvert(r, l->type);
			break;
		}
		if (nullpointer(eval(l))) {
			l = exprconvert(l, r->type);
			break;
		}
		if (r->type->kind != TYPEPOINTER)
			error(loc, "invalid operands to '%s' operator", tokstr[op]);
		if (l->type->base->kind == TYPEVOID)
			e = l, l = r, r = e;
		if (r->type->base->kind == TYPEVOID && l->type->base->kind != TYPEFUNC)
			r = exprconvert(r, l->type);
		else if (!typecompatible(l->type->base, r->type->base))
			error(loc, "pointer operands to '%s' operator are to incompatible types", tokstr[op]);
		break;
	case TLESS:
	case TGREATER:
	case TLEQ:
	case TGEQ:
		t = &typeint;
		if (lp & PROPREAL && rp & PROPREAL) {
			commonreal(&l, &r);
		} else if (l->type->kind == TYPEPOINTER && r->type->kind == TYPEPOINTER) {
			if (!typecompatible(l->type->base, r->type->base) || l->type->base->kind == TYPEFUNC)
				error(loc, "pointer operands to '%s' operator must be to compatible object types", tokstr[op]);
		} else {
			error(loc, "invalid operands to '%s' operator", tokstr[op]);
		}
		break;
	case TBOR:
	case TXOR:
	case TBAND:
		t = commonreal(&l, &r);
		break;
	case TADD:
		if (lp & PROPARITH && rp & PROPARITH) {
			t = commonreal(&l, &r);
			break;
		}
		if (r->type->kind == TYPEPOINTER)
			e = l, l = r, r = e, rp = lp;
		if (l->type->kind != TYPEPOINTER || !(rp & PROPINT))
			error(loc, "invalid operands to '+' operator");
		t = l->type;
		if (t->base->incomplete || t->base->kind == TYPEFUNC)
			error(loc, "pointer operand to '+' must be to complete object type");
		r = mkbinaryexpr(loc, TMUL, exprconvert(r, &typeulong), mkconstexpr(&typeulong, t->base->size));
		break;
	case TSUB:
		if (lp & PROPARITH && rp & PROPARITH) {
			t = commonreal(&l, &r);
			break;
		}
		if (l->type->kind != TYPEPOINTER || !(rp & PROPINT) && r->type->kind != TYPEPOINTER)
			error(loc, "invalid operands to '-' operator");
		if (l->type->base->incomplete || l->type->base->kind == TYPEFUNC)
			error(loc, "pointer operand to '-' must be to complete object type");
		if (rp & PROPINT) {
			t = l->type;
			r = mkbinaryexpr(loc, TMUL, exprconvert(r, &typeulong), mkconstexpr(&typeulong, t->base->size));
		} else {
			if (!typecompatible(l->type->base, r->type->base))
				error(&tok.loc, "pointer operands to '-' are to incompatible types");
			op = TDIV;
			t = &typelong;
			e = mkbinaryexpr(loc, TSUB, exprconvert(l, &typelong), exprconvert(r, &typelong));
			r = mkconstexpr(&typelong, l->type->base->size);
			l = e;
		}
		break;
	case TMOD:
		if (!(lp & PROPINT) || !(rp & PROPINT))
			error(loc, "operands to '%%' operator must be integer");
		t = commonreal(&l, &r);
		break;
	case TMUL:
	case TDIV:
		if (!(lp & PROPARITH) || !(rp & PROPARITH))
			error(loc, "operands to '%s' operator must be arithmetic", tokstr[op]);
		t = commonreal(&l, &r);
		break;
	case TSHL:
	case TSHR:
		if (!(lp & PROPINT) || !(rp & PROPINT))
			error(loc, "operands to '%s' operator must be integer", tokstr[op]);
		l = exprpromote(l);
		r = exprpromote(r);
		t = l->type;
		break;
	default:
		fatal("internal error: unknown binary operator %d", op);
	}
	e = mkexpr(EXPRBINARY, t, NULL);
	e->op = op;
	e->u.binary.l = l;
	e->u.binary.r = r;

	return e;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r13
movl %esi, %r14d
movq %rdx, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
leal -0x4a(%r14), %edx
cmpl $0x13, %edx
ja 0x74a9
movq %rcx, %r12
movq %rdi, %rbx
movq 0x8(%r13), %rax
movl 0x4(%rax), %ecx
movq 0x8(%r12), %r15
movl 0x4(%r15), %ebp
leaq 0xafd4(%rip), %rsi      # 0x122a8
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
testb $0x4, %cl
je 0x72eb
andl $0x4, %ebp
jne 0x739b
cmpl $0xc, (%rax)
jne 0x7445
cmpl $0xc, (%r15)
jne 0x7445
movq 0x20(%rax), %rdi
movq 0x20(%r15), %rsi
callq 0xc85a
testb %al, %al
je 0x7320
movq 0x8(%r13), %rax
movq 0x20(%rax), %rax
cmpl $0xe, (%rax)
jne 0x75c3
movl %r14d, %eax
leaq 0x142e6(%rip), %rcx     # 0x1b610
movq (%rcx,%rax,8), %rdx
leaq 0xbefe(%rip), %rsi      # 0x13233
jmp 0x745a
testb $0x2, %cl
je 0x7344
andl $0x2, %ebp
jne 0x7363
movl %r14d, %eax
leaq 0x142c2(%rip), %rcx     # 0x1b610
movq (%rcx,%rax,8), %rdx
leaq 0xc058(%rip), %rsi      # 0x133b1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
movq %r13, %rdi
callq 0x664f
movq %rax, %rbx
movq %rax, 0x10(%rsp)
movq %r12, %rdi
callq 0x664f
movq %rax, 0x8(%rsp)
movq 0x8(%rbx), %r15
jmp 0x77c5
testb $0x8, %cl
je 0x7494
andl $0x8, %ebp
je 0x7494
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x6e98
jmp 0x75c3
testb $0x8, %cl
je 0x73b9
andl $0x8, %ebp
jne 0x73d8
movl %r14d, %eax
leaq 0x1424d(%rip), %rcx     # 0x1b610
movq (%rcx,%rax,8), %rdx
leaq 0xbfb6(%rip), %rsi      # 0x13384
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x6e98
movq %rax, %r15
jmp 0x77c5
movl %r14d, %r12d
testb $0x10, %cl
jne 0x7413
leaq 0x14212(%rip), %rax     # 0x1b610
movq (%rax,%r12,8), %rdx
leaq 0xbd71(%rip), %rsi      # 0x1317a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
leaq 0x147e6(%rip), %r15     # 0x1bc00
testb $0x10, %bpl
jne 0x77c5
leaq 0x141e5(%rip), %rax     # 0x1b610
movq (%rax,%r12,8), %rdx
leaq 0xbd71(%rip), %rsi      # 0x131a7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
jmp 0x77c5
movl %r14d, %eax
leaq 0x141c1(%rip), %rcx     # 0x1b610
movq (%rcx,%rax,8), %rdx
leaq 0xbd7b(%rip), %rsi      # 0x131d5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
jmp 0x75c3
testb $0x8, %cl
je 0x7521
movl %ebp, %edx
andl $0x8, %edx
je 0x7521
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x6e98
movq %rax, %r15
jmp 0x773b
cmpl $0xc, (%rax)
jne 0x7538
leaq 0x8(%r13), %rbp
movq %r13, %r15
jmp 0x7572
leaq 0xbf2b(%rip), %rdi      # 0x133db
xorl %r15d, %r15d
movl %r14d, %esi
xorl %eax, %eax
callq 0xcffb
jmp 0x77c5
testb $0x8, %cl
je 0x75cf
movl %ebp, %ecx
andl $0x8, %ecx
je 0x75cf
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x6e98
movq %rax, %r15
jmp 0x77c1
testb $0x2, %cl
je 0x74f7
andl $0x2, %ebp
jne 0x7508
leaq 0xbe5c(%rip), %rsi      # 0x1335a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x6e98
movq %rax, %r15
pushq $0x51
jmp 0x77c3
cmpl $0xc, (%r15)
jne 0x76ab
movq %r12, 0x10(%rsp)
movq %r13, %r14
jmp 0x76b6
movq %r12, 0x10(%rsp)
movq %r13, 0x8(%rsp)
leaq 0x8(%r12), %rbp
cmpl $0xc, (%r15)
je 0x756c
movl %r14d, %eax
leaq 0x140b9(%rip), %rcx     # 0x1b610
movq (%rcx,%rax,8), %rdx
leaq 0xbc73(%rip), %rsi      # 0x131d5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
movq %r12, %r15
movq %r13, %r12
movq %r12, %rdi
callq 0x5d00
movq %rax, %rdi
callq 0x65e2
testb %al, %al
je 0x7599
movq (%rbp), %rsi
movq %r12, %rdi
callq 0x6618
movq %rax, 0x8(%rsp)
jmp 0x75c3
movq %r15, %rdi
callq 0x5d00
movq %rax, %rdi
callq 0x65e2
movq 0x8(%r12), %rsi
testb %al, %al
je 0x7742
movq %r15, %rdi
callq 0x6618
movq %rax, 0x10(%rsp)
leaq 0x14636(%rip), %r15     # 0x1bc00
jmp 0x77c5
cmpl $0xc, (%rax)
jne 0x75e0
testb $0x2, %bpl
jne 0x75f5
cmpl $0xc, (%r15)
je 0x75f5
leaq 0xbce9(%rip), %rsi      # 0x132d0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
movq 0x8(%r13), %rax
movq 0x20(%rax), %rax
cmpb $0x0, 0x3c(%rax)
jne 0x7604
cmpl $0xe, (%rax)
jne 0x7615
leaq 0xbce6(%rip), %rsi      # 0x132f1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
movq 0x8(%r13), %r15
testb $0x2, %bpl
jne 0x7786
movq 0x20(%r15), %rdi
movq 0x8(%r12), %rax
movq 0x20(%rax), %rsi
callq 0xc85a
testb %al, %al
jne 0x7652
leaq 0x14ac8(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xbcdd(%rip), %rsi      # 0x13328
xorl %eax, %eax
callq 0xc536
leaq 0x14657(%rip), %r15     # 0x1bcb0
movq %r13, %rdi
movq %r15, %rsi
callq 0x6618
movq %rax, %r14
movq %r12, %rdi
movq %r15, %rsi
callq 0x6618
pushq $0x4d
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
callq 0x728c
movq %rax, %rbx
movq 0x8(%r13), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rsi
movq %r15, %rdi
callq 0x8e6f
movq %rax, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
pushq $0x50
jmp 0x77c3
movq %r12, %r14
movq %rax, %r15
movq %r13, %r12
movl %ebp, %ecx
cmpl $0xc, (%r15)
setne %al
testb $0x2, %cl
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x76e0
leaq 0xbba7(%rip), %rsi      # 0x13278
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
movq 0x8(%r12), %r15
movq 0x20(%r15), %rax
cmpb $0x0, 0x3c(%rax)
jne 0x76ef
cmpl $0xe, (%rax)
jne 0x7700
leaq 0xbba3(%rip), %rsi      # 0x13299
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
leaq 0x14601(%rip), %r12     # 0x1bd08
movq %r14, %rdi
movq %r12, %rsi
callq 0x6618
movq %rax, %r14
movq 0x20(%r15), %rax
movq 0x10(%rax), %rsi
movq %r12, %rdi
callq 0x8e6f
pushq $0x4b
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
callq 0x728c
movq %rax, 0x8(%rsp)
pushq $0x4c
jmp 0x77c3
cmpl $0xc, (%rsi)
je 0x7766
movl %r14d, %eax
leaq 0x13ebf(%rip), %rcx     # 0x1b610
movq (%rcx,%rax,8), %rdx
leaq 0xba79(%rip), %rsi      # 0x131d5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc536
movq (%rbp), %rax
movq 0x20(%rax), %rax
cmpl $0x1, (%rax)
jne 0x77f7
movq %r12, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq %r12, %rax
jmp 0x77fd
leaq 0x1457b(%rip), %r14     # 0x1bd08
movq %r12, %rdi
movq %r14, %rsi
callq 0x6618
movq %rax, %r12
movq 0x20(%r15), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x8e6f
pushq $0x4b
popq %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %rax, %rcx
callq 0x728c
movq %rax, 0x8(%rsp)
pushq $0x4d
popq %r14
pushq $0x9
popq %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x6efa
movl %r14d, 0x14(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x30(%rax)
movq 0x8(%rsp), %rcx
movq %rcx, 0x38(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rax
movq %r12, %r15
movq 0x8(%r15), %rcx
movq 0x20(%rcx), %rsi
cmpl $0x1, (%rsi)
movq 0x8(%rax), %rax
movq 0x20(%rax), %rdi
jne 0x7817
cmpl $0xe, (%rdi)
jne 0x7841
callq 0xc85a
leaq 0x143dd(%rip), %r15     # 0x1bc00
testb %al, %al
jne 0x77c5
movl %r14d, %eax
leaq 0x13ddf(%rip), %rcx     # 0x1b610
movq (%rcx,%rax,8), %rdx
leaq 0xb9bb(%rip), %rsi      # 0x131f7
jmp 0x7436
movq %r15, %rdi
movq %rax, %rsi
jmp 0x758d