// File: /workspace/github_cpp_makefile_star2_O2/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, 0x30(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x20(%rsp)
leaq 0xb4de(%rip), %rbp      # 0x20594
leaq 0x40(%rsp), %r13
xorl %r15d, %r15d
cmpq %r14, 0x30bd96b(%rip)   # 0x30d2a30
jne 0x150d4
cmpb $0x0, 0x20bd94c(%rip)   # 0x20d2a1a
jne 0x15412
leaq 0x14(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %rdi
leaq 0xb32e(%rip), %rsi      # 0x20415
leaq 0x38(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
leaq 0x18(%rsp), %r8
leaq 0x3c(%rsp), %r9
xorl %eax, %eax
callq 0x4590
leal 0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0x153e8
cmpl $-0x1, 0x1c(%rsp)
je 0x153ef
leal 0x1(%r15), %ebx
cmpl $0x5, %eax
je 0x15132
leaq 0xb31f(%rip), %rdi      # 0x20448
movl %ebx, %esi
xorl %eax, %eax
callq 0x8b1f
movl 0x14(%rsp), %edx
cmpl $0x1d, %edx
jl 0x1514b
leaq 0xb329(%rip), %rdi      # 0x2046b
movl %ebx, %esi
xorl %eax, %eax
callq 0x8b1f
movl 0x1c(%rsp), %edx
leaq 0xafd25e(%rip), %rax    # 0xb123b4
cmpl (%rax), %edx
jle 0x1516a
leaq 0xb395(%rip), %rdi      # 0x204f6
movl %ebx, %esi
xorl %eax, %eax
callq 0x8b1f
movl 0x18(%rsp), %edx
leaq 0x117d247(%rip), %rax   # 0x11923bc
cmpl (%rax), %edx
jle 0x15189
leaq 0xb39d(%rip), %rdi      # 0x2051d
movl %ebx, %esi
xorl %eax, %eax
callq 0x8b1f
movl 0x38(%rsp), %edx
testl %edx, %edx
jns 0x151a1
leaq 0xb3ac(%rip), %rdi      # 0x20544
movl %ebx, %esi
xorl %eax, %eax
callq 0x8b1f
movl 0x18(%rsp), %edi
callq 0x5c19
movq %rax, %rdi
leaq 0xa3b6(%rip), %rsi      # 0x1f56a
callq 0x4330
testl %eax, %eax
jne 0x1522d
xorl %r12d, %r12d
leaq 0xb3a5(%rip), %rdi      # 0x2056c
movl %ebx, %esi
xorl %eax, %eax
callq 0x8f76
addl $0x2, %r15d
cmpl 0x14(%rsp), %r12d
jge 0x15211
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
leaq 0x48(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %eax, %eax
callq 0x4590
cmpl $0x3, %eax
je 0x1520c
leal (%r15,%r12), %esi
leaq 0xb39c(%rip), %rdi      # 0x205a1
xorl %eax, %eax
callq 0x8b1f
incl %r12d
jmp 0x151d4
movq %r14, %rdi
leaq 0x79bd(%rip), %rsi      # 0x1cbd8
xorl %eax, %eax
callq 0x4590
addl %r12d, %ebx
movl %ebx, %r15d
jmp 0x150be
callq 0x12917
movq %rax, %rbx
movl 0x38(%rsp), %eax
movl %eax, 0x14(%rbx)
movslq 0x1c(%rsp), %rax
movl %eax, 0x8(%rbx)
movl 0x18(%rsp), %ecx
movl %ecx, 0xc(%rbx)
movl 0x3c(%rsp), %ecx
movl %ecx, 0x10(%rbx)
movl 0x14(%rsp), %ecx
movl %ecx, 0x2c(%rbx)
leaq 0x30bd800(%rip), %rdx   # 0x30d2a60
movq (%rdx,%rax,8), %rcx
movq %rcx, (%rbx)
movq %rbx, (%rdx,%rax,8)
movq %rbx, %rdi
callq 0x13634
testb %al, %al
je 0x15280
movl $0x1, 0x30(%rbx)
jmp 0x152cf
movq %rbx, %rdi
callq 0x13656
testb %al, %al
je 0x15295
movl $0x2, 0x30(%rbx)
jmp 0x152cf
movq %rbx, %rdi
callq 0x135b8
testb %al, %al
je 0x152aa
movl $0x3, 0x30(%rbx)
jmp 0x152cf
movq %rbx, %rdi
callq 0x13678
testb %al, %al
je 0x152bf
movl $0x4, 0x30(%rbx)
jmp 0x152cf
movq %rbx, %rdi
callq 0x13612
testb %al, %al
jne 0x152a1
andl $0x0, 0x30(%rbx)
movq %rbx, %rdx
addq $0x48, %rbx
leal 0x2(%r15), %eax
movq %rax, 0x58(%rsp)
xorl %ecx, %ecx
movq %rdx, 0x60(%rsp)
movslq 0x2c(%rdx), %rax
movq %rcx, %r12
movq %r14, %rdi
cmpq %rax, %rcx
jge 0x153cf
movq %rbp, %rsi
movq %r13, %rdx
leaq 0x48(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %eax, %eax
callq 0x4590
cmpl $0x3, %eax
je 0x1532c
movq 0x58(%rsp), %rax
leaq (%rax,%r12), %rsi
leaq 0xb2b8(%rip), %rdi      # 0x205dd
xorl %eax, %eax
callq 0x8b1f
movapd 0x40(%rsp), %xmm1
movupd %xmm1, -0x10(%rbx)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rbx)
leaq 0x20ab0c8(%rip), %rax   # 0x20c0410
cmpl $0x6, (%rax)
movq 0x60(%rsp), %rdx
jl 0x153c0
movslq 0x8(%rdx), %rax
shlq $0x6, %rax
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
leaq 0x20bd6b7(%rip), %rcx   # 0x20d2a20
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 0x8e80(%rip), %xmm0     # 0x1e210
movsd 0x30(%rsp), %xmm1
addsd 0x8c8a(%rip), %xmm1     # 0x1e028
movsd %xmm1, 0x30(%rsp)
movsd 0x28(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
maxsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r12, %rcx
incq %rcx
addq $0x18, %rbx
jmp 0x152e6
leaq 0x7802(%rip), %rsi      # 0x1cbd8
xorl %eax, %eax
callq 0x4590
addl %r12d, %r15d
incl %r15d
jmp 0x150be
xorl %ebx, %ebx
jmp 0x155bf
movsd 0x28(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
leaq 0xb023(%rip), %rsi      # 0x20425
pushq $0x6
popq %rdi
movsd 0x20(%rsp), %xmm1
movb $0x2, %al
callq 0x9035
pushq $0x38
popq %rdi
callq 0x4410
movq %rax, %rbx
addq $0x18, %rax
movq %rax, 0x20(%rsp)
movaps 0x9fc3(%rip), %xmm0     # 0x1f3f0
movups %xmm0, (%rbx)
movaps 0x9fc9(%rip), %xmm0     # 0x1f400
movups %xmm0, 0x20(%rbx)
movapd 0x9fcd(%rip), %xmm0     # 0x1f410
movupd %xmm0, 0x10(%rbx)
andq $0x0, 0x30(%rbx)
xorl %ebp, %ebp
movq %rbx, 0x28(%rsp)
leaq 0xafcf59(%rip), %rax    # 0xb123b4
movslq (%rax), %rax
cmpq %rax, %rbp
jge 0x155b6
leaq 0x30bd5f2(%rip), %rax   # 0x30d2a60
movq (%rax,%rbp,8), %r13
testq %r13, %r13
jne 0x1548a
leaq 0x30bd5e2(%rip), %rax   # 0x30d2a60
cmpq $0x0, 0x8(%rax,%rbp,8)
je 0x155ad
callq 0x12fa8
movq %rax, %r15
movq 0x30(%rbx), %rax
movq %rax, (%r15)
movq %r15, 0x30(%rbx)
leaq 0x10(%r15), %r12
leaq 0x28(%r15), %r14
movaps 0x9f44(%rip), %xmm0     # 0x1f3f0
movups %xmm0, 0x10(%r15)
movaps 0x9f48(%rip), %xmm0     # 0x1f400
movups %xmm0, 0x30(%r15)
movapd 0x9f4b(%rip), %xmm0     # 0x1f410
movupd %xmm0, 0x20(%r15)
orl $-0x1, 0x50(%r15)
movl %ebp, 0x8(%r15)
andq $0x0, 0x48(%r15)
testq %r13, %r13
je 0x15519
movq (%r13), %rbx
movq 0x48(%r15), %rax
movq %rax, (%r13)
movq %r13, 0x48(%r15)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x157dd
movl 0x50(%r15), %ecx
movl 0x14(%r13), %eax
cmpl $-0x1, %ecx
je 0x15510
movq %rbx, %r13
cmpl %ecx, %eax
jge 0x154d9
movl %eax, 0x50(%r15)
movq %rbx, %r13
jmp 0x154d9
movq %rbp, %rax
orq $0x1, %rax
movq %rax, 0x30(%rsp)
leaq 0x30bd534(%rip), %rax   # 0x30d2a60
movq 0x8(%rax,%rbp,8), %r13
testq %r13, %r13
je 0x15571
movq (%r13), %rbx
movq 0x48(%r15), %rax
movq %rax, (%r13)
movq %r13, 0x48(%r15)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x157dd
movl 0x50(%r15), %ecx
movl 0x14(%r13), %eax
cmpl $-0x1, %ecx
je 0x15568
movq %rbx, %r13
cmpl %ecx, %eax
jge 0x15531
movl %eax, 0x50(%r15)
movq %rbx, %r13
jmp 0x15531
movq %r12, %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
movq 0x20(%rsp), %r15
movq %r15, %rdx
callq 0x13589
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x13589
leaq 0x30bd4c2(%rip), %rax   # 0x30d2a60
andq $0x0, (%rax,%rbp,8)
movq 0x30(%rsp), %rcx
andq $0x0, (%rax,%rcx,8)
addq $0x2, %rbp
jmp 0x15454
movq 0x30(%rbx), %rdi
callq 0x110c4
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq