// File: /workspace/github_c_makefile_star2_O0/ngkaho1234[P]ext4-extents-tree/extents.c
// Function: ext4_ext_delete_leaf
static int
ext4_ext_delete_leaf(struct ext4_ext_cursor *cur,
		     ext4_lblk_t tolblk,
		     int *stopp)
{
	int ret = 0;
	ssize_t ptr;
	int rootdepth;
	uint16_t nritems;
	struct ext4_extent *ext;
	struct ext4_extent_header *hdr;

	rootdepth = ext4_ext_cursor_depth(cur);
	*stopp = 0;

	while (1) {
		bool unwritten;
		ext4_extlen_t len;
		ext4_extlen_t flen;
		ext4_lblk_t endlblk;
		ext4_lblk_t startlblk;
		ext4_fsblk_t blocknr;

		ptr = cur->c_paths[0].p_ptr;
		hdr = cur->c_paths[0].p_hdr;
		nritems = ext4_ext_header_entries(hdr);

		ext4_assert(nritems > 0);

		ext = EXT_FIRST_EXTENT(hdr) + ptr;
		blocknr = ext4_ext_block(ext);
		startlblk = ext4_ext_lblock(ext);
		endlblk = startlblk + ext4_ext_len(ext) - 1;
		len = endlblk - startlblk + 1;
		unwritten = ext4_ext_is_unwritten(ext);

		/*
		 * We have to stop if the extent's key
		 * is greater than @tolblk.
		 */
		if (tolblk < startlblk) {
			*stopp = 1;
			break;
		}

		if (tolblk < endlblk) {
			/*
			 * In case @tolblk is smaller than the last
			 * logical block of the extent, we do not
			 * need to delete the extent. We modify it only.
			 */

			/*
			 * TODO: Unmap the underlying blocks!
			 */
			flen = tolblk - startlblk + 1;

			/*
			 * Adjust the starting block and length of the
			 * current extent.
			 */
			blocknr += flen;
			startlblk = tolblk + 1;
			len = endlblk - startlblk + 1;
			ext4_ext_store_lblock(ext, startlblk);
			ext4_ext_store_len(ext, len, unwritten);
			ext4_ext_store_block(ext, blocknr);

			if (!rootdepth)
				cur->c_cursor_op.c_root_dirty_func(cur);
			else
				fs_mark_buffer_dirty(cur->c_paths[0].p_bcb);

			*stopp = 1;
			break;
		}

		/*
		 * Delete the extent pointed to by the path.
		 */
		ext4_ext_delete_item(cur, 0);
		nritems--;

		/*
		 * TODO: Unmap the underlying blocks!
		 */
		flen = len;

		/*
		 * There are no more items we could delete.
		 */
		if (ptr >= nritems)
			break;
	}
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6720
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x69a0
movw %ax, -0x2e(%rbp)
movzwl -0x2e(%rbp), %eax
cmpl $0x0, %eax
jle 0x7e48
jmp 0x7e67
leaq 0x2e98(%rip), %rdi      # 0xace7
leaq 0x2b85(%rip), %rsi      # 0xa9db
movl $0x797, %edx            # imm = 0x797
leaq 0x2e91(%rip), %rcx      # 0xacf3
callq 0x20c0
movq -0x40(%rbp), %rax
addq $0xc, %rax
imulq $0xc, -0x28(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x7d40
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rdi
callq 0x69c0
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x38(%rbp), %rdi
callq 0x69d0
movw %ax, %cx
movl -0x5c(%rbp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
subl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
subl -0x50(%rbp), %eax
addl $0x1, %eax
movw %ax, -0x44(%rbp)
movq -0x38(%rbp), %rdi
callq 0x7ce0
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x41(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x7eec
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x7fbd
movl -0xc(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x7f8a
movl -0xc(%rbp), %eax
subl -0x50(%rbp), %eax
addl $0x1, %eax
movw %ax, -0x46(%rbp)
movzwl -0x46(%rbp), %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
subl -0x50(%rbp), %eax
addl $0x1, %eax
movw %ax, -0x44(%rbp)
movq -0x38(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0x7d70
movq -0x38(%rbp), %rdi
movw -0x44(%rbp), %cx
movb -0x41(%rbp), %al
andb $0x1, %al
movzwl %cx, %esi
movzbl %al, %edx
callq 0x7d00
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x7d90
cmpl $0x0, -0x2c(%rbp)
jne 0x7f6e
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rdi
callq *%rax
jmp 0x7f7e
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdi
callq 0x29b0
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x7fbd
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x84d0
movw -0x2e(%rbp), %ax
addw $-0x1, %ax
movw %ax, -0x2e(%rbp)
movw -0x44(%rbp), %ax
movw %ax, -0x46(%rbp)
movq -0x28(%rbp), %rax
movzwl -0x2e(%rbp), %ecx
cmpq %rcx, %rax
jl 0x7fb8
jmp 0x7fbd
jmp 0x7e10
movl -0x1c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)