// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlbsp/qbsp.cpp
// Function: SplitBrush(brush_s*, plane_t const*, brush_s**, brush_s**)
void SplitBrush (brush_t *in, const dplane_t *split, brush_t **front, brush_t **back)
	// 'in' will be freed
{
	in->next = NULL;
	bool onfront;
	bool onback;
	onfront = false;
	onback = false;
	side_t *s;
	for (s = in->sides; s; s = s->next)
	{
		switch (s->w->WindingOnPlaneSide (split->normal, split->dist, 2 * ON_EPSILON))
		{
		case SIDE_CROSS:
			onfront = true;
			onback = true;
			break;
		case SIDE_FRONT:
			onfront = true;
			break;
		case SIDE_BACK:
			onback = true;
			break;
		case SIDE_ON:
			break;
		}
		if (onfront && onback)
			break;
	}
	if (!onfront && !onback)
	{
		FreeBrush (in);
		*front = NULL;
		*back = NULL;
		return;
	}
	if (!onfront)
	{
		*front = NULL;
		*back = in;
		return;
	}
	if (!onback)
	{
		*front = in;
		*back = NULL;
		return;
	}
	*front = in;
	*back = NewBrushFromBrush (in);
	dplane_t frontclip = *split;
	dplane_t backclip = *split;
	VectorSubtract (vec3_origin, backclip.normal, backclip.normal);
	backclip.dist = -backclip.dist;
	ClipBrush (front, &frontclip, NORMAL_EPSILON);
	ClipBrush (back, &backclip, NORMAL_EPSILON);
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq $0x0, (%rdi)
movq 0x8(%rdi), %rbx
testq %rbx, %rbx
je 0x15462
xorl %ebp, %ebp
xorl %r13d, %r13d
movq 0x48(%rbx), %rdi
movsd 0x30(%r15), %xmm0
movq %r15, %rsi
movsd 0xd032(%rip), %xmm1     # 0x22460
callq 0xcfc4
cmpl $0x1, %eax
je 0x15444
testl %eax, %eax
je 0x15449
cmpl $-0x2, %eax
jne 0x1544c
movb $0x1, %r13b
movb $0x1, %bpl
jmp 0x1544c
movb $0x1, %r13b
testb $0x1, %r13b
je 0x15458
testb $0x1, %bpl
jne 0x15467
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x15419
jmp 0x15467
xorl %r13d, %r13d
xorl %ebp, %ebp
testb $0x1, %r13b
movq %r14, %rbx
je 0x15540
movq %r12, (%rbx)
testb $0x1, %bpl
je 0x15557
movq %r12, %rdi
callq 0x15244
movq 0x8(%rsp), %r14
movq %rax, (%r14)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups 0x30(%r15), %xmm3
leaq 0x50(%rsp), %rsi
movaps %xmm3, 0x30(%rsi)
movaps %xmm2, 0x20(%rsi)
movaps %xmm1, 0x10(%rsi)
movaps %xmm0, (%rsi)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups 0x30(%r15), %xmm3
leaq 0x10(%rsp), %r15
movaps %xmm0, (%r15)
movaps %xmm1, 0x10(%r15)
movaps %xmm3, 0x30(%r15)
movaps %xmm2, 0x20(%r15)
leaq 0xa8f6(%rip), %rax      # 0x1fde0
movapd (%rax), %xmm0
subpd (%r15), %xmm0
movapd %xmm0, (%r15)
movsd 0x10(%rax), %xmm0
subsd 0x10(%r15), %xmm0
movsd %xmm0, 0x10(%r15)
movsd 0x30(%r15), %xmm0
xorps 0xbdba(%rip), %xmm0     # 0x212d0
movlps %xmm0, 0x30(%r15)
movsd 0x8bed(%rip), %xmm0     # 0x1e110
movq %rbx, %rdi
callq 0x1528e
movq %r14, %rdi
movq %r15, %rsi
movsd 0x8bd7(%rip), %xmm0     # 0x1e110
callq 0x1528e
jmp 0x1557a
testb $0x1, %bpl
je 0x15565
movq $0x0, (%rbx)
movq 0x8(%rsp), %rax
movq %r12, (%rax)
jmp 0x1557a
movq 0x8(%rsp), %rax
movq $0x0, (%rax)
jmp 0x1557a
movq %r12, %rdi
callq 0x15204
xorl %eax, %eax
movq %rax, (%rbx)
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq