// File: /workspace/github_c_makefile_star2_O0/ngkaho1234[P]ext4-extents-tree/db_bitmap.c
// Function: bitmap_find_bits_clr
int bitmap_find_bits_clr(struct db_bitmap *db_bitmap, ext4_fsblk_t bit, ext4_fsblk_t ebit,
    ext4_fsblk_t *bit_id)
{
    ext4_fsblk_t i;
    uint64_t bcnt = ebit - bit + 1;
    uint8_t *bitmap = db_bitmap->bitmap;

    i = bit;

    while(i & 7){

        if(!bcnt)
            return -ENOSPC;

        if(bitmap_is_bit_clr(bitmap, i)){
            *bit_id = bit;
            return 0;
        }

        i++;
        bcnt--;
    }

    bit  = i;
    bitmap += (bit >> 3);


    while(bcnt >= 32){
        if(*(uint32_t *)bitmap != 0xFFFFFFFF)
            goto finish_it;

        bitmap += 4;
        bcnt -= 32;
        bit += 32;
    }

    while(bcnt >= 16){
        if(*(uint16_t *)bitmap != 0xFFFF)
            goto finish_it;

        bitmap += 2;
        bcnt -= 16;
        bit += 16;
    }

    finish_it:
    while(bcnt >= 8){
        if(*bitmap != 0xFF){
            for (i = 0; i < 8; ++i) {
                if(bitmap_is_bit_clr(bitmap, i)){
                    *bit_id = bit + i;
                    return 0;
                }
            }
        }

        bitmap += 1;
        bcnt -= 8;
        bit += 8;
    }

    for (i = 0; i < bcnt; ++i) {
        if(bitmap_is_bit_clr(bitmap, i)){
            *bit_id = bit + i;
            return 0;
        }
    }

    return -ENOSPC;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
subq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
andq $0x7, %rax
cmpq $0x0, %rax
je 0x5c91
cmpq $0x0, -0x38(%rbp)
jne 0x5c4d
movl $0xffffffe4, -0x4(%rbp) # imm = 0xFFFFFFE4
jmp 0x5e09
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x5e20
testb $0x1, %al
jne 0x5c60
jmp 0x5c77
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x5e09
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5c2c
movq -0x30(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
shrq $0x3, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x20, -0x38(%rbp)
jb 0x5ce1
movq -0x40(%rbp), %rax
cmpl $-0x1, (%rax)
je 0x5cbb
jmp 0x5d22
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
subq $0x20, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x18(%rbp)
jmp 0x5ca9
jmp 0x5ce3
cmpq $0x10, -0x38(%rbp)
jb 0x5d20
movq -0x40(%rbp), %rax
movzwl (%rax), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x5cfa
jmp 0x5d22
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
subq $0x10, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
jmp 0x5ce3
jmp 0x5d22
jmp 0x5d24
cmpq $0x8, -0x38(%rbp)
jb 0x5db5
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0x5d8c
movq $0x0, -0x30(%rbp)
cmpq $0x8, -0x30(%rbp)
jae 0x5d8a
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x5e20
testb $0x1, %al
jne 0x5d5f
jmp 0x5d7a
movq -0x18(%rbp), %rcx
addq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x5e09
jmp 0x5d7c
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x5d45
jmp 0x5d8c
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
subq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
jmp 0x5d24
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x5e02
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x5e20
testb $0x1, %al
jne 0x5dda
jmp 0x5df2
movq -0x18(%rbp), %rcx
addq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x5e09
jmp 0x5df4
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x5dbd
movl $0xffffffe4, -0x4(%rbp) # imm = 0xFFFFFFE4
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)