// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
leaq 0xa7af(%rip), %rsi      # 0x1c3e9
callq 0x3050
cmpl $0x0, %eax
jne 0x11c49
jmp 0x11fe9
movq -0x18(%rbp), %rdi
leaq 0xae88(%rip), %rsi      # 0x1cadc
callq 0x3050
cmpl $0x0, %eax
jne 0x11ce9
cmpl $0x200, -0x2c(%rbp)     # imm = 0x200
je 0x11c8b
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leaq 0xae6f(%rip), %rsi      # 0x1cae6
movl $0x200, %edx            # imm = 0x200
movb $0x0, %al
callq 0xcd70
movl %eax, -0x4(%rbp)
jmp 0x11ff0
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq 0x8(%rax), %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x3410
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x3330
jmp 0x11fe7
movq -0x18(%rbp), %rdi
leaq 0xae0b(%rip), %rsi      # 0x1caff
callq 0x3050
cmpl $0x0, %eax
jne 0x11db0
movq -0x10(%rbp), %rax
movzwl 0x50(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x88(%rcx), %rcx
movzwl (%rcx), %ecx
subl %ecx, %eax
addl $0x1, %eax
shll $0x9, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jl 0x11d31
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jbe 0x11d52
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
leaq 0xadc6(%rip), %rsi      # 0x1cb09
movb $0x0, %al
callq 0xcd70
movl %eax, -0x4(%rbp)
jmp 0x11ff0
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x8(%rax), %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x3410
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x3330
jmp 0x11fe5
movq -0x10(%rbp), %rax
movl 0xa8(%rax), %eax
addl $0x1, %eax
cmpl $0x3e8, %eax            # imm = 0x3E8
jl 0x11de4
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
leaq 0xad67(%rip), %rsi      # 0x1cb37
movl $0x3e8, %edx            # imm = 0x3E8
movb $0x0, %al
callq 0xcd70
movl %eax, -0x4(%rbp)
jmp 0x11ff0
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x12000
cmpl $0x0, %eax
je 0x11e17
movq -0x18(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
leaq 0xad4f(%rip), %rsi      # 0x1cb57
movb $0x0, %al
callq 0xcd70
movl %eax, -0x4(%rbp)
jmp 0x11ff0
movq -0x18(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x12110
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xa8(%rcx), %eax
jge 0x11edc
movq -0x10(%rbp), %rax
movslq -0x94(%rbp), %rcx
movq 0xb0(%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
leaq -0x60(%rbp), %rdi
movq -0xa0(%rbp), %rsi
addq $0x808, %rsi            # imm = 0x808
callq 0x3050
cmpl $0x0, %eax
jne 0x11ec6
leaq -0x90(%rbp), %rdi
movq -0xa0(%rbp), %rsi
addq $0x858, %rsi            # imm = 0x858
callq 0x3050
cmpl $0x0, %eax
jne 0x11ec6
leaq -0x60(%rbp), %rdx
leaq -0x90(%rbp), %rcx
movl $0xfffffffd, %edi       # imm = 0xFFFFFFFD
leaq 0xaccd(%rip), %rsi      # 0x1cb84
movb $0x0, %al
callq 0xcd70
movl %eax, -0x4(%rbp)
jmp 0x11ff0
jmp 0x11ec8
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x11e35
movl $0x8d0, %edi            # imm = 0x8D0
callq 0x33a0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movl 0xa8(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0xa8(%rsi)
movslq %ecx, %rcx
movq %rdx, 0xb0(%rax,%rcx,8)
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x884(%rax)
movl -0x2c(%rbp), %eax
movl %eax, %edi
callq 0x33a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x888(%rax)
movq -0x38(%rbp), %rax
movq 0x888(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x3330
movq -0x38(%rbp), %rdi
addq $0x808, %rdi            # imm = 0x808
leaq -0x60(%rbp), %rsi
callq 0x30c0
movq -0x38(%rbp), %rdi
addq $0x858, %rdi            # imm = 0x858
leaq -0x90(%rbp), %rsi
callq 0x30c0
movq -0x38(%rbp), %rax
addq $0x890, %rax            # imm = 0x890
movq %rax, -0xa8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x3060
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
movl $0x38, %edx
callq 0x3330
movq -0x38(%rbp), %rax
cmpl $0x46, 0x8a4(%rax)
jge 0x11fc6
movq -0x38(%rbp), %rax
movl $0x46, 0x8a4(%rax)
jmp 0x11fe3
movq -0x38(%rbp), %rax
cmpl $0x63, 0x8a4(%rax)
jle 0x11fe1
movq -0x38(%rbp), %rax
movl $0x63, 0x8a4(%rax)
jmp 0x11fe3
jmp 0x11fe5
jmp 0x11fe7
jmp 0x11fe9
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)