// File: /workspace/github_c_makefile_star2_O2/ngkaho1234[P]ext4-extents-tree/mkdb.c
// Function: mkdb
int mkdb(struct arg_table *tbl)
{
	int fd;
	struct block_device *bdev;
	struct buffer_head *bh;
	struct db_header *bhdr;
	printf("Path: %s, size: %llu blocks\n", tbl->path, tbl->size);
	fd = device_open(tbl->path);
	if (fd < 0) {
		perror("mkdb");
		return -1;
	}
	bdev = bdev_alloc(fd, DB_BLOCKSIZE_BITS);
	if (!bdev) {
		close(fd);
		fprintf(stderr, "mkdb: ""Insufficient resoures.\n");
		return -1;
	}
	simple_balloc(bdev->bd_super, (tbl->size));
	bh = sb_getblk(bdev->bd_super, 0);
	if (!bh) {
		close(fd);
		return -1;
	}
	memset(bh->b_data, 0, bh->b_size);
	bhdr = (struct db_header *)bh->b_data;
	bhdr->db_magic = DB_MAGIC;
	bhdr->db_nrblocks = (tbl->size);
	bhdr->db_bitmap_block = 1;
	bhdr->db_nrblocks = device_size(bdev->bd_super->s_bdev) >> bdev->bd_super->s_blocksize_bits;
	set_buffer_dirty(bh);
	brelse(bh);
	printf("Initialize: %s\n", initialize_bitmap(bhdr, bdev->bd_super)?"failed":"done");
	bdev_free(bdev);
	close(fd);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r12
movq 0x1000(%rdi), %rdx
leaq 0x3c2a(%rip), %rdi      # 0x602e
movq %r12, %rsi
xorl %eax, %eax
callq 0x20a0
movq %r12, %rdi
callq 0x2752
testl %eax, %eax
js 0x25a2
movl %eax, %ebx
pushq $0xc
popq %rsi
movl %eax, %edi
callq 0x277d
testq %rax, %rax
je 0x25b0
movq %rax, %r13
movq 0x10(%rax), %rdi
movq 0x1000(%r12), %rsi
callq 0x3166
movq 0x10(%r13), %rax
movq 0x10(%rax), %rdi
movl (%rax), %edx
xorl %esi, %esi
callq 0x2ef7
testq %rax, %rax
je 0x255f
movq %rax, %r15
movl %ebx, -0x2c(%rbp)
movq 0x10(%rax), %rdx
movq 0x18(%rax), %rdi
xorl %esi, %esi
callq 0x20d0
movq 0x18(%r15), %r14
movl $0xeeeeeeee, (%r14)     # imm = 0xEEEEEEEE
movq 0x1000(%r12), %rax
movq %rax, 0x4(%r14)
movq $0x1, 0xc(%r14)
movq 0x10(%r13), %rax
movq 0x10(%rax), %rdi
callq 0x3213
movq 0x10(%r13), %rcx
movb 0x8(%rcx), %cl
shrq %cl, %rax
movq %rax, 0x4(%r14)
orb $0x2, (%r15)
movq %r15, %rdi
callq 0x2fd1
movq %r13, -0x38(%rbp)
movq 0x10(%r13), %r12
movq 0x10(%r12), %rdi
callq 0x3213
movq %rax, %rbx
movb 0x8(%r12), %cl
shrq %cl, %rbx
movq 0xc(%r14), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3ab3
testq %rax, %rax
je 0x256b
movq %rax, %r13
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3a84
movl %eax, %r15d
movq %r13, %rdi
xorl %esi, %esi
callq 0x3cfa
leaq 0x3b80(%rip), %rdi      # 0x608f
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x20a0
testl %r15d, %r15d
movl $0x0, %eax
cmovlel %eax, %r15d
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x2543
movq 0xc(%r14), %rsi
addq %rbx, %rsi
movq %r13, %rdi
callq 0x3cfa
incq %rbx
jmp 0x252a
movq %r12, %rdi
movq %r13, %rsi
callq 0x3c47
movq %r13, %rdi
callq 0x3bd2
leaq 0x3b28(%rip), %rsi      # 0x6085
jmp 0x2572
movl %ebx, %edi
callq 0x20e0
pushq $-0x1
popq %rax
jmp 0x2593
leaq 0x3b0c(%rip), %rsi      # 0x607e
leaq 0x3af5(%rip), %rdi      # 0x606e
xorl %eax, %eax
callq 0x20a0
movq -0x38(%rbp), %rdi
callq 0x28ff
movl -0x2c(%rbp), %edi
callq 0x20e0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3aa2(%rip), %rdi      # 0x604b
callq 0x2230
jmp 0x2566
movl %ebx, %edi
callq 0x20e0
movq 0x7a3a(%rip), %rax      # 0x9ff8
movq (%rax), %rcx
leaq 0x3a88(%rip), %rdi      # 0x6050
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x2270
jmp 0x2566