// File: /workspace/github_c_makefile_star2_O3/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 0x3b6a(%rip), %rdi      # 0x602e
movq %r12, %rsi
xorl %eax, %eax
callq 0x20a0
movq %r12, %rdi
callq 0x27fe
testl %eax, %eax
js 0x2665
movl %eax, %ebx
movl %eax, %edi
movl $0xc, %esi
callq 0x282b
testq %rax, %rax
je 0x2673
movq %rax, %r14
movq 0x10(%rax), %rdi
movq 0x1000(%r12), %rsi
callq 0x322e
movq 0x10(%r14), %rax
movl (%rax), %edx
movq 0x10(%rax), %rdi
xorl %esi, %esi
callq 0x2fae
testq %rax, %rax
je 0x2621
movq %rax, %r13
movl %ebx, -0x2c(%rbp)
movq 0x10(%rax), %rdx
movq 0x18(%rax), %rdi
xorl %esi, %esi
callq 0x20d0
movq 0x18(%r13), %rbx
movl $0xeeeeeeee, (%rbx)     # imm = 0xEEEEEEEE
movq 0x1000(%r12), %rax
movq %rax, 0x4(%rbx)
movq $0x1, 0xc(%rbx)
movq 0x10(%r14), %rax
movq 0x10(%rax), %rdi
callq 0x32c9
movq 0x10(%r14), %rcx
movb 0x8(%rcx), %cl
shrq %cl, %rax
movq %rax, 0x4(%rbx)
orb $0x2, (%r13)
movq %r13, %rdi
callq 0x3094
movq 0x10(%r14), %r12
movq 0x10(%r12), %rdi
callq 0x32c9
movq %rax, %r15
movb 0x8(%r12), %cl
shrq %cl, %r15
movq 0xc(%rbx), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x3b93
testq %rax, %rax
je 0x262f
movq %rax, %r13
movq %r12, -0x38(%rbp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x3b64
movl %eax, %r12d
movq %r13, %rdi
xorl %esi, %esi
callq 0x3e2d
leaq 0x3aba(%rip), %rdi      # 0x608f
movq %r15, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x20a0
testl %r12d, %r12d
jle 0x2604
movl %r12d, %r15d
xorl %r12d, %r12d
movq 0xc(%rbx), %rsi
addq %r12, %rsi
movq %r13, %rdi
callq 0x3e2d
incq %r12
cmpq %r12, %r15
jne 0x25ed
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0x3d7e
movq %r13, %rdi
callq 0x3cfb
leaq 0x3a66(%rip), %rsi      # 0x6085
jmp 0x2636
movl %ebx, %edi
callq 0x20e0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2656
leaq 0x3a48(%rip), %rsi      # 0x607e
leaq 0x3a31(%rip), %rdi      # 0x606e
xorl %eax, %eax
callq 0x20a0
movq %r14, %rdi
callq 0x29bb
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 0x39df(%rip), %rdi      # 0x604b
callq 0x2230
jmp 0x2628
movl %ebx, %edi
callq 0x22e0
jmp 0x2628