// File: /workspace/github_c_makefile_star2_O2/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 0x7870
movl 0x108(%rbx), %esi
movq 0x118(%rbx), %rcx
movl 0x110(%rbx), %r8d
movq 0xf8(%rbx), %r9
movl %r15d, %edi
movl %ebp, %edx
callq 0xac8b
movq %rax, 0xe0(%rbx)
movl (%rbx), %edi
movq 0x30(%rbx), %rsi
movq %rax, %rdx
callq 0x8ec5
movq %rax, 0xd8(%rbx)
leaq 0xc(%rsp), %rdx
movq %rax, %rdi
movl %r14d, %esi
callq 0x8f18
testl %eax, %eax
je 0x7af4
leaq 0x169dd(%rip), %rax     # 0x1e238
movl (%rax), %edi
leaq 0xc589(%rip), %rsi      # 0x13ded
xorl %eax, %eax
callq 0x982c
jmp 0x7b04
testl %ebp, %ebp
je 0x7882
movq %rax, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x34a0
jmp 0x7894
pushq $0x2
popq %rsi
movq %rax, %rdi
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 0x78b7
movq 0x30(%rbx), %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x3520
movl %eax, %ebp
testl %ebp, %ebp
js 0x797b
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 0x798a
movl 0x110(%rbx), %edx
cmpl 0x78(%rbx), %edx
jae 0x7935
movq 0x30(%rbx), %rdi
xorl %esi, %esi
callq 0x9d76
movl 0x110(%rbx), %edx
testl %eax, %eax
jne 0x7935
movq 0x30(%rbx), %rsi
movl 0xf0(%rbx), %ecx
leal (%rdx,%rcx), %eax
decl %eax
xorl %edx, %edx
divl %ecx
movl 0x40(%rbx), %ecx
leaq 0xc6fe(%rip), %rdi      # 0x14024
movl %eax, %edx
xorl %eax, %eax
callq 0x9b87
movl 0x110(%rbx), %edx
movq 0x118(%rbx), %rsi
movl %edx, %edx
movl %ebp, %edi
callq 0x32b0
testl %eax, %eax
js 0x79e7
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x78(%rbx), %rcx
cmpq %rcx, %rax
jge 0x7a4a
movl (%rbx), %edx
movq 0x30(%rbx), %r8
leaq 0xc730(%rip), %rsi      # 0x1409c
pushq $-0x6
popq %rdi
xorl %eax, %eax
callq 0x982c
jmp 0x79fe
movl (%rbx), %edx
movq 0x30(%rbx), %rcx
leaq 0xc66d(%rip), %rsi      # 0x13ff5
jmp 0x79f4
movl 0x10c(%rbx), %edi
leal -0x1(%rdi), %eax
cmpl $0x2, %eax
jae 0x7a29
movl 0x3c(%rbx), %edx
movl 0x108(%rbx), %esi
movq 0x118(%rbx), %rcx
movl 0x110(%rbx), %r8d
xorl %r9d, %r9d
callq 0xac8b
movq %rax, %r14
movq %rax, %rdi
callq 0xb14b
testl %eax, %eax
je 0x7ab8
leaq 0x16863(%rip), %rax     # 0x1e238
movl (%rax), %edi
leaq 0xc712(%rip), %rsi      # 0x140f0
xorl %eax, %eax
callq 0x982c
jmp 0x79fe
movl (%rbx), %edx
movq 0x30(%rbx), %rcx
leaq 0xc683(%rip), %rsi      # 0x14077
pushq $-0x6
popq %rdi
xorl %eax, %eax
callq 0x982c
testl %eax, %eax
je 0x7af4
leaq 0x1682b(%rip), %rax     # 0x1e238
movl (%rax), %edi
leaq 0xc3f0(%rip), %rsi      # 0x13e06
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x982c
testl %edi, %edi
jne 0x7ae6
movl (%rbx), %esi
movq 0x30(%rbx), %rdx
leaq 0xc691(%rip), %rdi      # 0x140cf
xorl %eax, %eax
callq 0x99c3
jmp 0x7ae6
movb $0x0, 0xf5(%rbx)
cmpl $0x0, 0x10c(%rbx)
je 0x7aed
movq 0x118(%rbx), %rdi
movl 0x110(%rbx), %edx
xorl %esi, %esi
callq 0x9d5d
testl %eax, %eax
jne 0x7aed
movl 0x10c(%rbx), %edi
movl 0x3c(%rbx), %edx
movl 0x108(%rbx), %esi
movq 0x118(%rbx), %rcx
movl 0x110(%rbx), %r8d
xorl %r9d, %r9d
callq 0xac8b
movq %rax, %r14
movq %rax, %rdi
callq 0xadbf
movq %r14, %rdi
callq 0xb17a
movq %r14, %rdi
callq 0xad3a
jmp 0x7aed
movq %r14, %rdi
callq 0xad3a
movl (%rbx), %r14d
movl 0x10c(%rbx), %edi
callq 0xac6c
movq 0x30(%rbx), %rcx
leaq 0xc632(%rip), %rdi      # 0x1410b
movl %r14d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x99c3
movb $0x1, 0xf5(%rbx)
movl %ebp, %edi
callq 0x3260
andl $0x0, 0x120(%rbx)
movb $0x1, 0xf4(%rbx)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq