// File: /workspace/github_c_makefile_star2_O1/j-hoppe[P]tu58fs/xxdp.c
// Function: xxdp_filesystem_create
xxdp_filesystem_t *xxdp_filesystem_create(device_type_t dec_device, uint8_t *image_data,
		uint32_t image_size, boolarray_t *changedblocks) {
	xxdp_filesystem_t *_this;
	xxdp_radi_t *radi;
	int file_idx;
	_this = malloc(sizeof(xxdp_filesystem_t));

	_this->image_data = image_data;
	_this->image_size = image_size;
	_this->image_changed_blocks = changedblocks;

	_this->blockcount = NEEDED_BLOCKS(XXDP_BLOCKSIZE, _this->image_size);

	_this->dec_device = dec_device;
	_this->device_info = (device_info_t*) search_tagged_array(device_info_table,
			sizeof(device_info_t), _this->dec_device);
	assert(_this->device_info);

	// Search Random Access Device Information
	radi = (xxdp_radi_t*) search_tagged_array(xxdp_radi, sizeof(xxdp_radi_t),
			_this->dec_device);
	assert(radi);
	_this->radi = *radi; // copy

	xxdp_filesystem_recalc_radi(_this); // test: does XXDP understand
	// if image is enlarged, the precoded layout params of the device are not sufficient
	// for the enlarged blockcount.
	//see TU58: normally 1 prealloced block for 256KB tape
	if (_this->radi.blocks_num < (int)_this->blockcount) {
		// calculate new layout params in _this->radi
		if (xxdp_filesystem_recalc_radi(_this)) {
			error_set(ERROR_FILESYSTEM_FORMAT, "Can not calculate new layout params");
			return NULL;
		}
	}

	// these are always there, static allocated
	_this->bootblock = malloc(sizeof(xxdp_multiblock_t));
	_this->bootblock->data = NULL;
	_this->bootblock->data_size = 0;
	_this->monitor = malloc(sizeof(xxdp_multiblock_t));
	_this->monitor->data = NULL;
	_this->monitor->data_size = 0;
	_this->bitmap = malloc(sizeof(xxdp_bitmap_t));
	_this->mfd_blocklist = malloc(sizeof(xxdp_blocklist_t));
	_this->ufd_blocklist = malloc(sizeof(xxdp_blocklist_t));

	// files vary: dynamic allocate
	_this->file_count = 0;
	for (file_idx = 0; file_idx < XXDP_MAX_FILES_PER_IMAGE; file_idx++)
		_this->file[file_idx] = NULL;
	xxdp_filesystem_init(_this);
	return _this;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %r14
movl %edx, %r15d
movq %rsi, %r12
movl %edi, %ebp
movl $0x1ff0, %edi           # imm = 0x1FF0
callq 0x33c0
movq %rax, %rbx
movq %r12, (%rax)
movl %r15d, 0x8(%rax)
movq %r14, 0x10(%rax)
addl $0x1ff, %r15d           # imm = 0x1FF
shrl $0x9, %r15d
movl %r15d, 0x4c(%rax)
movl %ebp, 0x18(%rax)
leaq 0x106b0(%rip), %rdi     # 0x1c4c0
movl $0x20, %esi
movl %ebp, %edx
callq 0xb12a
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0xbf0b
leaq 0x10870(%rip), %rdi     # 0x1c6a0
movl $0x24, %esi
movl %ebp, %edx
callq 0xb12a
testq %rax, %rax
je 0xbf2a
movl 0x20(%rax), %ecx
movl %ecx, 0x48(%rbx)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x38(%rbx)
movups %xmm0, 0x28(%rbx)
movq %rbx, %rdi
callq 0xbf49
movl 0x3c(%rbx), %eax
cmpl 0x4c(%rbx), %eax
jge 0xbe72
movq %rbx, %rdi
callq 0xbf49
movl $0x18, %edi
callq 0x33c0
movq %rax, 0x80(%rbx)
xorl %r14d, %r14d
movq %r14, 0x8(%rax)
movl %r14d, 0x10(%rax)
movl $0x18, %edi
callq 0x33c0
movq %rax, 0x88(%rbx)
movq %r14, 0x8(%rax)
movl %r14d, 0x10(%rax)
movl $0x10804, %edi          # imm = 0x10804
callq 0x33c0
movq %rax, 0x90(%rbx)
movl $0x804, %edi            # imm = 0x804
callq 0x33c0
movq %rax, 0x98(%rbx)
movl $0x804, %edi            # imm = 0x804
callq 0x33c0
movq %rax, 0xa0(%rbx)
movl %r14d, 0xa8(%rbx)
movq %rbx, %rdi
addq $0xb0, %rdi
movl $0x1f40, %edx           # imm = 0x1F40
xorl %esi, %esi
callq 0x3230
movq %rbx, %rdi
callq 0xbfed
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8ea9(%rip), %rdi      # 0x14dbb
leaq 0x9bd8(%rip), %rsi      # 0x15af1
leaq 0x9bd8(%rip), %rcx      # 0x15af8
movl $0x101, %edx            # imm = 0x101
callq 0x3210
leaq 0xa822(%rip), %rdi      # 0x16753
leaq 0x9bb9(%rip), %rsi      # 0x15af1
leaq 0x9bb9(%rip), %rcx      # 0x15af8
movl $0x106, %edx            # imm = 0x106
callq 0x3210