// File: /workspace/github_c_makefile_star2_O2/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
andl $0x0, (%rax)
xorl %eax, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0xb568
movq 0x90(%rbx), %rcx
movb $0x0, 0x804(%rcx,%rax)
incq %rax
jmp 0xb54c
cmpl $0x10001, 0x4c(%rbx)    # imm = 0x10001
jb 0xb578
movl $0x10000, 0x4c(%rbx)    # imm = 0x10000
movzwl 0x40(%rbx), %eax
movzwl 0x48(%rbx), %ecx
movw %ax, 0x50(%rbx)
movq 0x80(%rbx), %rax
movw %cx, (%rax)
andw $0x0, 0x2(%rax)
movzwl 0x4a(%rbx), %ecx
movq 0x88(%rbx), %rdx
movw %cx, (%rdx)
movl 0x44(%rbx), %ecx
movl %ecx, 0x54(%rbx)
andw $0x0, 0x2(%rdx)
movq 0x98(%rbx), %rcx
movl 0x34(%rbx), %edx
movl 0x38(%rbx), %esi
testl %esi, %esi
js 0xb5c8
movw %si, 0x6(%rcx)
pushq $0x2
popq %rsi
pushq $0x1
jmp 0xb5cd
pushq $0x1
popq %rsi
pushq $0x2
popq %rdi
movl %edi, 0x58(%rbx)
movl %esi, (%rcx)
movw %dx, 0x4(%rcx)
movq 0xa0(%rbx), %rcx
andl $0x0, (%rcx)
movq 0x8(%rax), %rdi
callq 0x3050
movq 0x80(%rbx), %rax
andq $0x0, 0x8(%rax)
andl $0x0, 0x10(%rax)
movq 0x88(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x3050
movq 0x88(%rbx), %rax
andq $0x0, 0x8(%rax)
andl $0x0, 0x10(%rax)
pushq $0x16
popq %r14
cmpq $0x3fe, %r14            # imm = 0x3FE
je 0xb64f
movq (%rbx,%r14,8), %rax
testq %rax, %rax
je 0xb64a
movq 0x888(%rax), %rdi
callq 0x3050
movq (%rbx,%r14,8), %rdi
callq 0x3050
andq $0x0, (%rbx,%r14,8)
incq %r14
jmp 0xb61e
andl $0x0, 0xa8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq