// File: /workspace/github_c_makefile_star2_O3/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 0x7194
movq %rax, %rbx
movl $0x5e, %edi
callq 0xb00a
testb %al, %al
je 0x70f4
movq %r14, %rdi
callq 0x7252
movq %rax, %r15
movq %rax, 0x10(%rsp)
leaq 0xc679(%rip), %rsi      # 0x1362a
movl $0x5f, %edi
callq 0xafeb
movq %r14, %rdi
callq 0x6f6b
movq %rax, 0x8(%rsp)
movq 0x8(%r15), %r14
movq 0x8(%rax), %r13
cmpq %r13, %r14
je 0x7036
movq %rax, %r12
testb $0x8, 0x4(%r14)
je 0x6fe6
testb $0x8, 0x4(%r13)
jne 0x705b
leaq 0x149ab(%rip), %rbp     # 0x1b998
movq %r14, %rax
xorq %rbp, %rax
movq %r13, %rcx
xorq %rbp, %rcx
orq %rax, %rcx
je 0x706d
movq %r15, %rdi
callq 0x603c
movq %rax, %r15
movq %rax, 0x10(%rsp)
movq %r12, %rdi
callq 0x603c
movq %rax, %r12
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0x692f
testb %al, %al
je 0x703b
cmpl $0xc, (%r13)
jne 0x703b
movq %r13, %rbp
jmp 0x706d
movq %r14, %rbp
jmp 0x706d
movq %r12, %rdi
callq 0x692f
movl (%r14), %ecx
testb %al, %al
je 0x7106
movq %r14, %rbp
cmpl $0xc, %ecx
je 0x706d
jmp 0x7160
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x72d9
movq %rax, %rbp
movq %rbx, %rdi
callq 0x603c
movq %rax, %r15
cmpl $0x1, (%rax)
jne 0x70b3
movq 0x8(%r15), %rax
testb $0x2, 0x4(%rax)
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r14
je 0x70bd
cmpq $0x0, 0x30(%r15)
cmoveq %r14, %r12
movq %r12, %rdi
movq %rbp, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6965
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r14
movl $0x40, %edi
callq 0xe142
movq %rax, %rbx
movl $0x0, 0x10(%rax)
movq %rbp, 0x8(%rax)
movw $0x0, 0x4(%rax)
movl $0xa, (%rax)
movq %r15, 0x18(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movq %r12, 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 0x7160
cmpl $0xc, (%r13)
jne 0x7160
movl 0x38(%r13), %ebp
orl 0x38(%r14), %ebp
movq 0x20(%r14), %r14
leaq 0x14873(%rip), %rdi     # 0x1b998
cmpq %rdi, %r14
je 0x7154
movq 0x20(%r13), %r15
cmpq 0x13e6b(%rip), %r15     # 0x1afa0
je 0x7154
movq %r14, %rdi
movq %r15, %rsi
callq 0xd8b8
testb %al, %al
je 0x7180
movq %r14, %rdi
movq %r15, %rsi
callq 0xd9c5
movq %rax, %rdi
movl %ebp, %esi
callq 0xd803
jmp 0x706a
leaq 0x14fa1(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xc50e(%rip), %rsi      # 0x13680
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xd55c
jmp 0x70f4
leaq 0x14f81(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xc4b2(%rip), %rsi      # 0x13644
jmp 0x7172