// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movq 0x30(%rdi), %rax
movq 0x8(%rax), %rcx
pushq $0x2
popq %r14
testq %rcx, %rcx
je 0x5889
movzwl 0x2(%rcx), %ecx
testq %rcx, %rcx
je 0x5889
movq 0x10(%rax), %rax
cmpq $-0x1, %rax
je 0x5889
cmpq %rcx, %rax
jge 0x5889
movq %rdi, %r15
movq (%rdi), %rax
movzwl 0x6(%rax), %ebx
xorl %esi, %esi
callq 0x58f8
movl %ebx, -0x50(%rbp)
movl %ebx, %eax
imulq $0x18, %rax, %rax
movq %rax, -0x58(%rbp)
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r15, -0x38(%rbp)
cmpq %r12, -0x58(%rbp)
je 0x5583
movq 0x30(%r15), %rax
movq 0x8(%rax,%r12), %rax
cmpw $0x0, 0x2(%rax)
je 0x5502
movl %r13d, -0x40(%rbp)
movl 0xc(%rax), %r13d
movq 0x10(%r15), %rdi
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x38(%r15), %rcx
callq 0x40b2
testq %rax, %rax
je 0x5885
movq %rax, %r15
subl $0x1, %r13d
movl $0x0, %eax
cmovbl %eax, %r13d
movq %r15, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x4299
testl %eax, %eax
jne 0x55b7
movq 0x30(%r15), %r14
movq (%r14,%r12), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r12), %rdx
cmpq 0x8(%rdx), %rcx
je 0x5415
movq 0x8(%rax,%r12), %rsi
movzwl 0x2(%rsi), %eax
movzwl 0x4(%rsi), %ecx
shrl %ecx
cmpw %cx, %ax
jae 0x5415
movq 0x8(%r14,%r12), %rbx
movzwl 0x2(%rbx), %ecx
leal (%rcx,%rax), %r13d
movzwl 0x4(%rbx), %edx
cmpl %edx, %r13d
jbe 0x554f
movq %r15, %rdi
callq 0x426f
andq $0x0, -0x48(%rbp)
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movl -0x40(%rbp), %esi
leaq -0x48(%rbp), %rdx
leaq -0x2a(%rbp), %rcx
callq 0x59f1
movl %eax, %r14d
testl %eax, %eax
jne 0x55c7
movq -0x48(%rbp), %rdi
cmpb $0x0, -0x2a(%rbp)
jne 0x55cb
movq 0x30(%rbx), %rax
movq 0x8(%rax,%r12), %r13
movzwl 0x2(%r13), %eax
movzwl 0x4(%r13), %ecx
shrl %ecx
cmpw %cx, %ax
jae 0x55d0
movq 0x30(%rdi), %rcx
movq 0x8(%rcx,%r12), %rbx
movzwl 0x2(%rbx), %ecx
leal (%rcx,%rax), %r15d
movzwl 0x4(%rbx), %edx
cmpl %edx, %r15d
ja 0x55d0
leaq 0xc(%rbx), %rsi
movq %rsi, -0x60(%rbp)
movl %eax, %eax
imulq $0xc, %rax, %r14
leaq (%rbx,%r14), %rdi
addq $0xc, %rdi
movl %ecx, %eax
imulq $0xc, %rax, %rdx
callq 0x2210
addq $0xc, %r13
movq -0x60(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2180
movw %r15w, 0x2(%rbx)
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r12), %rdi
callq 0x2710
movq -0x48(%rbp), %r15
testq %r15, %r15
je 0x589b
movq %r15, %rdi
movl -0x40(%rbp), %r13d
movl %r13d, %esi
xorl %edx, %edx
callq 0x4a98
movq %r15, %rdi
callq 0x426f
movq -0x38(%rbp), %r15
movq 0x30(%r15), %rax
movq 0x20(%rax,%r12), %rbx
imulq $0xc, 0x28(%rax,%r12), %r14
movq %r15, %rdi
movl %r13d, %esi
pushq $0x1
popq %rdx
callq 0x417f
movl 0x10(%rbx,%r14), %eax
movzwl 0x14(%rbx,%r14), %esi
shlq $0x20, %rsi
orq %rax, %rsi
movq %r15, %rdi
callq *0x28(%r15)
incl %r13d
movq %r15, %rdi
movl %r13d, %esi
callq 0x58f8
addq $0x18, %r12
jmp 0x5361
movl %ecx, %ecx
imulq $0xc, %rcx, %rcx
leaq (%rbx,%rcx), %rdi
addq $0xc, %rdi
addq $0xc, %rsi
movl %eax, %eax
imulq $0xc, %rax, %rdx
callq 0x2180
movw %r13w, 0x2(%rbx)
movq (%r14,%r12), %rdi
callq 0x2710
movl -0x40(%rbp), %r13d
jmp 0x54f6
movq (%r15), %rax
cmpw $0x0, 0x2(%rax)
je 0x55f4
pushq $0x1
popq %rdx
movq %r15, %rdi
movl -0x50(%rbp), %esi
callq 0x4b2c
testl %eax, %eax
jne 0x55af
leaq -0x29(%rbp), %rsi
movq %r15, %rdi
callq 0x5ac6
testl %eax, %eax
je 0x5616
movl %eax, %r14d
jmp 0x5889
movl %eax, %r14d
movq %r15, %rdi
callq 0x426f
jmp 0x5889
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x55d5
callq 0x426f
testl %r14d, %r14d
jne 0x5889
xorl %r14d, %r14d
movq -0x38(%rbp), %rdi
movl -0x40(%rbp), %esi
xorl %edx, %edx
callq 0x4a98
jmp 0x5889
andw $0x0, 0x6(%rax)
movq %r15, %rdi
callq *0x18(%r15)
pushq $0x1
popq %rdx
movq %r15, %rdi
movl -0x50(%rbp), %esi
callq 0x417f
xorl %r14d, %r14d
jmp 0x5889
leaq -0x29(%rbp), %r13
cmpb $0x1, -0x29(%rbp)
jne 0x560e
movq (%r15), %rsi
movzwl 0x6(%rsi), %r12d
testl %r12d, %r12d
je 0x5665
movq 0x8(%r15), %rdx
movq 0x10(%r15), %rdi
movq 0x38(%r15), %rcx
callq 0x40b2
testq %rax, %rax
je 0x5885
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4299
testl %eax, %eax
je 0x5670
movl %eax, %r14d
xorl %r12d, %r12d
jmp 0x584f
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0x584c
movq -0x38(%rbp), %rax
movq (%rax), %r14
movzwl 0x4(%r14), %eax
movl %eax, -0x60(%rbp)
movzwl 0x2(%r14), %r13d
pushq $0x1
popq %rdi
pushq $0x3c
popq %rsi
callq 0x2140
movq (%r14), %rcx
movq %rcx, (%rax)
movq %r14, -0x58(%rbp)
movl 0x8(%r14), %ecx
movl %ecx, 0x8(%rax)
movq %r12, -0x78(%rbp)
leal -0x1(%r12), %ecx
movq %rcx, -0x40(%rbp)
movw %cx, 0x6(%rax)
movq %rax, -0x70(%rbp)
movq %rax, %rdi
addq $0xc, %rdi
xorl %r14d, %r14d
movl %r13d, -0x64(%rbp)
movl %r13d, %r12d
pushq $-0x1
popq %rax
movq %rax, -0x50(%rbp)
subl $0x1, %r12d
jb 0x5767
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x40(%rbp), %rcx
movq (%rax,%rcx), %rdx
movq 0x30(%r15), %rsi
movq (%rsi,%rcx), %rsi
movq 0x8(%rsi), %rsi
cmpq 0x8(%rdx), %rsi
jne 0x5709
leaq (%rax,%rcx), %rdx
movl %r14d, %esi
addq 0x10(%rdx), %rsi
movq %rsi, -0x50(%rbp)
movq 0x8(%rax,%rcx), %rsi
movzwl 0x2(%rsi), %eax
addl %eax, %r14d
cmpl -0x60(%rbp), %r14d
ja 0x58ba
addq $0xc, %rsi
imulq $0xc, %rax, %r13
movq %rdi, %rbx
movq %r13, %rdx
callq 0x2180
movq %r15, %rdi
movq -0x40(%rbp), %rsi
leaq -0x48(%rbp), %rdx
leaq -0x2a(%rbp), %rcx
callq 0x59f1
testl %eax, %eax
jne 0x576d
movq %r15, %rdi
callq 0x426f
movq -0x48(%rbp), %r15
cmpb $0x1, -0x2a(%rbp)
je 0x577d
movq %rbx, %rdi
addq %r13, %rdi
jmp 0x56cd
leaq -0x29(%rbp), %r13
jmp 0x5791
movl %eax, %r14d
movq -0x70(%rbp), %r12
leaq -0x29(%rbp), %r13
jmp 0x584f
testq %r15, %r15
je 0x578a
movq %r15, %rdi
callq 0x426f
leaq -0x29(%rbp), %r13
xorl %r15d, %r15d
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
pushq $0x2
popq %rdx
callq 0x417f
movl -0x64(%rbp), %eax
imulq $0xc, %rax, %rbx
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x57d3
movq -0x58(%rbp), %rcx
movl 0x10(%rcx,%r12), %eax
movzwl 0x14(%rcx,%r12), %esi
shlq $0x20, %rsi
orq %rax, %rsi
movq -0x38(%rbp), %rdi
callq *0x28(%rdi)
addq $0xc, %r12
jmp 0x57ab
movq -0x70(%rbp), %r12
movw %r14w, 0x2(%r12)
movups 0x10(%r12), %xmm0
movups 0x20(%r12), %xmm1
movups 0x2c(%r12), %xmm2
movq -0x58(%rbp), %rcx
movups %xmm2, 0x2c(%rcx)
movups %xmm1, 0x20(%rcx)
movups %xmm0, 0x10(%rcx)
movzwl (%r12), %eax
movw %ax, (%rcx)
movzwl 0x2(%r12), %eax
movw %ax, 0x2(%rcx)
movq 0x4(%r12), %rax
movq %rax, 0x4(%rcx)
movl 0xc(%r12), %eax
movl %eax, 0xc(%rcx)
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x525f
movq -0x50(%rbp), %rdx
cmpq $-0x1, %rdx
je 0x58d9
movq 0x30(%rbx), %rax
movl -0x78(%rbp), %ecx
imulq $0x18, %rcx, %rcx
movq %rdx, -0x8(%rax,%rcx)
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x2030
testq %r15, %r15
je 0x5864
movq %r15, %rdi
callq 0x426f
testl %r14d, %r14d
jne 0x5889
movq -0x38(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x5ac6
testl %eax, %eax
je 0x561a
jmp 0x55af
pushq $0xc
popq %r14
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12af(%rip), %rdi      # 0x6b51
leaq 0x1132(%rip), %rsi      # 0x69db
leaq 0x12a6(%rip), %rcx      # 0x6b56
movl $0x977, %edx            # imm = 0x977
callq 0x20c0
leaq 0x158b(%rip), %rdi      # 0x6e4c
leaq 0x1113(%rip), %rsi      # 0x69db
leaq 0x1594(%rip), %rcx      # 0x6e63
movl $0x727, %edx            # imm = 0x727
callq 0x20c0
leaq 0x15b3(%rip), %rdi      # 0x6e93
leaq 0x10f4(%rip), %rsi      # 0x69db
leaq 0x1575(%rip), %rcx      # 0x6e63
movl $0x744, %edx            # imm = 0x744
callq 0x20c0