// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl $0x0, (%rax)
movl $0x0, -0xc(%rbp)
cmpl $0x10000, -0xc(%rbp)    # imm = 0x10000
jge 0xfbaf
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0xc(%rbp), %rcx
movb $0x0, 0x804(%rax,%rcx)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xfb84
movq -0x8(%rbp), %rax
cmpl $0x10000, 0x4c(%rax)    # imm = 0x10000
jbe 0xfbc7
movq -0x8(%rbp), %rax
movl $0x10000, 0x4c(%rax)    # imm = 0x10000
movq -0x8(%rbp), %rax
movw 0x40(%rax), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x50(%rax)
movq -0x8(%rbp), %rax
movw 0x48(%rax), %cx
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movw %cx, (%rax)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movw $0x0, 0x2(%rax)
movq -0x8(%rbp), %rax
movw 0x4a(%rax), %cx
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movw %cx, (%rax)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movw $0x0, 0x2(%rax)
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jl 0xfc9e
movq -0x8(%rbp), %rax
movl $0x1, 0x58(%rax)
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movl $0x2, (%rax)
movq -0x8(%rbp), %rax
movl 0x34(%rax), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movw %cx, 0x4(%rax)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movw %cx, 0x6(%rax)
jmp 0xfcd3
movq -0x8(%rbp), %rax
movl $0x2, 0x58(%rax)
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movl $0x1, (%rax)
movq -0x8(%rbp), %rax
movl 0x34(%rax), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movw %cx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0xfd0a
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3040
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movl $0x0, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0xfd55
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3040
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movl $0x0, 0x10(%rax)
movl $0x0, -0xc(%rbp)
cmpl $0x3e8, -0xc(%rbp)      # imm = 0x3E8
jge 0xfe10
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq $0x0, 0xb0(%rax,%rcx,8)
je 0xfe00
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq 0xb0(%rax,%rcx,8), %rax
cmpq $0x0, 0x888(%rax)
je 0xfdd7
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq 0xb0(%rax,%rcx,8), %rax
movq 0x888(%rax), %rdi
callq 0x3040
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq 0xb0(%rax,%rcx,8), %rdi
callq 0x3040
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq $0x0, 0xb0(%rax,%rcx,8)
jmp 0xfe02
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xfd81
movq -0x8(%rbp), %rax
movl $0x0, 0xa8(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)