// File: /workspace/github_c_makefile_star2_O3/j-hoppe[P]tu58fs/rt11.c
// Function: rt11_filesystem_init
void rt11_filesystem_init(rt11_filesystem_t *_this) {
	int i;
	// set device params

	// image may be variable sized !
	_this->blockcount = NEEDED_BLOCKS(RT11_BLOCKSIZE, _this->image_size);

	/*
	 _this->blockcount = _this->radi->block_count;
	 */

	if (_this->blockcount < 0)
		fatal("rt11_filesystem_init(): RT-11 blockcount for device %s not yet defined!",
				_this->device_info->device_name);

	// trunc large devices, only 64K blocks addressable = 32MB
	// no support for partitioned disks at the moment
	assert(_this->blockcount <= RT11_MAX_BLOCKCOUNT);

#ifdef DEFAULTBOOTLOADER
	// link default bootblock to const byte array
	_this->nobootblock->blocknr = 0;
	_this->nobootblock->byte_offset = 0;
	_this->nobootblock->data = rt11_nobootblock;
	_this->nobootblock->data_size = 512;
#endif

	if (_this->bootblock->data)
		free(_this->bootblock->data);
	stream_init(_this->bootblock);

	if (_this->monitor->data)
		free(_this->monitor->data);
	stream_init(_this->monitor);

	for (i = 0; i < RT11_MAX_FILES_PER_IMAGE; i++) {
		rt11_file_destroy(_this->file[i]);
		_this->file[i] = NULL;
	}
	_this->file_count = 0;

	// defaults for home block, according to [VFFM91], page 1-3
	_this->pack_cluster_size = 1;
	_this->first_dir_blocknr = 6;
	strcpy(_this->system_version, "V3A");
	strcpy(_this->volume_id, "RT11A       ");
	strcpy(_this->owner_name, "            ");
	strcpy(_this->system_id, "DECRT11A    ");
	_this->dir_entry_extra_bytes = 0;
	_this->homeblock_chksum = 0;
	_this->struct_changed = 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl $0x1ff, %eax            # imm = 0x1FF
addl 0x8(%rdi), %eax
movl %eax, %ecx
shrl $0x9, %ecx
movl %ecx, 0x6c(%rdi)
cmpl $0x2000200, %eax        # imm = 0x2000200
jae 0xe83e
movq %rdi, %rbx
movq 0x78(%rdi), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0xe73a
callq 0x3050
movq 0x78(%rbx), %rax
movw $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rax)
movb $0x0, 0x14(%rax)
movq 0x80(%rbx), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0xe769
callq 0x3050
xorps %xmm0, %xmm0
movq 0x80(%rbx), %rax
movw $0x0, (%rax)
movups %xmm0, 0x4(%rax)
movb $0x0, 0x14(%rax)
movl $0x12, %r15d
movq (%rbx,%r15,8), %r14
testq %r14, %r14
je 0xe7b1
movq 0x80(%r14), %rdi
callq 0x1071e
movq 0x90(%r14), %rdi
callq 0x1071e
movq 0x88(%r14), %rdi
callq 0x1071e
movq %r14, %rdi
callq 0x3050
movq $0x0, (%rbx,%r15,8)
incq %r15
cmpq $0x3fa, %r15            # imm = 0x3FA
jne 0xe77c
movl $0x1, 0x30(%rbx)
movw $0x6, 0x34(%rbx)
movl $0x413356, 0x36(%rbx)   # imm = 0x413356
movabsq $0x2020204131315452, %rax # imm = 0x2020204131315452
movq %rax, 0x3a(%rbx)
movabsq $0x20202020202020, %rax # imm = 0x20202020202020
movq %rax, 0x3f(%rbx)
movabsq $0x2020202020202020, %rcx # imm = 0x2020202020202020
movq %rcx, 0x47(%rbx)
movq %rax, 0x4c(%rbx)
movabsq $0x4131315452434544, %rax # imm = 0x4131315452434544
movq %rax, 0x54(%rbx)
movabsq $0x20202020413131, %rax # imm = 0x20202020413131
movq %rax, 0x59(%rbx)
xorl %eax, %eax
movw %ax, 0x68(%rbx)
movw %ax, 0x62(%rbx)
movq $0x0, 0x88(%rbx)
popq %rbx
popq %r14
popq %r15
retq
leaq 0x7fab(%rip), %rdi      # 0x167f0
leaq 0x7f34(%rip), %rsi      # 0x16780
leaq 0x7fc6(%rip), %rcx      # 0x16819
movl $0x143, %edx            # imm = 0x143
callq 0x3200