// File: /workspace/github_c_makefile_star2_O3/wuxb45[P]SLB/lib1.c
// Function: kvmap1_clean
static void
kvmap1_clean(struct kvmap1 * const map)
{
  for (u64 i = map->max_level; i >= KVMAP_MIN_LEVEL; i--) {
    struct __kvmap1_level * const level = &(map->levels[i]);
    if (level->bm == NULL) continue;
    const u64 nr_slots = KVMAP_SLOTS_OF(i);
    for (u64 j = 0; j < nr_slots; j++) {
      if (bitmap_test(level->bm, j)) {
        struct __kvmap_slot * const slot = &(level->table[j]);
        for (u64 k = 0; k < 8; k++) {
          struct __kvmap_entry * const e = &(slot->e[k]);
          if (e->ptr) {
            kvmap1_put_entry(map, e, NULL);
            //(void)atomic_fetch_sub(&(map->nr_kv), 1);
            (void)atomic_fetch_sub(&(level->nr_kv), 1);
          }
        }
      }
    }
    debug_assert(atomic_load(&(level->nr_kv)) == 0);
    if (level->table) {
      pages_unmap(level->table, level->alloc_size);
      level->table = NULL;
    }
    free(level->bm);
    level->bm = NULL;
  }
  debug_assert(atomic_load(&(map->nr_kv)) == 0);
  kvmap1_init(map);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rdx
movq 0x58(%rdi), %rbx
cmpq $0x10, %rbx
movq %rdi, -0x30(%rbp)
jb 0xd519
leaq 0x10128(%rdx), %rax
movq %rax, -0x38(%rbp)
movq %rbx, %r12
shlq $0x5, %r12
cmpq $0x0, 0x8(%rax,%r12)
je 0xd503
addq %rax, %r12
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %rbx, -0x40(%rbp)
movq 0x8(%r12), %rax
cmpq %r15, (%rax)
jbe 0xd4ae
movq %r15, %rcx
shrq $0x6, %rcx
movq 0x10(%rax,%rcx,8), %rax
btq %r15, %rax
jae 0xd4ae
movq (%r12), %r14
addq %r13, %r14
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
cmpq $0x10000, %rdi          # imm = 0x10000
jb 0xd4a5
movq 0x10(%rdx), %rax
testq %rax, %rax
je 0xd497
shrq $0x10, %rdi
movq 0x18(%rdx), %rsi
callq *%rax
movq -0x30(%rbp), %rdx
movq $0x0, (%r14,%rbx,8)
lock
decq 0x18(%r12)
incq %rbx
cmpq $0x8, %rbx
jne 0xd473
incq %r15
movq -0x40(%rbp), %rbx
shrxq %rbx, %r15, %rax
addq $0x40, %r13
testq %rax, %rax
je 0xd44e
movq 0x18(%r12), %rax
testq %rax, %rax
jne 0xd512
movq (%r12), %rdi
testq %rdi, %rdi
je 0xd4e8
movq 0x10(%r12), %rsi
callq 0x6410
movq $0x0, (%r12)
movq 0x8(%r12), %rdi
callq 0x6060
movq $0x0, 0x8(%r12)
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rax
decq %rbx
cmpq $0xf, %rbx
ja 0xd42e
jmp 0xd519
callq 0x66ef
jmp 0xd4cd
movq 0xa8(%rdx), %rax
testq %rax, %rax
jne 0xd5c1
movl $0x10, %eax
movq %rax, 0x58(%rdx)
movq %rax, 0x60(%rdx)
movq %rax, 0x68(%rdx)
movq -0x30(%rbp), %rax
leaq 0x10338(%rax), %rdx
movl $0x400000, %edi         # imm = 0x400000
movl $0x1, %esi
callq 0x82a0
movq %rax, %r15
movq -0x30(%rbp), %rax
movq %r15, 0x10328(%rax)
movl $0x1, %edi
movl $0x2010, %esi           # imm = 0x2010
callq 0x62d0
movq %rax, %r14
movq $0x10000, (%rax)        # imm = 0x10000
xorl %eax, %eax
xchgq %rax, 0x8(%r14)
movq -0x30(%rbp), %rax
movq %r14, 0x10330(%rax)
testq %r15, %r15
je 0xd5cf
leaq 0x10(%r14), %rdi
movq (%r14), %rbx
leaq 0x3f(%rbx), %rdx
shrq $0x3, %rdx
andq $-0x8, %rdx
movl $0xff, %esi
callq 0x6210
xchgq %rbx, 0x8(%r14)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x66ef
movq -0x30(%rbp), %rdx
jmp 0xd529
callq 0x66ef
movq -0x30(%rbp), %rax
movq 0x10330(%rax), %r14
testq %r14, %r14
jne 0xd591
movq %rax, %rbx
callq 0x66ef
movq 0x10330(%rbx), %r14
jmp 0xd591