// File: jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_reader_init_file_v2
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size)
{
    mz_uint64 file_size;
    MZ_FILE *pFile;

    if ((!pZip) || (!pFilename) || ((archive_size) && (archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)))
        return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);

    pFile = MZ_FOPEN(pFilename, "rb");
    if (!pFile)
        return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);

    file_size = archive_size;
    if (!file_size)
    {
        if (MZ_FSEEK64(pFile, 0, SEEK_END))
        {
            MZ_FCLOSE(pFile);
            return mz_zip_set_error(pZip, MZ_ZIP_FILE_SEEK_FAILED);
        }

        file_size = MZ_FTELL64(pFile);
    }

    /* TODO: Better sanity check archive_size and the # of actual remaining bytes */

    if (file_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
    {
	MZ_FCLOSE(pFile);
        return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
    }

    if (!mz_zip_reader_init_internal(pZip, flags))
    {
        MZ_FCLOSE(pFile);
        return MZ_FALSE;
    }

    pZip->m_zip_type = MZ_ZIP_TYPE_FILE;
    pZip->m_pRead = mz_zip_file_read_func;
    pZip->m_pIO_opaque = pZip;
    pZip->m_pState->m_pFile = pFile;
    pZip->m_archive_size = file_size;
    pZip->m_pState->m_file_archive_start_ofs = file_start_ofs;

    if (!mz_zip_reader_read_central_dir(pZip, flags))
    {
        mz_zip_reader_end_internal(pZip, MZ_FALSE);
        return MZ_FALSE;
    }

    return MZ_TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x48(%rbp)
movq %rsi, -0x50(%rbp)
movl %edx, -0x54(%rbp)
movq %rcx, -0x60(%rbp)
movq %r8, -0x68(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xd31a
cmpq $0x0, -0x50(%rbp)
je 0xd31a
cmpq $0x0, -0x68(%rbp)
je 0xd346
cmpq $0x16, -0x68(%rbp)
jae 0xd346
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x18, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0xd33a
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0x40(%rbp)
jmp 0xd4d1
movq -0x50(%rbp), %rdi
leaq 0x28ec8(%rip), %rsi     # 0x36219
callq 0x3370
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0xd38d
movq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x11, -0x1c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xd381
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0x40(%rbp)
jmp 0xd4d1
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0xd3f5
movq -0x78(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x3510
cmpl $0x0, %eax
je 0xd3e8
movq -0x78(%rbp), %rdi
callq 0x3300
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x16, -0x2c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xd3dc
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0x40(%rbp)
jmp 0xd4d1
movq -0x78(%rbp), %rdi
callq 0x3480
movq %rax, -0x70(%rbp)
cmpq $0x16, -0x70(%rbp)
jae 0xd431
movq -0x78(%rbp), %rdi
callq 0x3300
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x8, -0x3c(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xd425
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0x40(%rbp)
jmp 0xd4d1
movq -0x48(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0xbe80
cmpl $0x0, %eax
jne 0xd454
movq -0x78(%rbp), %rdi
callq 0x3300
movl $0x0, -0x40(%rbp)
jmp 0xd4d1
movq -0x48(%rbp), %rax
movl $0x4, 0x18(%rax)
movq -0x48(%rbp), %rax
leaq 0x76(%rip), %rcx        # 0xd4e0
movq %rcx, 0x48(%rax)
movq -0x48(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x78(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x68(%rax), %rax
movq %rcx, 0x70(%rax)
movq -0x70(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x68(%rax), %rax
movq %rcx, 0x78(%rax)
movq -0x48(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0xc040
cmpl $0x0, %eax
jne 0xd4ca
movq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0xbbf0
movl $0x0, -0x40(%rbp)
jmp 0xd4d1
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)