// File: jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_reader_locate_header_sig(mz_zip_archive*, unsigned int, unsigned int, long*)
static mz_bool mz_zip_reader_locate_header_sig(mz_zip_archive *pZip, mz_uint32 record_sig, mz_uint32 record_size, mz_int64 *pOfs)
{
    mz_int64 cur_file_ofs;
    mz_uint32 buf_u32[4096 / sizeof(mz_uint32)];
    mz_uint8 *pBuf = (mz_uint8 *)buf_u32;

    /* Basic sanity checks - reject files which are too small */
    if (pZip->m_archive_size < record_size)
        return MZ_FALSE;

    /* Find the record by scanning the file from the end towards the beginning. */
    cur_file_ofs = MZ_MAX((mz_int64)pZip->m_archive_size - (mz_int64)sizeof(buf_u32), 0);
    for (;;)
    {
        int i, n = (int)MZ_MIN(sizeof(buf_u32), pZip->m_archive_size - cur_file_ofs);

        if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, n) != (mz_uint)n)
            return MZ_FALSE;

        for (i = n - 4; i >= 0; --i)
        {
            mz_uint s = MZ_READ_LE32(pBuf + i);
            if (s == record_sig)
            {
                if ((pZip->m_archive_size - (cur_file_ofs + i)) >= record_size)
                    break;
            }
        }

        if (i >= 0)
        {
            cur_file_ofs += i;
            break;
        }

        /* Give up if we've searched the entire file, or we've gone back "too far" (~64kb) */
        if ((!cur_file_ofs) || ((pZip->m_archive_size - cur_file_ofs) >= (MZ_UINT16_MAX + record_size)))
            return MZ_FALSE;

        cur_file_ofs = MZ_MAX(cur_file_ofs - (sizeof(buf_u32) - 3), 0);
    }

    *pOfs = cur_file_ofs;
    return MZ_TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1060, %rsp           # imm = 0x1060
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0x1030(%rbp), %rax
movq %rax, -0x1038(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x18(%rbp), %ecx
cmpq %rcx, %rax
jae 0x1f402
movl $0x0, -0x4(%rbp)
jmp 0x1f5c4
movq -0x10(%rbp), %rax
movq (%rax), %rax
subq $0x1000, %rax           # imm = 0x1000
cmpq $0x0, %rax
jle 0x1f42b
movq -0x10(%rbp), %rax
movq (%rax), %rax
subq $0x1000, %rax           # imm = 0x1000
movq %rax, -0x1050(%rbp)
jmp 0x1f436
xorl %eax, %eax
movq %rax, -0x1050(%rbp)
jmp 0x1f436
movq -0x1050(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
subq -0x28(%rbp), %rcx
movl $0x1000, %eax           # imm = 0x1000
cmpq %rcx, %rax
jae 0x1f464
movl $0x1000, %eax           # imm = 0x1000
movq %rax, -0x1058(%rbp)
jmp 0x1f476
movq -0x10(%rbp), %rax
movq (%rax), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x1058(%rbp)
movq -0x1058(%rbp), %rax
movl %eax, -0x1040(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x60(%rcx), %rdi
movq -0x28(%rbp), %rsi
movq -0x1038(%rbp), %rdx
movslq -0x1040(%rbp), %rcx
callq *%rax
movl -0x1040(%rbp), %ecx
cmpq %rcx, %rax
je 0x1f4be
movl $0x0, -0x4(%rbp)
jmp 0x1f5c4
movl -0x1040(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x103c(%rbp)
cmpl $0x0, -0x103c(%rbp)
jl 0x1f52f
movq -0x1038(%rbp), %rax
movslq -0x103c(%rbp), %rcx
movl (%rax,%rcx), %eax
movl %eax, -0x1044(%rbp)
movl -0x1044(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x1f51c
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x103c(%rbp), %rdx
addq %rdx, %rcx
subq %rcx, %rax
movl -0x18(%rbp), %ecx
cmpq %rcx, %rax
jb 0x1f51a
jmp 0x1f52f
jmp 0x1f51c
jmp 0x1f51e
movl -0x103c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x103c(%rbp)
jmp 0x1f4cd
cmpl $0x0, -0x103c(%rbp)
jl 0x1f549
movslq -0x103c(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1f5b2
cmpq $0x0, -0x28(%rbp)
je 0x1f56b
movq -0x10(%rbp), %rax
movq (%rax), %rax
subq -0x28(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jb 0x1f574
movl $0x0, -0x4(%rbp)
jmp 0x1f5c4
movq -0x28(%rbp), %rax
subq $0xffd, %rax            # imm = 0xFFD
cmpq $0x0, %rax
jbe 0x1f597
movq -0x28(%rbp), %rax
subq $0xffd, %rax            # imm = 0xFFD
movq %rax, -0x1060(%rbp)
jmp 0x1f5a2
xorl %eax, %eax
movq %rax, -0x1060(%rbp)
jmp 0x1f5a2
movq -0x1060(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1f441
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1060, %rsp           # imm = 0x1060
popq %rbp
retq