// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlcsg/brush.cpp
// Function: MakeBrushPlanes(brush_s*)
bool            MakeBrushPlanes(brush_t* b)
{
    int             i;
    int             j;
    int             planenum;
    side_t*         s;
    bface_t*        f;
    vec3_t          origin;

    //
    // if the origin key is set (by an origin brush), offset all of the values
    //
    GetVectorForKey(&g_entities[b->entitynum], "origin", origin);

    //
    // convert to mapplanes
    //
    // for each side in this brush
    for (i = 0; i < b->numsides; i++)
    {
        s = &g_brushsides[b->firstside + i];
        for (j = 0; j < 3; j++)
        {
            VectorSubtract(s->planepts[j], origin, s->planepts[j]);
        }
        planenum = PlaneFromPoints(s->planepts[0], s->planepts[1], s->planepts[2]);
        if (planenum == -1)
        {
            Fatal(assume_PLANE_WITH_NO_NORMAL, "Entity %i, Brush %i, Side %i: plane with no normal", 
#ifdef HLCSG_COUNT_NEW
				b->originalentitynum, b->originalbrushnum
#else
				b->entitynum, b->brushnum
#endif
				, i);
        }

        //
        // see if the plane has been used already
        //
        for (f = b->hulls[0].faces; f; f = f->next)
        {
            if (f->planenum == planenum || f->planenum == (planenum ^ 1))
            {
                Fatal(assume_BRUSH_WITH_COPLANAR_FACES, "Entity %i, Brush %i, Side %i: has a coplanar plane at (%.0f, %.0f, %.0f), texture %s",
#ifdef HLCSG_COUNT_NEW
					b->originalentitynum, b->originalbrushnum
#else
                      b->entitynum, b->brushnum
#endif
					  , i, s->planepts[0][0] + origin[0], s->planepts[0][1] + origin[1],
                      s->planepts[0][2] + origin[2], s->td.name);
            }
        }

        f = (bface_t*)Alloc(sizeof(*f));                             // TODO: This leaks

        f->planenum = planenum;
        f->plane = &g_mapplanes[planenum];
        f->next = b->hulls[0].faces;
        b->hulls[0].faces = f;
        f->texinfo = g_onlyents ? 0 : TexinfoForBrushTexture(f->plane, &s->td, origin
#ifdef ZHLT_HIDDENSOUNDTEXTURE
						, s->shouldhide
#endif
						);
#ifdef HLCSG_CUSTOMHULL
		f->bevel = b->bevel || s->bevel;
#endif
    }

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movslq 0x8(%rdi), %rax
leaq (%rax,%rax,4), %rdi
shlq $0x3, %rdi
addq 0x17f2e(%rip), %rdi     # 0x27fd8
leaq 0x11a6c(%rip), %rsi     # 0x21b1d
movq %rsp, %rdx
callq 0x82a6
cmpl $0x0, 0x14(%rbx)
jle 0x10269
movl $0x98, %edx
addq 0x17ef9(%rip), %rdx     # 0x27fc8
xorl %ebp, %ebp
movslq 0x10(%rbx), %rax
movslq %ebp, %rcx
addq %rax, %rcx
imulq $0xd0, %rcx, %rcx
leaq 0x3abd4f7(%rip), %rsi   # 0x3acd5e0
leaq (%rsi,%rcx), %r13
leaq (%rsi,%rcx), %rdi
addq $0x88, %rdi
movapd (%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
imulq $0xd0, %rax, %rax
movq %rdx, 0x20(%rsp)
addq %rdx, %rax
xorl %ecx, %ecx
movupd -0x10(%rax,%rcx), %xmm2
subpd %xmm0, %xmm2
movupd %xmm2, -0x10(%rax,%rcx)
movsd (%rax,%rcx), %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, (%rax,%rcx)
addq $0x18, %rcx
cmpq $0x48, %rcx
jne 0x10114
leaq 0xa0(%r13), %rsi
leaq 0xb8(%r13), %rdx
callq 0xe136
movl %eax, %r14d
cmpl $-0x1, %eax
jne 0x10172
movl (%rbx), %edx
movl 0x4(%rbx), %ecx
movl $0x5, %edi
leaq 0xf5d1(%rip), %rsi      # 0x1f739
movl %ebp, %r8d
xorl %eax, %eax
callq 0xa253
movq 0x90(%rbx), %r12
testq %r12, %r12
je 0x101e7
leaq 0x60(%r13), %r15
movl 0x8(%r12), %eax
cmpl %r14d, %eax
je 0x10194
xorl %r14d, %eax
cmpl $0x1, %eax
jne 0x101de
movl (%rbx), %edx
movsd 0x88(%r13), %xmm0
movsd 0x90(%r13), %xmm1
addsd (%rsp), %xmm0
addsd 0x8(%rsp), %xmm1
movl 0x4(%rbx), %ecx
movsd 0x98(%r13), %xmm2
addsd 0x10(%rsp), %xmm2
movl $0x6, %edi
leaq 0xf59b(%rip), %rsi      # 0x1f76c
movl %ebp, %r8d
movq %r15, %r9
movb $0x3, %al
callq 0xa253
movq (%r12), %r12
testq %r12, %r12
jne 0x10182
movl $0x68, %edi
callq 0x4974
movq %rax, %r15
movl %r14d, 0x8(%rax)
movslq %r14d, %rax
shlq $0x6, %rax
leaq 0x20bc72a(%rip), %rcx   # 0x20cc930
addq %rcx, %rax
movq %rax, 0x10(%r15)
movq 0x90(%rbx), %rax
movq %rax, (%r15)
movq %r15, 0x90(%rbx)
xorl %eax, %eax
leaq 0x61bd402(%rip), %rcx   # 0x61cd629
cmpb $0x0, (%rcx)
jne 0x1023b
movq 0x10(%r15), %rdi
movq %r13, %rsi
movq %rsp, %rdx
callq 0x1a251
movl %eax, 0x20(%r15)
movb $0x1, %al
cmpb $0x0, 0x20(%rbx)
jne 0x1024e
movb 0x80(%r13), %al
movb %al, 0x30(%r15)
incl %ebp
movq 0x20(%rsp), %rdx
addq $0xd0, %rdx
cmpl 0x14(%rbx), %ebp
jl 0x100d1
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq