// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/src/hash_table.c
// Function: lxw_insert_hash_element
lxw_hash_element *
lxw_insert_hash_element(lxw_hash_table *lxw_hash, void *key, void *value,
                        size_t key_len)
{
    size_t hash_key = _generate_hash_key(key, key_len, lxw_hash->num_buckets);
    struct lxw_hash_bucket_list *list = NULL;
    lxw_hash_element *element = NULL;

    if (!lxw_hash->buckets[hash_key]) {
        /* The key isn't in the LXW_HASH hash table. */

        /* Create a linked list in the bucket to hold the lxw_hash keys. */
        list = calloc(1, sizeof(struct lxw_hash_bucket_list));
        GOTO_LABEL_ON_MEM_ERROR(list, mem_error1);

        /* Initialize the bucket linked list. */
        SLIST_INIT(list);

        /* Create an lxw_hash element to add to the linked list. */
        element = calloc(1, sizeof(lxw_hash_element));
        GOTO_LABEL_ON_MEM_ERROR(element, mem_error1);

        /* Store the key and value. */
        element->key = key;
        element->value = value;

        /* Add the lxw_hash element to the bucket's linked list. */
        SLIST_INSERT_HEAD(list, element, lxw_hash_list_pointers);

        /* Also add it to the insertion order linked list. */
        STAILQ_INSERT_TAIL(lxw_hash->order_list, element,
                           lxw_hash_order_pointers);

        /* Store the bucket list at the hash index. */
        lxw_hash->buckets[hash_key] = list;

        lxw_hash->used_buckets++;
        lxw_hash->unique_count++;

        return element;
    }
    else {
        /* The key is already in the table or there is a hash collision. */
        list = lxw_hash->buckets[hash_key];

        /* Iterate over the keys in the bucket's linked list. */
        SLIST_FOREACH(element, list, lxw_hash_list_pointers) {
            if (memcmp(element->key, key, key_len) == 0) {
                /* The key already exists in the table. Update the value. */
                if (lxw_hash->free_value)
                    free(element->value);

                element->value = value;
                return element;
            }
        }

        /* Key doesn't exist in the list so this is a hash collision.
         * Create an lxw_hash element to add to the linked list. */
        element = calloc(1, sizeof(lxw_hash_element));
        GOTO_LABEL_ON_MEM_ERROR(element, mem_error2);

        /* Store the key and value. */
        element->key = key;
        element->value = value;

        /* Add the lxw_hash element to the bucket linked list. */
        SLIST_INSERT_HEAD(list, element, lxw_hash_list_pointers);

        /* Also add it to the insertion order linked list. */
        STAILQ_INSERT_TAIL(lxw_hash->order_list, element,
                           lxw_hash_order_pointers);

        lxw_hash->unique_count++;

        return element;
    }

mem_error1:
    free(list);

mem_error2:
    free(element);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, %edx
callq 0x2b2a0
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x2b4a0
movl $0x1, %edi
movl $0x8, %esi
callq 0xc870
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x2b3ab
movq 0x51c6f(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x3ad3d(%rip), %rsi     # 0x660d0
leaq 0x3d550(%rip), %rdx     # 0x688ea
movl $0x52, %ecx
movb $0x0, %al
callq 0xc8f0
jmp 0x2b5e1
jmp 0x2b3ad
jmp 0x2b3af
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movl $0x1, %edi
movl $0x20, %esi
callq 0xc870
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x2b3fd
movq 0x51c1d(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x3aceb(%rip), %rsi     # 0x660d0
leaq 0x3d4fe(%rip), %rdx     # 0x688ea
movl $0x59, %ecx
movb $0x0, %al
callq 0xc8f0
jmp 0x2b5e1
jmp 0x2b3ff
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2b432
movq -0x40(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
addq $0x10, %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2b5fb
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x2b51f
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xc830
cmpl $0x0, %eax
jne 0x2b50f
movq -0x10(%rbp), %rax
cmpb $0x0, 0xd(%rax)
je 0x2b4f6
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xc0d0
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2b5fb
jmp 0x2b511
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x2b4bf
movl $0x1, %edi
movl $0x20, %esi
callq 0xc870
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x2b562
movq 0x51ab8(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x3ab86(%rip), %rsi     # 0x660d0
leaq 0x3d399(%rip), %rdx     # 0x688ea
movl $0x81, %ecx
movb $0x0, %al
callq 0xc8f0
jmp 0x2b5ea
jmp 0x2b564
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2b597
movq -0x40(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
addq $0x10, %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2b5fb
movq -0x38(%rbp), %rdi
callq 0xc0d0
movq -0x40(%rbp), %rdi
callq 0xc0d0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)