// File: /workspace/github_c_makefile_star2_O0/ngkaho1234[P]ext4-extents-tree/extmaker.c
// Function: main
int main(int argc, char **argv)
{
	int dir;
	int err;
	struct inode *inode;
	int m = 0;
	time_t a, b;
	ext4_lblk_t from, to;

	if (argc < 4)
		return -1;

	inode = open_ext4_db(argv[1]);
	from = strtoul(argv[2], NULL, 0);
	to = strtoul(argv[3], NULL, 0);
	dir = (to > from)?1:-1;
	a = clock();
	for (m = 0;m < 1;m++)
		for (; (int32_t)(to - from) * dir >= 0; from += 1 * dir) {
			bool notfound;
			struct ext4_extent ext;
			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, "Inserting block: %" PRIu32 "\n", from);
				ext4_ext_store_lblk(&ext, from);
				ext4_ext_store_pblk(&ext, 0xDEADBEEF);
				ext4_ext_set_len(&ext, 1);
				err = ext4_ext_insert(cur, &ext);
				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, "clock: %ld\n", (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, -0x24(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x23ef
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x25fc
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2610
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2230
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2230
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %edx
movl -0x3c(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmoval %ecx, %eax
movl %eax, -0x14(%rbp)
callq 0x2090
movq %rax, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x1, -0x24(%rbp)
jge 0x25b6
jmp 0x2460
movl -0x40(%rbp), %eax
subl -0x3c(%rbp), %eax
imull -0x14(%rbp), %eax
cmpl $0x0, %eax
jl 0x25a6
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 0x62b0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movl -0x3c(%rbp), %esi
leaq -0x41(%rbp), %rdx
callq 0x6640
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x24ee
movq 0xbb3f(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movl -0x18(%rbp), %edi
callq 0x2280
movq -0x60(%rbp), %rdi
movq %rax, %rdx
movl -0x3c(%rbp), %ecx
leaq 0x7b2b(%rip), %rsi      # 0xa004
movb $0x0, %al
callq 0x2160
movq -0x58(%rbp), %rdi
callq 0x6600
jmp 0x25a6
testb $0x1, -0x41(%rbp)
je 0x258c
movq 0xbaf9(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movl -0x3c(%rbp), %edx
leaq 0x7b0c(%rip), %rsi      # 0xa018
movb $0x0, %al
callq 0x2160
movl -0x3c(%rbp), %esi
leaq -0x4d(%rbp), %rdi
callq 0x2770
leaq -0x4d(%rbp), %rdi
movl $0xdeadbeef, %esi       # imm = 0xDEADBEEF
callq 0x2790
leaq -0x4d(%rbp), %rdi
movl $0x1, %esi
callq 0x27e0
movq -0x58(%rbp), %rdi
leaq -0x4d(%rbp), %rsi
callq 0x6c40
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x258a
movq 0xbaa0(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x18(%rbp), %edi
callq 0x2280
movq -0x68(%rbp), %rdi
movq %rax, %rdx
movl -0x3c(%rbp), %ecx
leaq 0x7a8c(%rip), %rsi      # 0xa004
movb $0x0, %al
callq 0x2160
movq -0x58(%rbp), %rdi
callq 0x6600
jmp 0x25a6
jmp 0x258c
movq -0x58(%rbp), %rdi
callq 0x6600
movl -0x14(%rbp), %eax
shll $0x0, %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x2460
jmp 0x25a8
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2454
callq 0x2090
movq %rax, -0x38(%rbp)
movq 0xba32(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
movq %rax, %rdx
leaq 0x7a48(%rip), %rsi      # 0xa02d
movb $0x0, %al
callq 0x2160
movq -0x20(%rbp), %rdi
callq 0x2800
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)