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

    pZip->m_pWrite = mz_zip_file_write_func;
    pZip->m_pNeeds_keepalive = NULL;

    if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
        pZip->m_pRead = mz_zip_file_read_func;

    pZip->m_pIO_opaque = pZip;

    if (!mz_zip_writer_init_v2(pZip, size_to_reserve_at_beginning, flags))
        return MZ_FALSE;

    if (NULL == (pFile = MZ_FOPEN(pFilename, (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) ? "w+b" : "wb")))
    {
        mz_zip_writer_end(pZip);
        return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
    }

    pZip->m_pState->m_pFile = pFile;
    pZip->m_zip_type = MZ_ZIP_TYPE_FILE;

    if (size_to_reserve_at_beginning)
    {
        mz_uint64 cur_ofs = 0;
        char buf[4096];

        MZ_CLEAR_OBJ(buf);

        do
        {
            size_t n = (size_t)MZ_MIN(sizeof(buf), size_to_reserve_at_beginning);
            if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_ofs, buf, n) != n)
            {
                mz_zip_writer_end(pZip);
                return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
            }
            cur_ofs += n;
            size_to_reserve_at_beginning -= n;
        } while (size_to_reserve_at_beginning);
    }

    return MZ_TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1060, %rsp           # imm = 0x1060
movq %rdi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movl %ecx, -0x3c(%rbp)
movq -0x28(%rbp), %rax
leaq 0x1db(%rip), %rcx       # 0x13220
movq %rcx, 0x50(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x58(%rax)
movl -0x3c(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x13071
movq -0x28(%rbp), %rax
leaq -0x5b8d(%rip), %rcx     # 0xd4e0
movq %rcx, 0x48(%rax)
movq -0x28(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x3c(%rbp), %edx
callq 0x12810
cmpl $0x0, %eax
jne 0x1309e
movl $0x0, -0x20(%rbp)
jmp 0x1320f
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %ecx
andl $0x8000, %ecx           # imm = 0x8000
leaq 0x2316a(%rip), %rsi     # 0x3621c
leaq 0x23166(%rip), %rax     # 0x3621f
cmpl $0x0, %ecx
cmovneq %rax, %rsi
callq 0x3370
movq %rax, %rcx
movq %rcx, -0x48(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x13108
movq -0x28(%rbp), %rdi
callq 0x132f0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x11, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x130fc
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0x20(%rbp)
jmp 0x1320f
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movq %rcx, 0x70(%rax)
movq -0x28(%rbp), %rax
movl $0x4, 0x18(%rax)
cmpq $0x0, -0x38(%rbp)
je 0x13208
movq $0x0, -0x50(%rbp)
leaq -0x1050(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x3190
movl $0x1000, %eax           # imm = 0x1000
cmpq -0x38(%rbp), %rax
jae 0x13162
movl $0x1000, %eax           # imm = 0x1000
movq %rax, -0x1060(%rbp)
jmp 0x1316d
movq -0x38(%rbp), %rax
movq %rax, -0x1060(%rbp)
movq -0x1060(%rbp), %rax
movq %rax, -0x1058(%rbp)
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x60(%rcx), %rdi
movq -0x50(%rbp), %rsi
leaq -0x1050(%rbp), %rdx
movq -0x1058(%rbp), %rcx
callq *%rax
cmpq -0x1058(%rbp), %rax
je 0x131da
movq -0x28(%rbp), %rdi
callq 0x132f0
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x13, -0x1c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x131d1
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0x20(%rbp)
jmp 0x1320f
movq -0x1058(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x1058(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x13149
jmp 0x13208
movl $0x1, -0x20(%rbp)
movl -0x20(%rbp), %eax
addq $0x1060, %rsp           # imm = 0x1060
popq %rbp
retq
nopl (%rax,%rax)