// File: /workspace/github_c_makefile_star2_O1/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 0x4aca(%rip), %rdi      # 0x702e
movq %r12, %rsi
xorl %eax, %eax
callq 0x20a0
movq %r12, %rdi
callq 0x28aa
testl %eax, %eax
js 0x2705
movl %eax, %ebx
movl %eax, %edi
movl $0xc, %esi
callq 0x28d7
testq %rax, %rax
je 0x2713
movq %rax, %r14
movq 0x10(%rax), %rdi
movq 0x1000(%r12), %rsi
callq 0x3334
movq 0x10(%r14), %rax
movq 0x10(%rax), %rdi
movl (%rax), %edx
xorl %esi, %esi
callq 0x30b0
testq %rax, %rax
je 0x26c1
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 0x33cf
movq 0x10(%r14), %rcx
movb 0x8(%rcx), %cl
shrq %cl, %rax
movq %rax, 0x4(%rbx)
orb $0x2, (%r13)
movq %r13, %rdi
callq 0x319a
movq 0x10(%r14), %r12
movq 0x10(%r12), %rdi
callq 0x33cf
movq %rax, %r15
movb 0x8(%r12), %cl
shrq %cl, %r15
movq 0xc(%rbx), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x3c93
testq %rax, %rax
je 0x26cf
movq %rax, %r13
movq %r12, -0x38(%rbp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x3c64
movl %eax, %r12d
movq %r13, %rdi
xorl %esi, %esi
callq 0x3f19
leaq 0x4a1a(%rip), %rdi      # 0x708f
movq %r15, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x20a0
testl %r12d, %r12d
jle 0x26a4
movl %r12d, %r15d
xorl %r12d, %r12d
movq 0xc(%rbx), %rsi
addq %r12, %rsi
movq %r13, %rdi
callq 0x3f19
incq %r12
cmpq %r12, %r15
jne 0x268d
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0x3e6a
movq %r13, %rdi
callq 0x3e0a
leaq 0x49c6(%rip), %rsi      # 0x7085
jmp 0x26d6
movl %ebx, %edi
callq 0x20e0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x26f6
leaq 0x49a8(%rip), %rsi      # 0x707e
leaq 0x4991(%rip), %rdi      # 0x706e
xorl %eax, %eax
callq 0x20a0
movq %r14, %rdi
callq 0x2a85
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 0x493f(%rip), %rdi      # 0x704b
callq 0x2230
jmp 0x26c8
movl %ebx, %edi
callq 0x22e0
jmp 0x26c8