// File: /workspace/github_c_makefile_star2_O1/ngkaho1234[P]ext4-extents-tree/extents.c
// Function: ext4_ext_delete
int
ext4_ext_delete(struct ext4_ext_cursor *cur)
{
	int ret = 0;
	uint16_t nritems;
	int i;
	int rootdepth;
	struct ext4_extent_header *hdr;

	rootdepth = ext4_ext_cursor_depth(cur);
	hdr = cur->c_paths[0].p_hdr;

	/*
	 * We return ENOENT as error if we found the buffer of the lowest
	 * level is unpinned, have no entries in it, or the pointer being
	 * out-of-range.
	 */
	if (!hdr || !ext4_ext_header_entries(hdr))
		return ENOENT;
	if (cur->c_paths[0].p_ptr == -1)
		return ENOENT;
	if (cur->c_paths[0].p_ptr >= ext4_ext_header_entries(hdr))
		return ENOENT;

	/*
	 * Delete the extent at leaf.
	 */
	ext4_ext_delete_item(cur, 0);

	for (i = 0; i < rootdepth; i++) {
		int merged = 0;
		ssize_t ptr;
		struct ext4_ext_cursor *ncur;
		struct ext4_extent_idx *idx;
		struct ext4_extent_header *uhdr;

		hdr = cur->c_paths[i].p_hdr;

		nritems = ext4_ext_header_entries(hdr);
		if (nritems) {
			/*
			 * Try to merge the node with left sibling or
			 * right sibling.
			 */
			ret = ext4_ext_try_merge(cur, i, &ncur, &merged);
			if (ret)
				goto out;

			if (merged == 1) {
				ext4_assert(ncur);

				/*
				 * After merging to left sibling,
				 * we need not to update the first key of the
				 * left sibling at every level.
				 */

				/*
				 * Throw away the cursor to sibling.
				 */
				ext4_ext_cursor_free(ncur);
			} else if (merged == 2) {
				ext4_assert(ncur);

				/*
				 * After merging to right sibling,
				 * we need to update the first key of the
				 * right sibling at every level until we
				 * meet a non-leftmost key.
				 */
				ext4_ext_update_index(ncur, i, 0);

				/*
				 * Throw away the cursor to sibling.
				 */
				ext4_ext_cursor_free(ncur);
			} else {
				/*
				 * No merge happens, so do nothing.
				 */
				ext4_assert(!ncur);
				break;
			}
		}
		/*
		 * If we have merged two nodes into one, or we leave
		 * nothing in the node after deletion of an item,
		 * we free the block of the node.
		 *
		 * At the next iteration we delete the key of the node.
		 */

		/*
		 * Get the respective key in parent node.
		 */
		uhdr = cur->c_paths[i + 1].p_hdr;
		ptr = cur->c_paths[i + 1].p_ptr;
		idx = EXT_FIRST_INDEX(uhdr) + ptr;

		/*
		 * Unpin the buffer of this node, and free
		 * the block of it.
		 */
		ext4_ext_cursor_unpin(cur, i, 1);
		cur->c_cursor_op.c_free_block_func(cur, ext4_idx_block(idx));

		/*
		 * Delete the index of the current node at parent node.
		 */
		ext4_ext_delete_item(cur, i + 1);
	}

	if (i < rootdepth) {
		/*
		 * We might have removed the leftmost key in the node,
		 * so we need to update the first key of the right
		 * sibling at every level until we meet a non-leftmost
		 * key.
		 */
		ext4_ext_update_index(cur, i, 0);
	} else {
		if (!ext4_ext_tree_empty(cur)) {
			/*
			 * Reload the cursor's path so that it points to
			 * a valid key again.
			 */
			ret = ext4_ext_reload_paths(cur, i, true);
			if (ret)
				goto out;

			ret = ext4_ext_tree_shrink(cur);
		} else {
			/*
			 * For empty root we need to make sure that the
			 * depth of the root level is 0.
			 */
			hdr = cur->c_root;
			ext4_ext_header_set_depth(hdr, 0);
			cur->c_cursor_op.c_root_dirty_func(cur);
			ext4_ext_cursor_unpin(cur, rootdepth, 1);
		}
	}

out:
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x30(%rdi), %rax
movq 0x8(%rax), %rcx
movl $0x2, %r12d
testq %rcx, %rcx
je 0x5cd1
movzwl 0x2(%rcx), %ecx
testq %rcx, %rcx
je 0x5cd1
movq 0x10(%rax), %rax
cmpq $-0x1, %rax
je 0x5cd1
cmpq %rcx, %rax
jge 0x5cd1
movq %rdi, %rbx
movq (%rdi), %rax
movzwl 0x6(%rax), %r13d
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x5d40
testq %r13, %r13
setne %cl
je 0x5c6b
leal (,%r13,8), %eax
leaq (%rax,%rax,2), %rax
movq %rax, -0x60(%rbp)
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rbx, -0x38(%rbp)
movq %r13, -0x48(%rbp)
movb %cl, -0x29(%rbp)
movq 0x30(%rbx), %rax
movq 0x8(%rax,%r14), %rcx
cmpw $0x0, 0x2(%rcx)
je 0x5bdc
movq 0x8(%rax,%r14), %rax
movl 0xc(%rax), %r12d
movq 0x10(%rbx), %rdi
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x38(%rbx), %rcx
callq 0x4377
movq %rax, %r13
movb $0x1, %bl
testq %rax, %rax
je 0x59e2
subl $0x1, %r12d
movl $0x0, %eax
cmovbl %eax, %r12d
movq %r13, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x45c1
movl %eax, %r12d
movb $0x1, %al
testl %r12d, %r12d
jne 0x59ea
movq 0x30(%r13), %rax
movq (%rax,%r14), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq (%rcx,%r14), %rcx
cmpq 0x8(%rcx), %rax
sete %al
xorl %r12d, %r12d
jmp 0x59ea
movl $0xc, %r12d
movb $0x1, %al
xorl %r8d, %r8d
testl %r12d, %r12d
jne 0x5a6d
testb %al, %al
jne 0x5a6d
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax,%r14), %rsi
movzwl 0x2(%rsi), %eax
movzwl 0x4(%rsi), %ecx
shrl %ecx
cmpw %cx, %ax
jae 0x5a6d
movq 0x30(%r13), %rcx
movq 0x8(%rcx,%r14), %rdi
movzwl 0x2(%rdi), %ecx
leal (%rcx,%rax), %r9d
movzwl 0x4(%rdi), %edx
cmpl %edx, %r9d
ja 0x5a6d
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq %rdi, %rbx
leaq (%rdi,%rcx,4), %rdi
addq $0xc, %rdi
addq $0xc, %rsi
shll $0x2, %eax
leaq (%rax,%rax,2), %rdx
movl %r9d, -0x30(%rbp)
callq 0x2180
movl -0x30(%rbp), %eax
movw %ax, 0x2(%rbx)
movq 0x30(%r13), %rax
movq (%rax,%r14), %rdi
callq 0x2863
movl $0x1, %r8d
xorl %ebx, %ebx
testq %r13, %r13
sete %al
xorb $0x1, %bl
orb %bl, %al
jne 0x5a8b
movq %r13, %rdi
movl %r8d, %r13d
callq 0x4592
movl %r13d, %r8d
xorl %r13d, %r13d
testl %r12d, %r12d
setne %al
orb %bl, %al
movq -0x38(%rbp), %rbx
jne 0x5b93
movq $0x0, -0x40(%rbp)
movq %rbx, %rdi
movl %r15d, %esi
leaq -0x40(%rbp), %rdx
leaq -0x2a(%rbp), %rcx
callq 0x61a8
movl %eax, %r12d
xorl %r8d, %r8d
movb $0x1, %al
testl %r12d, %r12d
jne 0x5b67
cmpb $0x0, -0x2a(%rbp)
jne 0x5b67
movq 0x30(%rbx), %rcx
movq 0x8(%rcx,%r14), %r13
movzwl 0x2(%r13), %ecx
movzwl 0x4(%r13), %edx
shrl %edx
cmpw %dx, %cx
jae 0x5b67
movq -0x40(%rbp), %rdx
movq 0x30(%rdx), %rdx
movq 0x8(%rdx,%r14), %rbx
movzwl 0x2(%rbx), %edx
leal (%rdx,%rcx), %edi
movzwl 0x4(%rbx), %esi
cmpl %esi, %edi
ja 0x5b67
leaq 0xc(%rbx), %rsi
movq %rsi, -0x50(%rbp)
shll $0x2, %ecx
leaq (%rcx,%rcx,2), %rax
movq %rax, -0x58(%rbp)
movl %edi, -0x30(%rbp)
leaq (%rbx,%rax), %rdi
addq $0xc, %rdi
shll $0x2, %edx
leaq (%rdx,%rdx,2), %rdx
callq 0x2210
addq $0xc, %r13
movq -0x50(%rbp), %rdi
movq %r13, %rsi
movq -0x58(%rbp), %rdx
callq 0x2180
movl -0x30(%rbp), %eax
movw %ax, 0x2(%rbx)
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r14), %rdi
callq 0x2863
movl $0x2, %r8d
xorl %eax, %eax
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x5b8b
movl %r8d, %ebx
callq 0x4592
movl %ebx, %r8d
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %r13
movq -0x38(%rbp), %rbx
movl $0x5, %eax
testl %r12d, %r12d
jne 0x5c29
cmpl $0x2, %r8d
je 0x5bbb
cmpl $0x1, %r8d
jne 0x5c4a
testq %r13, %r13
jne 0x5bd1
jmp 0x5d02
testq %r13, %r13
je 0x5d21
movq %r13, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x4f25
movq %r13, %rdi
callq 0x4592
xorl %r12d, %r12d
movq 0x30(%rbx), %rax
movq 0x20(%rax,%r14), %rbx
movq 0x28(%rax,%r14), %rax
leaq (%rax,%rax,2), %r13
movq -0x38(%rbp), %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x445b
movl 0x10(%rbx,%r13,4), %eax
movzwl 0x14(%rbx,%r13,4), %esi
movq -0x38(%rbp), %rbx
shlq $0x20, %rsi
orq %rax, %rsi
movq %rbx, %rdi
callq *0x28(%rbx)
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x5d40
xorl %eax, %eax
testl %eax, %eax
jne 0x5c5d
incq %r15
movq -0x48(%rbp), %r13
cmpq %r13, %r15
setb %cl
addq $0x18, %r14
cmpq %r14, -0x60(%rbp)
jne 0x595c
jmp 0x5c70
testq %r13, %r13
jne 0x5ce3
xorl %r12d, %r12d
movl $0x2, %eax
jmp 0x5c29
cmpl $0x2, %eax
movq -0x48(%rbp), %r13
jne 0x5cd1
movb -0x29(%rbp), %cl
jmp 0x5c73
xorl %r12d, %r12d
jmp 0x5c73
movl %r13d, %r15d
testb $0x1, %cl
je 0x5c87
movq %rbx, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x4f25
jmp 0x5cd1
movq (%rbx), %rax
cmpw $0x0, 0x2(%rax)
je 0x5cb5
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x4fed
movl %eax, %r12d
testl %eax, %eax
jne 0x5cd1
movq %rbx, %rdi
callq 0x5e29
movl %eax, %r12d
jmp 0x5cd1
movw $0x0, 0x6(%rax)
movq %rbx, %rdi
callq *0x18(%rbx)
movq %rbx, %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x445b
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ebd(%rip), %rdi      # 0x7ba7
leaq 0x1d12(%rip), %rsi      # 0x7a03
leaq 0x1e81(%rip), %rcx      # 0x7b79
movl $0x989, %edx            # imm = 0x989
callq 0x20c0
leaq 0x1e9f(%rip), %rdi      # 0x7ba8
leaq 0x1cf3(%rip), %rsi      # 0x7a03
leaq 0x1e62(%rip), %rcx      # 0x7b79
movl $0x96a, %edx            # imm = 0x96A
callq 0x20c0
leaq 0x1e80(%rip), %rdi      # 0x7ba8
leaq 0x1cd4(%rip), %rsi      # 0x7a03
leaq 0x1e43(%rip), %rcx      # 0x7b79
movl $0x977, %edx            # imm = 0x977
callq 0x20c0