// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rdx, %r14
movq %rdi, %r12
movq $0x0, (%rdi)
movq 0x8(%rdi), %r13
testq %r13, %r13
je 0x1526d
movq %rsi, %r15
movq %rbx, 0x8(%rsp)
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x48(%r13), %rdi
movsd 0x30(%r15), %xmm0
movq %r15, %rsi
movsd 0xc307(%rip), %xmm1     # 0x21458
callq 0xcdf6
testl %eax, %eax
je 0x15170
cmpl $0x1, %eax
je 0x15166
cmpl $-0x2, %eax
jne 0x15169
jmp 0x15194
movb $0x1, %bpl
testb $0x1, %bl
jne 0x15172
jmp 0x15178
movb $0x1, %bl
testb $0x1, %bpl
jne 0x15181
movq (%r13), %r13
testq %r13, %r13
jne 0x1513c
testb $0x1, %bl
je 0x15256
testb $0x1, %bpl
je 0x1527f
movq %r12, (%r14)
movq %r12, %rdi
callq 0x14f6c
movq 0x8(%rsp), %rbx
movq %rax, (%rbx)
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 0x9bd0(%rip), %rax      # 0x1edd0
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 0xb084(%rip), %xmm0     # 0x202b0
movlps %xmm0, 0x30(%r15)
movsd 0x7edf(%rip), %xmm0     # 0x1d118
movq %r14, %rdi
callq 0x14fb5
movq %rbx, %rdi
movq %r15, %rsi
movsd 0x7ec9(%rip), %xmm0     # 0x1d118
callq 0x14fb5
jmp 0x1528e
testb $0x1, %bpl
movq 0x8(%rsp), %rbx
je 0x1526d
movq $0x0, (%r14)
movq %r12, (%rbx)
jmp 0x1528e
movq %r12, %rdi
callq 0x14f2c
xorl %eax, %eax
movq %rax, (%r14)
movq %rax, (%rbx)
jmp 0x1528e
movq %r12, (%r14)
movq 0x8(%rsp), %rax
movq $0x0, (%rax)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq