// File: /workspace/github_c_makefile_star2_O3/Paxa[P]fast_excel/libxlsxwriter/src/packager.c
// Function: write_app_file
STATIC lxw_error
_write_app_file(lxw_packager *self)
{
    lxw_workbook *workbook = self->workbook;
    lxw_sheet *sheet;
    lxw_worksheet *worksheet;
    lxw_chartsheet *chartsheet;
    lxw_defined_name *defined_name;
    lxw_app *app;
    char *buffer = NULL;
    size_t buffer_size = 0;
    uint32_t named_range_count = 0;
    char *autofilter;
    char *has_range;
    char number[LXW_ATTR_32] = { 0 };
    lxw_error err = LXW_NO_ERROR;

    app = lxw_app_new();
    if (!app) {
        err = LXW_ERROR_MEMORY_MALLOC_FAILED;
        goto mem_error;
    }

    app->file = lxw_get_filehandle(&buffer, &buffer_size, self->tmpdir);
    if (!app->file) {
        err = LXW_ERROR_CREATING_TMPFILE;
        goto mem_error;
    }

    if (self->workbook->num_worksheets) {
        lxw_snprintf(number, LXW_ATTR_32, "%d",
                     self->workbook->num_worksheets);
        lxw_app_add_heading_pair(app, "Worksheets", number);
    }

    if (self->workbook->num_chartsheets) {
        lxw_snprintf(number, LXW_ATTR_32, "%d",
                     self->workbook->num_chartsheets);
        lxw_app_add_heading_pair(app, "Charts", number);
    }

    STAILQ_FOREACH(sheet, workbook->sheets, list_pointers) {
        if (!sheet->is_chartsheet) {
            worksheet = sheet->u.worksheet;
            lxw_app_add_part_name(app, worksheet->name);
        }
    }

    STAILQ_FOREACH(sheet, workbook->sheets, list_pointers) {
        if (sheet->is_chartsheet) {
            chartsheet = sheet->u.chartsheet;
            lxw_app_add_part_name(app, chartsheet->name);
        }
    }

    /* Add the Named Ranges parts. */
    TAILQ_FOREACH(defined_name, workbook->defined_names, list_pointers) {

        has_range = strchr(defined_name->formula, '!');
        autofilter = strstr(defined_name->app_name, "_FilterDatabase");

        /* Only store defined names with ranges (except for autofilters). */
        if (has_range && !autofilter) {
            lxw_app_add_part_name(app, defined_name->app_name);
            named_range_count++;
        }
    }

    /* Add the Named Range heading pairs. */
    if (named_range_count) {
        lxw_snprintf(number, LXW_ATTR_32, "%d", named_range_count);
        lxw_app_add_heading_pair(app, "Named Ranges", number);
    }

    /* Set the app/doc properties. */
    app->properties = workbook->properties;

    app->doc_security = workbook->read_only;

    lxw_app_assemble_xml_file(app);

    err = _add_to_zip(self, app->file, &buffer, &buffer_size,
                      "docProps/app.xml");

    fclose(app->file);
    free(buffer);

mem_error:
    lxw_app_free(app);

    return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r12
movq 0x8(%rdi), %r13
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq %rax, (%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
callq 0xcb00
movq %rax, %rbx
testq %rax, %rax
je 0x224d1
movq 0x70(%r12), %rdx
leaq 0x8(%rsp), %rdi
movq %rsp, %rsi
callq 0xce00
movq %rax, (%rbx)
testq %rax, %rax
je 0x224d8
movq 0x8(%r12), %rax
movzwl 0xb2(%rax), %ecx
testl %ecx, %ecx
je 0x22350
leaq 0x2322b(%rip), %rdx     # 0x45550
leaq 0x20(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0xc570
leaq 0x20eaa(%rip), %rsi     # 0x431ea
movq %rbx, %rdi
movq %r15, %rdx
callq 0xc1c0
movq 0x8(%r12), %rax
movzwl 0xb4(%rax), %ecx
testl %ecx, %ecx
je 0x22388
leaq 0x231ee(%rip), %rdx     # 0x45550
leaq 0x20(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0xc570
leaq 0x20e78(%rip), %rsi     # 0x431f5
movq %rbx, %rdi
movq %r15, %rdx
callq 0xc1c0
movq 0x8(%r13), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x223de
cmpb $0x0, (%r14)
jne 0x223ad
movq 0x8(%r14), %rax
movq 0xb8(%rax), %rsi
movq %rbx, %rdi
callq 0xcf90
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x22394
movq 0x8(%r13), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x223de
cmpb $0x0, (%r14)
je 0x223d8
movq 0x8(%r14), %rax
movq 0x38(%rax), %rsi
movq %rbx, %rdi
callq 0xcf90
movq 0x10(%r14), %r14
jmp 0x223bd
movq %r13, 0x18(%rsp)
movq 0x60(%r13), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x22482
movq %r12, 0x10(%rsp)
xorl %ebp, %ebp
leaq 0x240ef(%rip), %r15     # 0x464f0
leaq 0x103(%r14), %rdi
movl $0x21, %esi
callq 0xc4c0
movq %rax, %r13
leaq 0x83(%r14), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xd080
testq %r13, %r13
je 0x2243e
testq %rax, %rax
jne 0x2243e
movq %rbx, %rdi
movq %r12, %rsi
callq 0xcf90
incl %ebp
movq 0x288(%r14), %r14
testq %r14, %r14
jne 0x22401
testl %ebp, %ebp
movq 0x10(%rsp), %r12
je 0x22482
leaq 0x230f6(%rip), %rdx     # 0x45550
leaq 0x20(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc570
leaq 0x20d85(%rip), %rsi     # 0x431fc
movq %rbx, %rdi
movq %r15, %rdx
callq 0xc1c0
movq 0x18(%rsp), %rcx
movq 0x70(%rcx), %rax
movq %rax, 0x18(%rbx)
movb 0xce(%rcx), %al
movb %al, 0x28(%rbx)
movq %rbx, %rdi
callq 0xc2e0
movq (%rbx), %rsi
leaq 0x1fa44(%rip), %r8      # 0x41eee
leaq 0x8(%rsp), %r15
movq %rsp, %rcx
movq %r12, %rdi
movq %r15, %rdx
callq 0x224f6
movl %eax, %ebp
movq (%rbx), %rdi
callq 0xc420
movq (%r15), %rdi
callq 0xc0c0
jmp 0x224dd
movl $0x1, %ebp
jmp 0x224dd
movl $0x3, %ebp
movq %rbx, %rdi
callq 0xcc90
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq