// File: /workspace/github_c_makefile_star2_O0/wuxb45[P]SLB/lib1.c
// Function: kvmap2_set
bool
kvmap2_set(struct kvmap2 * const map2, const struct kv * const kv0)
{
  u64 i = UINT64_MAX;
  u64 j = UINT64_MAX;
  u64 k = UINT64_MAX;
  u64 hmax[2];
  u64 hi[2];
  //u64 hj[2];
  u64 hk[2];

  const struct kv * const kv = kv_alloc_dup(kv0, &(map2->mm));
  if (kv == NULL) return false;

  for (u64 x = 0; x < 2; x++) {
    kvmap1_lock_hash(map2->maps[x], kv);
  }
  for (u64 x = 0; x < 2; x++) {
    struct kvmap1 * const map = map2->maps[x];
    if (kvmap1_locate_key(map, kv, &i, &j, &k)) {
      kvmap1_unlock_hash(map2->maps[1 - x], kv);
      struct __kvmap_entry * const e = &(map->levels[i].table[j].e[k]);
      kvmap1_put_entry(map, e, kv);
      kvmap1_unlock_hash(map2->maps[x], kv);
      return true;
    }
    hi[x] = i;
    hk[x] = k;
    hmax[x] = map->max_level;
    const u64 bar0 = hmax[x] + (x * map2->sz_shift);
    if (bar0 < hmax[0]) {
      hmax[x] += (hmax[0] - bar0);
    }
  }

  // insert with no split
  for (u64 x = 0; x < 2; x++) {
    if (hk[x] < 8) {
      kvmap1_unlock_hash(map2->maps[1 - x], kv);
      const bool ret = kvmap1_insert(map2->maps[x], kv, hi[x]);
      (void)ret;
      kvmap1_unlock_hash(map2->maps[x], kv);
      debug_assert(ret);
      return true;
    }
  }

  // insert with limited number of splits
  for (u64 x = 0; x < 2; x++) {
    if (hmax[x] > hi[x]) {
      const bool ret = kvmap1_insert(map2->maps[x], kv, hmax[x]);
      if (ret) {
        for (u64 y = 0; y < 2; y++) {
          kvmap1_unlock_hash(map2->maps[y], kv);
        }
        return true;
      }
    }
  }

  // cuckoo
  for (u64 x = 0; x < 2; x++) {
    if (kvmap2_cuckoo(map2, x, kv)) {
      kvmap1_unlock_hash(map2->maps[1 - x], kv);
      const bool ret = kvmap1_insert(map2->maps[x], kv, hmax[x]);
      (void)ret;
      kvmap1_unlock_hash(map2->maps[x], kv);
      debug_assert(ret);
      return true;
    }
  }

  // bad luck: expand
  kvmap1_unlock_hash(map2->maps[1], kv);
  const bool ret = kvmap1_insert(map2->maps[0], kv, 64);
  (void)ret;
  debug_assert(ret);
  kvmap1_unlock_hash(map2->maps[0], kv);
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $-0x1, -0x20(%rbp)
movq $-0x1, -0x28(%rbp)
movq $-0x1, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xf860
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0xf41c
movb $0x0, -0x1(%rbp)
jmp 0xf847
movq $0x0, -0x70(%rbp)
cmpq $0x2, -0x70(%rbp)
jae 0xf44f
movq -0x10(%rbp), %rax
movq -0x70(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
callq 0xf070
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xf424
movq $0x0, -0x78(%rbp)
cmpq $0x2, -0x78(%rbp)
jae 0xf59c
movq -0x10(%rbp), %rax
movq -0x78(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
movq -0x68(%rbp), %rsi
leaq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rcx
leaq -0x30(%rbp), %r8
callq 0xf0d0
testb $0x1, %al
jne 0xf495
jmp 0xf518
movq -0x10(%rbp), %rax
movl $0x1, %ecx
subq -0x78(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
callq 0xf230
movq -0x80(%rbp), %rax
addq $0x10128, %rax          # imm = 0x10128
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq -0x30(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0xf8d0
movq -0x10(%rbp), %rax
movq -0x78(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
callq 0xf230
movb $0x1, -0x1(%rbp)
jmp 0xf847
movq -0x20(%rbp), %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x50(%rbp,%rax,8)
movq -0x30(%rbp), %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x60(%rbp,%rax,8)
movq -0x80(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x40(%rbp,%rax,8)
movq -0x78(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rax
movq -0x78(%rbp), %rcx
movq -0x10(%rbp), %rdx
imulq 0x50(%rdx), %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0xf589
movq -0x40(%rbp), %rcx
subq -0x90(%rbp), %rcx
movq -0x78(%rbp), %rax
addq -0x40(%rbp,%rax,8), %rcx
movq %rcx, -0x40(%rbp,%rax,8)
jmp 0xf58b
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0xf457
movq $0x0, -0x98(%rbp)
cmpq $0x2, -0x98(%rbp)
jae 0xf65a
movq -0x98(%rbp), %rax
cmpq $0x8, -0x60(%rbp,%rax,8)
jae 0xf641
movq -0x10(%rbp), %rax
movl $0x1, %ecx
subq -0x98(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
callq 0xf230
movq -0x10(%rbp), %rax
movq -0x98(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
movq -0x98(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rdx
callq 0xf9b0
andb $0x1, %al
movb %al, -0x99(%rbp)
movq -0x10(%rbp), %rax
movq -0x98(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
callq 0xf230
movb -0x99(%rbp), %al
andb $0x1, %al
movzbl %al, %edi
callq 0x7640
movb $0x1, -0x1(%rbp)
jmp 0xf847
jmp 0xf643
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0xf5a7
movq $0x0, -0xa8(%rbp)
cmpq $0x2, -0xa8(%rbp)
jae 0xf72d
movq -0xa8(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rax
movq -0xa8(%rbp), %rcx
cmpq -0x50(%rbp,%rcx,8), %rax
jbe 0xf714
movq -0x10(%rbp), %rax
movq -0xa8(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
movq -0xa8(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdx
callq 0xf9b0
andb $0x1, %al
movb %al, -0xa9(%rbp)
testb $0x1, -0xa9(%rbp)
je 0xf712
movq $0x0, -0xb8(%rbp)
cmpq $0x2, -0xb8(%rbp)
jae 0xf709
movq -0x10(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
callq 0xf230
movq -0xb8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb8(%rbp)
jmp 0xf6d2
movb $0x1, -0x1(%rbp)
jmp 0xf847
jmp 0xf714
jmp 0xf716
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0xf665
movq $0x0, -0xc0(%rbp)
cmpq $0x2, -0xc0(%rbp)
jae 0xf7f3
movq -0x10(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0xfab0
testb $0x1, %al
jne 0xf760
jmp 0xf7da
movq -0x10(%rbp), %rax
movl $0x1, %ecx
subq -0xc0(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
callq 0xf230
movq -0x10(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
movq -0xc0(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdx
callq 0xf9b0
andb $0x1, %al
movb %al, -0xc1(%rbp)
movq -0x10(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rsi
callq 0xf230
movb -0xc1(%rbp), %al
andb $0x1, %al
movzbl %al, %edi
callq 0x7640
movb $0x1, -0x1(%rbp)
jmp 0xf847
jmp 0xf7dc
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
jmp 0xf738
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x68(%rbp), %rsi
callq 0xf230
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x68(%rbp), %rsi
movl $0x40, %edx
callq 0xf9b0
andb $0x1, %al
movb %al, -0xc2(%rbp)
movb -0xc2(%rbp), %al
andb $0x1, %al
movzbl %al, %edi
callq 0x7640
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x68(%rbp), %rsi
callq 0xf230
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)