// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r15
movq %rdi, %rdx
movq $-0x1, %rax
movq %rax, -0x50(%rbp)
movq %rax, -0x68(%rbp)
movq %rax, -0x48(%rbp)
movl 0x8(%rsi), %eax
movl 0xc(%rsi), %ecx
leaq 0x10(%rax,%rcx), %r12
movq 0x8(%rdi), %rsi
movq %r12, %rdi
movq %rdx, -0x30(%rbp)
callq *(%rdx)
movq %rax, %rbx
testq %rax, %rax
je 0xce91
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x6340
movq %rbx, -0x38(%rbp)
testq %rbx, %rbx
je 0xce77
xorl %ebx, %ebx
movq -0x38(%rbp), %r14
movq -0x30(%rbp), %r15
movq 0x58(%r15,%rbx,8), %rax
movq (%r14), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6050
cmpl $0x23, %eax
je 0xceac
incq %rbx
cmpq $0x1, %rbx
je 0xc974
shlq $0x10, %r14
movq %r14, -0x40(%rbp)
xorl %r13d, %r13d
movq -0x30(%rbp), %r14
movq 0x58(%r14,%r13,8), %r12
movq %r12, %rdi
movq -0x38(%rbp), %rbx
movq %rbx, %rsi
leaq -0x50(%rbp), %rdx
leaq -0x68(%rbp), %rcx
leaq -0x48(%rbp), %r8
callq 0xc667
movl %eax, %r15d
testb %al, %al
je 0xcab0
movq %r13, %rax
xorq $0x1, %rax
movq 0x58(%r14,%rax,8), %rax
movq (%rbx), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6320
movq -0x50(%rbp), %rax
shlq $0x5, %rax
movq -0x68(%rbp), %r14
shlq $0x6, %r14
addq 0x10128(%r12,%rax), %r14
movq -0x48(%rbp), %rbx
movq (%r14,%rbx,8), %rdi
cmpq $0x10000, %rdi          # imm = 0x10000
jb 0xca4d
movq 0x10(%r12), %rax
testq %rax, %rax
je 0xca4d
shrq $0x10, %rdi
movq 0x18(%r12), %rsi
callq *%rax
movzwl (%r14,%rbx,8), %eax
movq -0x40(%rbp), %rsi
orq %rsi, %rax
movq %rax, (%r14,%rbx,8)
movq -0x38(%rbp), %rdx
movq (%rdx), %rax
movb 0x50(%r12), %cl
rolq %cl, %rax
movq %rax, %rcx
shrq $0x20, %rcx
xorl %eax, %ecx
movl %ecx, %eax
shrl $0x10, %eax
xorl %ecx, %eax
movzwl %ax, %eax
orq %rsi, %rax
movq %rax, (%r14,%rbx,8)
movq -0x30(%rbp), %rax
movq 0x58(%rax,%r13,8), %rax
movq (%rdx), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6320
jmp 0xcaf7
movq -0x50(%rbp), %rax
movq %rax, -0xc0(%rbp,%r13,8)
movq -0x48(%rbp), %rax
movq %rax, -0xd0(%rbp,%r13,8)
movq 0x58(%r12), %rdx
movq %rdx, -0x90(%rbp,%r13,8)
movq 0x50(%r14), %rax
imulq %r13, %rax
addq %rax, %rdx
movq -0x90(%rbp), %rcx
cmpq %rcx, %rdx
jae 0xcaf7
subq %rax, %rcx
movq %rcx, -0x90(%rbp,%r13,8)
testb %r15b, %r15b
jne 0xce77
incq %r13
cmpq $0x1, %r13
je 0xc9b5
movq -0x30(%rbp), %rax
addq $0x60, %rax
xorl %ebx, %ebx
movq -0x38(%rbp), %r13
cmpq $0x7, -0xd0(%rbp,%rbx,8)
jbe 0xcdaa
incq %rbx
addq $-0x8, %rax
cmpq $0x1, %rbx
je 0xcb1b
xorl %ebx, %ebx
movq -0x38(%rbp), %r12
movq -0x30(%rbp), %r13
movq -0x90(%rbp,%rbx,8), %rdx
cmpq -0xc0(%rbp,%rbx,8), %rdx
jbe 0xcba6
movq -0x30(%rbp), %rax
movq 0x58(%rax,%rbx,8), %rdi
movq -0x38(%rbp), %rsi
callq 0xceb3
testb %al, %al
je 0xcba6
movl %eax, %r15d
xorl %r14d, %r14d
movq 0x58(%r13,%r14,8), %rax
movq (%r12), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6320
incq %r14
cmpq $0x1, %r14
je 0xcb6f
testb %r15b, %r15b
jne 0xce77
leaq 0x1(%rbx), %rax
testq %rbx, %rbx
movq %rax, %rbx
je 0xcb41
xorl %ebx, %ebx
movq -0x38(%rbp), %r13
movq $-0x1, %rax
movq %rax, -0x78(%rbp)
movq %rax, -0x70(%rbp)
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movq 0x58(%rax,%rbx,8), %r15
movq %r15, %rdi
movq %r13, %rsi
leaq -0x78(%rbp), %rdx
leaq -0x70(%rbp), %rcx
leaq -0xa8(%rbp), %r8
callq 0xc667
movq -0x78(%rbp), %rax
shlq $0x5, %rax
movq -0x70(%rbp), %rcx
shlq $0x6, %rcx
movq %rax, -0x98(%rbp)
addq 0x10128(%r15,%rax), %rcx
movq %rcx, -0x60(%rbp)
movl $0x1, %eax
movq %rbx, -0x40(%rbp)
subq %rbx, %rax
movq %rax, -0x58(%rbp)
movb $0x1, %r14b
xorl %ebx, %ebx
movq -0x60(%rbp), %rax
movq (%rax,%rbx,8), %r15
cmpq $0x10000, %r15          # imm = 0x10000
jb 0xcd25
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %r12
movq -0x40(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
shrq $0x10, %r15
movq (%r15), %rax
movb 0x50(%r12), %cl
rolq %cl, %rax
andl $0xffc0, %eax           # imm = 0xFFC0
leaq (%r12,%rax), %rdi
addq $0xe8, %rdi
callq 0x6510
testl %eax, %eax
je 0xcc8d
cmpl $0x10, %eax
je 0xccc8
jmp 0xceac
leaq 0xe8(%r12), %r13
movq 0x58(%r12), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0xceb3
testb %al, %al
jne 0xcce3
movq (%r15), %rax
movb 0x50(%r12), %cl
rolq %cl, %rax
andl $0xffc0, %eax           # imm = 0xFFC0
addq %rax, %r13
movq %r13, %rdi
callq 0x6320
movq -0x38(%rbp), %r13
cmpq $0x7, %rbx
leaq 0x1(%rbx), %rax
setb %r14b
movq %rax, %rbx
cmpq $0x8, %rax
jne 0xcc29
jmp 0xcd25
movq -0x60(%rbp), %rax
movq $0x0, (%rax,%rbx,8)
movq -0x98(%rbp), %rax
movq -0xa0(%rbp), %rcx
lock
decq 0x10140(%rcx,%rax)
movq (%r15), %rax
movb 0x50(%r12), %cl
rolq %cl, %rax
andl $0xffc0, %eax           # imm = 0xFFC0
addq %rax, %r13
movq %r13, %rdi
callq 0x6320
movq -0x38(%rbp), %r13
testb $0x1, %r14b
jne 0xce06
movq -0x40(%rbp), %rcx
leaq 0x1(%rcx), %rbx
testq %rcx, %rcx
je 0xcbb8
movq -0x30(%rbp), %rbx
movq 0x60(%rbx), %rax
movq (%r13), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6320
movq 0x58(%rbx), %rdi
movl $0x40, %edx
movq %r13, %rsi
callq 0xceb3
testb %al, %al
je 0xcea2
movq 0x58(%rbx), %rax
movq (%r13), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6320
jmp 0xce77
movq (%rax), %rdi
movq (%r13), %rax
movb 0x50(%rdi), %cl
rolq %cl, %rax
movl $0xffc0, %ecx           # imm = 0xFFC0
andl %ecx, %eax
movl $0xe8, %r12d
addq %r12, %rdi
addq %rax, %rdi
callq 0x6320
movq -0x30(%rbp), %r14
movq 0x58(%r14,%rbx,8), %rdi
movq -0xc0(%rbp,%rbx,8), %rdx
movq %r13, %rsi
callq 0xceb3
movl %eax, %r15d
movq 0x58(%r14,%rbx,8), %rdi
movq (%r13), %rax
movb 0x50(%rdi), %cl
rolq %cl, %rax
movl $0xffc0, %ecx           # imm = 0xFFC0
andl %ecx, %eax
addq %r12, %rdi
jmp 0xce6a
movq -0x30(%rbp), %r12
movq -0x58(%rbp), %rax
movq 0x58(%r12,%rax,8), %rdi
movq (%r13), %rax
movb 0x50(%rdi), %cl
rolq %cl, %rax
movl $0xffc0, %ecx           # imm = 0xFFC0
andl %ecx, %eax
movl $0xe8, %r14d
addq %r14, %rdi
addq %rax, %rdi
callq 0x6320
movq -0x40(%rbp), %rbx
movq 0x58(%r12,%rbx,8), %rdi
movq -0x90(%rbp,%rbx,8), %rdx
movq %r13, %rsi
callq 0xceb3
movl %eax, %r15d
movq 0x58(%r12,%rbx,8), %rdi
movq (%r13), %rax
movb 0x50(%rdi), %cl
rolq %cl, %rax
movl $0xffc0, %ecx           # imm = 0xFFC0
andl %ecx, %eax
addq %r14, %rdi
addq %rax, %rdi
callq 0x6320
testb %r15b, %r15b
je 0xce9b
cmpq $0x0, -0x38(%rbp)
setne %al
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x66ef
jmp 0xc94f
callq 0x66ef
jmp 0xce77
callq 0x66ef
jmp 0xcd81
xorl %edi, %edi
callq 0x6530