// File: /workspace/github_c_makefile_star2_O1/lucvoo[P]sparse-dev/linearize.c
// Function: linearize_logical
static pseudo_t linearize_logical(struct entrypoint *ep, struct expression *expr)
{
	struct symbol *ctype = expr->ctype;
	struct basic_block *other, *merge;
	struct instruction *node;
	pseudo_t src1, src2, phi2;

	if (!ep->active || !expr->left || !expr->right)
		return VOID;

	other = alloc_basic_block(ep, expr->right->pos);
	merge = alloc_basic_block(ep, expr->pos);
	node = alloc_phi_node(merge, ctype, NULL);

	// LHS and its shortcut
	if (expr->op == SPECIAL_LOGICAL_OR) {
		linearize_cond_branch(ep, expr->left, merge, other);
		src1 = value_pseudo(1);
	} else {
		linearize_cond_branch(ep, expr->left, other, merge);
		src1 = value_pseudo(0);
	}
	insert_phis(merge, src1, ctype, node);

	// RHS
	set_activeblock(ep, other);
	src2 = linearize_expression_to_bool(ep, expr->right);
	src2 = cast_pseudo(ep, src2, &bool_ctype, ctype);
	phi2 = alloc_phi(ep->active, src2, ctype);
	link_phi(node, phi2);

	// join
	set_activeblock(ep, merge);
	add_instruction(&merge->insns, node);
	return node->target;
}

// Assembly:
leaq 0x50d74(%rip), %rax     # 0x669d0
cmpq $0x0, 0x20(%rdi)
je 0x16014
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r13
cmpq $0x0, 0x20(%rsi)
je 0x16006
movq 0x28(%r13), %rcx
testq %rcx, %rcx
je 0x16006
movq %rdi, %r14
movq 0x10(%r13), %r12
movq 0x8(%rcx), %rbx
xorl %edi, %edi
callq 0x30217
movq %rax, %rbp
movq %rbx, (%rax)
movq %r14, 0x10(%rax)
movl 0x520be(%rip), %eax     # 0x67d70
leal 0x1(%rax), %ecx
movl %ecx, 0x520b5(%rip)     # 0x67d70
movl %eax, 0x38(%rbp)
movq 0x8(%r13), %rbx
xorl %edi, %edi
callq 0x30217
movq %rax, %r15
movq %rbx, (%rax)
movq %r14, 0x10(%rax)
movl 0x52097(%rip), %eax     # 0x67d70
leal 0x1(%rax), %ecx
movl %ecx, 0x5208e(%rip)     # 0x67d70
movl %eax, 0x38(%r15)
movq %r15, %rdi
movq %r12, 0x20(%rsp)
movq %r12, %rsi
xorl %edx, %edx
callq 0x13863
movq %rax, 0x10(%rsp)
cmpl $0x10e, 0x4(%r13)       # imm = 0x10E
movq 0x20(%r13), %rsi
movq %r14, 0x40(%rsp)
movq %r13, 0x30(%rsp)
movq %rbp, 0x28(%rsp)
movq %r14, %rdi
jne 0x15d2f
movq %r15, %rdx
movq %rbp, %rcx
callq 0x1703a
movl $0x1, %edi
jmp 0x15d3c
movq %rbp, %rdx
movq %r15, %rcx
callq 0x1703a
xorl %edi, %edi
callq 0x136d3
movq %rax, 0x50(%rsp)
movq %r15, 0x38(%rsp)
movq 0x18(%r15), %rax
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x15e59
movq 0x10(%rsp), %rax
addq $0x38, %rax
movq %rax, 0x48(%rsp)
movq 0x18(%rsp), %r15
movzwl (%r15), %eax
testb %al, %al
jle 0x15e4a
xorl %r14d, %r14d
movq 0x18(%r15,%r14,8), %rbp
movzwl %ax, %eax
cmpl $0x100, %eax            # imm = 0x100
jb 0x15d97
testq %rbp, %rbp
je 0x15e37
movq 0x50(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x13787
movq %rax, %rbx
leaq 0x28(%rbp), %r13
movq %r13, %rdi
callq 0x22b10
movq %rax, %r12
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2285b
movq %r13, %rdi
movq %r12, %rsi
callq 0x2285b
movq %rbp, 0x8(%rbx)
movq 0x20(%rbx), %r13
movq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x2285b
movq %r13, (%rax)
testq %r13, %r13
je 0x15e2a
movq %rax, %rbx
movl 0x4(%r13), %eax
cmpl $0x6, %eax
ja 0x15e01
movl $0x43, %ecx
btl %eax, %ecx
jb 0x15e2a
leaq 0x4b3a8(%rip), %rdi     # 0x611b0
movl $0x10, %esi
callq 0x2fd3c
movq %rbx, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x8(%r13), %rdi
movq %rax, %rsi
callq 0x2285b
movq 0x18(%r13), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x38(%rax)
incq %r14
movl (%r15), %eax
movsbq %al, %rcx
cmpq %rcx, %r14
jl 0x15d7f
movq 0x10(%r15), %r15
cmpq 0x18(%rsp), %r15
jne 0x15d70
movq 0x40(%rsp), %r15
movq %r15, %rdi
movq 0x28(%rsp), %rsi
callq 0x1401d
movq 0x30(%rsp), %rax
movq 0x28(%rax), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x1447d
movq %rax, %rbx
movq 0x10(%r14), %r14
testq %r14, %r14
sete %al
leaq 0x50b3d(%rip), %rsi     # 0x669d0
cmpq %rsi, %rbx
sete %cl
orb %al, %cl
jne 0x15f53
movzbl (%r14), %eax
movq %r14, %rcx
cmpl $0x3, %eax
jne 0x15eb1
movq 0x60(%r14), %rcx
cmpq 0x4b128(%rip), %rcx     # 0x60fe0
je 0x15ec7
cmpl $0x6, 0x4(%rbx)
jne 0x15ecf
cmpq $0x2, 0x18(%rbx)
jae 0x15ecf
movq %rbx, %rsi
jmp 0x15f53
movq %r14, %rcx
cmpl $0x3, %eax
jne 0x15edb
movq 0x60(%r14), %rcx
movq 0x60(%rcx), %rax
cmpq 0x4b05a(%rip), %rax     # 0x60f40
je 0x15ef6
xorl %edi, %edi
callq 0x136d3
movl $0x30, %edx
jmp 0x15f33
fldz
fstpt (%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x149c4
cmpb $0x3, (%r14)
movq %r14, %rcx
jne 0x15f13
movq 0x60(%r14), %rcx
movq 0x60(%rcx), %rcx
movl $0x30, %edx
cmpq 0x4b01d(%rip), %rcx     # 0x60f40
jne 0x15f33
leaq 0x2cd24(%rip), %rcx     # 0x42c50
movsbl 0x183(%rcx), %edx
leaq 0x560fe(%rip), %rsi     # 0x6c038
movq %r15, %rdi
movq %rbx, %rcx
movq %rax, %r8
callq 0x16d46
movq %rax, %rsi
movq 0x18(%rax), %rax
movq %r14, 0x40(%rax)
leaq 0x560de(%rip), %rdx     # 0x6c038
movq %r15, %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rcx
callq 0x175ad
movq 0x20(%r15), %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x13822
movq %rax, %rbx
movq 0x10(%rsp), %rdi
addq $0x38, %rdi
movq %rax, %rsi
callq 0x2285b
movq %rbx, (%rax)
testq %rbx, %rbx
je 0x15fd6
movq %rax, %r14
movl 0x4(%rbx), %eax
cmpl $0x6, %eax
ja 0x15faa
movl $0x43, %ecx
btl %eax, %ecx
jb 0x15fd6
leaq 0x4b1ff(%rip), %rdi     # 0x611b0
movl $0x10, %esi
callq 0x2fd3c
movq %r14, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movq %rbx, %rdi
addq $0x8, %rdi
movq %rax, %rsi
callq 0x2285b
movq 0x18(%rbx), %rax
movq 0x10(%rsp), %r14
movq %r14, 0x38(%rax)
movq %r15, %rdi
movq 0x38(%rsp), %rbx
movq %rbx, %rsi
callq 0x1401d
addq $0x28, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2285b
movq 0x20(%r14), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq