// File: /workspace/github_c_makefile_star2_O3/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 0x7c80(%rip), %rsi      # 0x15d0b
movq %rax, 0x18(%rsp)
movq %rax, %rdi
xorl %eax, %eax
callq 0x3310
cmpl $0x0, 0x4c(%r14)
je 0xe3a3
leaq 0x7cc7(%rip), %r13      # 0x15d73
leaq 0x7cb3(%rip), %rbp      # 0x15d66
xorl %r15d, %r15d
xorl %edx, %edx
movq %r14, 0x20(%rsp)
movb $0x0, 0x30(%rsp)
testw %dx, %dx
movl %edx, 0x10(%rsp)
jne 0xe103
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7c50(%rip), %rsi      # 0x15d2d
leaq 0x7c10(%rip), %rdx      # 0x15cf4
leaq 0x7b41(%rip), %rcx      # 0x15c2c
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3510
movl 0x10(%rsp), %edx
movq 0x88(%r14), %rax
movzwl (%rax), %ecx
movl %r15d, 0x14(%rsp)
movl %r15d, %r8d
subl %ecx, %r8d
js 0xe15c
movzwl 0x2(%rax), %r9d
cmpl %r9d, %r8d
jge 0xe15c
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7c0a(%rip), %rsi      # 0x15d40
leaq 0x7bb1(%rip), %rdx      # 0x15cee
leaq 0x7b0b(%rip), %rcx      # 0x15c4f
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3510
movl 0x10(%rsp), %edx
movq 0x98(%r14), %rax
movl (%rax), %r12d
testq %r12, %r12
je 0xe1b2
xorl %ebx, %ebx
movq 0x98(%r14), %rax
cmpw %dx, 0x4(%rax,%rbx,2)
jne 0xe1aa
leaq 0x130(%rsp), %r15
movq %r15, %rdi
leaq 0x7bcc(%rip), %rsi      # 0x15d59
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x3510
movl 0x10(%rsp), %edx
incq %rbx
cmpq %rbx, %r12
jne 0xe16d
movq 0xa0(%r14), %rax
movl (%rax), %r12d
testq %r12, %r12
je 0xe204
xorl %ebx, %ebx
movq 0xa0(%r14), %rax
cmpw %dx, 0x4(%rax,%rbx,2)
jne 0xe1fc
leaq 0x130(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x3510
movl 0x10(%rsp), %edx
incq %rbx
cmpq %rbx, %r12
jne 0xe1c3
movq 0x90(%r14), %rax
movl (%rax), %r12d
testq %r12, %r12
je 0xe256
xorl %ebx, %ebx
movq 0x90(%r14), %rax
cmpw %dx, 0x4(%rax,%rbx,2)
jne 0xe24e
leaq 0x130(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x3510
movl 0x10(%rsp), %edx
incq %rbx
cmpq %rbx, %r12
jne 0xe215
movl 0xa8(%r14), %eax
testl %eax, %eax
jle 0xe2f6
xorl %r12d, %r12d
movq 0xb0(%r14,%r12,8), %rbp
movl (%rbp), %r15d
testq %r15, %r15
je 0xe2e7
leaq 0x808(%rbp), %rax
movq %rax, 0x28(%rsp)
leaq 0x858(%rbp), %r14
xorl %r13d, %r13d
cmpw %dx, 0x4(%rbp,%r13,2)
jne 0xe2d3
movl %r15d, (%rsp)
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7ad6(%rip), %rsi      # 0x15d83
movl %r12d, %edx
movq 0x28(%rsp), %rcx
movq %r14, %r8
movl %r13d, %r9d
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3510
movl 0x10(%rsp), %edx
incq %r13
cmpq %r13, %r15
jne 0xe28f
movq 0x20(%rsp), %r14
movl 0xa8(%r14), %eax
incq %r12
movslq %eax, %rcx
cmpq %rcx, %r12
jl 0xe268
movq 0x90(%r14), %rax
movzwl %dx, %ecx
movb 0x804(%rax,%rcx), %al
testb %al, %al
sete %dl
movb 0x30(%rsp), %cl
testb %cl, %cl
setne %sil
xorb %dl, %sil
jne 0xe359
testb %al, %al
leaq 0x7a9e(%rip), %rdx      # 0x15dc2
leaq 0x7a93(%rip), %rax      # 0x15dbe
cmoveq %rax, %rdx
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7a5d(%rip), %rsi      # 0x15d9e
xorl %eax, %eax
callq 0x3530
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3510
movb 0x30(%rsp), %cl
testb %cl, %cl
leaq 0x7a11(%rip), %r13      # 0x15d73
leaq 0x79fd(%rip), %rbp      # 0x15d66
movl 0x14(%rsp), %edx
je 0xe38f
movl %edx, %ecx
shll $0x9, %ecx
movq 0x18(%rsp), %rdi
leaq 0x7a47(%rip), %rsi      # 0x15dc7
movl %ecx, %r8d
leaq 0x30(%rsp), %r9
xorl %eax, %eax
callq 0x3310
movl 0x10(%rsp), %edx
incl %edx
movzwl %dx, %r15d
cmpl %r15d, 0x4c(%r14)
ja 0xe0bd
movq %r14, %rdi
callq 0xdf2d
movl 0x4c(%r14), %ecx
movl %ecx, %r9d
subl %eax, %r9d
leaq 0x7a26(%rip), %rsi      # 0x15de2
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