// File: /workspace/github_c_makefile_star2_O1/j-hoppe[P]tu58fs/xxdp.c
// Function: xxdp_filesystem_file_add
int xxdp_filesystem_file_add(xxdp_filesystem_t *_this, char *hostfname, time_t hostfdate,
		uint8_t *data, uint32_t data_size) {

	if (!strcasecmp(hostfname, XXDP_VOLUMEINFO_FILNAM "." XXDP_VOLUMEINFO_EXT)) {
		// evaluate parameter file ?
	} else if (!strcasecmp(hostfname, XXDP_BOOTBLOCK_FILNAM "." XXDP_BOOTBLOCK_EXT)) {
		if (data_size != XXDP_BLOCKSIZE)
			return error_set(ERROR_FILESYSTEM_FORMAT, "Boot block not %d bytes\n",
			XXDP_BLOCKSIZE);
		_this->bootblock->data_size = data_size;
		_this->bootblock->data = realloc(_this->bootblock->data, data_size);
		memcpy(_this->bootblock->data, data, data_size);
	} else if (!strcasecmp(hostfname, XXDP_MONITOR_FILNAM "." XXDP_MONITOR_EXT)) {
		// assume max len of monitor
		int n = XXDP_BLOCKSIZE * (_this->preallocated_blockcount - _this->monitor->blocknr + 1);
		if (n < 0 || data_size > (unsigned)n)
			return error_set(ERROR_FILESYSTEM_OVERFLOW,
					"Monitor too big: is %d bytes, only %d allowed", data_size, n);
		_this->monitor->data_size = data_size;
		_this->monitor->data = realloc(_this->monitor->data, data_size);
		memcpy(_this->monitor->data, data, data_size);
	} else {
		xxdp_file_t *f;
		char filnam[40], ext[40];
		int file_idx;
		// regular file
		if (_this->file_count + 1 >= XXDP_MAX_FILES_PER_IMAGE)
			return error_set(ERROR_FILESYSTEM_OVERFLOW, "Too many files, only %d allowed",
			XXDP_MAX_FILES_PER_IMAGE);
		if (xxdp_filesystem_layout_test(_this, data_size))
			return error_set(ERROR_FILESYSTEM_OVERFLOW,
					"Disk full, file \"%s\" with %d bytes too large", hostfname, data_size);

		// make filename.extension to "FILN  .E  "
		xxdp_filename_from_host(hostfname, filnam, ext);

		// duplicate file name? Likely! because of trunc to six letters
		for (file_idx = 0; file_idx < _this->file_count; file_idx++) {
			xxdp_file_t *f1 = _this->file[file_idx];
			if (!strcasecmp(filnam, f1->filnam) && !strcasecmp(ext, f1->ext))
				return error_set(ERROR_FILESYSTEM_DUPLICATE, "Duplicate filename %s.%s", filnam,
						ext);
		}
		// now insert
		f = malloc(sizeof(xxdp_file_t));
		_this->file[_this->file_count++] = f;
		f->data_size = data_size;
		f->data = malloc(data_size);
		memcpy(f->data, data, data_size);
		strcpy(f->filnam, filnam);
		strcpy(f->ext, ext);

		f->date = *localtime(&hostfdate);
		// only range 1970..1999 allowed
		if (f->date.tm_year < 70)
			f->date.tm_year = 70;
		else if (f->date.tm_year > 99)
			f->date.tm_year = 99;
	}
	return ERROR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, %r15d
movq %rcx, %r13
movq %rsi, %r12
movq %rdi, %r14
movq %rdx, 0x8(%rsp)
leaq 0x8012(%rip), %rsi      # 0x154bb
movq %r12, %rdi
callq 0x3060
testl %eax, %eax
je 0xd69a
leaq 0x86ce(%rip), %rsi      # 0x15b8e
movq %r12, %rdi
callq 0x3060
testl %eax, %eax
je 0xd512
leaq 0x86de(%rip), %rsi      # 0x15bb1
movq %r12, %rdi
callq 0x3060
testl %eax, %eax
je 0xd55b
movslq 0xa8(%r14), %rdx
cmpq $0x3e7, %rdx            # imm = 0x3E7
jl 0xd5bc
leaq 0x86ef(%rip), %rsi      # 0x15be9
xorl %ebx, %ebx
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
movl $0x3e8, %edx            # imm = 0x3E8
xorl %eax, %eax
callq 0x9f8f
jmp 0xd694
cmpl $0x200, %r15d           # imm = 0x200
jne 0xd6ad
movq 0x80(%r14), %rax
movl $0x200, 0x10(%rax)      # imm = 0x200
movq 0x8(%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x3430
movq 0x80(%r14), %rcx
movq %rax, 0x8(%rcx)
movl $0x200, %edx            # imm = 0x200
movq %rax, %rdi
movq %r13, %rsi
callq 0x3350
jmp 0xd69a
movzwl 0x50(%r14), %edx
movq 0x88(%r14), %rax
movzwl (%rax), %ecx
subl %ecx, %edx
movl %edx, %ecx
shll $0x9, %ecx
addl $0x200, %ecx            # imm = 0x200
cmpl $-0x1, %edx
setge %dl
cmpl %r15d, %ecx
setae %bl
andb %dl, %bl
je 0xd76f
movl %r15d, 0x10(%rax)
movq 0x8(%rax), %rdi
movl %r15d, %r15d
movq %r15, %rsi
callq 0x3430
movq 0x88(%r14), %rcx
movq %rax, 0x8(%rcx)
movq %rax, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3350
jmp 0xd787
leal 0x1c(%rdx), %eax
cltq
imulq $-0x6db6db6d, %rax, %rax # imm = 0x92492493
shrq $0x20, %rax
addl %edx, %eax
addl $0x1c, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0x4, %eax
addl %ecx, %eax
xorl %ecx, %ecx
movl $0x0, %esi
testl %edx, %edx
jle 0xd61b
xorl %edi, %edi
movl $0x1fd, %r8d            # imm = 0x1FD
movl $0x80808081, %r9d       # imm = 0x80808081
xorl %esi, %esi
movq 0xb0(%r14,%rdi,8), %r10
movl 0x884(%r10), %r10d
addl %r8d, %r10d
imulq %r9, %r10
shrq $0x28, %r10
addl %r10d, %esi
incq %rdi
cmpq %rdi, %rdx
jne 0xd5f6
leal 0x1fd(%r15), %edx
movslq %edx, %rdx
imulq $-0x7f7f7f7f, %rdx, %rdx # imm = 0x80808081
shrq $0x20, %rdx
addl %r15d, %edx
addl $0x1fd, %edx            # imm = 0x1FD
movl %edx, %edi
shrl $0x1f, %edi
sarl $0x8, %edx
addl %edi, %edx
movl 0x4c(%r14), %edi
movzwl 0x50(%r14), %r8d
subl %r8d, %edi
movzwl 0x2e(%r14), %r8d
subl %r8d, %eax
cmovgl %eax, %ecx
addl %edx, %ecx
addl %esi, %ecx
cmpl %edi, %ecx
jle 0xd6d3
leaq 0x8d67(%rip), %rsi      # 0x163d0
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
xorl %eax, %eax
callq 0x9f8f
testl %eax, %eax
je 0xd6d3
leaq 0x8589(%rip), %rsi      # 0x15c09
xorl %ebx, %ebx
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
movq %r12, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x9f8f
movl %eax, %ebp
testb %bl, %bl
je 0xd69c
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x84e4(%rip), %rsi      # 0x15b98
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x200, %edx            # imm = 0x200
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9f8f
movq %r13, (%rsp)
leaq 0x40(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %r12, %rdi
callq 0xd884
movl 0xa8(%r14), %r13d
testl %r13d, %r13d
jle 0xd794
xorl %ebx, %ebx
movq 0xb0(%r14,%rbx,8), %r13
leaq 0x808(%r13), %rsi
leaq 0x40(%rsp), %rdi
callq 0x3060
movb $0x1, %r12b
testl %eax, %eax
jne 0xd755
addq $0x858, %r13            # imm = 0x858
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x3060
testl %eax, %eax
jne 0xd755
xorl %r12d, %r12d
movl $0xfffffffd, %edi       # imm = 0xFFFFFFFD
leaq 0x84f4(%rip), %rsi      # 0x15c36
leaq 0x40(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x9f8f
movl %eax, %ebp
testb %r12b, %r12b
je 0xd87d
incq %rbx
movslq 0xa8(%r14), %r13
cmpq %r13, %rbx
jl 0xd6fb
jmp 0xd794
leaq 0x8445(%rip), %rsi      # 0x15bbb
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
movl %r15d, %edx
xorl %eax, %eax
callq 0x9f8f
movl %eax, %ebp
testb %bl, %bl
jne 0xd69a
jmp 0xd69c
movl $0x8d0, %edi            # imm = 0x8D0
callq 0x33c0
movq %rax, %r12
leal 0x1(%r13), %eax
movl %eax, 0xa8(%r14)
movslq %r13d, %rax
movq %r12, 0xb0(%r14,%rax,8)
movl %r15d, 0x884(%r12)
movl %r15d, %r14d
movq %r14, %rdi
callq 0x33c0
movq %rax, 0x888(%r12)
movq %rax, %rdi
movq (%rsp), %rsi
movq %r14, %rdx
callq 0x3350
leaq 0x808(%r12), %rdi
leaq 0x40(%rsp), %rsi
callq 0x30d0
leaq 0x858(%r12), %rdi
leaq 0x10(%rsp), %rsi
callq 0x30d0
leaq 0x8(%rsp), %rdi
callq 0x3070
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm1, 0x8a0(%r12)
movups %xmm0, 0x890(%r12)
movups %xmm2, 0x8b0(%r12)
movq 0x30(%rax), %rax
movq %rax, 0x8c0(%r12)
movl 0x8a4(%r12), %eax
cmpl $0x45, %eax
jg 0xd861
movl $0x46, 0x8a4(%r12)
movb $0x1, %bl
jmp 0xd696
movb $0x1, %bl
cmpl $0x64, %eax
jl 0xd696
movl $0x63, 0x8a4(%r12)
jmp 0xd696
xorl %ebx, %ebx
jmp 0xd696