// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/src/workbook.c
// Function: store_defined_name
STATIC lxw_error
_store_defined_name(lxw_workbook *self, const char *name,
                    const char *app_name, const char *formula, int16_t index,
                    uint8_t hidden)
{
    lxw_sheet *sheet;
    lxw_worksheet *worksheet;
    lxw_defined_name *defined_name;
    lxw_defined_name *list_defined_name;
    char name_copy[LXW_DEFINED_NAME_LENGTH];
    char *tmp_str;
    char *worksheet_name;

    /* Do some checks on the input data */
    if (!name || !formula)
        return LXW_ERROR_NULL_PARAMETER_IGNORED;

    if (lxw_utf8_strlen(name) > LXW_DEFINED_NAME_LENGTH ||
        lxw_utf8_strlen(formula) > LXW_DEFINED_NAME_LENGTH) {
        return LXW_ERROR_128_STRING_LENGTH_EXCEEDED;
    }

    /* Allocate a new defined_name to be added to the linked list of names. */
    defined_name = calloc(1, sizeof(struct lxw_defined_name));
    RETURN_ON_MEM_ERROR(defined_name, LXW_ERROR_MEMORY_MALLOC_FAILED);

    /* Copy the user input string. */
    lxw_strcpy(name_copy, name);

    /* Set the worksheet index or -1 for a global defined name. */
    defined_name->index = index;
    defined_name->hidden = hidden;

    /* Check for local defined names like like "Sheet1!name". */
    tmp_str = strchr(name_copy, '!');

    if (tmp_str == NULL) {
        /* The name is global. We just store the defined name string. */
        lxw_strcpy(defined_name->name, name_copy);
    }
    else {
        /* The name is worksheet local. We need to extract the sheet name
         * and map it to a sheet index. */

        /* Split the into the worksheet name and defined name. */
        *tmp_str = '\0';
        tmp_str++;
        worksheet_name = name_copy;

        /* Remove any worksheet quoting. */
        if (worksheet_name[0] == '\'')
            worksheet_name++;
        if (worksheet_name[strlen(worksheet_name) - 1] == '\'')
            worksheet_name[strlen(worksheet_name) - 1] = '\0';

        /* Search for worksheet name to get the equivalent worksheet index. */
        STAILQ_FOREACH(sheet, self->sheets, list_pointers) {
            if (sheet->is_chartsheet)
                continue;
            else
                worksheet = sheet->u.worksheet;

            if (strcmp(worksheet_name, worksheet->name) == 0) {
                defined_name->index = worksheet->index;
                lxw_strcpy(defined_name->normalised_sheetname,
                           worksheet_name);
            }
        }

        /* If we didn't find the worksheet name we exit. */
        if (defined_name->index == -1)
            goto mem_error;

        lxw_strcpy(defined_name->name, tmp_str);
    }

    /* Print titles and repeat title pass in the name used for App.xml. */
    if (app_name) {
        lxw_strcpy(defined_name->app_name, app_name);
        lxw_strcpy(defined_name->normalised_sheetname, app_name);
    }
    else {
        lxw_strcpy(defined_name->app_name, name);
    }

    /* We need to normalize the defined names for sorting. This involves
     * removing any _xlnm namespace  and converting it to lowercase. */
    tmp_str = strstr(name_copy, "_xlnm.");

    if (tmp_str)
        lxw_strcpy(defined_name->normalised_name, defined_name->name + 6);
    else
        lxw_strcpy(defined_name->normalised_name, defined_name->name);

    lxw_str_tolower(defined_name->normalised_name);
    lxw_str_tolower(defined_name->normalised_sheetname);

    /* Strip leading "=" from the formula. */
    if (formula[0] == '=')
        lxw_strcpy(defined_name->formula, formula + 1);
    else
        lxw_strcpy(defined_name->formula, formula);

    /* We add the defined name to the list in sorted order. */
    list_defined_name = TAILQ_FIRST(self->defined_names);

    if (list_defined_name == NULL ||
        _compare_defined_names(defined_name, list_defined_name) < 1) {
        /* List is empty or defined name goes to the head. */
        TAILQ_INSERT_HEAD(self->defined_names, defined_name, list_pointers);
        return LXW_NO_ERROR;
    }

    TAILQ_FOREACH(list_defined_name, self->defined_names, list_pointers) {
        int res = _compare_defined_names(defined_name, list_defined_name);

        /* The entry already exists. We exit and don't overwrite. */
        if (res == 0)
            goto mem_error;

        /* New defined name is inserted in sorted order before other entries. */
        if (res < 0) {
            TAILQ_INSERT_BEFORE(list_defined_name, defined_name,
                                list_pointers);
            return LXW_NO_ERROR;
        }
    }

    /* If the entry wasn't less than any of the entries in the list we add it
     * to the end. */
    TAILQ_INSERT_TAIL(self->defined_names, defined_name, list_pointers);
    return LXW_NO_ERROR;

mem_error:
    free(defined_name);
    return LXW_ERROR_MEMORY_MALLOC_FAILED;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl %r8d, -0x104(%rbp)
movq %rcx, %rax
movl -0x104(%rbp), %ecx
movq %rax, -0x100(%rbp)
movq %rdx, %rax
movq -0x100(%rbp), %rdx
movq %rax, -0xf8(%rbp)
movq %rsi, %rax
movq -0xf8(%rbp), %rsi
movq %rax, -0xf0(%rbp)
movq %rdi, %r8
movq -0xf0(%rbp), %rdi
movb %r9b, %al
movq %r8, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movw %cx, -0x2a(%rbp)
movb %al, -0x2b(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x3f2b6
cmpq $0x0, -0x28(%rbp)
jne 0x3f2c2
movl $0xc, -0x4(%rbp)
jmp 0x3f84f
movq -0x18(%rbp), %rdi
callq 0xd180
cmpq $0x80, %rax
ja 0x3f2e4
movq -0x28(%rbp), %rdi
callq 0xd180
cmpq $0x80, %rax
jbe 0x3f2f0
movl $0x13, -0x4(%rbp)
jmp 0x3f84f
movl $0x1, %edi
movl $0x298, %esi            # imm = 0x298
callq 0xc870
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x3f33a
movq 0x3dce7(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x26db5(%rip), %rsi     # 0x660d0
leaq 0x2c32e(%rip), %rdx     # 0x6b650
movl $0x2af, %ecx            # imm = 0x2AF
movb $0x0, %al
callq 0xc8f0
movl $0x1, -0x4(%rbp)
jmp 0x3f84f
jmp 0x3f33c
leaq -0xd0(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x80, %esi
leaq 0x2d551(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
movw -0x2a(%rbp), %cx
movq -0x48(%rbp), %rax
movw %cx, (%rax)
movb -0x2b(%rbp), %cl
movq -0x48(%rbp), %rax
movb %cl, 0x2(%rax)
leaq -0xd0(%rbp), %rdi
movl $0x21, %esi
callq 0xc520
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
jne 0x3f3b8
movq -0x48(%rbp), %rdi
addq $0x3, %rdi
leaq -0xd0(%rbp), %rcx
movl $0x80, %esi
leaq 0x2d4f8(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
jmp 0x3f526
movq -0xd8(%rbp), %rax
movb $0x0, (%rax)
movq -0xd8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x27, %eax
jne 0x3f403
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0xe0(%rbp), %rdi
callq 0xc4e0
movq %rax, %rcx
movq -0x110(%rbp), %rax
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x27, %eax
jne 0x3f460
movq -0xe0(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0xe0(%rbp), %rdi
callq 0xc4e0
movq %rax, %rcx
movq -0x118(%rbp), %rax
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x3f4f3
movq -0x38(%rbp), %rax
cmpb $0x0, (%rax)
je 0x3f481
jmp 0x3f4e2
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0xe0(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0xb8(%rax), %rsi
callq 0xc880
cmpl $0x0, %eax
jne 0x3f4e0
movq -0x40(%rbp), %rax
movw 0xd0(%rax), %cx
movq -0x48(%rbp), %rax
movw %cx, (%rax)
movq -0x48(%rbp), %rdi
addq $0x203, %rdi            # imm = 0x203
movq -0xe0(%rbp), %rcx
movl $0x80, %esi
leaq 0x2d3cb(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
jmp 0x3f4e2
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x3f46f
movq -0x48(%rbp), %rax
movswl (%rax), %eax
cmpl $-0x1, %eax
jne 0x3f504
jmp 0x3f83f
movq -0x48(%rbp), %rdi
addq $0x3, %rdi
movq -0xd8(%rbp), %rcx
movl $0x80, %esi
leaq 0x2d385(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
cmpq $0x0, -0x20(%rbp)
je 0x3f573
movq -0x48(%rbp), %rdi
addq $0x83, %rdi
movq -0x20(%rbp), %rcx
movl $0x80, %esi
leaq 0x2d35c(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
movq -0x48(%rbp), %rdi
addq $0x203, %rdi            # imm = 0x203
movq -0x20(%rbp), %rcx
movl $0x80, %esi
leaq 0x2d33a(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
jmp 0x3f595
movq -0x48(%rbp), %rdi
addq $0x83, %rdi
movq -0x18(%rbp), %rcx
movl $0x80, %esi
leaq 0x2d316(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
leaq -0xd0(%rbp), %rdi
leaq 0x2cd16(%rip), %rsi     # 0x6c2b9
callq 0xd130
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
je 0x3f5e5
movq -0x48(%rbp), %rdi
addq $0x183, %rdi            # imm = 0x183
movq -0x48(%rbp), %rcx
addq $0x3, %rcx
addq $0x6, %rcx
movl $0x80, %esi
leaq 0x2d2c8(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
jmp 0x3f60b
movq -0x48(%rbp), %rdi
addq $0x183, %rdi            # imm = 0x183
movq -0x48(%rbp), %rcx
addq $0x3, %rcx
movl $0x80, %esi
leaq 0x2d2a0(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
movq -0x48(%rbp), %rdi
addq $0x183, %rdi            # imm = 0x183
callq 0xce00
movq -0x48(%rbp), %rdi
addq $0x203, %rdi            # imm = 0x203
callq 0xce00
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x3f65f
movq -0x48(%rbp), %rdi
addq $0x103, %rdi            # imm = 0x103
movq -0x28(%rbp), %rcx
addq $0x1, %rcx
movl $0x80, %esi
leaq 0x2d24e(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
jmp 0x3f681
movq -0x48(%rbp), %rdi
addq $0x103, %rdi            # imm = 0x103
movq -0x28(%rbp), %rcx
movl $0x80, %esi
leaq 0x2d22a(%rip), %rdx     # 0x6c8a4
movb $0x0, %al
callq 0xc5d0
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x3f6ad
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x44290
cmpl $0x1, %eax
jge 0x3f72f
jmp 0x3f6af
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq %rax, 0x288(%rcx)
cmpq $0x0, %rax
je 0x3f6ea
movq -0x48(%rbp), %rcx
addq $0x288, %rcx            # imm = 0x288
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq (%rax), %rax
movq %rcx, 0x290(%rax)
jmp 0x3f701
movq -0x48(%rbp), %rcx
addq $0x288, %rcx            # imm = 0x288
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x290(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3f84f
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x3f7e4
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x44290
movl %eax, -0xe4(%rbp)
cmpl $0x0, -0xe4(%rbp)
jne 0x3f76a
jmp 0x3f83f
cmpl $0x0, -0xe4(%rbp)
jge 0x3f7ce
jmp 0x3f775
movq -0x50(%rbp), %rax
movq 0x290(%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x290(%rax)
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x288(%rax)
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %rax
movq 0x290(%rax), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
addq $0x288, %rcx            # imm = 0x288
movq -0x50(%rbp), %rax
movq %rcx, 0x290(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3f84f
jmp 0x3f7d0
movq -0x50(%rbp), %rax
movq 0x288(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x3f73e
jmp 0x3f7e6
movq -0x48(%rbp), %rax
movq $0x0, 0x288(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x8(%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x290(%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
addq $0x288, %rcx            # imm = 0x288
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3f84f
movq -0x48(%rbp), %rdi
callq 0xc0d0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax,%rax)