// File: /workspace/github_cpp_makefile_star2_O1/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 0xe378
movq %rdi, %rbx
movq 0x68(%rdi), %r13
testq %r13, %r13
je 0xe02f
cmpl $0x2, 0x14(%rbx)
jne 0xe02f
cmpl $0x0, 0x64(%r13)
je 0xe044
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, 0x8(%r13)
jae 0xe06a
jmp 0xe076
testq %rbx, %rbx
je 0xe378
movl $0x18, 0x1c(%rbx)
jmp 0xe378
cmpl $0xffff, 0x10(%rbx)     # imm = 0xFFFF
ja 0xe06a
movq (%rbx), %rax
addq 0x8(%r13), %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
addq $0x16, %rax
cmpq %rcx, %rax
jae 0xe076
movl $0x2, 0x1c(%rbx)
jmp 0xe378
cmpl $0x0, 0x10(%rbx)
je 0xe0ab
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
movq 0x8(%r13), %r14
movq %rsi, 0x8(%rbx)
movq (%r13), %rdx
movq %rsi, -0x38(%rbp)
movq %r14, %rcx
callq *0x50(%rbx)
cmpq %r14, %rax
jne 0xe36e
movq %r14, -0x30(%rbp)
addq %r14, (%rbx)
jmp 0xe0bb
movq $0x0, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
cmpl $0x0, 0x64(%r13)
je 0xe296
movq (%rbx), %r12
leaq -0x140(%rbp), %r15
xorl %r14d, %r14d
movl $0x100, %edx            # imm = 0x100
movq %r15, %rdi
xorl %esi, %esi
callq 0x3160
movl $0x6064b50, (%r15)      # imm = 0x6064B50
movb $0x2c, 0x4(%r15)
movl %r14d, 0x5(%r15)
movabsq $0x2d031e00000000, %rax # imm = 0x2D031E00000000
movq %rax, 0x8(%r15)
movl 0x10(%rbx), %eax
movb %al, 0x18(%r15)
movl %eax, %ecx
shrl $0x8, %ecx
movb %cl, 0x19(%r15)
movl %eax, %edx
shrl $0x10, %edx
movb %dl, 0x1a(%r15)
movl %eax, %esi
shrl $0x18, %esi
movb %sil, 0x1b(%r15)
movl %r14d, 0x1c(%r15)
movb %al, 0x20(%r15)
movb %cl, 0x21(%r15)
movb %dl, 0x22(%r15)
movb %sil, 0x23(%r15)
movl %r14d, 0x24(%r15)
movq -0x30(%rbp), %rcx
movb %cl, 0x28(%r15)
movb %ch, -0x117(%rbp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x2a(%r15)
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x2b(%r15)
movq %rcx, %rax
shrq $0x20, %rax
movb %al, 0x2c(%r15)
movq %rcx, %rax
shrq $0x28, %rax
movb %al, 0x2d(%r15)
movq %rcx, %rax
shrq $0x30, %rax
movb %al, 0x2e(%r15)
movq %rcx, %rax
shrq $0x38, %rax
movb %al, 0x2f(%r15)
movq -0x38(%rbp), %rcx
movb %cl, 0x30(%r15)
movb %ch, -0x10f(%rbp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x32(%r15)
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x33(%r15)
movq %rcx, %rax
shrq $0x20, %rax
movb %al, 0x34(%r15)
movq %rcx, %rax
shrq $0x28, %rax
movb %al, 0x35(%r15)
movq %rcx, %rax
shrq $0x30, %rax
movb %al, 0x36(%r15)
movq %rcx, %rax
shrq $0x38, %rax
movb %al, 0x37(%r15)
movq 0x60(%rbx), %rdi
movl $0x38, %ecx
movq %r12, -0x40(%rbp)
movq %r12, %rsi
movq %r15, %rdx
callq *0x50(%rbx)
cmpq $0x38, %rax
jne 0xe365
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 0x3160
movl $0x7064b50, (%r12)      # imm = 0x7064B50
movq -0x40(%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)
movl $0x1, 0x10(%r12)
movq 0x60(%rbx), %rdi
movl $0x14, %ecx
movq %r15, %rsi
movq %r12, %rdx
callq *0x50(%rbx)
cmpq $0x14, %rax
jne 0xe365
addq $0x14, (%rbx)
leaq -0x140(%rbp), %r15
xorl %r14d, %r14d
movl $0x100, %edx            # imm = 0x100
movq %r15, %rdi
xorl %esi, %esi
callq 0x3160
movl $0x6054b50, (%r15)      # imm = 0x6054B50
movl 0x10(%rbx), %eax
movl $0xffff, %ecx           # imm = 0xFFFF
cmpl %ecx, %eax
cmovbl %eax, %ecx
movb %cl, 0x8(%r15)
movl %ecx, %esi
shrl $0x8, %esi
movb %sil, 0x9(%r15)
movb %cl, 0xa(%r15)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rdx
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movb %sil, 0xb(%r15)
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 -0x38(%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 (%rbx), %rsi
movq 0x60(%rbx), %rdi
movl $0x16, %ecx
movq %r15, %rdx
callq *0x50(%rbx)
cmpq $0x16, %rax
jne 0xe365
movq 0x70(%r13), %rdi
testq %rdi, %rdi
je 0xe352
callq 0x32c0
cmpl $-0x1, %eax
je 0xe38d
addq $0x16, (%rbx)
movl $0x3, 0x14(%rbx)
movl $0x1, %r14d
jmp 0xe378
movl $0x13, 0x1c(%rbx)
jmp 0xe378
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 0xe378