// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x4, %edi
jge 0x23e8
pushq $-0x1
popq %r14
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r12
movq 0x8(%rsi), %rdi
callq 0x279a
pushq $0xc
popq %rsi
movl %eax, %edi
callq 0x27c5
movq %rax, %r14
movq 0x10(%rax), %r15
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0x2140
movq %rax, %rbx
movq %r15, (%rax)
leaq 0x25c(%rip), %rax       # 0x267b
movq %rax, 0x78(%rbx)
leaq 0x8(%rbx), %rsi
movaps 0x3be2(%rip), %xmm0     # 0x6010
movups %xmm0, 0x8(%rbx)
leaq 0x20(%rbx), %r15
movl $0x2d, 0x20(%rbx)
pushq $-0x1
popq %rdi
pushq $0x10
popq %rdx
callq 0x3a84
movl %eax, 0x28(%rbx)
pushq $0x4
popq %r13
movl %eax, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x3a84
movl %eax, 0x28(%rbx)
leaq 0x24(%rbx), %rsi
movl %eax, %edi
movq %r13, %rdx
callq 0x3a84
movl %eax, 0x28(%rbx)
movq %r14, %rdi
callq 0x325b
testq %rax, %rax
je 0x2673
movq (%rbx), %rdi
callq 0x3f98
movq %rax, %r15
movq %rbx, %rax
addq $0x38, %rax
movq %rax, -0x38(%rbp)
movq 0x10(%r15), %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
je 0x24d0
movq -0x38(%rbp), %rdi
callq 0x5a22
orb $0x1, 0x74(%rbx)
movq %rbx, -0x40(%rbp)
movq %r15, 0x18(%rbx)
movq 0x10(%r12), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
movq %rax, %r15
movq 0x18(%r12), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
movq %rax, -0x58(%rbp)
cmpl %eax, %r15d
movl $0x0, %ebx
adcl $-0x1, %ebx
orl $0x1, %ebx
callq 0x2090
movq %rax, -0x48(%rbp)
movl %ebx, %r13d
imull %ebx, %ebx
movb $0x1, %r14b
testb $0x1, %r14b
je 0x25fd
movq -0x58(%rbp), %rax
movl %eax, %r14d
subl %r15d, %r14d
imull %r13d, %r14d
testl %r14d, %r14d
js 0x25f5
movq -0x40(%rbp), %rdx
movq (%rdx), %rdi
movq (%rdi), %rcx
movq -0x38(%rbp), %rsi
callq 0x40fa
movq %rax, %r12
movq %rax, %rdi
movl %r15d, %esi
leaq -0x29(%rbp), %rdx
callq 0x42e1
testl %eax, %eax
jne 0x25b8
cmpb $0x1, -0x29(%rbp)
je 0x257b
movq %r12, %rdi
callq 0x42b7
addl %r13d, %r15d
subl %ebx, %r14d
jmp 0x2533
movq 0x7a76(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x3aa8(%rip), %rsi      # 0x6034
movl %r15d, %edx
xorl %eax, %eax
callq 0x2160
movl %r15d, -0x64(%rbp)
movabsq $-0x21524110ffffffff, %rax # imm = 0xDEADBEEF00000001
movq %rax, -0x60(%rbp)
movq %r12, %rdi
leaq -0x64(%rbp), %rsi
callq 0x455a
testl %eax, %eax
je 0x256b
movq 0x7a39(%rip), %rcx      # 0x9ff8
movq (%rcx), %rcx
movq %rcx, -0x50(%rbp)
movl %eax, %edi
callq 0x2280
xorl %r14d, %r14d
movq -0x50(%rbp), %rdi
leaq 0x3a45(%rip), %rsi      # 0x6020
movq %rax, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2160
movq %r12, %rdi
callq 0x42b7
jmp 0x251b
xorl %r14d, %r14d
jmp 0x251b
callq 0x2090
movq 0x79ef(%rip), %rcx      # 0x9ff8
movq (%rcx), %rdi
subq -0x48(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
leaq 0x3a28(%rip), %rsi      # 0x6049
xorl %r14d, %r14d
movq %rax, %rdx
xorl %eax, %eax
callq 0x2160
movq -0x40(%rbp), %rbx
movq (%rbx), %rax
movq 0x18(%rbx), %r12
movq 0x10(%rax), %r15
testb $0x1, 0x74(%rbx)
je 0x2651
movq 0x78(%rbx), %rax
testq %rax, %rax
je 0x2651
movq %rbx, %rdi
callq *%rax
movq %rbx, %rdi
callq 0x2030
movq %r12, %rdi
callq 0x4025
movq %r15, %rdi
callq 0x2947
callq 0x276e
jmp 0x23d6
pushq $0x1
popq %rdi
callq 0x2250