// File: /workspace/github_c_makefile_star2_O3/Paxa[P]fast_excel/libxlsxwriter/src/packager.c
// Function: lxw_packager_new
lxw_packager *
lxw_packager_new(const char *filename, const char *tmpdir, uint8_t use_zip64)
{
    zlib_filefunc_def filefunc;
    lxw_packager *packager = calloc(1, sizeof(lxw_packager));
    GOTO_LABEL_ON_MEM_ERROR(packager, mem_error);

    packager->buffer = calloc(1, LXW_ZIP_BUFFER_SIZE);
    GOTO_LABEL_ON_MEM_ERROR(packager->buffer, mem_error);

    packager->filename = NULL;
    packager->tmpdir = tmpdir;

    if (filename) {
        packager->filename = lxw_strdup(filename);
        GOTO_LABEL_ON_MEM_ERROR(packager->filename, mem_error);
    }

    packager->buffer_size = LXW_ZIP_BUFFER_SIZE;
    packager->use_zip64 = use_zip64;

    /* Initialize the zip_fileinfo struct to Jan 1 1980 like Excel. */
    packager->zipfile_info.tmz_date.tm_sec = 0;
    packager->zipfile_info.tmz_date.tm_min = 0;
    packager->zipfile_info.tmz_date.tm_hour = 0;
    packager->zipfile_info.tmz_date.tm_mday = 1;
    packager->zipfile_info.tmz_date.tm_mon = 0;
    packager->zipfile_info.tmz_date.tm_year = 1980;
    packager->zipfile_info.dosDate = 0;
    packager->zipfile_info.internal_fa = 0;
    packager->zipfile_info.external_fa = 0;

    packager->output_buffer = NULL;
    packager->output_buffer_size = 0;

    /* Create a zip container for the xlsx file. */
    if (packager->filename) {
#ifdef _WIN32
        packager->zipfile = _open_zipfile_win32(packager->filename);
#else
        packager->zipfile = zipOpen(packager->filename, 0);
#endif
    }
    else {
        fill_fopen_filefunc(&filefunc);
        filefunc.opaque = packager;
        filefunc.zopen_file = _fopen_memstream;
        filefunc.zclose_file = _fclose_memstream;
        packager->zipfile = zipOpen2(packager->filename, 0, NULL, &filefunc);
    }

    if (packager->zipfile == NULL)
        goto mem_error;

    return packager;

mem_error:
    lxw_packager_free(packager);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movl $0x1, %edi
movl $0x80, %esi
callq 0xc7f0
movq %rax, %rbx
testq %rax, %rax
je 0x1fed3
movl $0x1, %edi
movl $0x4000, %esi           # imm = 0x4000
callq 0xc7f0
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x1feda
movq %r15, 0x70(%rbx)
testq %r14, %r14
je 0x1fe45
movq %r14, %rdi
callq 0xcce0
movq %rax, 0x58(%rbx)
testq %rax, %rax
jne 0x1fe47
movl $0xbb, %edi
jmp 0x1fedf
xorl %eax, %eax
movq $0x4000, 0x10(%rbx)     # imm = 0x4000
movb %bpl, 0x78(%rbx)
movaps 0x22df6(%rip), %xmm0    # 0x42c50
movups %xmm0, 0x28(%rbx)
movabsq $0x7bc00000000, %rcx    # imm = 0x7BC00000000
movq %rcx, 0x38(%rbx)
xorl %ecx, %ecx
movq %rcx, 0x68(%rbx)
movq %rcx, 0x18(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rbx)
movq %rcx, 0x50(%rbx)
testq %rax, %rax
je 0x1fe92
movq %rax, %rdi
xorl %esi, %esi
callq 0xc8f0
jmp 0x1fec8
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xc660
movq %rbx, 0x38(%r14)
leaq 0x52(%rip), %rax        # 0x1fefc
movq %rax, (%r14)
leaq 0x5c(%rip), %rax        # 0x1ff10
movq %rax, 0x28(%r14)
movq 0x58(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %r14, %rcx
callq 0xd010
movq %rax, 0x20(%rbx)
testq %rax, %rax
jne 0x1feee
jmp 0x1fee4
movl $0xb1, %edi
jmp 0x1fedf
movl $0xb4, %edi
callq 0xdc64
movq %rbx, %rdi
callq 0xcc50
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq