// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/src/workbook.c
// Function: workbook_close
lxw_error
workbook_close(lxw_workbook *self)
{
    lxw_sheet *sheet = NULL;
    lxw_worksheet *worksheet = NULL;
    lxw_packager *packager = NULL;
    lxw_error error = LXW_NO_ERROR;
    char codename[LXW_MAX_SHEETNAME_LENGTH] = { 0 };

    /* Add a default worksheet if non have been added. */
    if (!self->num_sheets)
        workbook_add_worksheet(self, NULL);

    /* Ensure that at least one worksheet has been selected. */
    if (self->active_sheet == 0) {
        sheet = STAILQ_FIRST(self->sheets);
        if (!sheet->is_chartsheet) {
            worksheet = sheet->u.worksheet;
            worksheet->selected = LXW_TRUE;
            worksheet->hidden = 0;
        }
    }

    /* Set the active sheet and check if a metadata file is needed. */
    STAILQ_FOREACH(sheet, self->sheets, list_pointers) {
        if (sheet->is_chartsheet)
            continue;
        else
            worksheet = sheet->u.worksheet;

        if (worksheet->index == self->active_sheet)
            worksheet->active = LXW_TRUE;

        if (worksheet->has_dynamic_arrays)
            self->has_metadata = LXW_TRUE;
    }

    /* Set workbook and worksheet VBA codenames if a macro has been added. */
    if (self->vba_project) {
        if (!self->vba_codename)
            workbook_set_vba_name(self, "ThisWorkbook");

        STAILQ_FOREACH(sheet, self->sheets, list_pointers) {
            if (sheet->is_chartsheet)
                continue;
            else
                worksheet = sheet->u.worksheet;

            if (!worksheet->vba_codename) {
                lxw_snprintf(codename, LXW_MAX_SHEETNAME_LENGTH, "Sheet%d",
                             worksheet->index + 1);

                worksheet_set_vba_name(worksheet, codename);
            }
        }
    }

    /* Prepare the worksheet VML elements such as comments. */
    _prepare_vml(self);

    /* Set the defined names for the worksheets such as Print Titles. */
    _prepare_defined_names(self);

    /* Prepare the drawings, charts and images. */
    _prepare_drawings(self);

    /* Add cached data to charts. */
    _add_chart_cache_data(self);

    /* Set the table ids for the worksheet tables. */
    _prepare_tables(self);

    /* Create a packager object to assemble sub-elements into a zip file. */
    packager = lxw_packager_new(self->filename,
                                self->options.tmpdir,
                                self->options.use_zip64);

    /* If the packager fails it is generally due to a zip permission error. */
    if (packager == NULL) {
        LXW_PRINTF(LXW_STDERR "[ERROR] workbook_close(): "
                   "Error creating '%s'. "
                   "System error = %s\n", self->filename, strerror(errno));

        error = LXW_ERROR_CREATING_XLSX_FILE;
        goto mem_error;
    }

    /* Set the workbook object in the packager. */
    packager->workbook = self;

    /* Assemble all the sub-files in the xlsx package. */
    error = lxw_create_package(packager);

    if (!self->filename) {
        *self->options.output_buffer = packager->output_buffer;
        *self->options.output_buffer_size = packager->output_buffer_size;
    }

    /* Error and non-error conditions fall through to the cleanup code. */
    if (error == LXW_ERROR_CREATING_TMPFILE) {
        LXW_PRINTF(LXW_STDERR "[ERROR] workbook_close(): "
                   "Error creating tmpfile(s) to assemble '%s'. "
                   "System error = %s\n", self->filename, strerror(errno));
    }

    /* If LXW_ERROR_ZIP_FILE_OPERATION then errno is set by zip. */
    if (error == LXW_ERROR_ZIP_FILE_OPERATION) {
        LXW_PRINTF(LXW_STDERR "[ERROR] workbook_close(): "
                   "Zip ZIP_ERRNO error while creating xlsx file '%s'. "
                   "System error = %s\n", self->filename, strerror(errno));
    }

    /* If LXW_ERROR_ZIP_PARAMETER_ERROR then errno is set by zip. */
    if (error == LXW_ERROR_ZIP_PARAMETER_ERROR) {
        LXW_PRINTF(LXW_STDERR "[ERROR] workbook_close(): "
                   "Zip ZIP_PARAMERROR error while creating xlsx file '%s'. "
                   "System error = %s\n", self->filename, strerror(errno));
    }

    /* If LXW_ERROR_ZIP_BAD_ZIP_FILE then errno is set by zip. */
    if (error == LXW_ERROR_ZIP_BAD_ZIP_FILE) {
        LXW_PRINTF(LXW_STDERR "[ERROR] workbook_close(): "
                   "Zip ZIP_BADZIPFILE error while creating xlsx file '%s'. "
                   "This may require the use_zip64 option for large files. "
                   "System error = %s\n", self->filename, strerror(errno));
    }

    /* If LXW_ERROR_ZIP_INTERNAL_ERROR then errno is set by zip. */
    if (error == LXW_ERROR_ZIP_INTERNAL_ERROR) {
        LXW_PRINTF(LXW_STDERR "[ERROR] workbook_close(): "
                   "Zip ZIP_INTERNALERROR error while creating xlsx file '%s'. "
                   "System error = %s\n", self->filename, strerror(errno));
    }

    /* The next 2 error conditions don't set errno. */
    if (error == LXW_ERROR_ZIP_FILE_ADD) {
        LXW_PRINTF(LXW_STDERR "[ERROR] workbook_close(): "
                   "Zip error adding file to xlsx file '%s'.\n",
                   self->filename);
    }

    if (error == LXW_ERROR_ZIP_CLOSE) {
        LXW_PRINTF(LXW_STDERR "[ERROR] workbook_close(): "
                   "Zip error closing xlsx file '%s'.\n", self->filename);
    }

mem_error:
    lxw_packager_free(packager);
    lxw_workbook_free(self);
    return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movl $0x7f, %edx
callq 0xc6a0
movq -0x8(%rbp), %rax
cmpw $0x0, 0xb0(%rax)
jne 0x3df1c
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xcc20
movq -0x8(%rbp), %rax
movzwl 0xb8(%rax), %eax
cmpl $0x0, %eax
jne 0x3df68
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x3df66
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movb $0x1, 0xd3(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0xd4(%rax)
jmp 0x3df68
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3dfe2
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x3df89
jmp 0x3dfd4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movzwl 0xd0(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0xb8(%rcx), %ecx
cmpl %ecx, %eax
jne 0x3dfba
movq -0x18(%rbp), %rax
movb $0x1, 0xd2(%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x151(%rax)
je 0x3dfd2
movq -0x8(%rbp), %rax
movb $0x1, 0xd5(%rax)
jmp 0x3dfd4
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x3df77
movq -0x8(%rbp), %rax
cmpq $0x0, 0xe8(%rax)
je 0x3e097
movq -0x8(%rbp), %rax
cmpq $0x0, 0xf8(%rax)
jne 0x3e012
movq -0x8(%rbp), %rdi
leaq 0x2d6f0(%rip), %rsi     # 0x6b6fd
callq 0xc490
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3e095
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x3e033
jmp 0x3e087
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x158(%rax)
jne 0x3e085
leaq -0xb0(%rbp), %rdi
movq -0x18(%rbp), %rax
movzwl 0xd0(%rax), %ecx
addl $0x1, %ecx
movl $0x7f, %esi
leaq 0x2d5ed(%rip), %rdx     # 0x6b65b
movb $0x0, %al
callq 0xc5d0
movq -0x18(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xd060
jmp 0x3e087
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x3e021
jmp 0x3e097
movq -0x8(%rbp), %rdi
callq 0x3e420
movq -0x8(%rbp), %rdi
callq 0x3e5a0
movq -0x8(%rbp), %rdi
callq 0x3eb30
movq -0x8(%rbp), %rdi
callq 0x3f020
movq -0x8(%rbp), %rdi
callq 0x3f170
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rsi
movq -0x8(%rbp), %rax
movzbl 0x98(%rax), %edx
callq 0xce30
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3e14f
movq 0x3eefc(%rip), %rax     # 0x7cff8
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0xb8(%rbp)
callq 0xc180
movl (%rax), %edi
callq 0xd0a0
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rdx
movq %rax, %rcx
leaq 0x2d5ce(%rip), %rsi     # 0x6b70a
movb $0x0, %al
callq 0xc8f0
movl $0x2, -0x24(%rbp)
jmp 0x3e399
movq -0x8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rdi
callq 0xc620
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x80(%rax)
jne 0x3e1a1
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rcx, (%rax)
cmpl $0x3, -0x24(%rbp)
jne 0x3e1f5
movq 0x3ee4a(%rip), %rax     # 0x7cff8
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0xc8(%rbp)
callq 0xc180
movl (%rax), %edi
callq 0xd0a0
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rdx
movq %rax, %rcx
leaq 0x2d55e(%rip), %rsi     # 0x6b74c
movb $0x0, %al
callq 0xc8f0
cmpl $0x5, -0x24(%rbp)
jne 0x3e249
movq 0x3edf6(%rip), %rax     # 0x7cff8
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0xd8(%rbp)
callq 0xc180
movl (%rax), %edi
callq 0xd0a0
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rdx
movq %rax, %rcx
leaq 0x2d563(%rip), %rsi     # 0x6b7a5
movb $0x0, %al
callq 0xc8f0
cmpl $0x6, -0x24(%rbp)
jne 0x3e29d
movq 0x3eda2(%rip), %rax     # 0x7cff8
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0xe8(%rbp)
callq 0xc180
movl (%rax), %edi
callq 0xd0a0
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %rdx
movq %rax, %rcx
leaq 0x2d56f(%rip), %rsi     # 0x6b805
movb $0x0, %al
callq 0xc8f0
cmpl $0x7, -0x24(%rbp)
jne 0x3e2f1
movq 0x3ed4e(%rip), %rax     # 0x7cff8
movq (%rax), %rax
movq %rax, -0x100(%rbp)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0xf8(%rbp)
callq 0xc180
movl (%rax), %edi
callq 0xd0a0
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rdx
movq %rax, %rcx
leaq 0x2d580(%rip), %rsi     # 0x6b86a
movb $0x0, %al
callq 0xc8f0
cmpl $0x8, -0x24(%rbp)
jne 0x3e345
movq 0x3ecfa(%rip), %rax     # 0x7cff8
movq (%rax), %rax
movq %rax, -0x110(%rbp)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x108(%rbp)
callq 0xc180
movl (%rax), %edi
callq 0xd0a0
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rdx
movq %rax, %rcx
leaq 0x2d5c8(%rip), %rsi     # 0x6b906
movb $0x0, %al
callq 0xc8f0
cmpl $0x9, -0x24(%rbp)
jne 0x3e36e
movq 0x3eca6(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdx
leaq 0x2d607(%rip), %rsi     # 0x6b96e
movb $0x0, %al
callq 0xc8f0
cmpl $0xa, -0x24(%rbp)
jne 0x3e397
movq 0x3ec7d(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdx
leaq 0x2d622(%rip), %rsi     # 0x6b9b2
movb $0x0, %al
callq 0xc8f0
jmp 0x3e399
movq -0x20(%rbp), %rdi
callq 0xccf0
movq -0x8(%rbp), %rdi
callq 0xcbf0
movl -0x24(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw (%rax,%rax)