// File: /workspace/github_c_makefile_star2_O1/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 0x3580
movq %rax, 0x30(%rbx)
movl %r12d, 0x38(%rbx)
movl %ebp, 0x3c(%rbx)
movl %r15d, 0x10c(%rbx)
testl %r12d, %r12d
je 0x7c0d
movl 0x108(%rbx), %esi
movq 0x118(%rbx), %rcx
movl 0x110(%rbx), %r8d
movq 0xf8(%rbx), %r9
movl %r15d, %edi
movl %ebp, %edx
callq 0xb6e7
movq %rax, 0xe0(%rbx)
movl (%rbx), %edi
movq 0x30(%rbx), %rsi
movq %rax, %rdx
callq 0x9457
movq %rax, 0xd8(%rbx)
leaq 0xc(%rsp), %rdx
movq %rax, %rdi
movl %r14d, %esi
callq 0x94ad
testl %eax, %eax
je 0x7ec1
leaq 0x16650(%rip), %rax     # 0x1e248
movl (%rax), %edi
leaq 0xd204(%rip), %rsi      # 0x14e05
xorl %eax, %eax
callq 0x9f8f
jmp 0x7ed4
movl $0x0, 0xc(%rsp)
movq %rax, %rdi
testl %ebp, %ebp
je 0x7c27
xorl %esi, %esi
xorl %eax, %eax
callq 0x34b0
jmp 0x7c38
movl $0x2, %esi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x34b0
movl %eax, %ebp
testl %eax, %eax
setns %al
testl %r14d, %r14d
sete %cl
orb %al, %cl
jne 0x7c61
movq 0x30(%rbx), %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x3530
movl %eax, %ebp
movl $0x1, 0xc(%rsp)
testl %ebp, %ebp
js 0x7cf8
movq 0x30(%rbx), %rdi
leaq 0x48(%rbx), %rsi
callq 0x3330
movq 0x118(%rbx), %rdi
movl 0x110(%rbx), %edx
xorl %esi, %esi
callq 0x3230
cmpl $0x0, 0xc(%rsp)
je 0x7d16
movl 0x10c(%rbx), %edi
leal -0x1(%rdi), %eax
cmpl $0x2, %eax
jae 0x7da6
movl 0x3c(%rbx), %edx
movl 0x108(%rbx), %esi
movq 0x118(%rbx), %rcx
movl 0x110(%rbx), %r8d
xorl %r9d, %r9d
callq 0xb6e7
movq %rax, %r15
movq %rax, %rdi
callq 0xbbc4
movl %eax, %r14d
testl %eax, %eax
je 0x7de1
leaq 0x16565(%rip), %rax     # 0x1e248
movl (%rax), %edi
leaq 0xd41c(%rip), %rsi      # 0x15108
xorl %eax, %eax
callq 0x9f8f
jmp 0x7e0f
movl (%rbx), %edx
movq 0x30(%rbx), %rcx
leaq 0xd308(%rip), %rsi      # 0x1500d
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
xorl %eax, %eax
callq 0x9f8f
jmp 0x7e9a
movl 0x110(%rbx), %edx
cmpl 0x78(%rbx), %edx
jae 0x7d5b
movq 0x30(%rbx), %rdi
xorl %esi, %esi
callq 0xa543
testl %eax, %eax
jne 0x7d5b
movq 0x30(%rbx), %rsi
movl 0x110(%rbx), %eax
movl 0xf0(%rbx), %ecx
addl %ecx, %eax
decl %eax
xorl %edx, %edx
divl %ecx
movl 0x40(%rbx), %ecx
leaq 0xd2ea(%rip), %rdi      # 0x1503c
movl %eax, %edx
xorl %eax, %eax
callq 0xa2ef
movq 0x118(%rbx), %rsi
movl 0x110(%rbx), %edx
movl %ebp, %edi
callq 0x32c0
testl %eax, %eax
js 0x7dc0
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x78(%rbx), %rcx
cmpq %rcx, %rax
jge 0x7e21
movl (%rbx), %edx
movq 0x30(%rbx), %r8
leaq 0xd322(%rip), %rsi      # 0x150b4
xorl %r15d, %r15d
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
xorl %eax, %eax
callq 0x9f8f
jmp 0x7e8c
testl %edi, %edi
jne 0x7e18
movl (%rbx), %esi
movq 0x30(%rbx), %rdx
leaq 0xd330(%rip), %rdi      # 0x150e7
xorl %eax, %eax
callq 0xa127
jmp 0x7e18
movl (%rbx), %edx
movq 0x30(%rbx), %rcx
leaq 0xd2c2(%rip), %rsi      # 0x1508f
xorl %r15d, %r15d
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
xorl %eax, %eax
callq 0x9f8f
jmp 0x7e8c
movq %r15, %rdi
callq 0xb79c
movl (%rbx), %r15d
movl 0x10c(%rbx), %edi
callq 0xb6c8
movq 0x30(%rbx), %rcx
leaq 0xd321(%rip), %rdi      # 0x15123
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0xa127
testl %r14d, %r14d
jne 0x7e9a
movb $0x1, 0xf5(%rbx)
jmp 0x7e91
movb $0x0, 0xf5(%rbx)
movb $0x1, %r15b
cmpl $0x0, 0x10c(%rbx)
je 0x7e8c
movq 0x118(%rbx), %rdi
movl 0x110(%rbx), %edx
xorl %esi, %esi
callq 0xa525
testl %eax, %eax
jne 0x7e8c
movl 0x10c(%rbx), %edi
movl 0x3c(%rbx), %edx
movl 0x108(%rbx), %esi
movq 0x118(%rbx), %rcx
movl 0x110(%rbx), %r8d
xorl %r9d, %r9d
callq 0xb6e7
movq %rax, %r14
movq %rax, %rdi
callq 0xb829
movq %r14, %rdi
callq 0xbbf5
movq %r14, %rdi
callq 0xb79c
testb %r15b, %r15b
je 0x7e9a
movl %ebp, %edi
callq 0x3270
xorl %eax, %eax
testl %eax, %eax
je 0x7ec1
leaq 0x163a3(%rip), %rax     # 0x1e248
movl (%rax), %edi
leaq 0xcf70(%rip), %rsi      # 0x14e1e
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9f8f
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