// File: /workspace/github_c_makefile_star2_O3/ngkaho1234[P]ext4-extents-tree/exttraverse.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;
	bool notfound;
	struct ext4_ext_cursor *cur;

	if (argc < 4)
		return EXIT_FAILURE;

	from = strtoul(argv[2], NULL, 0);
	dir = atoi(argv[3]);
	if (dir != 1 && dir != -1)
		return EXIT_FAILURE;

	a = clock();
	inode = open_ext4_db(argv[1]);

	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);
		return EXIT_FAILURE;
	}
	if (notfound) {
		fprintf(stderr, "Block: %" PRIu32 " not found\n", from);
		return EXIT_FAILURE;
	}

	while (1) {
		struct ext4_extent *ext;
		if (dir == -1) {
			bool noprev;
			err = ext4_ext_decrement(cur, &noprev);
			if (err || noprev)
				break;
		} else {
			bool nonext;
			err = ext4_ext_increment(cur, &nonext);
			if (err || nonext)
				break;
		}
		ext = ext4_ext_cursor_ext(cur);
		printf("Extents start: %" PRIu32 " len: %" PRIu16 "\n",
				ext4_ext_lblk(ext), ext4_ext_len(ext));
	}
	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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0x1, %ebx
cmpl $0x4, %edi
jl 0x24d1
movq %rsi, %r14
movq 0x10(%rsi), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
movq %rax, %r15
movq 0x18(%r14), %rdi
callq 0x2240
movl %eax, %r12d
cmpl $0x1, %eax
je 0x24e2
cmpl $-0x1, %r12d
je 0x24e2
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, -0x40(%rbp)
callq 0x2090
movq %rax, -0x38(%rbp)
movq 0x8(%r14), %rdi
callq 0x289a
movl %eax, %edi
movl $0xc, %esi
callq 0x28c7
movq %rax, %r15
movq 0x10(%rax), %r13
movl $0x1, %edi
movl $0x80, %esi
callq 0x2140
movq %rax, %r14
movq %r13, (%rax)
leaq 0x251(%rip), %rax       # 0x2778
movq %rax, 0x78(%r14)
leaq 0x8(%r14), %rsi
movaps 0x4ada(%rip), %xmm0     # 0x7010
movups %xmm0, 0x8(%r14)
leaq 0x20(%r14), %r13
movl $0x2d, 0x20(%r14)
movl $0x10, %edx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3bb8
movl %eax, 0x28(%r14)
movl $0x4, %edx
movl %eax, %edi
movq %r13, %rsi
callq 0x3bb8
movl %eax, 0x28(%r14)
leaq 0x24(%r14), %rsi
movl $0x4, %edx
movl %eax, %edi
callq 0x3bb8
movl %eax, 0x28(%r14)
movq %r15, %rdi
callq 0x3365
testq %rax, %rax
je 0x271b
movq (%r14), %rdi
callq 0x41ac
movq %rax, %r13
movq %r14, %r15
addq $0x38, %r15
movq 0x10(%rax), %rax
movups 0x14(%rax), %xmm0
movups 0x24(%rax), %xmm1
movups 0x34(%rax), %xmm2
movups 0x40(%rax), %xmm3
movups %xmm0, 0x38(%r14)
movups %xmm1, 0x48(%r14)
movups %xmm2, 0x58(%r14)
movups %xmm3, 0x64(%r14)
cmpw $0xf30a, 0x38(%r14)     # imm = 0xF30A
je 0x25e2
movq %r15, %rdi
callq 0x5e08
orb $0x1, 0x74(%r14)
movq %r13, 0x18(%r14)
movq (%r14), %rdi
movq (%rdi), %rcx
movq %r15, %rsi
movq %r14, %rdx
callq 0x431b
movq %rax, %r15
leaq -0x2b(%rbp), %rdx
movq %rax, %rdi
movq -0x40(%rbp), %r13
movl %r13d, %esi
callq 0x455d
testl %eax, %eax
jne 0x2637
cmpb $0x0, -0x2b(%rbp)
je 0x266c
movq 0x89da(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x4a0c(%rip), %rsi      # 0x7034
movl %r13d, %edx
xorl %eax, %eax
callq 0x2160
jmp 0x24d1
movq 0x89ba(%rip), %rcx      # 0xaff8
movq (%rcx), %r14
movl %eax, %edi
callq 0x2290
leaq 0x49d1(%rip), %rsi      # 0x7020
movq %r14, %rdi
movq %rax, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2160
movq %r15, %rdi
callq 0x452e
jmp 0x24d1
leaq -0x29(%rbp), %r13
movq %r15, %rdi
cmpl $-0x1, %r12d
jne 0x268e
leaq -0x2a(%rbp), %rsi
callq 0x50a2
testl %eax, %eax
jne 0x26aa
cmpb $0x0, -0x2a(%rbp)
je 0x26a0
jmp 0x26ae
movq %r13, %rsi
callq 0x5104
testl %eax, %eax
jne 0x26aa
cmpb $0x0, -0x29(%rbp)
jne 0x26ae
movq %r15, %rdi
callq 0x22e0
jmp 0x2670
movl %eax, %ebx
jmp 0x26b0
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x452e
callq 0x2090
movq %rax, %r15
movq 0x8931(%rip), %rax      # 0xaff8
movq (%rax), %r12
negl %ebx
movl %ebx, %edi
callq 0x2290
movq %rax, %r8
subq -0x38(%rbp), %r15
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
movq %r15, %rax
imulq %rcx
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0x12, %rdx
addq %rdx, %rcx
leaq 0x4965(%rip), %rsi      # 0x7064
xorl %ebx, %ebx
movq %r12, %rdi
movq %r8, %rdx
xorl %eax, %eax
callq 0x2160
movq %r14, %rdi
callq 0x2725
jmp 0x24d1
movl $0x1, %edi
callq 0x2260