// File: /workspace/github_c_makefile_star2_O3/j-hoppe[P]tu58fs/xxdp.c
// Function: xxdp_filesystem_init
void xxdp_filesystem_init(xxdp_filesystem_t *_this) {
	int i;

	// empty block bitmap
	_this->bitmap->blocklist.count = 0; // position not known
	for (i = 0; i < XXDP_MAX_BLOCKCOUNT; i++)
		_this->bitmap->used[i] = 0;

	// set device params
	// _this->blockcount = _this->radi->blocks_num;
	// trunc large devices, only 64K blocks addressable = 32MB
	if (_this->blockcount > XXDP_MAX_BLOCKCOUNT)
		_this->blockcount = XXDP_MAX_BLOCKCOUNT;

	_this->preallocated_blockcount = _this->radi.prealloc_blocks_num;
	_this->bootblock->blocknr = _this->radi.boot_block;
	_this->bootblock->blockcount = 0; // may not exist
	_this->monitor->blocknr = _this->radi.monitor_block;

	_this->interleave = _this->radi.interleave;
	_this->monitor->blockcount = 0; // may not exist
	_this->mfd_blocklist->count = 0;

	// which sort of MFD?
	if (_this->radi.mfd2 >= 0) {
		_this->mfd_variety = 1; // 2 blocks
		_this->mfd_blocklist->count = 2;
		_this->mfd_blocklist->blocknr[0] = _this->radi.mfd1;
		_this->mfd_blocklist->blocknr[1] = _this->radi.mfd2;
	} else {
		_this->mfd_variety = 2; // single block format
		_this->mfd_blocklist->count = 1;
		_this->mfd_blocklist->blocknr[0] = _this->radi.mfd1;
	}
	_this->ufd_blocklist->count = 0;
	if (_this->bootblock->data)
		free(_this->bootblock->data);
	_this->bootblock->data = NULL;
	_this->bootblock->data_size = 0;
	if (_this->monitor->data)
		free(_this->monitor->data);
	_this->monitor->data = NULL;
	_this->monitor->data_size = 0;

	for (i = 0; i < XXDP_MAX_FILES_PER_IMAGE; i++)
		if (_this->file[i]) {
			if (_this->file[i]->data)
				free(_this->file[i]->data);
			free(_this->file[i]);
			_this->file[i] = NULL;
		}
	_this->file_count = 0;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x90(%rdi), %rax
movl $0x0, (%rax)
xorl %eax, %eax
movq 0x90(%rbx), %rcx
movb $0x0, 0x804(%rcx,%rax)
incq %rax
cmpq $0x10000, %rax          # imm = 0x10000
jne 0xbf8e
cmpl $0x10001, 0x4c(%rbx)    # imm = 0x10001
jb 0xbfb8
movl $0x10000, 0x4c(%rbx)    # imm = 0x10000
movzwl 0x40(%rbx), %eax
movzwl 0x48(%rbx), %edx
movw %ax, 0x50(%rbx)
movq 0x80(%rbx), %rcx
movw %dx, (%rcx)
xorl %edx, %edx
movw %dx, 0x2(%rcx)
movzwl 0x4a(%rbx), %esi
movq 0x88(%rbx), %rax
movw %si, (%rax)
movl 0x44(%rbx), %esi
movl %esi, 0x54(%rbx)
movw %dx, 0x2(%rax)
movq 0x98(%rbx), %rdx
movl 0x34(%rbx), %esi
movl 0x38(%rbx), %edi
testl %edi, %edi
js 0xc00e
movw %di, 0x6(%rdx)
movl $0x2, %edi
movl $0x1, %r8d
jmp 0xc019
movl $0x1, %edi
movl $0x2, %r8d
movl %r8d, 0x58(%rbx)
movl %edi, (%rdx)
movw %si, 0x4(%rdx)
movq 0xa0(%rbx), %rdx
movl $0x0, (%rdx)
movq 0x8(%rcx), %rdi
testq %rdi, %rdi
je 0xc04c
callq 0x3050
movq 0x80(%rbx), %rcx
movq 0x88(%rbx), %rax
movq $0x0, 0x8(%rcx)
movl $0x0, 0x10(%rcx)
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0xc070
callq 0x3050
movq 0x88(%rbx), %rax
movq $0x0, 0x8(%rax)
movl $0x0, 0x10(%rax)
movl $0x16, %r14d
movq (%rbx,%r14,8), %rdi
testq %rdi, %rdi
je 0xc0b3
movq 0x888(%rdi), %rax
testq %rax, %rax
je 0xc0a6
movq %rax, %rdi
callq 0x3050
movq (%rbx,%r14,8), %rdi
callq 0x3050
movq $0x0, (%rbx,%r14,8)
incq %r14
cmpq $0x3fe, %r14            # imm = 0x3FE
jne 0xc085
movl $0x0, 0xa8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq