// File: /workspace/github_cpp_makefile_star2_O2/jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_writer_finalize_archive
mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip)
{
    mz_zip_internal_state *pState;
    mz_uint64 central_dir_ofs, central_dir_size;
    mz_uint8 hdr[256];

    if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING))
        return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);

    pState = pZip->m_pState;

    if (pState->m_zip64)
    {
        if ((pZip->m_total_files > MZ_UINT32_MAX) || (pState->m_central_dir.m_size >= MZ_UINT32_MAX))
            return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
    }
    else
    {
        if ((pZip->m_total_files > MZ_UINT16_MAX) || ((pZip->m_archive_size + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) > MZ_UINT32_MAX))
            return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
    }

    central_dir_ofs = 0;
    central_dir_size = 0;
    if (pZip->m_total_files)
    {
        /* Write central directory */
        central_dir_ofs = pZip->m_archive_size;
        central_dir_size = pState->m_central_dir.m_size;
        pZip->m_central_directory_file_ofs = central_dir_ofs;
        if (pZip->m_pWrite(pZip->m_pIO_opaque, central_dir_ofs, pState->m_central_dir.m_p, (size_t)central_dir_size) != central_dir_size)
            return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);

        pZip->m_archive_size += central_dir_size;
    }

    if (pState->m_zip64)
    {
        /* Write zip64 end of central directory header */
        mz_uint64 rel_ofs_to_zip64_ecdr = pZip->m_archive_size;

        MZ_CLEAR_OBJ(hdr);
        MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDH_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG);
        MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE - sizeof(mz_uint32) - sizeof(mz_uint64));
        MZ_WRITE_LE16(hdr + MZ_ZIP64_ECDH_VERSION_MADE_BY_OFS, 0x031E); /* TODO: always Unix */
        MZ_WRITE_LE16(hdr + MZ_ZIP64_ECDH_VERSION_NEEDED_OFS, 0x002D);
        MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, pZip->m_total_files);
        MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_TOTAL_ENTRIES_OFS, pZip->m_total_files);
        MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_SIZE_OFS, central_dir_size);
        MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_OFS_OFS, central_dir_ofs);
        if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE)
            return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);

        pZip->m_archive_size += MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE;

        /* Write zip64 end of central directory locator */
        MZ_CLEAR_OBJ(hdr);
        MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG);
        MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS, rel_ofs_to_zip64_ecdr);
        MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS, 1);
        if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE) != MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE)
            return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);

        pZip->m_archive_size += MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE;
    }

    /* Write end of central directory record */
    MZ_CLEAR_OBJ(hdr);
    MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_SIG_OFS, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG);
    MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files));
    MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files));
    MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_SIZE_OFS, MZ_MIN(MZ_UINT32_MAX, central_dir_size));
    MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_OFS_OFS, MZ_MIN(MZ_UINT32_MAX, central_dir_ofs));

    if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
        return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);

#ifndef MINIZ_NO_STDIO
    if ((pState->m_pFile) && (MZ_FFLUSH(pState->m_pFile) == EOF))
        return mz_zip_set_error(pZip, MZ_ZIP_FILE_CLOSE_FAILED);
#endif /* #ifndef MINIZ_NO_STDIO */

    pZip->m_archive_size += MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE;

    pZip->m_zip_mode = MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED;
    return MZ_TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
xorl %r14d, %r14d
testq %rdi, %rdi
je 0xdde6
movq %rdi, %rbx
movq 0x68(%rdi), %r13
testq %r13, %r13
je 0xda83
cmpl $0x2, 0x14(%rbx)
jne 0xda83
movl 0x64(%r13), %eax
testl %eax, %eax
je 0xda8f
movq 0x8(%r13), %r8
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
cmpq %rcx, %r8
ja 0xdac2
movl 0x10(%rbx), %ecx
movq (%rbx), %rdx
movq %rdx, -0x30(%rbp)
jmp 0xdace
movl $0x18, 0x1c(%rbx)
jmp 0xdde6
movl 0x10(%rbx), %ecx
cmpl $0xffff, %ecx           # imm = 0xFFFF
ja 0xdac2
movq (%rbx), %rsi
movq 0x8(%r13), %rdi
movq %rsi, -0x30(%rbp)
movq %rdi, %r8
leaq (%rsi,%rdi), %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
addq %rsi, %rdx
addq $0x16, %rdx
cmpq %rsi, %rdx
jae 0xdace
movl $0x2, 0x1c(%rbx)
jmp 0xdde6
testl %ecx, %ecx
je 0xdb07
movq -0x30(%rbp), %rsi
movq %rsi, 0x8(%rbx)
movq 0x60(%rbx), %rdi
movq (%r13), %rdx
movq %r8, %r14
movq %r8, %rcx
callq *0x50(%rbx)
cmpq %r14, %rax
jne 0xdddc
movq (%rbx), %rcx
addq %r14, %rcx
movq %rcx, (%rbx)
movl 0x64(%r13), %eax
movl 0x10(%rbx), %r12d
jmp 0xdb19
xorl %r12d, %r12d
movq -0x30(%rbp), %rcx
movq $0x0, -0x30(%rbp)
xorl %r14d, %r14d
movq %r14, -0x40(%rbp)
testl %eax, %eax
movq %rcx, -0x38(%rbp)
je 0xdd08
leaq -0x130(%rbp), %r15
xorl %r14d, %r14d
movl $0xf0, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x3180
movl $0x6064b50, -0x10(%r15) # imm = 0x6064B50
movb $0x2c, -0xc(%r15)
movabsq $0x2d031e00000000, %rax # imm = 0x2D031E00000000
movq %rax, -0x8(%r15)
andl $0x0, -0xb(%r15)
movb %r12b, 0x8(%r15)
movl %r12d, %eax
shrl $0x8, %eax
movb %al, 0x9(%r15)
movl %r12d, %ecx
shrl $0x10, %ecx
movb %cl, 0xa(%r15)
movl %r12d, %edx
shrl $0x18, %edx
movb %dl, 0xb(%r15)
andl $0x0, 0xc(%r15)
movb %r12b, 0x10(%r15)
movb %al, 0x11(%r15)
movb %cl, 0x12(%r15)
movb %dl, 0x13(%r15)
andl $0x0, 0x14(%r15)
movq -0x40(%rbp), %rcx
movb %cl, 0x18(%r15)
movb %ch, -0x117(%rbp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x1a(%r15)
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x1b(%r15)
movq %rcx, %rax
shrq $0x20, %rax
movb %al, 0x1c(%r15)
movq %rcx, %rax
shrq $0x28, %rax
movb %al, 0x1d(%r15)
movq %rcx, %rax
shrq $0x30, %rax
movb %al, 0x1e(%r15)
movq %rcx, %rax
shrq $0x38, %rax
movb %al, 0x1f(%r15)
movq -0x30(%rbp), %rcx
movb %cl, 0x20(%r15)
movb %ch, -0x10f(%rbp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x22(%r15)
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x23(%r15)
movq %rcx, %rax
shrq $0x20, %rax
movb %al, 0x24(%r15)
movq %rcx, %rax
shrq $0x28, %rax
movb %al, 0x25(%r15)
movq %rcx, %rax
shrq $0x30, %rax
movb %al, 0x26(%r15)
movq %rcx, %rax
shrq $0x38, %rax
movb %al, 0x27(%r15)
movq 0x60(%rbx), %rdi
leaq -0x140(%rbp), %rdx
pushq $0x38
popq %rcx
movq -0x38(%rbp), %rsi
callq *0x50(%rbx)
cmpq $0x38, %rax
jne 0xddd3
movq (%rbx), %r15
addq $0x38, %r15
movq %r15, (%rbx)
leaq -0x140(%rbp), %r12
xorl %r14d, %r14d
movl $0x100, %edx            # imm = 0x100
movq %r12, %rdi
xorl %esi, %esi
callq 0x3180
movl $0x7064b50, (%r12)      # imm = 0x7064B50
movq -0x38(%rbp), %rcx
movb %cl, 0x8(%r12)
movb %ch, -0x137(%rbp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0xa(%r12)
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0xb(%r12)
movq %rcx, %rax
shrq $0x20, %rax
movb %al, 0xc(%r12)
movq %rcx, %rax
shrq $0x28, %rax
movb %al, 0xd(%r12)
movq %rcx, %rax
shrq $0x30, %rax
movb %al, 0xe(%r12)
shrq $0x38, %rcx
movb %cl, 0xf(%r12)
movb $0x1, 0x10(%r12)
movb $0x0, 0x12(%r12)
movq 0x60(%rbx), %rdi
pushq $0x14
popq %rcx
movq %r15, %rsi
movq %r12, %rdx
callq *0x50(%rbx)
cmpq $0x14, %rax
jne 0xddd3
movq (%rbx), %rax
addq $0x14, %rax
movq %rax, -0x38(%rbp)
movq %rax, (%rbx)
movl 0x10(%rbx), %r12d
leaq -0x140(%rbp), %r15
xorl %r14d, %r14d
movl $0x100, %edx            # imm = 0x100
movq %r15, %rdi
xorl %esi, %esi
callq 0x3180
movl $0x6054b50, (%r15)      # imm = 0x6054B50
movl $0xffff, %eax           # imm = 0xFFFF
cmpl %eax, %r12d
cmovbl %r12d, %eax
movb %al, 0x8(%r15)
movl %eax, %ecx
shrl $0x8, %ecx
movb %cl, 0x9(%r15)
movb %al, 0xa(%r15)
movb %cl, 0xb(%r15)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq -0x40(%rbp), %rdx
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movb %dl, 0xc(%r15)
movb %dh, -0x133(%rbp)
movl %edx, %ecx
shrl $0x10, %ecx
movb %cl, 0xe(%r15)
shrl $0x18, %edx
movb %dl, 0xf(%r15)
movq -0x30(%rbp), %rcx
cmpq %rax, %rcx
cmovbq %rcx, %rax
movb %al, 0x10(%r15)
movb %ah, -0x12f(%rbp)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x12(%r15)
shrl $0x18, %eax
movb %al, 0x13(%r15)
movq 0x60(%rbx), %rdi
pushq $0x16
popq %rcx
movq -0x38(%rbp), %rsi
movq %r15, %rdx
callq *0x50(%rbx)
cmpq $0x16, %rax
jne 0xddd3
movq 0x70(%r13), %rdi
testq %rdi, %rdi
je 0xddc2
callq 0x32c0
cmpl $-0x1, %eax
je 0xddfb
addq $0x16, (%rbx)
movl $0x3, 0x14(%rbx)
pushq $0x1
popq %r14
jmp 0xdde6
movl $0x13, 0x1c(%rbx)
jmp 0xdde6
movl $0x13, 0x1c(%rbx)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x15, 0x1c(%rbx)
jmp 0xdde6