// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x1ff0, %edi           # imm = 0x1FF0
callq 0x33a0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x200, %ecx            # imm = 0x200
subl $0x1, %ecx
shrl $0x9, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4c(%rax)
movl -0xc(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movl 0x18(%rax), %edx
leaq 0x13f59(%rip), %rdi     # 0x23750
movl $0x20, %esi
callq 0xe300
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0xf819
jmp 0xf838
leaq 0xc570(%rip), %rdi      # 0x1bd90
leaq 0xd1f4(%rip), %rsi      # 0x1ca1b
movl $0x101, %edx            # imm = 0x101
leaq 0xd1ef(%rip), %rcx      # 0x1ca22
callq 0x3200
movq -0x30(%rbp), %rax
movl 0x18(%rax), %edx
leaq 0x140ea(%rip), %rdi     # 0x23930
movl $0x24, %esi
callq 0xe300
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xf85d
jmp 0xf87c
leaq 0xde3f(%rip), %rdi      # 0x1d6a3
leaq 0xd1b0(%rip), %rsi      # 0x1ca1b
movl $0x106, %edx            # imm = 0x106
leaq 0xd1ab(%rip), %rcx      # 0x1ca22
callq 0x3200
movq -0x30(%rbp), %rdi
addq $0x28, %rdi
movq -0x38(%rbp), %rsi
movl $0x24, %edx
callq 0x3330
movq -0x30(%rbp), %rdi
callq 0xfa00
movq -0x30(%rbp), %rax
movl 0x3c(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x4c(%rcx), %eax
jge 0xf8db
movq -0x30(%rbp), %rdi
callq 0xfa00
cmpl $0x0, %eax
je 0xf8d9
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leaq 0xd1ba(%rip), %rsi      # 0x1ca7f
movb $0x0, %al
callq 0xcd70
movq $0x0, -0x8(%rbp)
jmp 0xf9eb
jmp 0xf8db
movl $0x18, %edi
callq 0x33a0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rax
movq $0x0, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rax
movl $0x0, 0x10(%rax)
movl $0x18, %edi
callq 0x33a0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movq $0x0, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movl $0x0, 0x10(%rax)
movl $0x10804, %edi          # imm = 0x10804
callq 0x33a0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x90(%rax)
movl $0x804, %edi            # imm = 0x804
callq 0x33a0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x98(%rax)
movl $0x804, %edi            # imm = 0x804
callq 0x33a0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0xa0(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0xa8(%rax)
movl $0x0, -0x3c(%rbp)
cmpl $0x3e8, -0x3c(%rbp)     # imm = 0x3E8
jge 0xf9da
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq $0x0, 0xb0(%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xf9b2
movq -0x30(%rbp), %rdi
callq 0xfb60
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)