// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x23ff
movl $0x1, -0x4(%rbp)
jmp 0x25ef
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
callq 0x2240
movl %eax, -0x14(%rbp)
cmpl $0x1, -0x14(%rbp)
je 0x243d
cmpl $-0x1, -0x14(%rbp)
je 0x243d
movl $0x1, -0x4(%rbp)
jmp 0x25ef
callq 0x2090
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2600
movq %rax, -0x20(%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 0x6260
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x35(%rbp), %rdx
callq 0x65f0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x24d9
movq 0xbb5b(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x18(%rbp), %edi
callq 0x2290
movq -0x58(%rbp), %rdi
movq %rax, %rdx
movl -0x34(%rbp), %ecx
leaq 0x7b47(%rip), %rsi      # 0xa004
movb $0x0, %al
callq 0x2160
movq -0x40(%rbp), %rdi
callq 0x65b0
movl $0x1, -0x4(%rbp)
jmp 0x25ef
testb $0x1, -0x35(%rbp)
je 0x2506
movq 0xbb12(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movl -0x34(%rbp), %edx
leaq 0x7b25(%rip), %rsi      # 0xa018
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x25ef
jmp 0x2508
cmpl $-0x1, -0x14(%rbp)
jne 0x252e
movq -0x40(%rbp), %rdi
leaq -0x49(%rbp), %rsi
callq 0x76e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x252a
testb $0x1, -0x49(%rbp)
je 0x252c
jmp 0x2586
jmp 0x254e
movq -0x40(%rbp), %rdi
leaq -0x4a(%rbp), %rsi
callq 0x77e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x254a
testb $0x1, -0x4a(%rbp)
je 0x254c
jmp 0x2586
jmp 0x254e
movq -0x40(%rbp), %rdi
callq 0x6b50
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2760
movl %eax, -0x5c(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2770
movl -0x5c(%rbp), %esi
movzwl %ax, %edx
leaq 0x7ab0(%rip), %rdi      # 0xa02d
movb $0x0, %al
callq 0x20a0
jmp 0x2508
movq -0x40(%rbp), %rdi
callq 0x65b0
callq 0x2090
movq %rax, -0x30(%rbp)
movq 0xba59(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x70(%rbp)
xorl %edi, %edi
subl -0x18(%rbp), %edi
callq 0x2290
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 0x7a70(%rip), %rsi      # 0xa048
movb $0x0, %al
callq 0x2160
movq -0x20(%rbp), %rdi
callq 0x27b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)