// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlbsp/qbsp.cpp
// Function: ReadSurfs(_IO_FILE*)
static surfchain_t* ReadSurfs(FILE* file)
{
    int             r;
#ifdef ZHLT_DETAILBRUSH
	int				detaillevel;
#endif
    int             planenum, g_texinfo, contents, numpoints;
    face_t*         f;
    int             i;
    double          v[3];
    int             line = 0;
#ifdef HLCSG_HLBSP_DOUBLEPLANE
	double			inaccuracy, inaccuracy_count = 0.0, inaccuracy_total = 0.0, inaccuracy_max = 0.0;
#endif

    // read in the polygons
    while (1)
    {
#ifdef HLBSP_REMOVEHULL2
		if (file == polyfiles[2] && g_nohull2)
			break;
#endif
        line++;
#ifdef ZHLT_DETAILBRUSH
        r = fscanf(file, "%i %i %i %i %i\n", &detaillevel, &planenum, &g_texinfo, &contents, &numpoints);
#else
        r = fscanf(file, "%i %i %i %i\n", &planenum, &g_texinfo, &contents, &numpoints);
#endif
        if (r == 0 || r == -1)
        {
            return NULL;
        }
        if (planenum == -1)                                // end of model
        {
#ifdef HLCSG_HLBSP_DOUBLEPLANE
			Developer (DEVELOPER_LEVEL_MEGASPAM, "inaccuracy: average %.8f max %.8f\n", inaccuracy_total / inaccuracy_count, inaccuracy_max);
#endif
            break;
        }
#ifdef ZHLT_DETAILBRUSH
		if (r != 5)
#else
        if (r != 4)
#endif
        {
            Error("ReadSurfs (line %i): scanf failure", line);
        }
        if (numpoints > MAXPOINTS)
        {
            Error("ReadSurfs (line %i): %i > MAXPOINTS\nThis is caused by a face with too many verticies (typically found on end-caps of high-poly cylinders)\n", line, numpoints);
        }
        if (planenum > g_numplanes)
        {
            Error("ReadSurfs (line %i): %i > g_numplanes\n", line, planenum);
        }
        if (g_texinfo > g_numtexinfo)
        {
            Error("ReadSurfs (line %i): %i > g_numtexinfo", line, g_texinfo);
        }
#ifdef ZHLT_DETAILBRUSH
		if (detaillevel < 0)
		{
			Error("ReadSurfs (line %i): detaillevel %i < 0", line, detaillevel);
		}
#endif

        if (!strcasecmp(GetTextureByNumber(g_texinfo), "skip"))
        {
            Verbose("ReadSurfs (line %i): skipping a surface", line);

            for (i = 0; i < numpoints; i++)
            {
                line++;
                //Verbose("skipping line %d", line);
                r = fscanf(file, "%lf %lf %lf\n", &v[0], &v[1], &v[2]);
                if (r != 3)
                {
                    Error("::ReadSurfs (face_skip), fscanf of points failed at line %i", line);
                }
            }
            fscanf(file, "\n");
            continue;
        }

        f = AllocFace();
#ifdef ZHLT_DETAILBRUSH
		f->detaillevel = detaillevel;
#endif
        f->planenum = planenum;
        f->texturenum = g_texinfo;
        f->contents = contents;
        f->numpoints = numpoints;
        f->next = validfaces[planenum];
        validfaces[planenum] = f;

        SetFaceType(f);

        for (i = 0; i < f->numpoints; i++)
        {
            line++;
            r = fscanf(file, "%lf %lf %lf\n", &v[0], &v[1], &v[2]);
            if (r != 3)
            {
                Error("::ReadSurfs (face_normal), fscanf of points failed at line %i", line);
            }
            VectorCopy(v, f->pts[i]);
#ifdef HLCSG_HLBSP_DOUBLEPLANE
			 if (DEVELOPER_LEVEL_MEGASPAM <= g_developer)
			 {
				const dplane_t *plane = &g_dplanes[f->planenum];
				inaccuracy = fabs (DotProduct (f->pts[i], plane->normal) - plane->dist);
				inaccuracy_count++;
				inaccuracy_total += inaccuracy;
				inaccuracy_max = qmax (inaccuracy, inaccuracy_max);
			}
#endif
        }
        fscanf(file, "\n");
    }

    return SurflistFromValidFaces();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r14
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %ebx, %ebx
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0xc2d9(%rip), %r13      # 0x23657
leaq 0x40(%rsp), %rbp
xorl %r12d, %r12d
cmpq %r14, 0x30bd6a3(%rip)   # 0x30d4a30
jne 0x1739c
cmpb $0x0, 0x20bd684(%rip)   # 0x20d4a1a
jne 0x1776c
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %rdi
leaq 0xc129(%rip), %rsi      # 0x234d8
leaq 0x24(%rsp), %rdx
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
leaq 0x3c(%rsp), %r9
xorl %eax, %eax
callq 0x4590
leal 0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0x17990
cmpl $-0x1, 0x14(%rsp)
je 0x17747
leal 0x1(%r12), %r15d
cmpl $0x5, %eax
je 0x173fc
leaq 0xc119(%rip), %rdi      # 0x2350b
movl %r15d, %esi
xorl %eax, %eax
callq 0x9f84
movl 0xc(%rsp), %edx
cmpl $0x1d, %edx
jl 0x17416
leaq 0xc122(%rip), %rdi      # 0x2352e
movl %r15d, %esi
xorl %eax, %eax
callq 0x9f84
movl 0x14(%rsp), %edx
leaq 0xafcf93(%rip), %rax    # 0xb143b4
cmpl (%rax), %edx
jle 0x17436
leaq 0xc18d(%rip), %rdi      # 0x235b9
movl %r15d, %esi
xorl %eax, %eax
callq 0x9f84
movl 0x10(%rsp), %edx
leaq 0x117cf7b(%rip), %rax   # 0x11943bc
cmpl (%rax), %edx
jle 0x17456
leaq 0xc194(%rip), %rdi      # 0x235e0
movl %r15d, %esi
xorl %eax, %eax
callq 0x9f84
movl 0x24(%rsp), %edx
testl %edx, %edx
jns 0x1746f
leaq 0xc1a2(%rip), %rdi      # 0x23607
movl %r15d, %esi
xorl %eax, %eax
callq 0x9f84
movl 0x10(%rsp), %edi
callq 0x62cc
movq %rax, %rdi
leaq 0xb1ab(%rip), %rsi      # 0x2262d
callq 0x4320
testl %eax, %eax
jne 0x174fc
leaq 0xc19d(%rip), %rdi      # 0x2362f
movl %r15d, %esi
xorl %eax, %eax
callq 0xa3d7
cmpl $0x0, 0xc(%rsp)
jle 0x174e3
xorl %r12d, %r12d
incl %r15d
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
leaq 0x48(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %eax, %eax
callq 0x4590
cmpl $0x3, %eax
je 0x174d9
leaq 0xc195(%rip), %rdi      # 0x23664
movl %r15d, %esi
xorl %eax, %eax
callq 0x9f84
incl %r12d
cmpl 0xc(%rsp), %r12d
jl 0x174a6
movq %r14, %rdi
leaq 0x879b(%rip), %rsi      # 0x1fc88
xorl %eax, %eax
callq 0x4590
movl %r15d, %r12d
jmp 0x17386
movl $0x4b8, %edi            # imm = 0x4B8
callq 0x4400
movq %rax, %r13
movl $0x4b8, %edx            # imm = 0x4B8
movq %rax, %rdi
xorl %esi, %esi
callq 0x4180
movl $0xffffffff, 0x8(%r13)  # imm = 0xFFFFFFFF
movl 0x24(%rsp), %eax
movl %eax, 0x14(%r13)
movslq 0x14(%rsp), %rax
movl %eax, 0x8(%r13)
movl 0x10(%rsp), %edi
movl %edi, 0xc(%r13)
movl 0x3c(%rsp), %ecx
movl %ecx, 0x10(%r13)
movl 0xc(%rsp), %ecx
movl %ecx, 0x2c(%r13)
leaq 0x30bd510(%rip), %rdx   # 0x30d4a60
movq (%rdx,%rax,8), %rcx
movq %rcx, (%r13)
movq %r13, (%rdx,%rax,8)
callq 0x62cc
movl $0x4, %edx
movq %rax, %rdi
leaq 0xb0b8(%rip), %rsi      # 0x22628
callq 0x43e0
testl %eax, %eax
je 0x175b0
movl 0xc(%r13), %edi
callq 0x62cc
movl $0x4, %edx
movq %rax, %rdi
leaq 0xb09c(%rip), %rsi      # 0x2262d
callq 0x43e0
testl %eax, %eax
je 0x175ba
movq %r13, %rdi
callq 0x157fd
testb %al, %al
je 0x175c4
movl $0x3, 0x30(%r13)
jmp 0x17618
movl $0x1, 0x30(%r13)
jmp 0x17618
movl $0x2, 0x30(%r13)
jmp 0x17618
movl 0xc(%r13), %edi
callq 0x62cc
movl $0x9, %edx
movq %rax, %rdi
leaq 0xb056(%rip), %rsi      # 0x22632
callq 0x43e0
testl %eax, %eax
je 0x17610
movl 0xc(%r13), %edi
callq 0x62cc
movl $0x7, %edx
movq %rax, %rdi
leaq 0xb023(%rip), %rsi      # 0x22620
callq 0x43e0
testl %eax, %eax
je 0x175a6
movl $0x0, 0x30(%r13)
jmp 0x17618
movl $0x4, 0x30(%r13)
cmpl $0x0, 0x2c(%r13)
jle 0x17727
movq %r13, %r15
addq $0x48, %r15
movq %r12, 0x58(%rsp)
leal 0x2(%r12), %eax
movq %rax, 0x60(%rsp)
xorl %r12d, %r12d
movq %r14, %rdi
leaq 0xc011(%rip), %rsi      # 0x23657
movq %rbp, %rdx
leaq 0x48(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %eax, %eax
callq 0x4590
cmpl $0x3, %eax
je 0x17676
movq 0x60(%rsp), %rax
leaq (%rax,%r12), %rsi
leaq 0xc031(%rip), %rdi      # 0x236a0
xorl %eax, %eax
callq 0x9f84
movapd 0x40(%rsp), %xmm1
movupd %xmm1, -0x10(%r15)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%r15)
leaq 0x20aad7c(%rip), %rax   # 0x20c2410
cmpl $0x6, (%rax)
jl 0x17707
movslq 0x8(%r13), %rax
shlq $0x6, %rax
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
leaq 0x20bd370(%rip), %rcx   # 0x20d4a20
mulsd 0x8(%rax,%rcx), %xmm2
mulsd (%rax,%rcx), %xmm1
addsd %xmm2, %xmm1
mulsd 0x10(%rax,%rcx), %xmm0
addsd %xmm1, %xmm0
subsd 0x30(%rax,%rcx), %xmm0
andpd 0x9c09(%rip), %xmm0     # 0x212e0
movsd 0x18(%rsp), %xmm1
addsd 0x99f3(%rip), %xmm1     # 0x210d8
movsd %xmm1, 0x18(%rsp)
movsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
maxsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
incq %r12
movslq 0x2c(%r13), %rax
addq $0x18, %r15
cmpq %rax, %r12
jl 0x1763c
movq 0x58(%rsp), %rax
leal (%rax,%r12), %r15d
incl %r15d
movq %r14, %rdi
leaq 0x8557(%rip), %rsi      # 0x1fc88
xorl %eax, %eax
callq 0x4590
movl %r15d, %r12d
leaq 0xbf15(%rip), %r13      # 0x23657
jmp 0x17386
movsd 0x30(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
leaq 0xbd8e(%rip), %rsi      # 0x234e8
movl $0x6, %edi
movsd 0x28(%rsp), %xmm1
movb $0x2, %al
callq 0xa496
movl $0x38, %edi
callq 0x4400
movq %rax, %rbx
movaps 0xad30(%rip), %xmm0     # 0x224b0
movups %xmm0, (%rax)
movaps 0xad36(%rip), %xmm0     # 0x224c0
movups %xmm0, 0x20(%rax)
movapd 0xad3a(%rip), %xmm0     # 0x224d0
movupd %xmm0, 0x10(%rax)
movq $0x0, 0x30(%rax)
leaq 0xafcc0a(%rip), %rax    # 0xb143b4
cmpl $0x0, (%rax)
jle 0x17987
xorl %ebp, %ebp
leaq 0x30bd2a4(%rip), %rax   # 0x30d4a60
movq (%rax,%rbp,8), %r13
testq %r13, %r13
jne 0x177d8
leaq 0x30bd294(%rip), %rax   # 0x30d4a60
cmpq $0x0, 0x8(%rax,%rbp,8)
je 0x17974
movl $0x58, %edi
callq 0x4400
movq %rax, %r12
leaq 0x10(%rax), %r15
leaq 0x28(%rax), %r14
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movupd %xmm0, 0x10(%rax)
movupd %xmm0, 0x20(%rax)
movupd %xmm0, 0x30(%rax)
movupd %xmm0, 0x40(%rax)
xorl %ecx, %ecx
movq %rcx, 0x50(%rax)
movq 0x30(%rbx), %rax
movq %rax, (%r12)
movq %r12, 0x30(%rbx)
movaps 0xac8e(%rip), %xmm0     # 0x224b0
movups %xmm0, 0x10(%r12)
movaps 0xac91(%rip), %xmm0     # 0x224c0
movups %xmm0, 0x30(%r12)
movapd 0xac93(%rip), %xmm0     # 0x224d0
movupd %xmm0, 0x20(%r12)
movl $0xffffffff, 0x50(%r12) # imm = 0xFFFFFFFF
movq %rbp, 0x18(%rsp)
movl %ebp, 0x8(%r12)
movq %rcx, 0x48(%r12)
testq %r13, %r13
je 0x178a2
movq (%r13), %rbp
movq 0x48(%r12), %rax
movq %rax, (%r13)
movq %r13, 0x48(%r12)
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x17bf8
movl 0x50(%r12), %eax
cmpl $-0x1, %eax
je 0x17891
cmpl %eax, 0x14(%r13)
jge 0x1789a
movl 0x14(%r13), %eax
movl %eax, 0x50(%r12)
movq %rbp, %r13
testq %rbp, %rbp
jne 0x17861
leaq 0x30bd1b7(%rip), %rax   # 0x30d4a60
movq 0x18(%rsp), %rcx
movq 0x8(%rax,%rcx,8), %r13
testq %r13, %r13
je 0x178f9
movq (%r13), %rbp
movq 0x48(%r12), %rax
movq %rax, (%r13)
movq %r13, 0x48(%r12)
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x17bf8
movl 0x50(%r12), %eax
cmpl $-0x1, %eax
je 0x178e8
cmpl %eax, 0x14(%r13)
jge 0x178f1
movl 0x14(%r13), %eax
movl %eax, 0x50(%r12)
movq %rbp, %r13
testq %rbp, %rbp
jne 0x178b8
movq 0x18(%rsp), %rbp
movq %rbp, %rax
orq $0x1, %rax
xorl %ecx, %ecx
xorl %esi, %esi
movsd (%r15,%rcx,8), %xmm0
movsd (%rbx,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1791f
movsd %xmm0, (%rbx,%rcx,8)
ucomisd 0x18(%rbx,%rcx,8), %xmm0
jbe 0x1792d
movsd %xmm0, 0x18(%rbx,%rcx,8)
incq %rcx
cmpq $0x3, %rcx
jne 0x17909
xorl %ecx, %ecx
movsd (%r14,%rcx,8), %xmm0
movsd (%rbx,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1794e
movsd %xmm0, (%rbx,%rcx,8)
ucomisd 0x18(%rbx,%rcx,8), %xmm0
jbe 0x1795c
movsd %xmm0, 0x18(%rbx,%rcx,8)
incq %rcx
cmpq $0x3, %rcx
jne 0x17938
leaq 0x30bd0f4(%rip), %rcx   # 0x30d4a60
movq %rsi, (%rcx,%rbp,8)
movq %rsi, (%rcx,%rax,8)
addq $0x2, %rbp
leaq 0xafca35(%rip), %rax    # 0xb143b4
cmpl %ebp, (%rax)
jg 0x177b5
movq 0x30(%rbx), %rdi
callq 0x12f10
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq