// File: /workspace/github_c_makefile_star2_O3/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 0x33b0
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 0x10718(%rip), %rdi     # 0x1c4b0
movl $0x20, %esi
movl %ebp, %edx
callq 0xb0ca
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0xbe93
leaq 0x108d8(%rip), %rdi     # 0x1c690
movl $0x24, %esi
movl %ebp, %edx
callq 0xb0ca
testq %rax, %rax
je 0xbeb2
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 0xbed1
movl 0x3c(%rbx), %eax
cmpl 0x4c(%rbx), %eax
jge 0xbdfa
movq %rbx, %rdi
callq 0xbed1
movl $0x18, %edi
callq 0x33b0
movq %rax, 0x80(%rbx)
xorl %r14d, %r14d
movq %r14, 0x8(%rax)
movl %r14d, 0x10(%rax)
movl $0x18, %edi
callq 0x33b0
movq %rax, 0x88(%rbx)
movq %r14, 0x8(%rax)
movl %r14d, 0x10(%rax)
movl $0x10804, %edi          # imm = 0x10804
callq 0x33b0
movq %rax, 0x90(%rbx)
movl $0x804, %edi            # imm = 0x804
callq 0x33b0
movq %rax, 0x98(%rbx)
movl $0x804, %edi            # imm = 0x804
callq 0x33b0
movq %rax, 0xa0(%rbx)
movl %r14d, 0xa8(%rbx)
movq %rbx, %rdi
addq $0xb0, %rdi
movl $0x1f40, %edx           # imm = 0x1F40
xorl %esi, %esi
callq 0x3220
movq %rbx, %rdi
callq 0xbf78
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8ef9(%rip), %rdi      # 0x14d93
leaq 0x9ce8(%rip), %rsi      # 0x15b89
leaq 0x9ce8(%rip), %rcx      # 0x15b90
movl $0x101, %edx            # imm = 0x101
callq 0x3200
leaq 0xa932(%rip), %rdi      # 0x167eb
leaq 0x9cc9(%rip), %rsi      # 0x15b89
leaq 0x9cc9(%rip), %rcx      # 0x15b90
movl $0x106, %edx            # imm = 0x106
callq 0x3200