// File: /workspace/github_c_makefile_star2_O3/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 0x593c
movzwl 0x2(%rcx), %ecx
testq %rcx, %rcx
je 0x593c
movq 0x10(%rax), %rax
cmpq $-0x1, %rax
je 0x593c
cmpq %rcx, %rax
jge 0x593c
movq %rdi, %r13
movq (%rdi), %rax
movzwl 0x6(%rax), %ebx
xorl %esi, %esi
callq 0x596d
movq %rbx, -0x48(%rbp)
testl %ebx, %ebx
je 0x58b3
movq -0x48(%rbp), %rax
leal (,%rax,8), %eax
leaq (%rax,%rax,2), %rax
movq %rax, -0x58(%rbp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r13, -0x40(%rbp)
movq 0x30(%r13), %rax
movq 0x8(%rax,%r15), %rax
cmpw $0x0, 0x2(%rax)
je 0x5825
movl %r12d, -0x30(%rbp)
movl 0xc(%rax), %r12d
movq 0x10(%r13), %rdi
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq 0x38(%r13), %rcx
callq 0x427f
testq %rax, %rax
je 0x5903
movq %rax, %r13
subl $0x1, %r12d
movl $0x0, %eax
cmovbl %eax, %r12d
movq %r13, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x44c1
testl %eax, %eax
jne 0x590b
movq 0x30(%r13), %r14
movq (%r14,%r15), %rax
movq 0x8(%rax), %rcx
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r15), %rdx
cmpq 0x8(%rdx), %rcx
je 0x5733
movq 0x8(%rax,%r15), %rsi
movzwl 0x2(%rsi), %eax
movzwl 0x4(%rsi), %ecx
shrl %ecx
cmpw %cx, %ax
jae 0x5733
movq 0x8(%r14,%r15), %rbx
movzwl 0x2(%rbx), %ecx
leal (%rcx,%rax), %r12d
movzwl 0x4(%rbx), %edx
cmpl %edx, %r12d
jbe 0x587e
movq %r13, %rdi
callq 0x4492
movq $0x0, -0x38(%rbp)
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
movl -0x30(%rbp), %esi
leaq -0x38(%rbp), %rdx
leaq -0x29(%rbp), %rcx
callq 0x5d86
movl %eax, %r12d
testl %eax, %eax
jne 0x5918
movq -0x38(%rbp), %rdi
cmpb $0x0, -0x29(%rbp)
jne 0x591c
movq 0x30(%rbx), %rax
movq 0x8(%rax,%r15), %r13
movzwl 0x2(%r13), %eax
movzwl 0x4(%r13), %ecx
shrl %ecx
cmpw %cx, %ax
jae 0x5921
movq 0x30(%rdi), %rcx
movq 0x8(%rcx,%r15), %r14
movzwl 0x2(%r14), %ecx
leal (%rcx,%rax), %ebx
movzwl 0x4(%r14), %edx
cmpl %edx, %ebx
ja 0x5921
leaq 0xc(%r14), %rsi
movq %rsi, -0x50(%rbp)
shll $0x2, %eax
leaq (%rax,%rax,2), %r12
leaq (%r14,%r12), %rdi
addq $0xc, %rdi
shll $0x2, %ecx
leaq (%rcx,%rcx,2), %rdx
callq 0x2210
addq $0xc, %r13
movq -0x50(%rbp), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2180
movw %bx, 0x2(%r14)
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r15), %rdi
callq 0x27b8
movq -0x38(%rbp), %r13
testq %r13, %r13
je 0x594e
movq %r13, %rdi
movl -0x30(%rbp), %r12d
movl %r12d, %esi
xorl %edx, %edx
callq 0x4d52
movq %r13, %rdi
callq 0x4492
movq -0x40(%rbp), %r13
movq 0x30(%r13), %rax
movq 0x20(%rax,%r15), %rbx
movq 0x28(%rax,%r15), %rax
leaq (%rax,%rax,2), %r14
movq %r13, %rdi
movl %r12d, %esi
movl $0x1, %edx
callq 0x435b
movl 0x10(%rbx,%r14,4), %eax
movzwl 0x14(%rbx,%r14,4), %esi
shlq $0x20, %rsi
orq %rax, %rsi
movq %r13, %rdi
callq *0x28(%r13)
incl %r12d
movq %r13, %rdi
movl %r12d, %esi
callq 0x596d
addq $0x18, %r15
cmpq %r15, -0x58(%rbp)
jne 0x5688
jmp 0x58b3
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rbx,%rcx,4), %rdi
addq $0xc, %rdi
addq $0xc, %rsi
shll $0x2, %eax
leaq (%rax,%rax,2), %rdx
callq 0x2180
movw %r12w, 0x2(%rbx)
movq (%r14,%r15), %rdi
callq 0x27b8
movl -0x30(%rbp), %r12d
jmp 0x5819
movq (%r13), %rax
cmpw $0x0, 0x2(%rax)
je 0x58e0
movq %r13, %rdi
movq -0x48(%rbp), %rsi
movl $0x1, %edx
callq 0x4e4e
testl %eax, %eax
jne 0x58db
movq %r13, %rdi
callq 0x5a56
movl %eax, %r12d
jmp 0x593c
movw $0x0, 0x6(%rax)
movq %r13, %rdi
callq *0x18(%r13)
movq %r13, %rdi
movq -0x48(%rbp), %rsi
movl $0x1, %edx
callq 0x435b
xorl %r12d, %r12d
jmp 0x593c
movl $0xc, %r12d
jmp 0x593c
movl %eax, %r12d
movq %r13, %rdi
callq 0x4492
jmp 0x593c
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x5926
callq 0x4492
testl %r12d, %r12d
jne 0x593c
xorl %r12d, %r12d
movq -0x40(%rbp), %rdi
movl -0x30(%rbp), %esi
xorl %edx, %edx
callq 0x4d52
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x120c(%rip), %rdi      # 0x6b61
leaq 0x108f(%rip), %rsi      # 0x69eb
leaq 0x1203(%rip), %rcx      # 0x6b66
movl $0x977, %edx            # imm = 0x977
callq 0x20c0