// File: /workspace/github_c_makefile_star2_O0/xiaowenhuyuehu[P]remote_access/src/utility/hash_table/hash_table.c
// Function: ht_add_lockless
int ht_add_lockless(void *ht, const void *key, unsigned int len_key, const void *val, unsigned int size_val)
{
    ht_item_t *p_item = NULL;
    ht_item_t *p_tmp = NULL;
    ht_item_t *new_tb = NULL;

    if (!ht || !key || !val || len_key <= 0 || size_val <= 0) {
        return -1;
    }

    p_item = _ht_find_lockless(ht, key, len_key);

    if (!p_item->key) {
        p_item->key = malloc(len_key);
        if (!p_item->key) {
            return -1;
        }
        memcpy(p_item->key, key, len_key);
        p_item->val = malloc(size_val);
        if (!p_item->val) {
            free(p_item->key);
            p_item->key = NULL;
            return -1;
        }
        memcpy(p_item->val, val, size_val);
        p_item->size_val = size_val;
        return 0;
    }

    //conflict: add to it's next item in the list.
    p_tmp = p_item;
    while (p_tmp) {
        if (NULL != p_tmp->key && !memcmp(p_tmp->key, key, len_key)) {
            free(p_tmp->val);
            p_tmp->val = NULL;
            p_tmp->val = malloc(size_val);
            if (!p_item->val) {
                free(p_tmp);
                return -1;
            }
            p_item->size_val = size_val;
            memcpy(p_item->val, val, size_val);
            return 0;//repeated key , just update it
        }
        p_item = p_tmp;
        p_tmp = p_tmp->next;
    }

    new_tb = (ht_item_t *)malloc(sizeof(ht_item_t));
    if (!new_tb) {
        return -1;
    }
    memset(new_tb, 0, sizeof(ht_item_t));
    new_tb->key = malloc(len_key);
    if (!new_tb->key) {
        free(new_tb);
        return -1;
    }
    memcpy(new_tb->key, key, len_key);
    new_tb->val = malloc(size_val);
    if (!new_tb->val) {
        free(new_tb->key);
        free(new_tb);
        return -1;
    }
    new_tb->size_val = size_val;
    memcpy(new_tb->val, val, size_val);
    p_item->next = new_tb;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x4794
cmpq $0x0, -0x18(%rbp)
je 0x4794
cmpq $0x0, -0x28(%rbp)
je 0x4794
cmpl $0x0, -0x1c(%rbp)
jbe 0x4794
cmpl $0x0, -0x2c(%rbp)
ja 0x47a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a29
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x4660
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x4870
movl -0x1c(%rbp), %eax
movl %eax, %edi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x47ec
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a29
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
callq 0x2570
movl -0x2c(%rbp), %eax
movl %eax, %edi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x4844
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0x2240
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a29
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x2570
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x4a29
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x493f
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq (%rcx), %rax
je 0x4926
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
callq 0x2490
cmpl $0x0, %eax
jne 0x4926
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2240
movq -0x40(%rbp), %rax
movq $0x0, 0x8(%rax)
movl -0x2c(%rbp), %eax
movl %eax, %edi
callq 0x2140
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x48fa
movq -0x40(%rbp), %rdi
callq 0x2240
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a29
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x2570
movl $0x0, -0x4(%rbp)
jmp 0x4a29
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x4878
movl $0x20, %edi
callq 0x2140
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x4960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a29
movq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2090
movl -0x1c(%rbp), %eax
movl %eax, %edi
callq 0x2140
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x49a3
movq -0x48(%rbp), %rdi
callq 0x2240
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a29
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
callq 0x2570
movl -0x2c(%rbp), %eax
movl %eax, %edi
callq 0x2140
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x49f6
movq -0x48(%rbp), %rax
movq (%rax), %rdi
callq 0x2240
movq -0x48(%rbp), %rdi
callq 0x2240
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a29
movl -0x2c(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x2570
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)