// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0xc850
movq %rax, %rbx
testq %rax, %rax
je 0x1cf68
pushq $0x1
popq %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0xc850
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x1cf6f
movq %r15, 0x70(%rbx)
testq %r14, %r14
je 0x1ced9
movq %r14, %rdi
callq 0xcd50
movq %rax, 0x58(%rbx)
testq %rax, %rax
jne 0x1cedb
movl $0xbb, %ecx
jmp 0x1cf74
xorl %eax, %eax
movq $0x4000, 0x10(%rbx)     # imm = 0x4000
movb %bpl, 0x78(%rbx)
movaps 0x22d62(%rip), %xmm0    # 0x3fc50
movups %xmm0, 0x28(%rbx)
movabsq $0x7bc00000000, %rcx    # imm = 0x7BC00000000
movq %rcx, 0x38(%rbx)
andq $0x0, 0x68(%rbx)
andq $0x0, 0x18(%rbx)
andq $0x0, 0x50(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rbx)
testq %rax, %rax
je 0x1cf27
movq %rax, %rdi
xorl %esi, %esi
callq 0xc950
jmp 0x1cf5d
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xc6c0
movq %rbx, 0x38(%r14)
leaq 0x6c(%rip), %rax        # 0x1cfab
movq %rax, (%r14)
leaq 0x76(%rip), %rax        # 0x1cfbf
movq %rax, 0x28(%r14)
movq 0x58(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %r14, %rcx
callq 0xd090
movq %rax, 0x20(%rbx)
testq %rax, %rax
jne 0x1cf9d
jmp 0x1cf93
movl $0xb1, %ecx
jmp 0x1cf74
movl $0xb4, %ecx
movq 0x3607d(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x2015b(%rip), %rsi     # 0x3d0e0
leaq 0x22cd4(%rip), %rdx     # 0x3fc60
xorl %eax, %eax
callq 0xc8d0
movq %rbx, %rdi
callq 0xccc0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq