// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/pcf.c
// Function: handler_bdf_encodings
static void handler_bdf_encodings(deark *c, lctx *d, struct table_entry *te)
{
	i64 pos = te->offset;
	int saved_indent_level;
	unsigned int min_char_or_byte2, max_char_or_byte2;
	unsigned int min_byte1, max_byte1;
	unsigned int default_char;
	unsigned int byte1_count, byte2_count;
	int is_singlebyte_encoding;
	i64 ncodepoints;
	i64 k;

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

	if(!read_and_check_format_field(c, d, te, pos)) goto done;
	pos += 4;
	if(te->fmt.gross_format != GFMT_DEFAULT) goto done;

	min_char_or_byte2 = (unsigned int)dbuf_getu16x(c->infile, pos, te->fmt.is_le);
	de_dbg(c, "min_char_or_byte2: %u", min_char_or_byte2);
	pos += 2;
	max_char_or_byte2 = (unsigned int)dbuf_getu16x(c->infile, pos, te->fmt.is_le);
	de_dbg(c, "max_char_or_byte2: %u", max_char_or_byte2);
	pos += 2;
	min_byte1 = (unsigned int)dbuf_getu16x(c->infile, pos, te->fmt.is_le);
	de_dbg(c, "min_byte1: %u", min_byte1);
	pos += 2;
	max_byte1 = (unsigned int)dbuf_getu16x(c->infile, pos, te->fmt.is_le);
	de_dbg(c, "max_byte1: %u", max_byte1);
	pos += 2;
	default_char = (unsigned int)dbuf_getu16x(c->infile, pos, te->fmt.is_le);
	de_dbg(c, "default_char: %u", default_char);
	pos += 2;

	if(min_char_or_byte2>max_char_or_byte2) goto done;
	if(min_byte1>max_byte1) goto done;

	is_singlebyte_encoding = (min_byte1==0 && max_byte1==0);
	de_dbg(c, "encoding type: %s", is_singlebyte_encoding?"single byte":"double byte");

	byte1_count = max_byte1-min_byte1+1;
	byte2_count = max_char_or_byte2-min_char_or_byte2+1;
	ncodepoints = (i64)byte1_count * (i64)byte2_count;
	de_dbg(c, "number of codepoints in table: %"I64_FMT, ncodepoints);

	d->has_encodings_table = 1;

	for(k=0; k<ncodepoints; k++) {
		unsigned int glyph_number;
		i32 codepoint;

		if(pos+2 > te->offset+te->size) break;
		glyph_number = (unsigned int)dbuf_getu16x(c->infile, pos, te->fmt.is_le);

		if(is_singlebyte_encoding) {
			codepoint = (i32)k + (i32)min_char_or_byte2;
		}
		else {
			unsigned int tmp_hi, tmp_lo;
			tmp_hi = ((unsigned int)k)/byte2_count;
			tmp_lo = ((unsigned int)k)%byte2_count;
			codepoint = (i32)(((min_char_or_byte2+tmp_hi)<<8) |
				(min_byte1+tmp_lo));
		}

		if(glyph_number!=0xffff && glyph_number<d->num_chars) {
			d->chars[glyph_number].codepoint = codepoint;
		}

		if(c->debug_level>=2) {
			char gstr[40];
			if(glyph_number==0xffff) {
				de_strlcpy(gstr, "no char", sizeof(gstr));
			}
			else {
				de_snprintf(gstr, sizeof(gstr), "char[%u]", glyph_number);
			}
			de_dbg2(c, "[%d]: codepoint %d = %s", (int)k, (int)codepoint, gstr);
		}

		pos += 2;
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r14
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
movq 0x30(%rdx), %r12
leaq 0x1c(%rsp), %rsi
callq 0xe8a1c
leaq 0x79886(%rip), %rsi     # 0x139e2a
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xc0832
testl %eax, %eax
je 0xc05d7
cmpl $0x0, 0x4(%r14)
je 0xc05f2
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4(%r12), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xeef43
movq %rax, %r15
leaq 0x79837(%rip), %rsi     # 0x139e45
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
leaq 0x6(%r12), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xeef43
movq %rax, %r13
leaq 0x79824(%rip), %rsi     # 0x139e5b
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe8617
leaq 0x8(%r12), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xeef43
leaq 0x79814(%rip), %rsi     # 0x139e71
movq %rbx, %rdi
movq %rax, 0x8(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
leaq 0xa(%r12), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xeef43
leaq 0x797f8(%rip), %rsi     # 0x139e7f
movq %rbx, %rdi
movq %rax, %rbp
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
leaq 0xc(%r12), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xeef43
leaq 0x797de(%rip), %rsi     # 0x139e8d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq %r15, 0x20(%rsp)
subl %r15d, %r13d
jb 0xc05d7
cmpl %ebp, 0x8(%rsp)
ja 0xc05d7
movq %rbp, %rax
movq %rbp, %r15
movq 0x8(%rsp), %rbp
orl %ebp, %eax
movq %rax, 0x38(%rsp)
leaq 0x797c4(%rip), %rax     # 0x139eb0
leaq 0x797c9(%rip), %rdx     # 0x139ebc
cmoveq %rax, %rdx
leaq 0x797a0(%rip), %rsi     # 0x139e9e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
subl %ebp, %r15d
incl %r15d
incl %r13d
movq %r13, 0x28(%rsp)
imulq %r15, %r13
leaq 0x797a7(%rip), %rsi     # 0x139ec8
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%rsp), %rax
movb $0x1, 0x50(%rax)
movq %r13, 0x30(%rsp)
testq %r13, %r13
je 0xc05d7
addq $0x10, %r12
leaq 0x40(%rsp), %rbp
xorl %r13d, %r13d
movq 0x28(%r14), %rax
addq 0x30(%r14), %rax
cmpq %rax, %r12
jg 0xc05d7
leaq -0x2(%r12), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xeef43
movq %rax, %rcx
cmpl $0x0, 0x38(%rsp)
je 0xc079b
movl %r13d, %eax
xorl %edx, %edx
divl 0x28(%rsp)
movl %edx, %r15d
addl 0x20(%rsp), %eax
shll $0x8, %eax
addl 0x8(%rsp), %r15d
orl %eax, %r15d
jmp 0xc07a4
movq 0x20(%rsp), %rax
leal (%rax,%r13), %r15d
cmpl $0xffff, %ecx           # imm = 0xFFFF
jne 0xc07c7
cmpl $0x2, (%rbx)
jl 0xc081b
movl $0x28, %edx
movq %rbp, %rdi
leaq 0x7972b(%rip), %rsi     # 0x139eeb
callq 0xe8219
jmp 0xc0801
movl %ecx, %eax
movq 0x10(%rsp), %rdx
cmpq 0x10(%rdx), %rax
jge 0xc07e6
movq 0x10(%rsp), %rdx
movq 0x18(%rdx), %rdx
leaq (%rax,%rax,2), %rax
movl %r15d, 0x4(%rdx,%rax,8)
cmpl $0x1, (%rbx)
jle 0xc081b
movl $0x28, %esi
movq %rbp, %rdi
leaq 0x796f9(%rip), %rdx     # 0x139ef3
xorl %eax, %eax
callq 0xe8193
movq %rbx, %rdi
leaq 0x796f1(%rip), %rsi     # 0x139efc
movl %r13d, %edx
movl %r15d, %ecx
movq %rbp, %r8
xorl %eax, %eax
callq 0xe87e4
incq %r13
addq $0x2, %r12
cmpq %r13, 0x30(%rsp)
jne 0xc0751
jmp 0xc05d7