// File: /workspace/github_c_makefile_star2_O1/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 0x72e4
movq %rax, %rbx
movl $0x5e, %edi
callq 0xb099
testb %al, %al
je 0x7217
movq %r14, %rdi
callq 0x73a2
movq %rax, %r15
movq %rax, 0x10(%rsp)
leaq 0xc4c4(%rip), %rsi      # 0x135ca
movl $0x5f, %edi
callq 0xb07a
movq %r14, %rdi
callq 0x70c0
movq %rax, 0x8(%rsp)
movq 0x8(%r15), %r14
movq 0x8(%rax), %r13
cmpq %r13, %r14
je 0x71a5
movq %rax, %r12
testb $0x8, 0x4(%r14)
je 0x713b
testb $0x8, 0x4(%r13)
jne 0x71aa
leaq 0x14856(%rip), %rbp     # 0x1b998
movq %r14, %rax
xorq %rbp, %rax
movq %r13, %rcx
xorq %rbp, %rcx
orq %rax, %rcx
je 0x71bc
movq %r15, %rdi
callq 0x61cc
movq %rax, %r15
movq %rax, 0x10(%rsp)
movq %r12, %rdi
callq 0x61cc
movq %rax, %r12
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0x6abb
testb %al, %al
je 0x718b
cmpl $0xc, (%r13)
jne 0x718b
movq %r13, %rbp
jmp 0x71bc
movq %r12, %rdi
callq 0x6abb
testb %al, %al
je 0x7255
cmpl $0xc, (%r14)
jne 0x7255
movq %r14, %rbp
jmp 0x71bc
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x7429
movq %rax, %rbp
movq %rbx, %rdi
callq 0x61cc
movq %rax, %r15
cmpl $0x1, (%rax)
jne 0x71d6
movq 0x8(%r15), %rax
testb $0x2, 0x4(%rax)
jne 0x7229
movl $0x40, %edi
callq 0xe13e
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 0x10(%rsp), %rax
movq %rax, 0x30(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0x38(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x30(%r15)
leaq 0x8(%rsp), %rax
leaq 0x10(%rsp), %rcx
cmoveq %rax, %rcx
movq (%rcx), %rdi
movq %rbp, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6af1
cmpl $0xc, (%r14)
jne 0x72b0
cmpl $0xc, (%r13)
jne 0x72b0
movl 0x38(%r13), %ebp
orl 0x38(%r14), %ebp
movq 0x20(%r14), %r14
leaq 0x14723(%rip), %rdi     # 0x1b998
cmpq %rdi, %r14
je 0x72a4
movq 0x20(%r13), %r15
cmpq 0x13d1b(%rip), %r15     # 0x1afa0
je 0x72a4
movq %r14, %rdi
movq %r15, %rsi
callq 0xd8c4
testb %al, %al
je 0x72d0
movq %r14, %rdi
movq %r15, %rsi
callq 0xd9c3
movq %rax, %rdi
movl %ebp, %esi
callq 0xd80f
jmp 0x71b9
leaq 0x14e51(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xc35e(%rip), %rsi      # 0x13620
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xd56a
jmp 0x7217
leaq 0x14e31(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xc302(%rip), %rsi      # 0x135e4
jmp 0x72c2