// File: /workspace/github_c_makefile_star2_O1/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
movl $0x1, %r12d
cmpl $0x4, %edi
jl 0x2552
movq %rsi, %rbx
movq 0x10(%rsi), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
movq %rax, %r14
movq 0x18(%rbx), %rdi
callq 0x2240
movl %eax, %r15d
cmpl $0x1, %eax
je 0x2564
cmpl $-0x1, %r15d
je 0x2564
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, -0x48(%rbp)
callq 0x2090
movq %rax, -0x40(%rbp)
movq 0x8(%rbx), %rdi
callq 0x2972
movl %eax, %edi
movl $0xc, %esi
callq 0x299f
movq %rax, %r13
movq 0x10(%rax), %r14
movl $0x1, %edi
movl $0x80, %esi
callq 0x2140
movq %rax, %rbx
movq %r14, (%rax)
andb $-0x2, 0x74(%rax)
addq $0x24, %rax
movq %rax, -0x38(%rbp)
leaq 0x292(%rip), %rax       # 0x2847
movq %rax, 0x78(%rbx)
leaq 0x8(%rbx), %rsi
movaps 0x4a4c(%rip), %xmm0     # 0x7010
movups %xmm0, 0x8(%rbx)
leaq 0x20(%rbx), %r14
movq $0x2d, 0x20(%rbx)
movl $0x10, %edx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3ce4
movl %eax, 0x28(%rbx)
movl $0x4, %edx
movl %eax, %edi
movq %r14, %rsi
callq 0x3ce4
movl %eax, 0x28(%rbx)
movl $0x4, %edx
movl %eax, %edi
movq -0x38(%rbp), %rsi
callq 0x3ce4
movl %eax, 0x28(%rbx)
movq %r13, %rdi
callq 0x3497
testq %rax, %rax
je 0x27e1
movq (%rbx), %rdi
callq 0x42cc
movq %rax, %r14
movq %rbx, %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(%rbx)
movups %xmm1, 0x48(%rbx)
movups %xmm2, 0x58(%rbx)
movups %xmm3, 0x64(%rbx)
cmpw $0xf30a, 0x38(%rbx)     # imm = 0xF30A
movq %rbx, -0x38(%rbp)
je 0x266e
movq %r13, %rdi
callq 0x6256
movq -0x38(%rbp), %rbx
orb $0x1, 0x74(%rbx)
movq %r14, 0x18(%rbx)
movq (%rbx), %rdi
movq (%rdi), %rcx
movq %r13, %rsi
movq %rbx, %rdx
callq 0x443f
movq %rax, %r14
leaq -0x2b(%rbp), %rdx
movq %rax, %rdi
movq -0x48(%rbp), %r13
movl %r13d, %esi
callq 0x4689
testl %eax, %eax
jne 0x26c3
cmpb $0x0, -0x2b(%rbp)
je 0x26f8
movq 0x894e(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x4980(%rip), %rsi      # 0x7034
movl %r13d, %edx
xorl %eax, %eax
callq 0x2160
jmp 0x2552
movq 0x892e(%rip), %rcx      # 0xaff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2290
leaq 0x4945(%rip), %rsi      # 0x7020
movq %rbx, %rdi
movq %rax, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2160
movq %r14, %rdi
callq 0x465a
jmp 0x2552
leaq -0x29(%rbp), %rbx
movq %r14, %rdi
cmpl $-0x1, %r15d
je 0x271a
movq %rbx, %rsi
callq 0x5399
movl %eax, %r12d
testl %eax, %eax
setne %al
orb -0x29(%rbp), %al
jmp 0x272e
leaq -0x2a(%rbp), %rsi
callq 0x5301
movl %eax, %r12d
testl %eax, %eax
setne %al
orb -0x2a(%rbp), %al
testb $0x1, %al
je 0x273e
movzbl %al, %eax
andl $0x1, %eax
leal (%rax,%rax,2), %r13d
jmp 0x276d
movq %r14, %rdi
callq 0x48f8
movl (%rax), %esi
movzwl 0x4(%rax), %eax
movl %eax, %edx
andl $0x7fff, %edx           # imm = 0x7FFF
cmpl $0x8001, %eax           # imm = 0x8001
cmovbl %eax, %edx
xorl %r13d, %r13d
leaq 0x48e3(%rip), %rdi      # 0x7049
xorl %eax, %eax
callq 0x20a0
testl %r13d, %r13d
je 0x26fc
movq %r14, %rdi
callq 0x465a
callq 0x2090
movq %rax, %rbx
movq 0x886f(%rip), %rax      # 0xaff8
movq (%rax), %r14
negl %r12d
movl %r12d, %edi
callq 0x2290
movq %rax, %r8
subq -0x40(%rbp), %rbx
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
movq %rbx, %rax
imulq %rcx
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0x12, %rdx
addq %rdx, %rcx
leaq 0x48a1(%rip), %rsi      # 0x7064
xorl %r12d, %r12d
movq %r14, %rdi
movq %r8, %rdx
xorl %eax, %eax
callq 0x2160
movq -0x38(%rbp), %rdi
callq 0x27eb
jmp 0x2552
movl $0x1, %edi
callq 0x2260