// File: 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:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rcx, 0x98(%rsp)
movq 0xb0(%rsp), %rax
movq $0x0, (%rax)
movb $0x0, 0x97(%rsp)
movb $0x0, 0x96(%rsp)
movq 0xb0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x88(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x254b9
movq 0x88(%rsp), %rax
movq 0x48(%rax), %rdi
movq 0xa8(%rsp), %rsi
movsd 0x30(%rsi), %xmm0
movsd 0x151ce(%rip), %xmm1    # 0x3a608
callq 0x10470
addl $0x2, %eax
movl %eax, %ecx
movq %rcx, (%rsp)
subl $0x4, %eax
ja 0x25489
movq (%rsp), %rax
leaq 0x151d0(%rip), %rcx     # 0x3a628
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x1, 0x97(%rsp)
movb $0x1, 0x96(%rsp)
jmp 0x25489
movb $0x1, 0x97(%rsp)
jmp 0x25489
movb $0x1, 0x96(%rsp)
jmp 0x25489
jmp 0x25489
testb $0x1, 0x97(%rsp)
je 0x2549f
testb $0x1, 0x96(%rsp)
je 0x2549f
jmp 0x254b9
jmp 0x254a1
movq 0x88(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x88(%rsp)
jmp 0x2540a
testb $0x1, 0x97(%rsp)
jne 0x254fd
testb $0x1, 0x96(%rsp)
jne 0x254fd
movq 0xb0(%rsp), %rdi
callq 0x250e0
movq 0xa0(%rsp), %rax
movq $0x0, (%rax)
movq 0x98(%rsp), %rax
movq $0x0, (%rax)
jmp 0x25659
testb $0x1, 0x97(%rsp)
jne 0x2552e
movq 0xa0(%rsp), %rax
movq $0x0, (%rax)
movq 0xb0(%rsp), %rcx
movq 0x98(%rsp), %rax
movq %rcx, (%rax)
jmp 0x25659
testb $0x1, 0x96(%rsp)
jne 0x2555f
movq 0xb0(%rsp), %rcx
movq 0xa0(%rsp), %rax
movq %rcx, (%rax)
movq 0x98(%rsp), %rax
movq $0x0, (%rax)
jmp 0x25659
movq 0xb0(%rsp), %rcx
movq 0xa0(%rsp), %rax
movq %rcx, (%rax)
movq 0xb0(%rsp), %rdi
callq 0x25140
movq %rax, %rcx
movq 0x98(%rsp), %rax
movq %rcx, (%rax)
movq 0xa8(%rsp), %rsi
leaq 0x48(%rsp), %rdi
movl $0x40, %edx
callq 0x4260
movq 0xa8(%rsp), %rsi
leaq 0x8(%rsp), %rdi
movl $0x40, %edx
callq 0x4260
leaq 0x1288e(%rip), %rax     # 0x37e50
movsd (%rax), %xmm0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x12877(%rip), %rax     # 0x37e50
movsd 0x8(%rax), %xmm0
subsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x1285f(%rip), %rax     # 0x37e50
movsd 0x10(%rax), %xmm0
subsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x38(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0xa0(%rsp), %rdi
leaq 0x48(%rsp), %rsi
movsd 0x10a2e(%rip), %xmm0    # 0x36068
callq 0x251c0
movq 0x98(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movsd 0x10a14(%rip), %xmm0    # 0x36068
callq 0x251c0
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)