// File: /workspace/github_c_makefile_star2_O1/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 0xc003
cmpl $0x10001, 0x4c(%rbx)    # imm = 0x10001
jb 0xc02d
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)
xorl %ecx, %ecx
movw %cx, 0x2(%rax)
movzwl 0x4a(%rbx), %edx
movq 0x88(%rbx), %rsi
movw %dx, (%rsi)
movl 0x44(%rbx), %edx
movl %edx, 0x54(%rbx)
movw %cx, 0x2(%rsi)
movq 0x98(%rbx), %rcx
movl $0x0, (%rcx)
movl 0x38(%rbx), %edx
testl %edx, %edx
js 0xc090
movl $0x1, 0x58(%rbx)
movl $0x2, (%rcx)
movzwl 0x34(%rbx), %esi
movw %si, 0x4(%rcx)
movw %dx, 0x6(%rcx)
jmp 0xc0a5
movl $0x2, 0x58(%rbx)
movl $0x1, (%rcx)
movzwl 0x34(%rbx), %edx
movw %dx, 0x4(%rcx)
movq 0xa0(%rbx), %rcx
movl $0x0, (%rcx)
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0xc0c0
callq 0x3050
movq 0x80(%rbx), %rax
movq $0x0, 0x8(%rax)
movl $0x0, 0x10(%rax)
movq 0x88(%rbx), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0xc0eb
callq 0x3050
movq 0x88(%rbx), %rax
movq $0x0, 0x8(%rax)
movl $0x0, 0x10(%rax)
movl $0x16, %r14d
movq (%rbx,%r14,8), %rax
testq %rax, %rax
je 0xc132
movq 0x888(%rax), %rdi
testq %rdi, %rdi
je 0xc121
callq 0x3050
movq (%rbx,%r14,8), %rdi
callq 0x3050
movq $0x0, (%rbx,%r14,8)
incq %r14
cmpq $0x3fe, %r14            # imm = 0x3FE
jne 0xc107
movl $0x0, 0xa8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq