// File: /workspace/github_c_makefile_star2_O0/ngkaho1234[P]ext4-extents-tree/extrm.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;

	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]);
	for (; (int32_t)(to - from) * dir >= 0; from += 1 * dir) {
		bool notfound;
		struct ext4_ext_cursor *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);
			ext4_ext_cursor_free(cur);
			break;
		}

		if (!notfound) {
			fprintf(stderr, "Removing extent containing block: %" PRIu32 "\n", from);
			err = ext4_ext_delete(cur);
			if (err) {
				fprintf(stderr, "err: %s, block: %" PRIu32 "\n",
						strerror(err), from);
				ext4_ext_cursor_free(cur);
				break;
			}
		}
		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 0x25c3
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 0x25d0
movq %rax, -0x20(%rbp)
movl -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
imull -0x14(%rbp), %eax
cmpl $0x0, %eax
jl 0x2563
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 0x61e0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x39(%rbp), %rdx
callq 0x6570
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x24db
movq 0xbb52(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movl -0x18(%rbp), %edi
callq 0x2280
movq -0x50(%rbp), %rdi
movq %rax, %rdx
movl -0x34(%rbp), %ecx
leaq 0x7b3e(%rip), %rsi      # 0xa004
movb $0x0, %al
callq 0x2160
movq -0x48(%rbp), %rdi
callq 0x6530
jmp 0x2563
testb $0x1, -0x39(%rbp)
jne 0x2549
movq 0xbb10(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movl -0x34(%rbp), %edx
leaq 0x7b23(%rip), %rsi      # 0xa018
movb $0x0, %al
callq 0x2160
movq -0x48(%rbp), %rdi
callq 0x8280
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x2547
movq 0xbae3(%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 0x7acf(%rip), %rsi      # 0xa004
movb $0x0, %al
callq 0x2160
movq -0x48(%rbp), %rdi
callq 0x6530
jmp 0x2563
jmp 0x2549
movq -0x48(%rbp), %rdi
callq 0x6530
movl -0x14(%rbp), %eax
shll $0x0, %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x244d
callq 0x2090
movq %rax, -0x30(%rbp)
movq 0xba85(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x68(%rbp)
xorl %edi, %edi
subl -0x18(%rbp), %edi
callq 0x2280
movq -0x68(%rbp), %rdi
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
subq -0x28(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
movq -0x60(%rbp), %rdx
movq %rax, %rcx
leaq 0x7a92(%rip), %rsi      # 0xa03e
movb $0x0, %al
callq 0x2160
movq -0x20(%rbp), %rdi
callq 0x2730
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)