// File: /workspace/github_c_makefile_star2_O2/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), %r15
leaq 0x1c(%rsp), %rsi
callq 0xdebae
leaq 0x73e34(%rip), %rsi     # 0x12cb1a
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xb8f61
testl %eax, %eax
je 0xb8d17
cmpl $0x0, 0x4(%r14)
je 0xb8d32
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4(%r15), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xe41b1
movq %rax, %r12
leaq 0x73de8(%rip), %rsi     # 0x12cb35
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
leaq 0x6(%r15), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xe41b1
movq %rax, %r13
leaq 0x73dd6(%rip), %rsi     # 0x12cb4b
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
leaq 0x8(%r15), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xe41b1
leaq 0x73dc7(%rip), %rsi     # 0x12cb61
movq %rbx, %rdi
movq %rax, 0x8(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
leaq 0xa(%r15), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xe41b1
leaq 0x73dac(%rip), %rsi     # 0x12cb6f
movq %rbx, %rdi
movq %rax, %rbp
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
leaq 0xc(%r15), %rsi
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
callq 0xe41b1
leaq 0x73d93(%rip), %rsi     # 0x12cb7d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq %r12, 0x20(%rsp)
subl %r12d, %r13d
jb 0xb8d17
cmpl %ebp, 0x8(%rsp)
ja 0xb8d17
movq %rbp, %rax
movq %rbp, %r12
addq $0xe, %r15
movq 0x8(%rsp), %rbp
orl %ebp, %eax
movq %rax, 0x30(%rsp)
leaq 0x73d75(%rip), %rax     # 0x12cba0
leaq 0x73d7a(%rip), %rdx     # 0x12cbac
cmoveq %rax, %rdx
leaq 0x73d51(%rip), %rsi     # 0x12cb8e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
subl %ebp, %r12d
incl %r12d
incl %r13d
movq %r13, 0x28(%rsp)
imulq %r12, %r13
leaq 0x73d58(%rip), %rsi     # 0x12cbb8
movq %rbx, %rdi
movq %r13, 0x38(%rsp)
movq %r13, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x10(%rsp), %rax
movb $0x1, 0x50(%rax)
leaq 0x40(%rsp), %r13
xorl %r12d, %r12d
cmpq %r12, 0x38(%rsp)
je 0xb8d17
leaq 0x2(%r15), %rbp
movq 0x28(%r14), %rax
addq 0x30(%r14), %rax
cmpq %rax, %rbp
jg 0xb8d17
movq 0x18(%rbx), %rdi
movl 0x10(%r14), %edx
movq %r15, %rsi
callq 0xe41b1
movq %rax, %rcx
cmpl $0x0, 0x30(%rsp)
je 0xb8eda
movl %r12d, %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 0xb8ee3
movq 0x20(%rsp), %rax
leal (%rax,%r12), %r15d
cmpl $0xffff, %ecx           # imm = 0xFFFF
jne 0xb8f04
cmpl $0x2, (%rbx)
jl 0xb8f56
movq %r13, %rdi
leaq 0x73ce1(%rip), %rsi     # 0x12cbdb
pushq $0x28
popq %rdx
callq 0xde492
jmp 0xb8f3c
movl %ecx, %eax
movq 0x10(%rsp), %rdx
cmpq 0x10(%rdx), %rax
jge 0xb8f23
movq 0x10(%rsp), %rdx
movq 0x18(%rdx), %rdx
imulq $0x18, %rax, %rax
movl %r15d, 0x4(%rdx,%rax)
cmpl $0x1, (%rbx)
jle 0xb8f56
movq %r13, %rdi
pushq $0x28
popq %rsi
leaq 0x73cae(%rip), %rdx     # 0x12cbe3
xorl %eax, %eax
callq 0xde40c
movq %rbx, %rdi
leaq 0x73ca6(%rip), %rsi     # 0x12cbec
movl %r12d, %edx
movl %r15d, %ecx
movq %r13, %r8
xorl %eax, %eax
callq 0xde9f1
incq %r12
movq %rbp, %r15
jmp 0xb8e83