// File: /workspace/github_c_makefile_star2_O0/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: remove_from_dir_entry
int remove_from_dir_entry(struct ext2_inode * parent_inode,
                          char *name)
{
    int *parent_inode_iblock_array = read_i_block_into_array(parent_inode);
    struct ext2_dir_entry *prev_entry;
    struct ext2_dir_entry *curr_entry;
    
    int i = -1;
    int curr_offset = 1024;
    while (parent_inode_iblock_array[i] != -1) {
        if (curr_offset == EXT2_BLOCK_SIZE) {
            i++;
            curr_offset = 0;
            prev_entry = (struct ext2_dir_entry *)(disk + EXT2_BLOCK_SIZE * parent_inode_iblock_array[i] + curr_offset);
            curr_entry = (struct ext2_dir_entry *)(disk + EXT2_BLOCK_SIZE * parent_inode_iblock_array[i] + curr_offset);
        }
        
        if (strncmp(name, curr_entry->name, curr_entry->name_len) == 0) {
            // do entry del
            prev_entry->rec_len += curr_entry->rec_len;
            // update inode link count
            struct ext2_inode *curr_inode = inode_table + curr_entry->inode - 1;
            curr_inode->i_links_count--;
            
            // inode link count drop to 0
            if (curr_inode->i_links_count == 0) {
                free_inode(curr_entry->inode);
            }
            
            free(parent_inode_iblock_array);
            return 0;
        }
        
        prev_entry = curr_entry;
        curr_offset += curr_entry->rec_len;
        curr_entry = (struct ext2_dir_entry *)(disk + EXT2_BLOCK_SIZE * parent_inode_iblock_array[i] + curr_offset);
    }
    
    free(parent_inode_iblock_array);
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x15b0
movq %rax, -0x20(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0x400, -0x38(%rbp)     # imm = 0x400
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
je 0x21fb
cmpl $0x400, -0x38(%rbp)     # imm = 0x400
jne 0x2128
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
leaq 0x3fd3(%rip), %rax      # 0x60b0
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shll $0xa, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
leaq 0x3faa(%rip), %rax      # 0x60b0
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shll $0xa, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
movq -0x30(%rbp), %rax
movzbl 0x6(%rax), %eax
movl %eax, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x21b7
movq -0x30(%rbp), %rax
movzwl 0x4(%rax), %edx
movq -0x28(%rbp), %rax
movzwl 0x4(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x4(%rax)
leaq 0x3f53(%rip), %rax      # 0x60b8
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movl (%rcx), %ecx
shlq $0x7, %rcx
addq %rcx, %rax
addq $-0x80, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movw 0x1a(%rax), %cx
addw $-0x1, %cx
movw %cx, 0x1a(%rax)
movq -0x40(%rbp), %rax
movzwl 0x1a(%rax), %eax
cmpl $0x0, %eax
jne 0x21a5
movq -0x30(%rbp), %rax
movl (%rax), %edi
callq 0x2220
movq -0x20(%rbp), %rdi
callq 0x1030
movl $0x0, -0x4(%rbp)
jmp 0x220b
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movzwl 0x4(%rax), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
leaq 0x3edc(%rip), %rax      # 0x60b0
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shll $0xa, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x20ab
movq -0x20(%rbp), %rdi
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)