// File: /workspace/github_c_makefile_star2_O1/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 0xd64b
leaq 0x10128(%rdx), %rax
movq %rax, -0x38(%rbp)
movq %rbx, %r12
shlq $0x5, %r12
cmpq $0x0, 0x8(%rax,%r12)
je 0xd635
addq %rax, %r12
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %rbx, -0x40(%rbp)
movq 0x8(%r12), %rax
cmpq %r15, (%rax)
jbe 0xd5e0
movq %r15, %rcx
shrq $0x6, %rcx
movq 0x10(%rax,%rcx,8), %rax
btq %r15, %rax
jae 0xd5e0
movq (%r12), %r14
addq %r13, %r14
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
cmpq $0x10000, %rdi          # imm = 0x10000
jb 0xd5d7
movq 0x10(%rdx), %rax
testq %rax, %rax
je 0xd5c9
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 0xd5a5
incq %r15
movq -0x40(%rbp), %rbx
shrxq %rbx, %r15, %rax
addq $0x40, %r13
testq %rax, %rax
je 0xd580
movq 0x18(%r12), %rax
testq %rax, %rax
jne 0xd644
movq (%r12), %rdi
testq %rdi, %rdi
je 0xd61a
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 0xd560
jmp 0xd64b
callq 0x66ef
jmp 0xd5ff
movq 0xa8(%rdx), %rax
testq %rax, %rax
jne 0xd703
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 0x831a
movq -0x30(%rbp), %rcx
movq %rax, 0x10328(%rcx)
movl $0x1, %edi
movl $0x2010, %esi           # imm = 0x2010
callq 0x62d0
movq -0x30(%rbp), %rdx
movq $0x10000, (%rax)        # imm = 0x10000
xorl %ecx, %ecx
xchgq %rcx, 0x8(%rax)
movq %rax, 0x10330(%rdx)
cmpq $0x0, 0x10328(%rdx)
je 0xd711
cmpq $0x0, 0x10330(%rdx)
je 0xd71c
movq 0x10330(%rdx), %rbx
leaq 0x10(%rbx), %rdi
movq (%rbx), %r14
leaq 0x3f(%r14), %rdx
shrq $0x3, %rdx
andq $-0x8, %rdx
movl $0xff, %esi
callq 0x6210
xchgq %r14, 0x8(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x66ef
movq -0x30(%rbp), %rdx
jmp 0xd65b
callq 0x66ef
movq -0x30(%rbp), %rdx
jmp 0xd6c2
callq 0x66ef
movq -0x30(%rbp), %rdx
jmp 0xd6cc