// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x1000(%rax), %rdx
leaq 0x7c1c(%rip), %rdi      # 0xa02e
movb $0x0, %al
callq 0x20a0
movq -0x10(%rbp), %rdi
callq 0x2bc0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x2443
leaq 0x7c19(%rip), %rdi      # 0xa04b
callq 0x2230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x25a5
movl -0x14(%rbp), %edi
movl $0xc, %esi
callq 0x2c10
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2487
movl -0x14(%rbp), %edi
callq 0x20e0
movq 0xbb8e(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x7bdc(%rip), %rsi      # 0xa050
movb $0x0, %al
callq 0x2170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x25a5
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x1000(%rax), %rsi
callq 0x3c10
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x25b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x24cf
movl -0x14(%rbp), %edi
callq 0x20e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x25a5
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
xorl %esi, %esi
callq 0x20d0
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl $0xeeeeeeee, (%rax)     # imm = 0xEEEEEEEE
movq -0x10(%rbp), %rax
movq 0x1000(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x4(%rax)
movq -0x30(%rbp), %rax
movq $0x1, 0xc(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rdi
callq 0x3ce0
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl 0x8(%rcx), %ecx
shrq %cl, %rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x4(%rax)
movq -0x28(%rbp), %rdi
callq 0x25e0
movq -0x28(%rbp), %rdi
callq 0x3ab0
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2600
movl %eax, %ecx
leaq 0x7b14(%rip), %rsi      # 0xa085
leaq 0x7b06(%rip), %rax      # 0xa07e
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x7ae8(%rip), %rdi      # 0xa06e
movb $0x0, %al
callq 0x20a0
movq -0x20(%rbp), %rdi
callq 0x2e50
movl -0x14(%rbp), %edi
callq 0x20e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop