// File: /workspace/github_c_makefile_star2_O0/ngkaho1234[P]ext4-extents-tree/extrm-ranged.c
// Function: main
int main(int argc, char **argv)
{
	int dir;
	int err = 0;
	struct inode *inode;
	time_t a, b;
	ext4_lblk_t from, to;
	bool notfound;
	struct ext4_ext_cursor *cur;

	if (argc < 4)
		return -1;

	from = strtoul(argv[2], NULL, 0);
	to = strtoul(argv[3], NULL, 0);
	dir = (to > from)?1:-1;
	a = clock();
	inode = open_ext4_db(argv[1]);

	if (dir == -1) {
		ext4_lblk_t tmp = to;
		to = from;
		from = tmp;
	}

	cur = ext4_ext_cursor_alloc(inode->i_sb, inode->i_data, inode, inode->i_sb->s_blocksize);

	err = ext4_ext_lookup_extent(cur, from, &notfound);
	if (err) {
		fprintf(stderr, "err: %s, block: %" PRIu32 "\n",
				strerror(err), from);
		goto out;
	}

	if (!notfound) {
		fprintf(stderr, "Removing extent containing block: %" PRIu32 " - %" PRIu32 "\n",
			from, to);
		err = ext4_ext_delete_range(cur, from, to);
		if (err) {
			fprintf(stderr, "err: %s, block: %" PRIu32 "\n",
					strerror(err), from);
		}
	}

out:
	ext4_ext_cursor_free(cur);

	b = clock();
	fprintf(stderr, "err: %s, clock: %ld\n", strerror(-err), (b - a)/CLOCKS_PER_SEC);
	free_ext4_db(inode);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x23ef
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x25ab
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2230
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2230
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %edx
movl -0x34(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmoval %ecx, %eax
movl %eax, -0x14(%rbp)
callq 0x2090
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x25c0
movq %rax, -0x20(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x2465
movl -0x38(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x38, %rsi
movq -0x20(%rbp), %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
callq 0x61d0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x39(%rbp), %rdx
callq 0x6560
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x24d4
movq 0xbb4d(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x18(%rbp), %edi
callq 0x2280
movq -0x58(%rbp), %rdi
movq %rax, %rdx
movl -0x34(%rbp), %ecx
leaq 0x7b39(%rip), %rsi      # 0xa004
movb $0x0, %al
callq 0x2160
jmp 0x2542
testb $0x1, -0x39(%rbp)
jne 0x2540
movq 0xbb17(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movl -0x34(%rbp), %edx
movl -0x38(%rbp), %ecx
leaq 0x7b27(%rip), %rsi      # 0xa018
movb $0x0, %al
callq 0x2160
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
callq 0x7870
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x253e
movq 0xbae1(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movl -0x18(%rbp), %edi
callq 0x2280
movq -0x60(%rbp), %rdi
movq %rax, %rdx
movl -0x34(%rbp), %ecx
leaq 0x7acd(%rip), %rsi      # 0xa004
movb $0x0, %al
callq 0x2160
jmp 0x2540
jmp 0x2542
movq -0x48(%rbp), %rdi
callq 0x6520
callq 0x2090
movq %rax, -0x30(%rbp)
movq 0xba9d(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x70(%rbp)
xorl %edi, %edi
subl -0x18(%rbp), %edi
callq 0x2280
movq -0x70(%rbp), %rdi
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
subq -0x28(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
movq -0x68(%rbp), %rdx
movq %rax, %rcx
leaq 0x7aaf(%rip), %rsi      # 0xa043
movb $0x0, %al
callq 0x2160
movq -0x20(%rbp), %rdi
callq 0x2720
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)