// File: /workspace/github_c_makefile_star2_O0/j-hoppe[P]tu58fs/xxdp.c
// Function: parse_mfd
static void parse_mfd(xxdp_filesystem_t *_this) {
	unsigned n;
	xxdp_blocknr_t blknr, mfdblknr;

	xxdp_blocklist_get(_this, _this->mfd_blocklist, _this->radi.mfd1);
	if (_this->mfd_blocklist->count == 2) {
		// 2 blocks. first predefined, fetch 2nd from image
		// Prefer MFD data over linked list scan, why?
		if (_this->mfd_variety != 1)
			warning("MFD is 2 blocks, variety 1 expected, but variety %d defined",
					_this->mfd_variety);
		/*
		 _this->mfd_blocklist->count = 2;
		 _this->mfd_blocklist->blocknr[0] = _this->radi.mfd1;
		 _this->mfd_blocklist->blocknr[1] = xxdp_image_get_word(_this,
		 _this->mfd_blocklist->blocknr[0], 0);
		 */
		mfdblknr = _this->mfd_blocklist->blocknr[0];

		_this->interleave = xxdp_image_get_word(_this, mfdblknr, 1);
		// build bitmap,
		// word[2] = bitmap start block, word[3] = pointer to bitmap #1, always the same?
		// a 0 terminated list of bitmap blocks is in MFD1, word 2,3,...
		// Prefer MFD data over linked list scan, why?
		n = 0;
		do {
			assert(n + 3 < 255);
			blknr = xxdp_image_get_word(_this, mfdblknr, n + 3);
			if (blknr > 0) {
				_this->bitmap->blocklist.blocknr[n] = blknr;
				n++;
			}
		} while (blknr > 0);
		_this->bitmap->blocklist.count = n;

		mfdblknr = _this->mfd_blocklist->blocknr[1];
		// Get start of User File Directory from MFD2, word 2, then scan linked list
		blknr = xxdp_image_get_word(_this, mfdblknr, 2);
		xxdp_blocklist_get(_this, _this->ufd_blocklist, blknr);
	} else if (_this->mfd_blocklist->count == 1) {
		// var 2: "MFD1/2" RL01/2 ?
		if (_this->mfd_variety != 2)
			warning( "MFD is 1 blocks, variety 2 expected, but variety %d defined",
					_this->mfd_variety);

		mfdblknr = _this->mfd_blocklist->blocknr[0];

		// Build UFD block list
		blknr = xxdp_image_get_word(_this, mfdblknr, 1);
		xxdp_blocklist_get(_this, _this->ufd_blocklist, blknr);
		// verify len
		n = xxdp_image_get_word(_this, mfdblknr, 2);
		if (n != _this->ufd_blocklist->count)
			warning( "UFD block count is %u, but %d in MFD1/2",
					_this->ufd_blocklist->count, n);
		// best choice is len of disk list

		// Build Bitmap block list
		blknr = xxdp_image_get_word(_this, mfdblknr, 3);
		xxdp_blocklist_get(_this, &(_this->bitmap->blocklist), blknr);
		// verify len
		n = xxdp_image_get_word(_this, mfdblknr, 4);
		if (n != _this->bitmap->blocklist.count)
			warning("Bitmap block count is %u, but %d in MFD1/2",
					_this->bitmap->blocklist.count, n);

		// total num of blocks
		n = _this->blockcount = xxdp_image_get_word(_this, mfdblknr, 7);
		if (n != _this->blockcount)
			warning("Device blockcount is %u in RADI, but %d in MFD1/2",
					_this->blockcount, n);

		n = _this->preallocated_blockcount = xxdp_image_get_word(_this, mfdblknr, 8);
		if (n != _this->radi.prealloc_blocks_num)
			warning("Device preallocated blocks are %u in RADI, but %d in MFD1/2",
					_this->radi.prealloc_blocks_num, n);

		_this->interleave = xxdp_image_get_word(_this, mfdblknr, 9);
		if (_this->interleave != _this->radi.interleave)
			warning("Device interleave is %u in RADI, but %d in MFD1/2",
					_this->radi.interleave, _this->interleave);

		n = _this->monitor->blocknr = xxdp_image_get_word(_this, mfdblknr, 11);
		if (n != _this->radi.monitor_block)
			warning("Monitor core start is %u in RADI, but %d in MFD1/2",
					_this->radi.monitor_block, n);
		_this->monitor->blockcount = _this->preallocated_blockcount - _this->monitor->blocknr;

		warning("Position of bad block file not yet evaluated");
	} else
	fatal("Invalid block count in MFD: %d", _this->mfd_blocklist->count);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x34(%rax), %eax
movzwl %ax, %edx
callq 0x13370
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
cmpl $0x2, (%rax)
jne 0x10198
movq -0x8(%rbp), %rax
cmpl $0x1, 0x58(%rax)
je 0x1008d
movq -0x8(%rbp), %rax
movl 0x58(%rax), %esi
leaq 0xccc2(%rip), %rdi      # 0x1cd48
movb $0x0, %al
callq 0xd050
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movw 0x4(%rax), %ax
movw %ax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movzwl %ax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addl $0x3, %eax
cmpl $0xff, %eax
jae 0x100d2
jmp 0x100f1
leaq 0xccab(%rip), %rdi      # 0x1cd84
leaq 0xc93b(%rip), %rsi      # 0x1ca1b
movl $0x189, %edx            # imm = 0x189
leaq 0xcca4(%rip), %rcx      # 0x1cd90
callq 0x3200
movq -0x8(%rbp), %rdi
movw -0x10(%rbp), %cx
movl -0xc(%rbp), %eax
addl $0x3, %eax
movzwl %cx, %esi
movzbl %al, %edx
callq 0x13420
movw %ax, -0xe(%rbp)
movzwl -0xe(%rbp), %eax
cmpl $0x0, %eax
jle 0x10137
movw -0xe(%rbp), %dx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movw %dx, 0x4(%rax,%rcx,2)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x10139
movzwl -0xe(%rbp), %eax
cmpl $0x0, %eax
jg 0x100c3
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movw 0x6(%rax), %ax
movw %ax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movw %ax, -0xe(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rsi
movzwl -0xe(%rbp), %edx
callq 0x13370
jmp 0x10442
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
cmpl $0x1, (%rax)
jne 0x10425
movq -0x8(%rbp), %rax
cmpl $0x2, 0x58(%rax)
je 0x101cb
movq -0x8(%rbp), %rax
movl 0x58(%rax), %esi
leaq 0xcbf0(%rip), %rdi      # 0x1cdb4
movb $0x0, %al
callq 0xd050
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movw 0x4(%rax), %ax
movw %ax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movw %ax, -0xe(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rsi
movzwl -0xe(%rbp), %edx
callq 0x13370
movq -0x8(%rbp), %rdi
movl $0x2, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movzwl %ax, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0xa0(%rcx), %rcx
cmpl (%rcx), %eax
je 0x10254
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rax
movl (%rax), %esi
movl -0xc(%rbp), %edx
leaq 0xcba3(%rip), %rdi      # 0x1cdf0
movb $0x0, %al
callq 0xd050
movq -0x8(%rbp), %rdi
movl $0x3, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movw %ax, -0xe(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rsi
movzwl -0xe(%rbp), %edx
callq 0x13370
movq -0x8(%rbp), %rdi
movl $0x4, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movzwl %ax, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x90(%rcx), %rcx
cmpl (%rcx), %eax
je 0x102ca
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl (%rax), %esi
movl -0xc(%rbp), %edx
leaq 0xcb55(%rip), %rdi      # 0x1ce18
movb $0x0, %al
callq 0xd050
movq -0x8(%rbp), %rdi
movl $0x7, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movzwl %ax, %eax
movq -0x8(%rbp), %rcx
movl %eax, 0x4c(%rcx)
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4c(%rcx), %eax
je 0x1030d
movq -0x8(%rbp), %rax
movl 0x4c(%rax), %esi
movl -0xc(%rbp), %edx
leaq 0xcb3d(%rip), %rdi      # 0x1ce43
movb $0x0, %al
callq 0xd050
movq -0x8(%rbp), %rdi
movl $0x8, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movq -0x8(%rbp), %rcx
movw %ax, 0x50(%rcx)
movzwl %ax, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x40(%rcx), %ecx
cmpl %ecx, %eax
je 0x10355
movq -0x8(%rbp), %rax
movzwl 0x40(%rax), %esi
movl -0xc(%rbp), %edx
leaq 0xcb27(%rip), %rdi      # 0x1ce75
movb $0x0, %al
callq 0xd050
movq -0x8(%rbp), %rdi
movl $0x9, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movzwl %ax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x8(%rbp), %rax
movl 0x54(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x44(%rcx), %eax
je 0x1039d
movq -0x8(%rbp), %rax
movl 0x44(%rax), %esi
movq -0x8(%rbp), %rax
movl 0x54(%rax), %edx
leaq 0xcb1b(%rip), %rdi      # 0x1ceb1
movb $0x0, %al
callq 0xd050
movq -0x8(%rbp), %rdi
movl $0xb, %edx
movzwl -0x10(%rbp), %esi
callq 0x13420
movq -0x8(%rbp), %rcx
movq 0x88(%rcx), %rcx
movw %ax, (%rcx)
movzwl %ax, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x4a(%rcx), %ecx
cmpl %ecx, %eax
je 0x103eb
movq -0x8(%rbp), %rax
movzwl 0x4a(%rax), %esi
movl -0xc(%rbp), %edx
leaq 0xcaff(%rip), %rdi      # 0x1cee3
movb $0x0, %al
callq 0xd050
movq -0x8(%rbp), %rax
movzwl 0x50(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x88(%rcx), %rcx
movzwl (%rcx), %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movw %cx, 0x2(%rax)
leaq 0xcafa(%rip), %rdi      # 0x1cf16
movb $0x0, %al
callq 0xd050
jmp 0x10440
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movl (%rax), %esi
leaq 0xcb0a(%rip), %rdi      # 0x1cf43
movb $0x0, %al
callq 0xd140
jmp 0x10442
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)