// File: /workspace/github_c_makefile_star2_O3/j-hoppe[P]tu58fs/image.c
// Function: image_open
int image_open(image_t *_this, int shared, int readonly, int allowcreate, char *fname,
		filesystem_type_t dec_filesystem) {
	int filecreated;
	// save some data
	_this->host_fpath = strdup(fname); // free'd on close
	_this->shared = shared;
	_this->readonly = readonly;
	_this->dec_filesystem = dec_filesystem;
	if (shared) {
		// make filesystem from files and allocate data
		_this->pdp_filesystem = filesystem_create(dec_filesystem, _this->dec_device,
				_this->readonly, _this->data, _this->data_size, _this->changedblocks);

		_this->hostdir = hostdir_create(_this->unit, _this->host_fpath, _this->pdp_filesystem);

		if (hostdir_load(_this->hostdir, allowcreate, &filecreated))
			return error_set(error_code, "Opening shared directory");
		// data and data_size may have been enlarged !
	} else {
		// also initializes new tape
		if (image_hostfile_open(_this, allowcreate, &filecreated))
			return error_set(error_code, "Opening image file");
	}
	_this->seekpos = 0;
	_this->open = 1;

	return ERROR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %r9d, %r15d
movl %ecx, %r14d
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, %rbx
movq %r8, %rdi
callq 0x3570
movq %rax, 0x30(%rbx)
movl %r12d, 0x38(%rbx)
movl %ebp, 0x3c(%rbx)
movl %r15d, 0x10c(%rbx)
testl %r12d, %r12d
je 0x7b93
movl 0x108(%rbx), %esi
movq 0x118(%rbx), %rcx
movl 0x110(%rbx), %r8d
movq 0xf8(%rbx), %r9
movl %r15d, %edi
movl %ebp, %edx
callq 0xb66f
movq %rax, 0xe0(%rbx)
movl (%rbx), %edi
movq 0x30(%rbx), %rsi
movq %rax, %rdx
callq 0x934d
movq %rax, 0xd8(%rbx)
leaq 0xc(%rsp), %rdx
movq %rax, %rdi
movl %r14d, %esi
callq 0x93a3
testl %eax, %eax
je 0x7e1a
leaq 0x166ba(%rip), %rax     # 0x1e238
movl (%rax), %edi
leaq 0xd256(%rip), %rsi      # 0x14ddd
xorl %eax, %eax
callq 0x9f73
jmp 0x7e2d
movq %rax, %rdi
testl %ebp, %ebp
je 0x7ba5
xorl %esi, %esi
xorl %eax, %eax
callq 0x34a0
jmp 0x7bb6
movl $0x2, %esi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x34a0
movl %eax, %ebp
testl %eax, %eax
setns %al
testl %r14d, %r14d
sete %r14b
orb %al, %r14b
jne 0x7bd9
movq 0x30(%rbx), %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x3520
movl %eax, %ebp
testl %ebp, %ebp
js 0x7c9f
movq 0x30(%rbx), %rdi
leaq 0x48(%rbx), %rsi
callq 0x3320
movq 0x118(%rbx), %rdi
movl 0x110(%rbx), %edx
xorl %esi, %esi
callq 0x3220
testb %r14b, %r14b
je 0x7cae
movl 0x110(%rbx), %edx
cmpl 0x78(%rbx), %edx
jae 0x7c57
movq 0x30(%rbx), %rdi
xorl %esi, %esi
callq 0xa526
movl 0x110(%rbx), %edx
testl %eax, %eax
jne 0x7c57
movq 0x30(%rbx), %rsi
movl 0xf0(%rbx), %ecx
leal (%rdx,%rcx), %eax
decl %eax
xorl %edx, %edx
divl %ecx
movl 0x40(%rbx), %ecx
leaq 0xd3cc(%rip), %rdi      # 0x15014
movl %eax, %edx
xorl %eax, %eax
callq 0xa2d7
movl 0x110(%rbx), %edx
movq 0x118(%rbx), %rsi
movl %edx, %edx
movl %ebp, %edi
callq 0x32b0
testl %eax, %eax
js 0x7d0b
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x78(%rbx), %rcx
cmpq %rcx, %rax
jge 0x7d70
movl (%rbx), %edx
movq 0x30(%rbx), %r8
leaq 0xd3fe(%rip), %rsi      # 0x1508c
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
xorl %eax, %eax
callq 0x9f73
jmp 0x7d24
movl (%rbx), %edx
movq 0x30(%rbx), %rcx
leaq 0xd339(%rip), %rsi      # 0x14fe5
jmp 0x7d18
movl 0x10c(%rbx), %edi
leal -0x1(%rdi), %eax
cmpl $0x2, %eax
jae 0x7d4f
movl 0x3c(%rbx), %edx
movl 0x108(%rbx), %esi
movq 0x118(%rbx), %rcx
movl 0x110(%rbx), %r8d
xorl %r9d, %r9d
callq 0xb66f
movq %rax, %r14
movq %rax, %rdi
callq 0xbb46
testl %eax, %eax
je 0x7dde
leaq 0x1653f(%rip), %rax     # 0x1e238
movl (%rax), %edi
leaq 0xd3de(%rip), %rsi      # 0x150e0
xorl %eax, %eax
callq 0x9f73
jmp 0x7d24
movl (%rbx), %edx
movq 0x30(%rbx), %rcx
leaq 0xd34f(%rip), %rsi      # 0x15067
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
xorl %eax, %eax
callq 0x9f73
testl %eax, %eax
je 0x7e1a
leaq 0x16505(%rip), %rax     # 0x1e238
movl (%rax), %edi
leaq 0xd0ba(%rip), %rsi      # 0x14df6
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9f73
testl %edi, %edi
jne 0x7e0c
movl (%rbx), %esi
movq 0x30(%rbx), %rdx
leaq 0xd35b(%rip), %rdi      # 0x150bf
xorl %eax, %eax
callq 0xa10f
jmp 0x7e0c
movb $0x0, 0xf5(%rbx)
cmpl $0x0, 0x10c(%rbx)
je 0x7e13
movq 0x118(%rbx), %rdi
movl 0x110(%rbx), %edx
xorl %esi, %esi
callq 0xa508
testl %eax, %eax
jne 0x7e13
movl 0x10c(%rbx), %edi
movl 0x3c(%rbx), %edx
movl 0x108(%rbx), %esi
movq 0x118(%rbx), %rcx
movl 0x110(%rbx), %r8d
xorl %r9d, %r9d
callq 0xb66f
movq %rax, %r14
movq %rax, %rdi
callq 0xb7b1
movq %r14, %rdi
callq 0xbb77
movq %r14, %rdi
callq 0xb724
jmp 0x7e13
movq %r14, %rdi
callq 0xb724
movl (%rbx), %r14d
movl 0x10c(%rbx), %edi
callq 0xb650
movq 0x30(%rbx), %rcx
leaq 0xd2fc(%rip), %rdi      # 0x150fb
movl %r14d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0xa10f
movb $0x1, 0xf5(%rbx)
movl %ebp, %edi
callq 0x3260
movl $0x0, 0x120(%rbx)
movb $0x1, 0xf4(%rbx)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq