// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xf860
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x12ef1
movb $0x0, -0x1(%rbp)
jmp 0x13105
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x12d40
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10c00
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movq -0x30(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x6e50
movq -0x28(%rbp), %rax
shrq $0x6, %rax
movq -0x10(%rbp), %rcx
movq 0xd0(%rcx), %rcx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
subq $0x1, %rcx
andq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x12ffe
movq -0x48(%rbp), %rax
movq (%rax), %rax
andq $0xffff, %rax           # imm = 0xFFFF
cmpq -0x38(%rbp), %rax
jne 0x12fed
movq -0x48(%rbp), %rax
movq (%rax), %rdi
shrq $0x10, %rdi
callq 0xf220
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0xe110
testb $0x1, %al
jne 0x12fb6
jmp 0x12feb
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x11390
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movq -0x30(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x6ed0
movb $0x1, -0x1(%rbp)
jmp 0x13105
jmp 0x12fed
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x12f71
movl $0x10, %edi
callq 0x6380
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x13058
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x13034
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rsi
callq *%rax
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movq -0x30(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x6ed0
movb $0x0, -0x1(%rbp)
jmp 0x13105
movq -0x58(%rbp), %rax
vpxor %xmm0, %xmm0, %xmm0
vmovdqu %xmm0, (%rax)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x11390
movq -0x10(%rbp), %rcx
movq $0x1, -0x68(%rbp)
movq -0x68(%rbp), %rax
lock
xaddq %rax, 0x88(%rcx)
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movq -0x30(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x6ed0
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0xd8(%rcx), %rax
jbe 0x13101
movq -0x10(%rbp), %rdi
callq 0x13110
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq