// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/pcf.c
// Function: handler_bitmaps
static void handler_bitmaps(deark *c, lctx *d, struct table_entry *te)
{
	i64 pos = te->offset;
	i64 nglyphs;
	i64 k;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "bitmap table at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	if(!read_and_check_format_field(c, d, te, pos)) goto done;
	pos += 4;
	d->bitmaps_fmt = te->fmt; // struct copy

	nglyphs = dbuf_getu32x(c->infile, pos, te->fmt.is_le);
	pos += 4;
	de_dbg(c, "glyph count: %d", (int)nglyphs);

	if(nglyphs != d->num_chars) {
		de_warn(c, "Expected %d bitmaps, found %d", (int)d->num_chars, (int)nglyphs);
	}
	if(nglyphs < d->num_chars) {
		d->num_chars = nglyphs;
	}

	for(k=0; k<d->num_chars; k++) {
		d->chars[k].bitmap_offset = (unsigned int)dbuf_getu32x(c->infile, pos, te->fmt.is_le);
		pos += 4;
		if(c->debug_level>=2)
			de_dbg2(c, "char[%d] glyph offset: %u", (int)k, d->chars[k].bitmap_offset);
	}

	for(k=0; k<4; k++) {
		i64 bitmapsize;
		int use_this_one;

		bitmapsize = dbuf_getu32x(c->infile, pos, te->fmt.is_le);
		pos += 4;
		use_this_one = (((unsigned int)k)==te->fmt.glyph_padding_code);
		de_dbg(c, "bitmapsize[if padding=%d]: %u%s", (int)k, (unsigned int)bitmapsize,
			use_this_one?" *":"");
		if(use_this_one) {
			d->bitmaps_data_len = bitmapsize;
		}
	}

	if(pos + d->bitmaps_data_len > te->offset+te->size) {
		// error
		d->bitmaps_data_len = 0;
		goto done;
	}

	if(te->fmt.is_le && te->fmt.scan_unit_value>1) {
		// TODO: Support this
		de_err(c, "Little-endian byte order is not supported");
		goto done;
	}

	de_dbg(c, "bitmaps data at %"I64_FMT", len=%"I64_FMT, pos, d->bitmaps_data_len);
	d->bitmaps_data = de_malloc(c, d->bitmaps_data_len);
	de_read(d->bitmaps_data, pos, d->bitmaps_data_len);
	if(!te->fmt.msbit_first) {
		reverse_bit_order(d->bitmaps_data, d->bitmaps_data_len);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq 0x30(%rdx), %r12
leaq 0xc(%rsp), %rsi
callq 0xdebae
leaq 0x73fd2(%rip), %rsi     # 0x12ca54
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xb8f61
testl %eax, %eax
je 0xb8c5d
leaq 0x4(%r12), %rsi
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x40(%r14)
movups %xmm0, 0x30(%r14)
movq 0x18(%rbx), %rdi
movl 0x10(%r15), %edx
callq 0xe41cb
movq %rax, %r13
leaq 0x73f89(%rip), %rsi     # 0x12ca68
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x10(%r14), %rdx
cmpq %rdx, %r13
je 0xb8b16
leaq 0x73f7c(%rip), %rsi     # 0x12ca78
movq %rbx, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0xdf05a
movq 0x10(%r14), %rax
cmpq %rax, %r13
jge 0xb8b19
movq %r13, 0x10(%r14)
movq %r13, %rax
addq $0x8, %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpq %rax, %rbp
jge 0xb8b6a
movq 0x18(%rbx), %rdi
movl 0x10(%r15), %edx
movq %r12, %rsi
callq 0xe41cb
movq 0x18(%r14), %rcx
movl %eax, (%rcx,%r13)
cmpl $0x2, (%rbx)
jl 0xb8b59
movq %rbx, %rdi
leaq 0x73f48(%rip), %rsi     # 0x12ca96
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xde9f1
incq %rbp
movq 0x10(%r14), %rax
addq $0x18, %r13
addq $0x4, %r12
jmp 0xb8b22
xorl %ebp, %ebp
cmpq $0x4, %rbp
je 0xb8be2
movq 0x18(%rbx), %rdi
movl 0x10(%r15), %edx
movq %r12, 0x10(%rsp)
movq %r12, %rsi
callq 0xe41cb
movq %rax, %r13
movq %r15, %rax
movq %r14, %r15
movq %rbx, %rdi
movq %rax, %r12
movl 0x8(%rax), %r14d
cmpl %r14d, %ebp
leaq 0x7f0bc(%rip), %r8      # 0x137c60
leaq 0x73f25(%rip), %rax     # 0x12cad0
cmoveq %rax, %r8
leaq 0x73efa(%rip), %rsi     # 0x12cab0
movl %ebp, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0xde896
cmpl %r14d, %ebp
movq %r15, %r14
jne 0xb8bce
movq %r13, 0x20(%r14)
incq %rbp
movq 0x10(%rsp), %rax
addq $0x4, %rax
movq %r12, %r15
movq %rax, %r12
jmp 0xb8b6c
movq 0x20(%r14), %rcx
leaq (%rcx,%r12), %rax
movq 0x28(%r15), %rdx
addq 0x30(%r15), %rdx
cmpq %rdx, %rax
jle 0xb8bfe
andq $0x0, 0x20(%r14)
jmp 0xb8c5d
cmpl $0x0, 0x10(%r15)
je 0xb8c1f
cmpl $0x2, 0x1c(%r15)
jb 0xb8c1f
leaq 0x73ec0(%rip), %rsi     # 0x12cad3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0xb8c5d
leaq 0x73ed7(%rip), %rsi     # 0x12cafd
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, 0x28(%r14)
movq 0x18(%rbx), %rdi
movq 0x20(%r14), %rcx
movq %rax, %rsi
movq %r12, %rdx
callq 0xe3cb7
cmpl $0x0, 0x14(%r15)
je 0xb8c78
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r14), %rax
movq 0x28(%r14), %rcx
xorl %edx, %edx
testq %rax, %rax
cmovleq %rdx, %rax
leaq 0x74040(%rip), %rsi     # 0x12ccd0
cmpq %rdx, %rax
je 0xb8c5d
movzbl (%rcx,%rdx), %edi
movl %edi, %r8d
andl $0xf, %r8d
movb (%r8,%rsi), %r8b
shlb $0x4, %r8b
shrl $0x4, %edi
orb (%rdi,%rsi), %r8b
movb %r8b, (%rcx,%rdx)
incq %rdx
jmp 0xb8c90