// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0xa8f0b(%rip), %rsi     # 0x1c568a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x11cb10
cmpl $0x0, %eax
jne 0x11c7b3
jmp 0x11caf4
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x11c7ce
jmp 0x11caf4
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165820
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %edx
leaq 0xa8eae(%rip), %rsi     # 0x1c56a5
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165820
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq 0xa8e88(%rip), %rsi     # 0x1c56bb
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165820
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %edx
leaq 0xa8e62(%rip), %rsi     # 0x1c56d1
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165820
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
leaq 0xa8e34(%rip), %rsi     # 0x1c56df
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165820
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %edx
leaq 0xa8e06(%rip), %rsi     # 0x1c56ed
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jbe 0x11c907
jmp 0x11caf4
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jbe 0x11c914
jmp 0x11caf4
xorl %eax, %eax
cmpl $0x0, -0x30(%rbp)
movb %al, -0x91(%rbp)
jne 0x11c92f
cmpl $0x0, -0x34(%rbp)
sete %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %ecx
leaq 0xa8dd1(%rip), %rdx     # 0x1c571c
leaq 0xa8dbe(%rip), %rax     # 0x1c5710
cmpl $0x0, %ecx
cmovneq %rax, %rdx
leaq 0xa8d9e(%rip), %rsi     # 0x1c56fe
movb $0x0, %al
callq 0x15b0d0
movl -0x34(%rbp), %eax
subl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl -0x40(%rbp), %ecx
imulq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rdx
leaq 0xa8d8c(%rip), %rsi     # 0x1c5728
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movb $0x1, 0x50(%rax)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0x11caf2
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x18(%rbp), %rdx
addq 0x28(%rdx), %rcx
cmpq %rcx, %rax
jle 0x11c9e3
jmp 0x11caf2
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165820
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x11ca10
movq -0x58(%rbp), %rax
addl -0x28(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x11ca3c
movq -0x58(%rbp), %rax
xorl %edx, %edx
divl -0x40(%rbp)
movl %eax, -0x64(%rbp)
movq -0x58(%rbp), %rax
xorl %edx, %edx
divl -0x40(%rbp)
movl %edx, -0x68(%rbp)
movl -0x28(%rbp), %eax
addl -0x64(%rbp), %eax
shll $0x8, %eax
movl -0x30(%rbp), %ecx
addl -0x68(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x60(%rbp)
cmpl $0xffff, -0x5c(%rbp)    # imm = 0xFFFF
je 0x11ca6a
movl -0x5c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x11ca6a
movl -0x60(%rbp), %ecx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x5c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x11cad5
cmpl $0xffff, -0x5c(%rbp)    # imm = 0xFFFF
jne 0x11ca96
leaq -0x90(%rbp), %rdi
leaq 0xa8cc1(%rip), %rsi     # 0x1c574b
movl $0x28, %edx
callq 0x15aa30
jmp 0x11cab3
leaq -0x90(%rbp), %rdi
movl -0x5c(%rbp), %ecx
movl $0x28, %esi
leaq 0xa8ca7(%rip), %rdx     # 0x1c5753
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl %eax, %edx
movl -0x60(%rbp), %ecx
leaq -0x90(%rbp), %r8
leaq 0xa8c8e(%rip), %rsi     # 0x1c575c
movb $0x0, %al
callq 0x15b350
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x11c9b3
jmp 0x11caf4
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x15b5a0
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)