// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/psf.c
// Function: do_psf1_unicode_table
static void do_psf1_unicode_table(deark *c, lctx *d, struct de_bitmap_font *font)
{
	i64 cur_idx;
	i64 pos;
	int got_cp;
	int found_fffe;
	i32 n;

	de_dbg(c, "Unicode table at %d", (int)d->unicode_table_pos);
	de_dbg_indent(c, 1);

	pos = d->unicode_table_pos;
	cur_idx = 0;
	got_cp = 0; // Have we set the codepoint for glyph[cur_idx]?
	found_fffe = 0;

	while(1) {
		if(cur_idx >= d->num_glyphs) break;
		if(pos+1 >= c->infile->len) break;
		n = (i32)de_getu16le(pos);
		pos+=2;

		if(n==0xffff) {
			if(!got_cp) {
				de_warn(c, "Missing codepoint for char #%d", (int)cur_idx);
			}
			cur_idx++;
			got_cp = 0;
			found_fffe = 0;
			continue;
		}
		else if(n==0xfffe) {
			found_fffe = 1;
		}

		if(found_fffe) {
			// Anything after 0xfffe is a multi-codepoint character, which we
			// don't support.
			continue;
		}

		if(!got_cp) {
			de_dbg2(c, "char[%d] = U+%04x", (int)cur_idx, (unsigned int)n);
			font->char_array[cur_idx].codepoint_unicode = n;
			got_cp = 1;
			continue;
		}

		// This is an "extra" codepoint for the current glyph.
		do_extra_codepoint(c, d, font, cur_idx, n);
	}

	font->has_unicode_codepoints = 1;
	font->prefer_unicode = 1;

	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, %edx
leaq 0xaaf8e(%rip), %rsi     # 0x1c4fc7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0x11a083
jmp 0x11a182
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x11a09e
jmp 0x11a182
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165280
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
cmpl $0xffff, -0x34(%rbp)    # imm = 0xFFFF
jne 0x11a104
cmpl $0x0, -0x2c(%rbp)
jne 0x11a0e5
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xaaf0f(%rip), %rsi     # 0x1c4fed
movb $0x0, %al
callq 0x15bc10
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x11a070
cmpl $0xfffe, -0x34(%rbp)    # imm = 0xFFFE
jne 0x11a114
movl $0x1, -0x30(%rbp)
jmp 0x11a116
cmpl $0x0, -0x30(%rbp)
je 0x11a121
jmp 0x11a070
cmpl $0x0, -0x2c(%rbp)
jne 0x11a164
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
movl -0x34(%rbp), %ecx
leaq 0xaaea0(%rip), %rsi     # 0x1c4fdb
movb $0x0, %al
callq 0x15b350
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x20(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl $0x1, -0x2c(%rbp)
jmp 0x11a070
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl -0x34(%rbp), %r8d
callq 0x11a1b0
jmp 0x11a070
movq -0x18(%rbp), %rax
movb $0x1, 0x11(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x12(%rax)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)