// File: /workspace/github_c_makefile_star2_O0/j-hoppe[P]tu58fs/xxdp.c
// Function: parse_bitmap
static void parse_bitmap(xxdp_filesystem_t *_this) {
	unsigned i, j, k;
	xxdp_blocknr_t blknr; // enumerates the block flags
	// assume consecutive bitmap blocks encode consecutive block numbers
	// what about map number?
	blknr = 0;
	for (i = 0; i < _this->bitmap->blocklist.count; i++) {
		unsigned map_wordcount;
		xxdp_blocknr_t map_blknr = _this->bitmap->blocklist.blocknr[i];
		xxdp_blocknr_t map_start_blknr; // block of 1st map block
		// mapnr = xxdp_image_get_word(_this, blknr, 2);
		map_wordcount = xxdp_image_get_word(_this, map_blknr, 2);
		assert(map_wordcount == XXDP_BITMAP_WORDS_PER_MAP);
		// verify link to start
		map_start_blknr = xxdp_image_get_word(_this, map_blknr, 3);
		assert(map_start_blknr == _this->bitmap->blocklist.blocknr[0]);
		// hexdump(ferr, IMAGE_BLOCKNR2PTR(_this, map_blknr), 512, "Block %u = bitmap %u", map_blknr, i);
		for (j = 0; j < map_wordcount; j++) {
			uint16_t map_flags = xxdp_image_get_word(_this, map_blknr, j + 4);
			// 16 flags per word. LSB = lowest blocknr
			for (k = 0; k < 16; k++) {
				assert(blknr == (i * XXDP_BITMAP_WORDS_PER_MAP + j) * 16 + k);
				if (map_flags & (1 << k))
					_this->bitmap->used[blknr] = 1;
				else
					_this->bitmap->used[blknr] = 0;
				blknr++;
			}
		}
	}
	// blknr is now count of defined blocks
	// _this->bitmap->blockcount = blknr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movw $0x0, -0x16(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x90(%rcx), %rcx
cmpl (%rcx), %eax
jae 0x1061b
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movw 0x4(%rax,%rcx,2), %ax
movw %ax, -0x1e(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2, %edx
movzwl -0x1e(%rbp), %esi
callq 0x13420
movzwl %ax, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x3c, -0x1c(%rbp)
jne 0x104b6
jmp 0x104d5
leaq 0xcb47(%rip), %rdi      # 0x1d004
leaq 0xc557(%rip), %rsi      # 0x1ca1b
movl $0x1d9, %edx            # imm = 0x1D9
leaq 0xcb5f(%rip), %rcx      # 0x1d02f
callq 0x3200
movq -0x8(%rbp), %rdi
movl $0x3, %edx
movzwl -0x1e(%rbp), %esi
callq 0x13420
movw %ax, -0x20(%rbp)
movzwl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x90(%rcx), %rcx
movzwl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jne 0x10504
jmp 0x10523
leaq 0xcb4b(%rip), %rdi      # 0x1d056
leaq 0xc509(%rip), %rsi      # 0x1ca1b
movl $0x1dc, %edx            # imm = 0x1DC
leaq 0xcb11(%rip), %rcx      # 0x1d02f
callq 0x3200
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x1060b
movq -0x8(%rbp), %rdi
movw -0x1e(%rbp), %cx
movl -0x10(%rbp), %eax
addl $0x4, %eax
movzwl %cx, %esi
movzbl %al, %edx
callq 0x13420
movw %ax, -0x22(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x10, -0x14(%rbp)
jae 0x105fb
movzwl -0x16(%rbp), %eax
imull $0x3c, -0xc(%rbp), %ecx
addl -0x10(%rbp), %ecx
shll $0x4, %ecx
addl -0x14(%rbp), %ecx
cmpl %ecx, %eax
jne 0x1057b
jmp 0x1059a
leaq 0xcb0b(%rip), %rdi      # 0x1d08d
leaq 0xc492(%rip), %rsi      # 0x1ca1b
movl $0x1e2, %edx            # imm = 0x1E2
leaq 0xca9a(%rip), %rcx      # 0x1d02f
callq 0x3200
movzwl -0x22(%rbp), %eax
movl -0x14(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x105ca
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movzwl -0x16(%rbp), %ecx
movb $0x1, 0x804(%rax,%rcx)
jmp 0x105e1
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movzwl -0x16(%rbp), %ecx
movb $0x0, 0x804(%rax,%rcx)
movw -0x16(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x16(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1055a
jmp 0x105fd
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1052a
jmp 0x1060d
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x10469
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)