// File: /workspace/github_cpp_makefile_star2_O2/jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_writer_init_from_reader_v2
mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags)
{
    mz_zip_internal_state *pState;

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

    if (flags & MZ_ZIP_FLAG_WRITE_ZIP64)
    {
        /* We don't support converting a non-zip64 file to zip64 - this seems like more trouble than it's worth. (What about the existing 32-bit data descriptors that could follow the compressed data?) */
        if (!pZip->m_pState->m_zip64)
            return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
    }

    /* No sense in trying to write to an archive that's already at the support max size */
    if (pZip->m_pState->m_zip64)
    {
        if (pZip->m_total_files == MZ_UINT32_MAX)
            return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
    }
    else
    {
        if (pZip->m_total_files == MZ_UINT16_MAX)
            return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);

        if ((pZip->m_archive_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_ZIP_LOCAL_DIR_HEADER_SIZE) > MZ_UINT32_MAX)
            return mz_zip_set_error(pZip, MZ_ZIP_FILE_TOO_LARGE);
    }

    pState = pZip->m_pState;

    if (pState->m_pFile)
    {
#ifdef MINIZ_NO_STDIO
        (void)pFilename;
        return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
#else
        if (pZip->m_pIO_opaque != pZip)
            return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);

        if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
        {
            if (!pFilename)
                return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);

            /* Archive is being read from stdio and was originally opened only for reading. Try to reopen as writable. */
            if (NULL == (pState->m_pFile = MZ_FREOPEN(pFilename, "r+b", pState->m_pFile)))
            {
                /* The mz_zip_archive is now in a bogus state because pState->m_pFile is NULL, so just close it. */
                mz_zip_reader_end_internal(pZip, MZ_FALSE);
                return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
            }
        }

        pZip->m_pWrite = mz_zip_file_write_func;
        pZip->m_pNeeds_keepalive = NULL;
#endif /* #ifdef MINIZ_NO_STDIO */
    }
    else if (pState->m_pMem)
    {
        /* Archive lives in a memory block. Assume it's from the heap that we can resize using the realloc callback. */
        if (pZip->m_pIO_opaque != pZip)
            return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);

        pState->m_mem_capacity = pState->m_mem_size;
        pZip->m_pWrite = mz_zip_heap_write_func;
        pZip->m_pNeeds_keepalive = NULL;
    }
    /* Archive is being read via a user provided read function - make sure the user has specified a write function too. */
    else if (!pZip->m_pWrite)
        return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);

    /* Start writing new files at the archive's current central directory location. */
    /* TODO: We could add a flag that lets the user start writing immediately AFTER the existing central dir - this would be safer. */
    pZip->m_archive_size = pZip->m_central_directory_file_ofs;
    pZip->m_central_directory_file_ofs = 0;

    /* Clear the sorted central dir offsets, they aren't useful or maintained now. */
    /* Even though we're now in write mode, files can still be extracted and verified, but file locates will be slow. */
    /* TODO: We could easily maintain the sorted central directory offsets. */
    mz_zip_array_clear(pZip, &pZip->m_pState->m_sorted_central_dir_offsets);

    pZip->m_zip_mode = MZ_ZIP_MODE_WRITING;

    return MZ_TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
xorl %r14d, %r14d
testq %rdi, %rdi
je 0xb36b
movq %rdi, %rbx
movq 0x68(%rdi), %r15
testq %r15, %r15
je 0xb364
cmpl $0x1, 0x14(%rbx)
jne 0xb364
btl $0xe, %edx
movl 0x64(%r15), %eax
jb 0xb297
testl %eax, %eax
jne 0xb29f
cmpl $0xffff, 0x10(%rbx)     # imm = 0xFFFF
je 0xb2f3
movq (%rbx), %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
addq $0x4c, %rax
cmpq %rcx, %rax
jae 0xb2a5
movl $0x3, 0x1c(%rbx)
jmp 0xb36b
testl %eax, %eax
je 0xb364
cmpl $-0x1, 0x10(%rbx)
je 0xb2f3
movq 0x70(%r15), %rdx
testq %rdx, %rdx
je 0xb2fc
cmpq %rbx, 0x60(%rbx)
jne 0xb364
leaq -0x194(%rip), %r12      # 0xb12b
cmpl $0x4, 0x18(%rbx)
jne 0xb321
testq %rsi, %rsi
je 0xb364
leaq 0xaf4e(%rip), %rax      # 0x16223
movq %rsi, %rdi
movq %rax, %rsi
callq 0x3230
movq %rax, 0x70(%r15)
testq %rax, %rax
je 0xb377
movq 0x68(%rbx), %r15
jmp 0xb321
movl $0x2, 0x1c(%rbx)
jmp 0xb36b
cmpq $0x0, 0x80(%r15)
je 0xb32c
cmpq %rbx, 0x60(%rbx)
jne 0xb364
movq 0x88(%r15), %rax
movq %rax, 0x90(%r15)
leaq -0x51b(%rip), %r12      # 0xae06
movq %r12, 0x50(%rbx)
andq $0x0, 0x58(%rbx)
jmp 0xb333
cmpq $0x0, 0x50(%rbx)
je 0xb364
movq 0x8(%rbx), %rax
movq 0x40(%rbx), %rdi
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movq 0x40(%r15), %rsi
callq *0x30(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%r15)
movups %xmm0, 0x40(%r15)
movl $0x2, 0x14(%rbx)
pushq $0x1
popq %r14
jmp 0xb36b
movl $0x18, 0x1c(%rbx)
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7ac9
movl $0x11, 0x1c(%rbx)
jmp 0xb36b