// File: /workspace/github_c_makefile_star2_O2/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 0x11148(%rip), %rdi     # 0x1c4b0
pushq $0x20
popq %rsi
movl %ebp, %edx
callq 0xa77f
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0xb45d
leaq 0x1130a(%rip), %rdi     # 0x1c690
pushq $0x24
popq %rsi
movl %ebp, %edx
callq 0xa77f
testq %rax, %rax
je 0xb47c
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 0xb49b
movl 0x3c(%rbx), %eax
cmpl 0x4c(%rbx), %eax
jge 0xb3c6
movq %rbx, %rdi
callq 0xb49b
pushq $0x18
popq %r14
movq %r14, %rdi
callq 0x33b0
andq $0x0, 0x8(%rax)
movq %rax, 0x80(%rbx)
andl $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0x33b0
andq $0x0, 0x8(%rax)
movq %rax, 0x88(%rbx)
andl $0x0, 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)
andl $0x0, 0xa8(%rbx)
pushq $0x16
popq %rax
cmpq $0x3fe, %rax            # imm = 0x3FE
je 0xb449
andq $0x0, (%rbx,%rax,8)
incq %rax
jmp 0xb437
movq %rbx, %rdi
callq 0xb539
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x893f(%rip), %rdi      # 0x13da3
leaq 0x96d1(%rip), %rsi      # 0x14b3c
leaq 0x96d1(%rip), %rcx      # 0x14b43
movl $0x101, %edx            # imm = 0x101
callq 0x3200
leaq 0xa31c(%rip), %rdi      # 0x1579f
leaq 0x96b2(%rip), %rsi      # 0x14b3c
leaq 0x96b2(%rip), %rcx      # 0x14b43
movl $0x106, %edx            # imm = 0x106
callq 0x3200