// File: /workspace/github_c_makefile_star2_O1/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 0x1fde0
movl $0x1, %edi
movl $0x4000, %esi           # imm = 0x4000
callq 0xc7f0
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x1fde7
movq $0x0, 0x58(%rbx)
movq %r15, 0x70(%rbx)
testq %r14, %r14
je 0x1fd53
movq %r14, %rdi
callq 0xcce0
movq %rax, 0x58(%rbx)
testq %rax, %rax
je 0x1fdee
movq $0x4000, 0x10(%rbx)     # imm = 0x4000
movb %bpl, 0x78(%rbx)
movaps 0x22eda(%rip), %xmm0    # 0x42c40
movups %xmm0, 0x28(%rbx)
movabsq $0x7bc00000000, %rax    # imm = 0x7BC00000000
movq %rax, 0x38(%rbx)
xorl %eax, %eax
movq %rax, 0x68(%rbx)
movq %rax, 0x18(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rbx)
movq %rax, 0x50(%rbx)
movq 0x58(%rbx), %rdi
testq %rdi, %rdi
je 0x1fd9f
xorl %esi, %esi
callq 0xc8f0
jmp 0x1fdd5
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xc660
movq %rbx, 0x38(%r14)
leaq 0x59(%rip), %rax        # 0x1fe10
movq %rax, (%r14)
leaq 0x63(%rip), %rax        # 0x1fe24
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 0x1fe02
jmp 0x1fdf8
movl $0xb1, %edi
jmp 0x1fdf3
movl $0xb4, %edi
jmp 0x1fdf3
movl $0xbb, %edi
callq 0xdc52
movq %rbx, %rdi
callq 0xcc50
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq