// File: /workspace/github_cpp_makefile_star2_O1/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 0xb565
movq %rdi, %rbx
movq 0x68(%rdi), %r15
testq %r15, %r15
je 0xb559
cmpl $0x1, 0x14(%rbx)
jne 0xb559
btl $0xe, %edx
jae 0xb4ec
cmpl $0x0, 0x64(%r15)
je 0xb55e
cmpl $0x0, 0x64(%r15)
movl 0x10(%rbx), %eax
je 0xb571
cmpl $-0x1, %eax
je 0xb578
movq 0x70(%r15), %rdx
testq %rdx, %rdx
je 0xb5a7
cmpq %rbx, 0x60(%rbx)
jne 0xb55e
leaq -0x16a(%rip), %r12      # 0xb3ab
cmpl $0x4, 0x18(%rbx)
jne 0xb5cc
testq %rsi, %rsi
je 0xb55e
leaq 0xbd18(%rip), %rax      # 0x17243
movq %rsi, %rdi
movq %rax, %rsi
callq 0x3220
movq %rax, 0x70(%r15)
testq %rax, %rax
jne 0xb5cc
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7dc3
movl $0x11, 0x1c(%rbx)
jmp 0xb565
testq %rbx, %rbx
je 0xb565
movl $0x18, 0x1c(%rbx)
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0xb581
movl $0x2, 0x1c(%rbx)
jmp 0xb565
movq (%rbx), %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
addq $0x4c, %rax
cmpq %rcx, %rax
jae 0xb4fb
movl $0x3, 0x1c(%rbx)
jmp 0xb565
cmpq $0x0, 0x80(%r15)
je 0xb5da
cmpq %rbx, 0x60(%rbx)
jne 0xb55e
movq 0x88(%r15), %rax
movq %rax, 0x90(%r15)
leaq -0x594(%rip), %r12      # 0xb038
movq %r12, 0x50(%rbx)
movq $0x0, 0x58(%rbx)
jmp 0xb5e5
cmpq $0x0, 0x50(%rbx)
je 0xb55e
movq 0x8(%rbx), %rax
movq 0x40(%rbx), %rdi
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
movq 0x68(%rbx), %r14
movq 0x40(%r14), %rsi
callq *0x30(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%r14)
movups %xmm0, 0x40(%r14)
movl $0x2, 0x14(%rbx)
movl $0x1, %r14d
jmp 0xb565