// File: /workspace/github_c_makefile_star2_O2/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, %r15
movl 0x4c(%rdi), %edx
leaq 0x789e(%rip), %rsi      # 0x14cbe
movq %rax, 0x18(%rsp)
movq %rax, %rdi
xorl %eax, %eax
callq 0x3310
leaq 0x78e3(%rip), %r13      # 0x14d19
xorl %r12d, %r12d
movq %r15, 0x20(%rsp)
movzwl %r12w, %ebp
cmpl %ebp, 0x4c(%r15)
jbe 0xd705
movb $0x0, 0x30(%rsp)
testl %ebp, %ebp
jne 0xd489
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7879(%rip), %rsi      # 0x14ce0
leaq 0x7839(%rip), %rdx      # 0x14ca7
leaq 0x776a(%rip), %rcx      # 0x14bdf
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3510
movq 0x88(%r15), %rax
movzwl (%rax), %ecx
movl %ebp, 0x14(%rsp)
movl %ebp, %r8d
subl %ecx, %r8d
js 0xd4dd
movzwl 0x2(%rax), %r9d
cmpl %r9d, %r8d
jge 0xd4dd
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7838(%rip), %rsi      # 0x14cf3
leaq 0x77df(%rip), %rdx      # 0x14ca1
leaq 0x7739(%rip), %rcx      # 0x14c02
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3510
movq 0x98(%r15), %rax
movl (%rax), %ebx
xorl %r14d, %r14d
movq %r12, 0x8(%rsp)
cmpq %r14, %rbx
je 0xd537
movq 0x98(%r15), %rax
cmpw %r12w, 0x4(%rax,%r14,2)
jne 0xd532
leaq 0x130(%rsp), %r12
movq %r12, %rdi
leaq 0x77f8(%rip), %rsi      # 0x14d0c
movl %r14d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq 0x8(%rsp), %r12
callq 0x3510
incq %r14
jmp 0xd4ee
movq 0xa0(%r15), %rax
movl (%rax), %ebx
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0xd588
movq 0xa0(%r15), %rax
cmpw %r12w, 0x4(%rax,%r14,2)
jne 0xd583
leaq 0x130(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq 0x8(%rsp), %r12
callq 0x3510
incq %r14
jmp 0xd543
movq 0x90(%r15), %rax
movl (%rax), %ebx
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0xd5dd
movq 0x90(%r15), %rax
cmpw %r12w, 0x4(%rax,%r14,2)
jne 0xd5d8
leaq 0x130(%rsp), %r12
movq %r12, %rdi
leaq 0x776c(%rip), %rsi      # 0x14d26
movl %r14d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq 0x8(%rsp), %r12
callq 0x3510
incq %r14
jmp 0xd594
xorl %ebx, %ebx
movslq 0xa8(%r15), %rax
cmpq %rax, %rbx
jge 0xd668
movq 0xb0(%r15,%rbx,8), %rbp
movl (%rbp), %r15d
leaq 0x808(%rbp), %rax
movq %rax, 0x28(%rsp)
leaq 0x858(%rbp), %r14
xorl %r13d, %r13d
cmpq %r13, %r15
je 0xd65b
cmpw %r12w, 0x4(%rbp,%r13,2)
jne 0xd656
movl %r15d, (%rsp)
leaq 0x130(%rsp), %r12
movq %r12, %rdi
leaq 0x7706(%rip), %rsi      # 0x14d36
movl %ebx, %edx
movq 0x28(%rsp), %rcx
movq %r14, %r8
movl %r13d, %r9d
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq 0x8(%rsp), %r12
callq 0x3510
incq %r13
jmp 0xd60d
incq %rbx
movq 0x20(%rsp), %r15
jmp 0xd5df
movq 0x90(%r15), %rax
movl 0x14(%rsp), %ebp
movl %ebp, %ecx
movb 0x804(%rax,%rcx), %al
testb %al, %al
sete %dl
movb 0x30(%rsp), %cl
testb %cl, %cl
setne %sil
xorb %dl, %sil
jne 0xd6ce
testb %al, %al
leaq 0x76dc(%rip), %rdx      # 0x14d75
leaq 0x76d1(%rip), %rax      # 0x14d71
cmoveq %rax, %rdx
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x769b(%rip), %rsi      # 0x14d51
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3510
movb 0x30(%rsp), %cl
testb %cl, %cl
leaq 0x7642(%rip), %r13      # 0x14d19
je 0xd6fb
movl %ebp, %ecx
shll $0x9, %ecx
movq 0x18(%rsp), %rdi
leaq 0x7690(%rip), %rsi      # 0x14d7a
movl %ebp, %edx
movl %ecx, %r8d
leaq 0x30(%rsp), %r9
xorl %eax, %eax
callq 0x3310
incl %ebp
movl %ebp, %r12d
jmp 0xd43e
movq %r15, %rdi
callq 0xd373
movl 0x4c(%r15), %ecx
movl %ecx, %r9d
subl %eax, %r9d
leaq 0x7677(%rip), %rsi      # 0x14d95
movq 0x18(%rsp), %rdi
movl %eax, %edx
movl %eax, %r8d
xorl %eax, %eax
callq 0x3310
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq