// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]cproc/expr.c
// Function: condexpr
struct expr *
condexpr(struct scope *s)
{
	struct expr *e, *l, *r;
	struct type *t, *lt, *rt;
	enum typequal tq;

	e = binaryexpr(s, NULL, 0);
	if (!consume(TQUESTION))
		return e;
	l = expr(s);
	expect(TCOLON, "in conditional expression");
	r = condexpr(s);

	lt = l->type;
	rt = r->type;
	if (lt == rt) {
		t = lt;
	} else if (lt->prop & PROPARITH && rt->prop & PROPARITH) {
		t = commonreal(&l, &r);
	} else if (lt == &typevoid && rt == &typevoid) {
		t = &typevoid;
	} else {
		l = eval(l);
		r = eval(r);
		if (nullpointer(l) && rt->kind == TYPEPOINTER) {
			t = rt;
		} else if (nullpointer(r) && lt->kind == TYPEPOINTER) {
			t = lt;
		} else if (lt->kind == TYPEPOINTER && rt->kind == TYPEPOINTER) {
			tq = lt->qual | rt->qual;
			lt = lt->base;
			rt = rt->base;
			if (lt == &typevoid || rt == &typevoid) {
				t = &typevoid;
			} else if (typecompatible(lt, rt)) {
				t = typecomposite(lt, rt);
			} else {
				error(&tok.loc, "operands of conditional operator must have compatible types");
				return NULL;  /* unreachable */
			}
			t = mkpointertype(t, tq);
		} else {
			error(&tok.loc, "invalid operands to conditional operator");
			return NULL;  /* unreachable */
		}
	}
	e = eval(e);
	if (e->kind == EXPRCONST && e->type->prop & PROPINT)
		return exprconvert(e->u.constant.u ? l : r, t);
	e = mkexpr(EXPRCOND, t, e);
	e->u.cond.t = l;
	e->u.cond.f = r;
	return e;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
xorl %esi, %esi
xorl %edx, %edx
callq 0x6d8b
movq %rax, %rbx
pushq $0x5e
popq %rdi
callq 0xa28d
testb %al, %al
je 0x6ceb
movq %r14, %rdi
callq 0x6e32
movq %rax, %r15
movq %rax, 0x10(%rsp)
leaq 0xba5f(%rip), %rsi      # 0x1262a
pushq $0x5f
popq %rdi
callq 0xa26e
movq %r14, %rdi
callq 0x6b87
movq %rax, 0x8(%rsp)
movq 0x8(%r15), %r14
movq 0x8(%rax), %r13
cmpq %r13, %r14
je 0x6c4e
movq %rax, %r12
testb $0x8, 0x4(%r14)
je 0x6bfe
testb $0x8, 0x4(%r13)
jne 0x6c73
leaq 0x14d93(%rip), %rbp     # 0x1b998
movq %r14, %rax
xorq %rbp, %rax
movq %r13, %rcx
xorq %rbp, %rcx
orq %rax, %rcx
je 0x6c85
movq %r15, %rdi
callq 0x5d00
movq %rax, %r15
movq %rax, 0x10(%rsp)
movq %r12, %rdi
callq 0x5d00
movq %rax, %r12
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0x65e2
testb %al, %al
je 0x6c53
cmpl $0xc, (%r13)
jne 0x6c53
movq %r13, %rbp
jmp 0x6c85
movq %r14, %rbp
jmp 0x6c85
movq %r12, %rdi
callq 0x65e2
movl (%r14), %ecx
testb %al, %al
je 0x6cfd
movq %r14, %rbp
cmpl $0xc, %ecx
je 0x6c85
jmp 0x6d57
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x6e98
movq %rax, %rbp
movq %rbx, %rdi
callq 0x5d00
cmpl $0x1, (%rax)
jne 0x6cc8
movq 0x8(%rax), %rcx
testb $0x2, 0x4(%rcx)
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %r14
je 0x6cd2
cmpq $0x0, 0x30(%rax)
cmoveq %r14, %r15
movq %r15, %rdi
movq %rbp, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6618
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %r14
pushq $0xa
popq %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x6efa
movq %rax, %rbx
movq %r15, 0x30(%rax)
movq %r14, 0x38(%rax)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0xc, %ecx
jne 0x6d57
cmpl $0xc, (%r13)
jne 0x6d57
movl 0x38(%r13), %ebp
orl 0x38(%r14), %ebp
movq 0x20(%r14), %r14
leaq 0x14c7c(%rip), %rdi     # 0x1b998
cmpq %rdi, %r14
je 0x6d4b
movq 0x20(%r13), %r15
cmpq 0x14274(%rip), %r15     # 0x1afa0
je 0x6d4b
movq %r14, %rdi
movq %r15, %rsi
callq 0xc85a
testb %al, %al
je 0x6d77
movq %r14, %rdi
movq %r15, %rsi
callq 0xc95e
movq %rax, %rdi
movl %ebp, %esi
callq 0xc7d5
jmp 0x6c82
leaq 0x153aa(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xb917(%rip), %rsi      # 0x12680
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xc536
jmp 0x6ceb
leaq 0x1538a(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xb8bb(%rip), %rsi      # 0x12644
jmp 0x6d69