// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/common/bspfile.cpp
// Function: SwapBSPFile(bool)
static void     SwapBSPFile(const bool todisk)
{
    int             i, j, c;
    dmodel_t*       d;
    dmiptexlump_t*  mtl;

    // models       
    for (i = 0; i < g_nummodels; i++)
    {
        d = &g_dmodels[i];

        for (j = 0; j < MAX_MAP_HULLS; j++)
        {
            d->headnode[j] = LittleLong(d->headnode[j]);
        }

        d->visleafs = LittleLong(d->visleafs);
        d->firstface = LittleLong(d->firstface);
        d->numfaces = LittleLong(d->numfaces);

        for (j = 0; j < 3; j++)
        {
            d->mins[j] = LittleFloat(d->mins[j]);
            d->maxs[j] = LittleFloat(d->maxs[j]);
            d->origin[j] = LittleFloat(d->origin[j]);
        }
    }

    //
    // vertexes
    //
    for (i = 0; i < g_numvertexes; i++)
    {
        for (j = 0; j < 3; j++)
        {
            g_dvertexes[i].point[j] = LittleFloat(g_dvertexes[i].point[j]);
        }
    }

    //
    // planes
    //      
    for (i = 0; i < g_numplanes; i++)
    {
        for (j = 0; j < 3; j++)
        {
            g_dplanes[i].normal[j] = LittleFloat(g_dplanes[i].normal[j]);
        }
        g_dplanes[i].dist = LittleFloat(g_dplanes[i].dist);
        g_dplanes[i].type = (planetypes)LittleLong(g_dplanes[i].type);
    }

    //
    // texinfos
    //      
    for (i = 0; i < g_numtexinfo; i++)
    {
        for (j = 0; j < 8; j++)
        {
            g_texinfo[i].vecs[0][j] = LittleFloat(g_texinfo[i].vecs[0][j]);
        }
        g_texinfo[i].miptex = LittleLong(g_texinfo[i].miptex);
        g_texinfo[i].flags = LittleLong(g_texinfo[i].flags);
    }

    //
    // faces
    //
    for (i = 0; i < g_numfaces; i++)
    {
        g_dfaces[i].texinfo = LittleShort(g_dfaces[i].texinfo);
        g_dfaces[i].planenum = LittleShort(g_dfaces[i].planenum);
        g_dfaces[i].side = LittleShort(g_dfaces[i].side);
        g_dfaces[i].lightofs = LittleLong(g_dfaces[i].lightofs);
        g_dfaces[i].firstedge = LittleLong(g_dfaces[i].firstedge);
        g_dfaces[i].numedges = LittleShort(g_dfaces[i].numedges);
    }

    //
    // nodes
    //
    for (i = 0; i < g_numnodes; i++)
    {
        g_dnodes[i].planenum = LittleLong(g_dnodes[i].planenum);
        for (j = 0; j < 3; j++)
        {
            g_dnodes[i].mins[j] = LittleShort(g_dnodes[i].mins[j]);
            g_dnodes[i].maxs[j] = LittleShort(g_dnodes[i].maxs[j]);
        }
        g_dnodes[i].children[0] = LittleShort(g_dnodes[i].children[0]);
        g_dnodes[i].children[1] = LittleShort(g_dnodes[i].children[1]);
        g_dnodes[i].firstface = LittleShort(g_dnodes[i].firstface);
        g_dnodes[i].numfaces = LittleShort(g_dnodes[i].numfaces);
    }

    //
    // leafs
    //
    for (i = 0; i < g_numleafs; i++)
    {
        g_dleafs[i].contents = LittleLong(g_dleafs[i].contents);
        for (j = 0; j < 3; j++)
        {
            g_dleafs[i].mins[j] = LittleShort(g_dleafs[i].mins[j]);
            g_dleafs[i].maxs[j] = LittleShort(g_dleafs[i].maxs[j]);
        }

        g_dleafs[i].firstmarksurface = LittleShort(g_dleafs[i].firstmarksurface);
        g_dleafs[i].nummarksurfaces = LittleShort(g_dleafs[i].nummarksurfaces);
        g_dleafs[i].visofs = LittleLong(g_dleafs[i].visofs);
    }

    //
    // clipnodes
    //
#ifdef ZHLT_XASH2
	for (int hull = 1; hull < MAX_MAP_HULLS; hull++)
	{
		for (i = 0; i < g_numclipnodes[hull - 1]; i++)
		{
			g_dclipnodes[hull - 1][i].planenum = LittleLong(g_dclipnodes[hull - 1][i].planenum);
			g_dclipnodes[hull - 1][i].children[0] = LittleShort(g_dclipnodes[hull - 1][i].children[0]);
			g_dclipnodes[hull - 1][i].children[1] = LittleShort(g_dclipnodes[hull - 1][i].children[1]);
		}
	}
#else
    for (i = 0; i < g_numclipnodes; i++)
    {
        g_dclipnodes[i].planenum = LittleLong(g_dclipnodes[i].planenum);
        g_dclipnodes[i].children[0] = LittleShort(g_dclipnodes[i].children[0]);
        g_dclipnodes[i].children[1] = LittleShort(g_dclipnodes[i].children[1]);
    }
#endif

    //
    // miptex
    //
    if (g_texdatasize)
    {
        mtl = (dmiptexlump_t*)g_dtexdata;
        if (todisk)
        {
            c = mtl->nummiptex;
        }
        else
        {
            c = LittleLong(mtl->nummiptex);
        }
        mtl->nummiptex = LittleLong(mtl->nummiptex);
        for (i = 0; i < c; i++)
        {
            mtl->dataofs[i] = LittleLong(mtl->dataofs[i]);
        }
    }

    //
    // marksurfaces
    //
    for (i = 0; i < g_nummarksurfaces; i++)
    {
        g_dmarksurfaces[i] = LittleShort(g_dmarksurfaces[i]);
    }

    //
    // surfedges
    //
    for (i = 0; i < g_numsurfedges; i++)
    {
        g_dsurfedges[i] = LittleLong(g_dsurfedges[i]);
    }

    //
    // edges
    //
    for (i = 0; i < g_numedges; i++)
    {
        g_dedges[i].v[0] = LittleShort(g_dedges[i].v[0]);
        g_dedges[i].v[1] = LittleShort(g_dedges[i].v[1]);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, 0x4(%rsp)
cmpl $0x0, 0x240f1(%rip)     # 0x29480
jle 0x544e
leaq 0x24118(%rip), %r14     # 0x294b4
leaq 0x24105(%rip), %r15     # 0x294a8
xorl %r12d, %r12d
leaq 0x240e3(%rip), %r13     # 0x29490
movq %r12, %rbp
shlq $0x6, %rbp
addq %r13, %rbp
xorl %ebx, %ebx
movl (%r14,%rbx,4), %edi
callq 0x8a38
movl %eax, (%r14,%rbx,4)
incq %rbx
cmpq $0x4, %rbx
jne 0x53b9
movl 0x34(%rbp), %edi
callq 0x8a38
movl %eax, 0x34(%rbp)
movl 0x38(%rbp), %edi
callq 0x8a38
movl %eax, 0x38(%rbp)
movl 0x3c(%rbp), %edi
callq 0x8a38
movl %eax, 0x3c(%rbp)
movq $-0x3, %rbp
movss -0xc(%r15,%rbp,4), %xmm0
callq 0x8a46
movss %xmm0, -0xc(%r15,%rbp,4)
movss (%r15,%rbp,4), %xmm0
callq 0x8a46
movss %xmm0, (%r15,%rbp,4)
movss 0xc(%r15,%rbp,4), %xmm0
callq 0x8a46
movss %xmm0, 0xc(%r15,%rbp,4)
incq %rbp
jne 0x53f7
incq %r12
movslq 0x24043(%rip), %rax     # 0x29480
addq $0x40, %r14
addq $0x40, %r15
cmpq %rax, %r12
jl 0x53ad
cmpl $0x0, 0x100bfbf(%rip)   # 0x1011414
jle 0x5491
leaq 0x100bfc2(%rip), %r14   # 0x1011420
xorl %r15d, %r15d
xorl %r12d, %r12d
movss (%r14,%r12,4), %xmm0
callq 0x8a46
movss %xmm0, (%r14,%r12,4)
incq %r12
cmpq $0x3, %r12
jne 0x5464
incq %r15
movslq 0x100bf8c(%rip), %rax   # 0x1011414
addq $0xc, %r14
cmpq %rax, %r15
jl 0x5461
cmpl $0x0, 0xb0bf6c(%rip)    # 0xb11404
jle 0x54fc
leaq 0xb0bf6f(%rip), %r14    # 0xb11410
xorl %r15d, %r15d
movq %r14, %r12
leaq (%r15,%r15,4), %rax
leaq (%r14,%rax,4), %r13
xorl %ebp, %ebp
movss (%r12,%rbp,4), %xmm0
callq 0x8a46
movss %xmm0, (%r12,%rbp,4)
incq %rbp
cmpq $0x3, %rbp
jne 0x54b1
movss 0xc(%r13), %xmm0
callq 0x8a46
movss %xmm0, 0xc(%r13)
movl 0x10(%r13), %edi
callq 0x8a38
movl %eax, 0x10(%r13)
incq %r15
movslq 0xb0bf11(%rip), %rax    # 0xb11404
addq $0x14, %r12
cmpq %rax, %r15
jl 0x54a7
cmpl $0x0, 0x118bf09(%rip)   # 0x119140c
jle 0x5563
leaq 0x118bf04(%rip), %r14   # 0x1191410
xorl %r15d, %r15d
movq %r14, %r12
leaq (%r15,%r15,4), %rax
leaq (%r14,%rax,8), %r13
xorl %ebp, %ebp
movss (%r12,%rbp,4), %xmm0
callq 0x8a46
movss %xmm0, (%r12,%rbp,4)
incq %rbp
cmpq $0x8, %rbp
jne 0x551c
movl 0x20(%r13), %edi
callq 0x8a38
movl %eax, 0x20(%r13)
movl 0x24(%r13), %edi
callq 0x8a38
movl %eax, 0x24(%r13)
incq %r15
movslq 0x118beb2(%rip), %rax   # 0x119140c
addq $0x28, %r12
cmpq %rax, %r15
jl 0x5512
cmpl $0x0, 0x1b8beaa(%rip)   # 0x1b91414
jle 0x55dd
leaq 0x1b8bead(%rip), %r14   # 0x1b91420
xorl %r15d, %r15d
movswl 0xa(%r14), %edi
callq 0x8a30
movw %ax, 0xa(%r14)
movswl (%r14), %edi
callq 0x8a30
movw %ax, (%r14)
movswl 0x2(%r14), %edi
callq 0x8a30
movw %ax, 0x2(%r14)
movl 0x10(%r14), %edi
callq 0x8a38
movl %eax, 0x10(%r14)
movl 0x4(%r14), %edi
callq 0x8a38
movl %eax, 0x4(%r14)
movswl 0x8(%r14), %edi
callq 0x8a30
movw %ax, 0x8(%r14)
incq %r15
movslq 0x1b8be40(%rip), %rax   # 0x1b91414
addq $0x14, %r14
cmpq %rax, %r15
jl 0x5576
cmpl $0x0, 0x10cbe34(%rip)   # 0x10d1418
jle 0x568f
leaq 0x10cbe3d(%rip), %r14   # 0x10d142e
xorl %r15d, %r15d
leaq 0x10cbe25(%rip), %r12   # 0x10d1420
leaq (%r15,%r15,2), %rax
leaq (%r12,%rax,8), %r13
movl (%r13), %edi
callq 0x8a38
movl %eax, (%r13)
movq $-0x3, %rbp
movswl (%r14,%rbp,2), %edi
callq 0x8a30
movw %ax, (%r14,%rbp,2)
movswl 0x6(%r14,%rbp,2), %edi
callq 0x8a30
movw %ax, 0x6(%r14,%rbp,2)
incq %rbp
jne 0x5617
movswl 0x4(%r13), %edi
callq 0x8a30
movw %ax, 0x4(%r13)
movswl 0x6(%r13), %edi
callq 0x8a30
movw %ax, 0x6(%r13)
movswl 0x14(%r13), %edi
callq 0x8a30
movw %ax, 0x14(%r13)
movswl 0x16(%r13), %edi
callq 0x8a30
movw %ax, 0x16(%r13)
incq %r15
movslq 0x10cbd96(%rip), %rax   # 0x10d1418
addq $0x18, %r14
cmpq %rax, %r15
jl 0x55fb
cmpl $0x0, 0xa2be3e(%rip)    # 0xa314d4
jle 0x5737
leaq 0xa2be4b(%rip), %r14    # 0xa314ee
xorl %r15d, %r15d
leaq 0xa2be33(%rip), %r12    # 0xa314e0
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %rbx
addq %r15, %rbx
leaq (%r12,%rbx), %r13
movl (%r12,%rbx), %edi
callq 0x8a38
movl %eax, (%r12,%rbx)
movq $-0x3, %rbp
movswl (%r14,%rbp,2), %edi
callq 0x8a30
movw %ax, (%r14,%rbp,2)
movswl 0x6(%r14,%rbp,2), %edi
callq 0x8a30
movw %ax, 0x6(%r14,%rbp,2)
incq %rbp
jne 0x56d0
movswl 0x14(%r13), %edi
callq 0x8a30
movw %ax, 0x14(%r13)
movswl 0x16(%r13), %edi
callq 0x8a30
movw %ax, 0x16(%r13)
movl 0x4(%r13), %edi
callq 0x8a38
movl %eax, 0x4(%r13)
incq %r15
movslq 0xa2bdaa(%rip), %rax    # 0xa314d4
addq $0x1c, %r14
cmpq %rax, %r15
jl 0x56ad
cmpl $0x0, 0x1ccbcd2(%rip)   # 0x1cd1410
jle 0x5788
xorl %r14d, %r14d
leaq 0x1ccbcd6(%rip), %r15   # 0x1cd1420
movl (%r15,%r14,8), %edi
callq 0x8a38
movl %eax, (%r15,%r14,8)
movswl 0x4(%r15,%r14,8), %edi
callq 0x8a30
movw %ax, 0x4(%r15,%r14,8)
movswl 0x6(%r15,%r14,8), %edi
callq 0x8a30
movw %ax, 0x6(%r15,%r14,8)
incq %r14
movslq 0x1ccbc8d(%rip), %rax   # 0x1cd1410
cmpq %rax, %r14
jl 0x574a
cmpl $0x0, 0x82bd25(%rip)    # 0x8314b4
je 0x57d8
movq 0x82bd20(%rip), %r14    # 0x8314b8
movl (%r14), %edi
cmpb $0x0, 0x4(%rsp)
je 0x57a6
movl %edi, %ebx
jmp 0x57b0
callq 0x8a38
movl %eax, %ebx
movl (%r14), %edi
callq 0x8a38
movl %eax, (%r14)
testl %ebx, %ebx
jle 0x57d8
movl %ebx, %ebx
xorl %r15d, %r15d
movl 0x4(%r14,%r15,4), %edi
callq 0x8a38
movl %eax, 0x4(%r14,%r15,4)
incq %r15
cmpq %r15, %rbx
jne 0x57c1
cmpl $0x0, 0x1e05c45(%rip)   # 0x1e0b424
jle 0x5809
leaq 0x1e05c48(%rip), %rbx   # 0x1e0b430
xorl %r14d, %r14d
movswl (%rbx), %edi
callq 0x8a30
movw %ax, (%rbx)
incq %r14
movslq 0x1e05c24(%rip), %rax   # 0x1e0b424
addq $0x2, %rbx
cmpq %rax, %r14
jl 0x57eb
cmpl $0x0, 0x1e25c24(%rip)   # 0x1e2b434
jle 0x5838
leaq 0x1e25c27(%rip), %rbx   # 0x1e2b440
xorl %r14d, %r14d
movl (%rbx), %edi
callq 0x8a38
movl %eax, (%rbx)
incq %r14
movslq 0x1e25c05(%rip), %rax   # 0x1e2b434
addq $0x4, %rbx
cmpq %rax, %r14
jl 0x581c
cmpl $0x0, 0x1d0bbdd(%rip)   # 0x1d1141c
jle 0x5879
xorl %ebx, %ebx
leaq 0x1d0bbd6(%rip), %r14   # 0x1d11420
movswl (%r14,%rbx,4), %edi
callq 0x8a30
movw %ax, (%r14,%rbx,4)
movswl 0x2(%r14,%rbx,4), %edi
callq 0x8a30
movw %ax, 0x2(%r14,%rbx,4)
incq %rbx
movslq 0x1d0bba8(%rip), %rax   # 0x1d1141c
cmpq %rax, %rbx
jl 0x584a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq