// File: /workspace/github_c_makefile_star2_O1/j-hoppe[P]tu58fs/xxdp.c
// Function: xxdp_filesystem_print_diag
void xxdp_filesystem_print_diag(xxdp_filesystem_t *_this, FILE *stream) {
	xxdp_blocknr_t blknr;
	int file_idx ;
	unsigned i, n;
	char line[256];
	char buff[256];
	int used;
	fprintf(stream, "Filesystem has %d blocks, usage:\n", _this->blockcount);
	for (blknr = 0; blknr < _this->blockcount; blknr++) {
		int blkoffset ;
		line[0] = 0;
		if (blknr == 0) {
			sprintf(buff, " BOOTBLOCK \"%s.%s\"", XXDP_BOOTBLOCK_FILNAM, XXDP_BOOTBLOCK_EXT);
			strcat(line, buff);
		}

		// monitor
		n = _this->monitor->blockcount;
		blkoffset = blknr - _this->monitor->blocknr;
		if (blkoffset >= 0 && blkoffset < (int)n) {
			sprintf(buff, " MONITOR \"%s.%s\" - %d/%d", XXDP_MONITOR_FILNAM, XXDP_MONITOR_EXT,
					blkoffset, n);
			strcat(line, buff);
		}

		// search mfd1, mfd2
		n = _this->mfd_blocklist->count;
		for (i = 0; i < n; i++)
			if (_this->mfd_blocklist->blocknr[i] == blknr) {
				sprintf(buff, " MFD - %d/%d", i, n);
				strcat(line, buff);
			}
		// search ufd
		n = _this->ufd_blocklist->count;
		for (i = 0; i < n; i++)
			if (_this->ufd_blocklist->blocknr[i] == blknr) {
				sprintf(buff, " UFD - %d/%d", i, n);
				strcat(line, buff);
			}
		// search bitmap
		n = _this->bitmap->blocklist.count;
		for (i = 0; i < n; i++)
			if (_this->bitmap->blocklist.blocknr[i] == blknr) {
				sprintf(buff, " BITMAP - %d/%d", i, n);
				strcat(line, buff);
			}
		// search file
		for (file_idx = 0; file_idx < _this->file_count; file_idx++) {
			unsigned j ;
			xxdp_file_t *f = _this->file[file_idx];
			n = f->blocklist.count;
			for (j = 0; j < n; j++)
				if (f->blocklist.blocknr[j] == blknr) {
					sprintf(buff, " file #%d: \"%s.%s\" - %d/%d", file_idx, f->filnam, f->ext, j, n);
					strcat(line, buff);
				}
		}
		// block marked in bitmap?
		used = _this->bitmap->used[blknr];
		if ((!used && line[0]) || (used && !line[0])) {
			sprintf(buff, " Bitmap mismatch, marked as %s!", used ? "USED" : "NOT USED");
			strcat(line, buff);
		}
		if (line[0]) {
			int offset = (IMAGE_BLOCKNR2PTR(_this, blknr) - IMAGE_BLOCKNR2PTR(_this, 0));
			fprintf(stream, "%5d @ 0x%06x = %#08o:  %s\n", blknr, offset, offset, line);
		}
	}
	n = xxdp_bitmap_count(_this);
	fprintf(stream, "Blocks marked as \"used\" in bitmap: %d. Free: %d - %d = %d.\n", n,
			_this->blockcount, n, _this->blockcount - n);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rsi, %rax
movq %rdi, %r14
movl 0x4c(%rdi), %edx
leaq 0x7b5c(%rip), %rsi      # 0x15c73
movq %rax, 0x18(%rsp)
movq %rax, %rdi
xorl %eax, %eax
callq 0x3320
cmpl $0x0, 0x4c(%r14)
je 0xe427
leaq 0x7ba3(%rip), %r13      # 0x15cdb
leaq 0x7b8f(%rip), %rbp      # 0x15cce
xorl %r15d, %r15d
xorl %edx, %edx
movq %r14, 0x20(%rsp)
movb $0x0, 0x30(%rsp)
testw %dx, %dx
movl %edx, 0x10(%rsp)
jne 0xe18f
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7b2c(%rip), %rsi      # 0x15c95
leaq 0x7aec(%rip), %rdx      # 0x15c5c
leaq 0x7a1d(%rip), %rcx      # 0x15b94
xorl %eax, %eax
callq 0x3540
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3520
movl 0x10(%rsp), %edx
movq 0x88(%r14), %rax
movzwl (%rax), %ecx
movl %r15d, 0x14(%rsp)
movl %r15d, %r8d
subl %ecx, %r8d
js 0xe1e8
movzwl 0x2(%rax), %r9d
cmpl %r9d, %r8d
jge 0xe1e8
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7ae6(%rip), %rsi      # 0x15ca8
leaq 0x7a8d(%rip), %rdx      # 0x15c56
leaq 0x79e7(%rip), %rcx      # 0x15bb7
xorl %eax, %eax
callq 0x3540
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3520
movl 0x10(%rsp), %edx
movq 0x98(%r14), %rax
movl (%rax), %r12d
testq %r12, %r12
je 0xe23e
xorl %ebx, %ebx
movq 0x98(%r14), %rax
cmpw %dx, 0x4(%rax,%rbx,2)
jne 0xe236
leaq 0x130(%rsp), %r15
movq %r15, %rdi
leaq 0x7aa8(%rip), %rsi      # 0x15cc1
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x3540
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x3520
movl 0x10(%rsp), %edx
incq %rbx
cmpq %rbx, %r12
jne 0xe1f9
movq 0xa0(%r14), %rax
movl (%rax), %r12d
testq %r12, %r12
je 0xe290
xorl %ebx, %ebx
movq 0xa0(%r14), %rax
cmpw %dx, 0x4(%rax,%rbx,2)
jne 0xe288
leaq 0x130(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x3540
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x3520
movl 0x10(%rsp), %edx
incq %rbx
cmpq %rbx, %r12
jne 0xe24f
movq 0x90(%r14), %rax
movl (%rax), %r12d
testq %r12, %r12
je 0xe2e2
xorl %ebx, %ebx
movq 0x90(%r14), %rax
cmpw %dx, 0x4(%rax,%rbx,2)
jne 0xe2da
leaq 0x130(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x3540
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x3520
movl 0x10(%rsp), %edx
incq %rbx
cmpq %rbx, %r12
jne 0xe2a1
cmpl $0x0, 0xa8(%r14)
jle 0xe37e
xorl %r12d, %r12d
movq 0xb0(%r14,%r12,8), %rbp
movl (%rbp), %r15d
testq %r15, %r15
je 0xe366
leaq 0x808(%rbp), %rax
movq %rax, 0x28(%rsp)
leaq 0x858(%rbp), %r14
xorl %r13d, %r13d
cmpw %dx, 0x4(%rbp,%r13,2)
jne 0xe35e
movl %r15d, (%rsp)
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x79b3(%rip), %rsi      # 0x15ceb
movl %r12d, %edx
movq 0x28(%rsp), %rcx
movq %r14, %r8
movl %r13d, %r9d
xorl %eax, %eax
callq 0x3540
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3520
movl 0x10(%rsp), %edx
incq %r13
cmpq %r13, %r15
jne 0xe31a
incq %r12
movq 0x20(%rsp), %r14
movslq 0xa8(%r14), %rax
cmpq %rax, %r12
jl 0xe2f3
movq 0x90(%r14), %rax
movzwl %dx, %ecx
movb 0x804(%rax,%rcx), %al
testb %al, %al
sete %cl
cmpb $0x0, 0x30(%rsp)
setne %dl
xorb %cl, %dl
jne 0xe3da
testb %al, %al
leaq 0x7981(%rip), %rdx      # 0x15d2a
leaq 0x7976(%rip), %rax      # 0x15d26
cmoveq %rax, %rdx
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7940(%rip), %rsi      # 0x15d06
xorl %eax, %eax
callq 0x3540
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3520
cmpb $0x0, 0x30(%rsp)
leaq 0x78f5(%rip), %r13      # 0x15cdb
leaq 0x78e1(%rip), %rbp      # 0x15cce
movl 0x14(%rsp), %edx
je 0xe413
movl %edx, %ecx
shll $0x9, %ecx
movq 0x18(%rsp), %rdi
leaq 0x792b(%rip), %rsi      # 0x15d2f
movl %ecx, %r8d
leaq 0x30(%rsp), %r9
xorl %eax, %eax
callq 0x3320
movl 0x10(%rsp), %edx
incl %edx
movzwl %dx, %r15d
cmpl %r15d, 0x4c(%r14)
ja 0xe149
movq %r14, %rdi
callq 0xe058
movl 0x4c(%r14), %ecx
movl %ecx, %r9d
subl %eax, %r9d
leaq 0x790a(%rip), %rsi      # 0x15d4a
movq 0x18(%rsp), %rdi
movl %eax, %edx
movl %eax, %r8d
xorl %eax, %eax
callq 0x3320
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq