// File: /workspace/github_c_makefile_star2_O0/ngkaho1234[P]ext4-extents-tree/extents.c
// Function: _ext4_ext_shrink
static int
__ext4_ext_shrink(struct ext4_ext_cursor *cur)
{
	int ret = 0;
	int i = 0;
	ssize_t ptr = -1;
	int maxnritems;
	int tnritems = 0;
	int nritems;
	struct ext4_extent_header *hdr;
	struct ext4_extent_header *thdr = NULL;
	int rootdepth;
	struct ext4_ext_cursor *ncur = NULL;
	union ext4_extent_item *titemp;
	struct ext4_extent_idx *idx;

	rootdepth = ext4_ext_cursor_depth(cur);
	if (!rootdepth)
		goto out;

	ncur = ext4_ext_cursor_alloc(cur->c_superblock, cur->c_root,
				     cur->c_fsinfo, cur->c_blocksz);
	if (!ncur)
		return ENOMEM;

	ret = ext4_ext_lookup_extent(ncur, 0, NULL);
	if (ret)
		goto out;

	hdr = cur->c_root;
	maxnritems = ext4_ext_header_max_entries(hdr);
	nritems = ext4_ext_header_entries(hdr);

	thdr = ext4_zalloc(EXT4_EXT_ROOT_SIZE);
	memcpy(thdr, hdr, sizeof(struct ext4_extent_header));
	ext4_ext_header_set_depth(thdr, rootdepth - 1);

	idx = EXT_FIRST_INDEX(hdr);
	titemp = EXT_FIRST_ITEM(thdr);

	for (i = 0; i < nritems; i++) {
		bool nosib;
		int nnritems;
		struct ext4_ext_cursor *tcur;
		struct ext4_extent_header *nhdr;
		union ext4_extent_item *nitemp;

		nhdr = cur->c_paths[rootdepth - 1].p_hdr;
		nitemp = EXT_FIRST_ITEM(nhdr);

		if (ext4_buf_blocknr(ncur->c_paths[rootdepth - 1].p_bcb) ==
		    ext4_buf_blocknr(cur->c_paths[rootdepth - 1].p_bcb)) {
			ptr = tnritems + cur->c_paths[rootdepth - 1].p_ptr;
		}

		nnritems = ext4_ext_header_entries(nhdr);
		tnritems += nnritems;
		ext4_assert(tnritems <= maxnritems);
		memcpy(titemp, nitemp, EXT4_EXT_ITEM_SIZE * nnritems);
		titemp += nnritems;

		ret =
		    ext4_ext_right_sibling(ncur, rootdepth - 1, &tcur, &nosib);
		if (ret)
			goto out;
		ext4_ext_cursor_free(ncur);
		ncur = NULL;
		if (nosib) {
			if (tcur)
				ext4_ext_cursor_free(tcur);
			break;
		}

		ncur = tcur;
	}
	ext4_ext_cursor_unpin(cur, rootdepth - 1, 2);

	for (i = 0; i < nritems; i++)
		cur->c_cursor_op.c_free_block_func(cur,
						   ext4_idx_block(idx + i));

	ext4_ext_header_set_entries(thdr, tnritems);
	memcpy(hdr, thdr, EXT4_EXT_ROOT_SIZE);

	rootdepth--;
	ext4_ext_cursor_reset_rootpath(cur);
	ext4_assert(ptr != -1);
	cur->c_paths[rootdepth].p_ptr = ptr;

out:
	if (thdr)
		ext4_free(thdr);
	if (ncur)
		ext4_ext_cursor_free(ncur);
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq $-0x1, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6720
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x9823
jmp 0x9b49
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
callq 0x6120
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x985e
movl $0xc, -0x4(%rbp)
jmp 0x9b6f
movq -0x50(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x64b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x987b
jmp 0x9b49
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x9430
movzwl %ax, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rdi
callq 0x69a0
movzwl %ax, %eax
movl %eax, -0x2c(%rbp)
movl $0x1, %edi
movl $0x3c, %esi
callq 0x2140
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rdi
movl -0x44(%rbp), %esi
subl $0x1, %esi
callq 0x80a0
movq -0x38(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x9a64
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x80(%rbp)
movq -0x50(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movl -0x44(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x9995
movslq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movl -0x44(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x20(%rbp)
movq -0x78(%rbp), %rdi
callq 0x69a0
movzwl %ax, %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jg 0x99b7
jmp 0x99d6
leaq 0x14ec(%rip), %rdi      # 0xaeaa
leaq 0x1016(%rip), %rsi      # 0xa9db
movl $0x727, %edx            # imm = 0x727
leaq 0x14f0(%rip), %rcx      # 0xaec1
callq 0x20c0
movq -0x58(%rbp), %rdi
movq -0x80(%rbp), %rsi
movslq -0x68(%rbp), %rax
imulq $0xc, %rax, %rdx
callq 0x2180
movl -0x68(%rbp), %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movl -0x44(%rbp), %esi
subl $0x1, %esi
leaq -0x70(%rbp), %rdx
leaq -0x61(%rbp), %rcx
callq 0x9450
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x9a25
jmp 0x9b49
movq -0x50(%rbp), %rdi
callq 0x6470
movq $0x0, -0x50(%rbp)
testb $0x1, -0x61(%rbp)
je 0x9a4e
cmpq $0x0, -0x70(%rbp)
je 0x9a4c
movq -0x70(%rbp), %rdi
callq 0x6470
jmp 0x9a64
movq -0x70(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x98f9
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
subl $0x1, %esi
movl $0x2, %edx
callq 0x62d0
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x9ad3
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x60(%rbp), %rdi
movslq -0x18(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
callq 0x6970
movq -0x90(%rbp), %rdi
movq %rax, %rsi
movq -0x88(%rbp), %rax
callq *%rax
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9a7f
movq -0x40(%rbp), %rdi
movl -0x28(%rbp), %eax
movzwl %ax, %esi
callq 0x87e0
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x3c, %edx
callq 0x2180
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rdi
callq 0x80c0
cmpq $-0x1, -0x20(%rbp)
je 0x9b0f
jmp 0x9b2e
leaq 0x13db(%rip), %rdi      # 0xaef1
leaq 0xebe(%rip), %rsi       # 0xa9db
movl $0x744, %edx            # imm = 0x744
leaq 0x1398(%rip), %rcx      # 0xaec1
callq 0x20c0
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x44(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, -0x40(%rbp)
je 0x9b59
movq -0x40(%rbp), %rdi
callq 0x2030
cmpq $0x0, -0x50(%rbp)
je 0x9b69
movq -0x50(%rbp), %rdi
callq 0x6470
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq