// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq 0x8(%rdi), %r12
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 0x2245d
movq 0x70(%r14), %rdx
leaq 0x8(%rsp), %rdi
movq %rsp, %rsi
callq 0xce00
movq %rax, (%rbx)
testq %rax, %rax
je 0x22464
movq 0x8(%r14), %rax
movzwl 0xb2(%rax), %ecx
testl %ecx, %ecx
je 0x222df
leaq 0x23287(%rip), %rdx     # 0x45540
leaq 0x20(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0xc570
leaq 0x20f06(%rip), %rsi     # 0x431da
movq %rbx, %rdi
movq %r15, %rdx
callq 0xc1c0
movq %r14, 0x18(%rsp)
movq 0x8(%r14), %rax
movzwl 0xb4(%rax), %ecx
testl %ecx, %ecx
je 0x22320
leaq 0x23246(%rip), %rdx     # 0x45540
leaq 0x20(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0xc570
leaq 0x20ed0(%rip), %rsi     # 0x431e5
movq %rbx, %rdi
movq %r15, %rdx
callq 0xc1c0
movq 0x8(%r12), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x2234c
cmpb $0x0, (%r14)
jne 0x22346
movq 0x8(%r14), %rax
movq 0xb8(%rax), %rsi
movq %rbx, %rdi
callq 0xcf90
movq 0x10(%r14), %r14
jmp 0x22328
movq 0x8(%r12), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x22375
cmpb $0x0, (%r14)
je 0x2236f
movq 0x8(%r14), %rax
movq 0x38(%rax), %rsi
movq %rbx, %rdi
callq 0xcf90
movq 0x10(%r14), %r14
jmp 0x22354
movq %r12, 0x10(%rsp)
movq 0x60(%r12), %rax
movq (%rax), %r14
xorl %ebp, %ebp
testq %r14, %r14
je 0x223d9
leaq 0x24150(%rip), %r15     # 0x464e0
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 0x223cd
testq %rax, %rax
jne 0x223cd
movq %rbx, %rdi
movq %r12, %rsi
callq 0xcf90
incl %ebp
movq 0x288(%r14), %r14
testq %r14, %r14
jne 0x22390
testl %ebp, %ebp
je 0x2240c
leaq 0x2315c(%rip), %rdx     # 0x45540
leaq 0x20(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc570
leaq 0x20deb(%rip), %rsi     # 0x431ec
movq %rbx, %rdi
movq %r15, %rdx
callq 0xc1c0
movq 0x10(%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 0x1faaa(%rip), %r8      # 0x41ede
leaq 0x8(%rsp), %r15
movq %rsp, %rcx
movq 0x18(%rsp), %rdi
movq %r15, %rdx
callq 0x22482
movl %eax, %ebp
movq (%rbx), %rdi
callq 0xc420
movq (%r15), %rdi
callq 0xc0c0
jmp 0x22469
movl $0x1, %ebp
jmp 0x22469
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