// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
pushq $0x1
popq %rbx
cmpl $0x4, %edi
jl 0x240f
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 0x2420
cmpl $-0x1, %r12d
je 0x2420
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, -0x48(%rbp)
callq 0x2090
movq %rax, -0x40(%rbp)
movq 0x8(%r14), %rdi
callq 0x27d2
pushq $0xc
popq %rsi
movl %eax, %edi
callq 0x27fd
movq %rax, %r13
movq 0x10(%rax), %r15
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0x2140
movq %rax, %r14
movq %r15, (%rax)
leaq 0x250(%rip), %rax       # 0x26b1
movq %rax, 0x78(%r14)
leaq 0x8(%r14), %rsi
movaps 0x3ba0(%rip), %xmm0     # 0x6010
movups %xmm0, 0x8(%r14)
leaq 0x20(%r14), %r15
movl $0x2d, 0x20(%r14)
pushq $-0x1
popq %rdi
pushq $0x10
popq %rdx
callq 0x3abc
movl %eax, 0x28(%r14)
pushq $0x4
popq %rdx
movl %eax, %edi
movq %r15, %rsi
movq %rdx, %r15
callq 0x3abc
movl %eax, 0x28(%r14)
leaq 0x24(%r14), %rsi
movl %eax, %edi
movq %r15, %rdx
callq 0x3abc
movl %eax, 0x28(%r14)
movq %r13, %rdi
callq 0x3293
testq %rax, %rax
je 0x26a9
movq (%r14), %rdi
callq 0x3fd0
movq %rax, %r15
movq %r14, %r13
addq $0x38, %r13
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 0x2517
movq %r13, %rdi
callq 0x5a5a
orb $0x1, 0x74(%r14)
movq %r15, 0x18(%r14)
movq (%r14), %rdi
movq (%rdi), %rcx
movq %r13, %rsi
movq %r14, -0x38(%rbp)
movq %r14, %rdx
callq 0x4132
movq %rax, %r15
leaq -0x2b(%rbp), %rdx
movq %rax, %rdi
movq -0x48(%rbp), %r13
movl %r13d, %esi
callq 0x4319
testl %eax, %eax
jne 0x2570
cmpb $0x0, -0x2b(%rbp)
je 0x25a5
movq 0x7aa1(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x3ad3(%rip), %rsi      # 0x6034
movl %r13d, %edx
xorl %eax, %eax
callq 0x2160
jmp 0x240f
movq 0x7a81(%rip), %rcx      # 0x9ff8
movq (%rcx), %r14
movl %eax, %edi
callq 0x2290
leaq 0x3a98(%rip), %rsi      # 0x6020
movq %r14, %rdi
movq %rax, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2160
movq %r15, %rdi
callq 0x42ef
jmp 0x240f
leaq 0x3a9d(%rip), %r13      # 0x6049
leaq -0x29(%rbp), %r14
movq %r15, %rdi
cmpl $-0x1, %r12d
je 0x25cd
movq %r14, %rsi
callq 0x4da4
testl %eax, %eax
jne 0x2609
cmpb $0x0, -0x29(%rbp)
je 0x25e0
jmp 0x260d
leaq -0x2a(%rbp), %rsi
callq 0x4d42
testl %eax, %eax
jne 0x2609
cmpb $0x0, -0x2a(%rbp)
jne 0x260d
movq %r15, %rdi
callq 0x4555
movl (%rax), %esi
movzwl 0x4(%rax), %eax
movl %eax, %edx
andl $0x7fff, %edx           # imm = 0x7FFF
cmpw $0x8001, %ax            # imm = 0x8001
cmovbl %eax, %edx
movq %r13, %rdi
xorl %eax, %eax
callq 0x20a0
jmp 0x25b0
movl %eax, %ebx
jmp 0x260f
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x42ef
callq 0x2090
movq %rax, %r14
movq 0x79d2(%rip), %rax      # 0x9ff8
movq (%rax), %r15
negl %ebx
movl %ebx, %edi
callq 0x2290
movq %rax, %rcx
subq -0x40(%rbp), %r14
movl $0xf4240, %esi          # imm = 0xF4240
movq %r14, %rax
cqto
idivq %rsi
leaq 0x3a17(%rip), %rsi      # 0x6064
xorl %ebx, %ebx
movq %r15, %rdi
movq %rcx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2160
movq -0x38(%rbp), %r12
movq (%r12), %rax
movq 0x18(%r12), %r15
movq 0x10(%rax), %r14
testb $0x1, 0x74(%r12)
je 0x2687
movq 0x78(%r12), %rax
testq %rax, %rax
je 0x2687
movq %r12, %rdi
callq *%rax
movq %r12, %rdi
callq 0x2030
movq %r15, %rdi
callq 0x405d
movq %r14, %rdi
callq 0x297f
callq 0x27a6
jmp 0x240f
pushq $0x1
popq %rdi
callq 0x2260