// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movq %rdi, %r14
movq $-0x1, %rax
movq %rax, -0x58(%rbp)
movq %rax, -0x98(%rbp)
movq %rax, -0x50(%rbp)
movq 0x8(%rdi), %rsi
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %ecx
leaq (%rax,%rcx), %r12
addq $0x10, %r12
movq %r12, %rdi
callq *(%r14)
movq %rax, %r15
testq %rax, %rax
je 0xccb4
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x6340
movb $0x1, %bl
xorl %eax, %eax
movq 0x58(%r14,%rax,8), %rax
movq (%r15), %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 0xcd5c
movl $0x1, %eax
testb $0x1, %bl
movl $0x0, %ebx
jne 0xc811
movq %r14, -0x38(%rbp)
movq %r15, -0x30(%rbp)
leaq -0x80(%rbp), %r13
leaq -0x70(%rbp), %r14
leaq -0xb0(%rbp), %rbx
movb $0x1, %cl
xorl %r15d, %r15d
movq -0x38(%rbp), %r12
movl %ecx, -0x40(%rbp)
movq 0x58(%r12,%r15,8), %rdi
movq %rdi, -0x48(%rbp)
movq -0x30(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0x98(%rbp), %rcx
leaq -0x50(%rbp), %r8
callq 0xc4f9
testb %al, %al
jne 0xc90d
movq -0x58(%rbp), %rax
movq %rax, (%r14)
movq -0x50(%rbp), %rax
movq %rax, (%rbx)
movq -0x48(%rbp), %rax
movq 0x58(%rax), %rcx
movq %rcx, (%r13)
imulq 0x50(%r12), %r15
addq %r15, %rcx
movq -0x80(%rbp), %rax
cmpq %rax, %rcx
jae 0xc8c8
subq %r15, %rax
movq %rax, (%r13)
movl $0x1, %r15d
leaq -0xc8(%rbp), %rbx
leaq -0x90(%rbp), %r14
leaq -0x78(%rbp), %r13
testb $0x1, -0x40(%rbp)
movl $0x0, %ecx
jne 0xc86d
cmpq $0x8, -0xb0(%rbp)
jae 0xc9eb
leaq -0x70(%rbp), %rbx
xorl %r14d, %r14d
movq -0x30(%rbp), %r15
movq -0x38(%rbp), %r12
jmp 0xca0e
movq %r15, -0x40(%rbp)
xorq $0x1, %r15
movq 0x58(%r12,%r15,8), %rax
movq -0x30(%rbp), %r15
movq (%r15), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6320
movq -0x58(%rbp), %rax
shlq $0x5, %rax
movq -0x98(%rbp), %r12
shlq $0x6, %r12
movq -0x48(%rbp), %r13
addq 0x10128(%r13,%rax), %r12
movq -0x50(%rbp), %r14
movq (%r12,%r14,8), %rdi
cmpq $0x10000, %rdi          # imm = 0x10000
jb 0xc985
movq 0x10(%r13), %rax
testq %rax, %rax
je 0xc985
shrq $0x10, %rdi
movq 0x18(%r13), %rsi
callq *%rax
movzwl (%r12,%r14,8), %edi
movq %r15, %rax
shlq $0x10, %rax
movzwl %di, %ecx
orq %rax, %rcx
movq %rcx, (%r12,%r14,8)
movq (%r15), %rdx
movb 0x50(%r13), %cl
rolq %cl, %rdx
movq %rdx, %rcx
shrq $0x20, %rcx
xorl %edx, %ecx
movl %ecx, %edx
shrl $0x10, %edx
xorl %ecx, %edx
movzwl %dx, %ecx
orq %rax, %rcx
movq %rcx, (%r12,%r14,8)
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x58(%rax,%rcx,8), %rax
movq (%r15), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6320
jmp 0xca74
cmpq $0x8, -0xc8(%rbp)
movq -0x30(%rbp), %r15
movq -0x38(%rbp), %r12
jae 0xca8c
movl $0x1, %r14d
leaq -0x90(%rbp), %rbx
movl %r14d, %eax
xorl $0x1, %eax
movq 0x58(%r12,%rax,8), %rdi
movq (%r15), %rax
movb 0x50(%rdi), %cl
rolq %cl, %rax
movl $0xffc0, %ecx           # imm = 0xFFC0
andl %ecx, %eax
movl $0xe8, %r13d
addq %r13, %rdi
addq %rax, %rdi
callq 0x6320
movq 0x58(%r12,%r14,8), %rdi
movq (%rbx), %rdx
movq %r15, %rsi
callq 0xcd63
movl %eax, %ebx
movq 0x58(%r12,%r14,8), %rdi
movq (%r15), %rax
movb 0x50(%rdi), %cl
rolq %cl, %rax
movl $0xffc0, %ecx           # imm = 0xFFC0
andl %ecx, %eax
addq %r13, %rdi
addq %rax, %rdi
callq 0x6320
testb %bl, %bl
je 0xcd4b
testq %r15, %r15
setne %al
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x80(%rbp), %rdx
leaq -0x70(%rbp), %rcx
movb $0x1, %bl
xorl %eax, %eax
movq (%rdx), %rdx
cmpq (%rcx), %rdx
jbe 0xcab5
movq 0x58(%r12,%rax,8), %rdi
movq %r15, %rsi
callq 0xcd63
testb %al, %al
jne 0xcccb
movl $0x1, %eax
movq %r14, %rcx
leaq -0x78(%rbp), %rdx
testb $0x1, %bl
movl $0x0, %ebx
jne 0xca98
movb $0x1, %al
xorl %r14d, %r14d
movl %eax, -0x5c(%rbp)
movq $-0x1, %rax
movq %rax, -0xa8(%rbp)
movq %rax, -0xa0(%rbp)
movq %rax, -0xd0(%rbp)
movq 0x58(%r12,%r14,8), %rbx
movq %rbx, %rdi
movq %r15, %rsi
leaq -0xa8(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
leaq -0xd0(%rbp), %r8
callq 0xc4f9
movq -0xa8(%rbp), %rax
shlq $0x5, %rax
movq -0xa0(%rbp), %rcx
shlq $0x6, %rcx
movq %rax, -0xb8(%rbp)
addq 0x10128(%rbx,%rax), %rcx
movq %rcx, -0x48(%rbp)
movq %r14, -0x40(%rbp)
xorq $0x1, %r14
movq %r14, -0x88(%rbp)
movb $0x1, %r14b
xorl %r13d, %r13d
movq -0x48(%rbp), %rax
movq (%rax,%r13,8), %rbx
cmpq $0x10000, %rbx          # imm = 0x10000
jb 0xcc05
movq -0x88(%rbp), %rax
movq 0x58(%r12,%rax,8), %r15
movq -0x40(%rbp), %rax
movq 0x58(%r12,%rax,8), %rax
movq %rax, -0xc0(%rbp)
shrq $0x10, %rbx
movq (%rbx), %rax
movb 0x50(%r15), %cl
rolq %cl, %rax
andl $0xffc0, %eax           # imm = 0xFFC0
leaq (%r15,%rax), %rdi
addq $0xe8, %rdi
callq 0x6510
testl %eax, %eax
je 0xcbb4
cmpl $0x10, %eax
je 0xcbec
jmp 0xcd5c
leaq 0xe8(%r15), %r12
movq 0x58(%r15), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcd63
testb %al, %al
jne 0xcc29
movq (%rbx), %rax
movb 0x50(%r15), %cl
rolq %cl, %rax
andl $0xffc0, %eax           # imm = 0xFFC0
addq %rax, %r12
movq %r12, %rdi
callq 0x6320
movq -0x38(%rbp), %r12
cmpq $0x7, %r13
leaq 0x1(%r13), %rax
setb %r14b
movq %rax, %r13
cmpq $0x8, %rax
jne 0xcb52
testb $0x1, %r14b
jne 0xcc70
movl $0x1, %r14d
testb $0x1, -0x5c(%rbp)
movl $0x0, %eax
movq -0x30(%rbp), %r15
jne 0xcad0
jmp 0xcd07
movq -0x48(%rbp), %rax
movq $0x0, (%rax,%r13,8)
movq -0xb8(%rbp), %rax
movq -0xc0(%rbp), %rcx
lock
decq 0x10140(%rcx,%rax)
movq (%rbx), %rax
movb 0x50(%r15), %cl
rolq %cl, %rax
andl $0xffc0, %eax           # imm = 0xFFC0
addq %rax, %r12
movq %r12, %rdi
callq 0x6320
testb $0x1, %r14b
movq -0x38(%rbp), %r12
je 0xcc0b
movq -0x88(%rbp), %rax
movq 0x58(%r12,%rax,8), %rdi
movq -0x30(%rbp), %r15
movq (%r15), %rax
movb 0x50(%rdi), %cl
rolq %cl, %rax
movl $0xffc0, %ecx           # imm = 0xFFC0
andl %ecx, %eax
movl $0xe8, %r13d
addq %r13, %rdi
addq %rax, %rdi
callq 0x6320
movq -0x40(%rbp), %r14
movq 0x58(%r12,%r14,8), %rdi
movq -0x80(%rbp,%r14,8), %rdx
jmp 0xca42
callq 0x66ef
xorl %edi, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x6340
jmp 0xca74
movb $0x1, %bl
xorl %eax, %eax
movq 0x58(%r12,%rax,8), %rax
movq (%r15), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6320
movl $0x1, %eax
testb $0x1, %bl
movl $0x0, %ebx
jne 0xcccf
jmp 0xca74
movq 0x60(%r12), %rax
movq (%r15), %rdx
movb 0x50(%rax), %cl
rolq %cl, %rdx
andl $0xffc0, %edx           # imm = 0xFFC0
leaq (%rax,%rdx), %rdi
addq $0xe8, %rdi
callq 0x6320
movq 0x58(%r12), %rdi
movl $0x40, %edx
movq %r15, %rsi
callq 0xcd63
testb %al, %al
je 0xcd55
movq 0x58(%r12), %rax
jmp 0xc9c7
callq 0x66ef
jmp 0xca74
callq 0x66ef
jmp 0xcd41
xorl %edi, %edi
callq 0x6530