// File: /workspace/github_c_makefile_star2_O1/wuxb45[P]SLB/lib1.c
// Function: chainmap_set
bool
chainmap_set(struct chainmap * const map, const struct kv * const kv0)
{
  const struct kv * const kv = kv_alloc_dup(kv0, &(map->mm));
  if (kv == NULL) return false;

  const u64 hash = kv->hash;
  const u64 lidx = kvmap_hlocks_index(hash);
  const u64 pkey = kvmap_pkey(hash);
  spinlock_lock(&(map->hlocks[lidx]));
  const u64 cid = (hash >> KVMAP_BASE_LEVEL) & ((UINT64_C(1) << map->power) - UINT64_C(1));
  struct chainnode * iter = map->table[cid];
  while (iter) {
    if (iter->e.pkey == pkey) {
      const struct kv * const curr = __u64_to_ptr(iter->e.ptr);
      if (kv_keymatch(kv, curr)) { // update
        kvmap_put_entry(&(map->mm), &(iter->e), kv);
        spinlock_unlock(&(map->hlocks[lidx]));
        return true;
      }
    }
    iter = iter->next;
  }
  // insert
  struct chainnode * const node = (typeof(node))malloc(sizeof(*node));
  if (node == NULL) {
    if (map->mm.rf) map->mm.rf((struct kv *)kv, map->mm.rp);
    spinlock_unlock(&(map->hlocks[lidx]));
    return false;
  }
  memset(node, 0, sizeof(*node));
  //chainmap_put_entry(map, &(node->e), kv);
  kvmap_put_entry(&(map->mm), &(node->e), kv);
  const u64 nr_kv = atomic_fetch_add(&(map->nr_kv), 1);
  node->next = map->table[cid];
  map->table[cid] = node;
  spinlock_unlock(&(map->hlocks[lidx]));
  if (nr_kv > map->trigger) {
    chainmap_expand(map);
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl 0x8(%rsi), %eax
movl 0xc(%rsi), %ecx
leaq (%rax,%rcx), %r12
addq $0x10, %r12
movq 0x8(%rdi), %rsi
movq %r12, %rdi
callq *(%rbx)
movq %rax, %r15
testq %rax, %rax
je 0xfeda
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x6340
movq (%r15), %r12
movq %r12, %r14
shrq $0x6, %r14
movl %r14d, %eax
andl $0x3ff, %eax            # imm = 0x3FF
shll $0x6, %eax
leaq (%rbx,%rax), %rdi
addq $0x138, %rdi            # imm = 0x138
movq %rdi, -0x30(%rbp)
callq 0x6050
cmpl $0x23, %eax
je 0xff56
movb 0xd0(%rbx), %al
bzhiq %rax, %r14, %rcx
movq 0xe8(%rbx), %rax
movq %rcx, -0x40(%rbp)
movq (%rax,%rcx,8), %r14
testq %r14, %r14
je 0xfdc1
movq %r12, %rax
shrq $0x20, %rax
xorq %r12, %rax
movq %rax, %r13
shrq $0x10, %r13
xorq %rax, %r13
leaq 0x10(%r15), %rax
movq %rax, -0x38(%rbp)
movq (%r14), %r12
movl %r13d, %eax
xorw %r12w, %ax
jne 0xfdb8
cmpq $0x10000, %r12          # imm = 0x10000
jb 0xfdb8
shrq $0x10, %r12
movq (%r15), %rax
cmpq (%r12), %rax
jne 0xfdb8
movl 0x8(%r15), %edx
cmpl 0x8(%r12), %edx
jne 0xfdb8
leaq 0x10(%r12), %rsi
movq -0x38(%rbp), %rdi
callq 0x63d0
testl %eax, %eax
je 0xfeef
movq 0x8(%r14), %r14
testq %r14, %r14
jne 0xfd75
movl $0x10, %edi
callq 0x63a0
testq %rax, %rax
je 0xfeaa
vxorps %xmm0, %xmm0, %xmm0
vmovups %xmm0, (%rax)
movq %r15, %rcx
shlq $0x10, %rcx
movq %rcx, (%rax)
movq (%r15), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
xorl %edx, %esi
movl %esi, %edx
shrl $0x10, %edx
xorl %esi, %edx
movzwl %dx, %edx
orq %rcx, %rdx
movq %rdx, (%rax)
movl $0x1, %r15d
lock
xaddq %r15, 0x88(%rbx)
movq 0xe8(%rbx), %rcx
movq -0x40(%rbp), %rsi
movq (%rcx,%rsi,8), %rdx
movq %rdx, 0x8(%rax)
movq %rax, (%rcx,%rsi,8)
movq -0x30(%rbp), %rdi
callq 0x6320
movb $0x1, %r14b
cmpq 0xd8(%rbx), %r15
jbe 0xfec8
leaq 0xf8(%rbx), %r14
movq %r14, %rdi
callq 0x6280
testl %eax, %eax
je 0xfe6b
cmpl $0xb, %eax
je 0xfe67
cmpl $0x10, %eax
jne 0xff56
xorl %r15d, %r15d
jmp 0xfe6e
movb $0x1, %al
jmp 0xfe70
movb $0x1, %r15b
xorl %eax, %eax
testb %al, %al
jne 0xfe48
movb $0x1, %r14b
testb $0x1, %r15b
je 0xfec8
leaq 0xe0(%rbx), %rdi
leaq 0x3fb9(%rip), %rdx      # 0x13e44
xorl %esi, %esi
movq %rbx, %rcx
callq 0x6430
movq 0xe0(%rbx), %rdi
leaq 0x5928(%rip), %rsi      # 0x157cb
callq 0x61d0
jmp 0xfec8
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0xfebc
movq 0x18(%rbx), %rsi
movq %r15, %rdi
callq *%rax
movq -0x30(%rbp), %rdi
callq 0x6320
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x66ef
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x6340
jmp 0xfec5
movq 0x40(%rbx), %rax
testq %rax, %rax
je 0xff06
movq 0x48(%rbx), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq *%rax
jmp 0xff18
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0xff18
movq 0x18(%rbx), %rsi
movq %r12, %rdi
callq *%rax
movzwl (%r14), %eax
movq %r15, %rcx
shlq $0x10, %rcx
orq %rcx, %rax
movq %rax, (%r14)
movq (%r15), %rax
movq %rax, %rdx
shrq $0x20, %rdx
xorl %eax, %edx
movl %edx, %eax
shrl $0x10, %eax
xorl %edx, %eax
movzwl %ax, %eax
orq %rcx, %rax
movq %rax, (%r14)
movq -0x30(%rbp), %rdi
callq 0x6320
movb $0x1, %r14b
jmp 0xfec8
xorl %edi, %edi
callq 0x6530