// File: FreeSlave[P]vhlt/hlbsp/solidbsp.cpp
// Function: CalcSurfaceInfo(surface_s*)
static void     CalcSurfaceInfo(surface_t* surf)
{
    int             i;
    int             j;
    face_t*         f;

    hlassume(surf->faces != NULL, assume_ValidPointer);    // "CalcSurfaceInfo() surface without a face"

    //
    // calculate a bounding box
    //
    for (i = 0; i < 3; i++)
    {
        surf->mins[i] = 99999;
        surf->maxs[i] = -99999;
    }

#ifdef ZHLT_DETAILBRUSH
	surf->detaillevel = -1;
#endif
    for (f = surf->faces; f; f = f->next)
    {
        if (f->contents >= 0)
        {
            Error("Bad contents");
        }
        for (i = 0; i < f->numpoints; i++)
        {
            for (j = 0; j < 3; j++)
            {
                if (f->pts[i][j] < surf->mins[j])
                {
                    surf->mins[j] = f->pts[i][j];
                }
                if (f->pts[i][j] > surf->maxs[j])
                {
                    surf->maxs[j] = f->pts[i][j];
                }
            }
        }
#ifdef ZHLT_DETAILBRUSH
		if (surf->detaillevel == -1 || f->detaillevel < surf->detaillevel)
		{
			surf->detaillevel = f->detaillevel;
		}
#endif
    }
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq $0x0, 0x48(%rax)
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x2, %esi
callq 0xbe90
movl $0x0, 0xc(%rsp)
cmpl $0x3, 0xc(%rsp)
jge 0x2ad42
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movsd 0xf909(%rip), %xmm0     # 0x3a620
movsd %xmm0, 0x10(%rax,%rcx,8)
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movsd 0xf8e9(%rip), %xmm0     # 0x3a618
movsd %xmm0, 0x28(%rax,%rcx,8)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x2acfe
movq 0x10(%rsp), %rax
movl $0xffffffff, 0x50(%rax) # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, (%rsp)
cmpq $0x0, (%rsp)
je 0x2aecb
movq (%rsp), %rax
cmpl $0x0, 0x10(%rax)
jl 0x2ad7e
leaq 0x10d57(%rip), %rdi     # 0x3bace
movb $0x0, %al
callq 0xb510
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq (%rsp), %rcx
cmpl 0x2c(%rcx), %eax
jge 0x2ae8e
movl $0x0, 0x8(%rsp)
cmpl $0x3, 0x8(%rsp)
jge 0x2ae7c
movq (%rsp), %rax
addq $0x38, %rax
movslq 0xc(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq 0x8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq 0x10(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsd 0x10(%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2ae0c
movq (%rsp), %rax
addq $0x38, %rax
movslq 0xc(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq 0x8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x10(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
movq (%rsp), %rax
addq $0x38, %rax
movslq 0xc(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq 0x8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x10(%rsp), %rax
movslq 0x8(%rsp), %rcx
ucomisd 0x28(%rax,%rcx,8), %xmm0
jbe 0x2ae6a
movq (%rsp), %rax
addq $0x38, %rax
movslq 0xc(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq 0x8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x10(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsd %xmm0, 0x28(%rax,%rcx,8)
jmp 0x2ae6c
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x2ad9f
jmp 0x2ae7e
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x2ad86
movq 0x10(%rsp), %rax
cmpl $-0x1, 0x50(%rax)
je 0x2aeaa
movq (%rsp), %rax
movl 0x14(%rax), %eax
movq 0x10(%rsp), %rcx
cmpl 0x50(%rcx), %eax
jge 0x2aeb9
movq (%rsp), %rax
movl 0x14(%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x50(%rax)
jmp 0x2aebb
movq (%rsp), %rax
movq (%rax), %rax
movq %rax, (%rsp)
jmp 0x2ad5b
addq $0x18, %rsp
retq