// File: /workspace/github_cpp_makefile_star2_O3/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 0xb5e4(%rip), %r13      # 0x22634
leaq 0x40(%rsp), %rbp
xorl %r12d, %r12d
cmpq %r14, 0x30bc9c1(%rip)   # 0x30d3a20
jne 0x1706e
cmpb $0x0, 0x20bc9a2(%rip)   # 0x20d3a0a
jne 0x1742c
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %rdi
leaq 0xb434(%rip), %rsi      # 0x224b5
leaq 0x24(%rsp), %rdx
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
leaq 0x3c(%rsp), %r9
xorl %eax, %eax
callq 0x4580
leal 0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0x17636
cmpl $-0x1, 0x14(%rsp)
je 0x17407
leal 0x1(%r12), %r15d
cmpl $0x5, %eax
je 0x170ce
leaq 0xb424(%rip), %rdi      # 0x224e8
movl %r15d, %esi
xorl %eax, %eax
callq 0x9e9c
movl 0xc(%rsp), %edx
cmpl $0x1d, %edx
jl 0x170e8
leaq 0xb42d(%rip), %rdi      # 0x2250b
movl %r15d, %esi
xorl %eax, %eax
callq 0x9e9c
movl 0x14(%rsp), %edx
leaq 0xafc2b1(%rip), %rax    # 0xb133a4
cmpl (%rax), %edx
jle 0x17108
leaq 0xb498(%rip), %rdi      # 0x22596
movl %r15d, %esi
xorl %eax, %eax
callq 0x9e9c
movl 0x10(%rsp), %edx
leaq 0x117c299(%rip), %rax   # 0x11933ac
cmpl (%rax), %edx
jle 0x17128
leaq 0xb49f(%rip), %rdi      # 0x225bd
movl %r15d, %esi
xorl %eax, %eax
callq 0x9e9c
movl 0x24(%rsp), %edx
testl %edx, %edx
jns 0x17141
leaq 0xb4ad(%rip), %rdi      # 0x225e4
movl %r15d, %esi
xorl %eax, %eax
callq 0x9e9c
movl 0x10(%rsp), %edi
callq 0x62ce
movq %rax, %rdi
leaq 0xa4b6(%rip), %rsi      # 0x2160a
callq 0x4320
testl %eax, %eax
jne 0x171ce
leaq 0xb4a8(%rip), %rdi      # 0x2260c
movl %r15d, %esi
xorl %eax, %eax
callq 0xa2ef
cmpl $0x0, 0xc(%rsp)
jle 0x171b5
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 0x4580
cmpl $0x3, %eax
je 0x171ab
leaq 0xb4a0(%rip), %rdi      # 0x22641
movl %r15d, %esi
xorl %eax, %eax
callq 0x9e9c
incl %r12d
cmpl 0xc(%rsp), %r12d
jl 0x17178
movq %r14, %rdi
leaq 0x7ab9(%rip), %rsi      # 0x1ec78
xorl %eax, %eax
callq 0x4580
movl %r15d, %r12d
jmp 0x17058
movl $0x1, %edi
movl $0x4b8, %esi            # imm = 0x4B8
callq 0x41e0
movq %rax, %r13
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 0x30bc840(%rip), %rdx   # 0x30d3a50
movq (%rdx,%rax,8), %rcx
movq %rcx, (%r13)
movq %r13, (%rdx,%rax,8)
callq 0x62ce
movl $0x4, %edx
movq %rax, %rdi
leaq 0xa3d5(%rip), %rsi      # 0x21605
callq 0x43e0
testl %eax, %eax
je 0x17270
movl 0xc(%r13), %edi
callq 0x62ce
movl $0x4, %edx
movq %rax, %rdi
leaq 0xa3b9(%rip), %rsi      # 0x2160a
callq 0x43e0
testl %eax, %eax
je 0x1727a
movq %r13, %rdi
callq 0x154f3
testb %al, %al
je 0x17284
movl $0x3, 0x30(%r13)
jmp 0x172d8
movl $0x1, 0x30(%r13)
jmp 0x172d8
movl $0x2, 0x30(%r13)
jmp 0x172d8
movl 0xc(%r13), %edi
callq 0x62ce
movl $0x9, %edx
movq %rax, %rdi
leaq 0xa373(%rip), %rsi      # 0x2160f
callq 0x43e0
testl %eax, %eax
je 0x172d0
movl 0xc(%r13), %edi
callq 0x62ce
movl $0x7, %edx
movq %rax, %rdi
leaq 0xa340(%rip), %rsi      # 0x215fd
callq 0x43e0
testl %eax, %eax
je 0x17266
movl $0x0, 0x30(%r13)
jmp 0x172d8
movl $0x4, 0x30(%r13)
cmpl $0x0, 0x2c(%r13)
jle 0x173e7
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 0xb32e(%rip), %rsi      # 0x22634
movq %rbp, %rdx
leaq 0x48(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %eax, %eax
callq 0x4580
cmpl $0x3, %eax
je 0x17336
movq 0x60(%rsp), %rax
leaq (%rax,%r12), %rsi
leaq 0xb34e(%rip), %rdi      # 0x2267d
xorl %eax, %eax
callq 0x9e9c
movapd 0x40(%rsp), %xmm1
movupd %xmm1, -0x10(%r15)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%r15)
leaq 0x20aa0ac(%rip), %rax   # 0x20c1400
cmpl $0x6, (%rax)
jl 0x173c7
movslq 0x8(%r13), %rax
shlq $0x6, %rax
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
leaq 0x20bc6a0(%rip), %rcx   # 0x20d3a10
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 0x8f29(%rip), %xmm0     # 0x202c0
movsd 0x18(%rsp), %xmm1
addsd 0x8d23(%rip), %xmm1     # 0x200c8
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 0x172fc
movq 0x58(%rsp), %rax
leal (%rax,%r12), %r15d
incl %r15d
movq %r14, %rdi
leaq 0x7887(%rip), %rsi      # 0x1ec78
xorl %eax, %eax
callq 0x4580
movl %r15d, %r12d
leaq 0xb232(%rip), %r13      # 0x22634
jmp 0x17058
movsd 0x30(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
leaq 0xb0ab(%rip), %rsi      # 0x224c5
movl $0x6, %edi
movsd 0x28(%rsp), %xmm1
movb $0x2, %al
callq 0xa3ae
movl $0x38, %edi
callq 0x4400
movq %rax, %rbx
movaps 0xa050(%rip), %xmm0     # 0x21490
movups %xmm0, (%rax)
movaps 0xa056(%rip), %xmm0     # 0x214a0
movups %xmm0, 0x20(%rax)
movapd 0xa05a(%rip), %xmm0     # 0x214b0
movupd %xmm0, 0x10(%rax)
movq $0x0, 0x30(%rax)
leaq 0xafbf3a(%rip), %rax    # 0xb133a4
movl (%rax), %eax
testl %eax, %eax
jle 0x1762f
xorl %r13d, %r13d
leaq 0x30bc5d2(%rip), %rcx   # 0x30d3a50
movq (%rcx,%r13,8), %rbp
testq %rbp, %rbp
jne 0x1749a
leaq 0x30bc5c2(%rip), %rcx   # 0x30d3a50
cmpq $0x0, 0x8(%rcx,%r13,8)
je 0x1761c
movl $0x1, %edi
movl $0x58, %esi
callq 0x41e0
movq %rax, %r12
leaq 0x10(%rax), %r15
leaq 0x28(%rax), %r14
movq 0x30(%rbx), %rax
movq %rax, (%r12)
movq %r12, 0x30(%rbx)
movaps 0x9fc9(%rip), %xmm0     # 0x21490
movups %xmm0, 0x10(%r12)
movaps 0x9fcc(%rip), %xmm0     # 0x214a0
movups %xmm0, 0x30(%r12)
movapd 0x9fce(%rip), %xmm0     # 0x214b0
movupd %xmm0, 0x20(%r12)
movl $0xffffffff, 0x50(%r12) # imm = 0xFFFFFFFF
movq %r13, 0x18(%rsp)
movl %r13d, 0x8(%r12)
movq $0x0, 0x48(%r12)
testq %rbp, %rbp
je 0x17546
movq %rbp, %r13
movq (%rbp), %rbp
movq 0x48(%r12), %rax
movq %rax, (%r13)
movq %r13, 0x48(%r12)
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x17875
movl 0x50(%r12), %ecx
movl 0x14(%r13), %eax
cmpl $-0x1, %ecx
je 0x1753f
cmpl %ecx, %eax
jge 0x17505
movl %eax, 0x50(%r12)
jmp 0x17505
leaq 0x30bc503(%rip), %rax   # 0x30d3a50
movq 0x18(%rsp), %rcx
movq 0x8(%rax,%rcx,8), %rbp
testq %rbp, %rbp
je 0x17598
movq %rbp, %r13
movq (%rbp), %rbp
movq 0x48(%r12), %rax
movq %rax, (%r13)
movq %r13, 0x48(%r12)
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x17875
movl 0x50(%r12), %ecx
movl 0x14(%r13), %eax
cmpl $-0x1, %ecx
je 0x17591
cmpl %ecx, %eax
jge 0x17557
movl %eax, 0x50(%r12)
jmp 0x17557
movq 0x18(%rsp), %r13
movq %r13, %rax
orq $0x1, %rax
xorl %ecx, %ecx
movsd (%r15,%rcx,8), %xmm0
movsd (%rbx,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x175bc
movsd %xmm0, (%rbx,%rcx,8)
ucomisd 0x18(%rbx,%rcx,8), %xmm0
jbe 0x175ca
movsd %xmm0, 0x18(%rbx,%rcx,8)
incq %rcx
cmpq $0x3, %rcx
jne 0x175a6
xorl %ecx, %ecx
movsd (%r14,%rcx,8), %xmm0
movsd (%rbx,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x175eb
movsd %xmm0, (%rbx,%rcx,8)
ucomisd 0x18(%rbx,%rcx,8), %xmm0
jbe 0x175f9
movsd %xmm0, 0x18(%rbx,%rcx,8)
incq %rcx
cmpq $0x3, %rcx
jne 0x175d5
leaq 0x30bc447(%rip), %rcx   # 0x30d3a50
xorl %edx, %edx
movq %rdx, (%rcx,%r13,8)
movq %rdx, (%rcx,%rax,8)
leaq 0xafbd8a(%rip), %rax    # 0xb133a4
movl (%rax), %eax
addq $0x2, %r13
cmpl %r13d, %eax
jg 0x17477
movq 0x30(%rbx), %rdi
jmp 0x17631
xorl %edi, %edi
callq 0x12c4d
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq