// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pkfont.c
// Function: de_run_pkfont
static void de_run_pkfont(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos;
	i64 bytesused;
	i64 i;
	u8 flagbyte;
	i64 chars_in_file = 0;

	d = de_malloc(c, sizeof(lctx));
	d->font = de_create_bitmap_font(c);
	d->font->has_nonunicode_codepoints = 1;

	pos = 0;
	while(pos < c->infile->len) {
		flagbyte = de_getbyte(pos);
		de_dbg(c, "flag byte at %d: 0x%02x (%s)", (int)pos, (unsigned int)flagbyte,
			get_flagbyte_name(flagbyte));
		bytesused = 0;

		if(flagbyte >= 240) {
			i64 dpos = 0;
			i64 dlen = 0;

			switch(flagbyte) {
			case PK_XXX1:
				dlen = (i64)de_getbyte(pos+1);
				dpos = pos + 2;
				bytesused = 2 + dlen;
				break;
			case PK_XXX2:
				dlen = de_getu16be(pos+1);
				dpos = pos + 3;
				bytesused = 3 + dlen;
				break;
			case PK_XXX3:
				dlen = dbuf_getint_ext(c->infile, pos+1, 3, 0, 0);
				dpos = pos + 4;
				bytesused = 4 + dlen;
				break;
			case PK_XXX4:
				dlen = de_getu32be(pos+1);
				dpos = pos + 5;
				bytesused = 5 + dlen;
				break;
			case PK_YYY:
				dlen = 4;
				dpos = pos + 1;
				bytesused = 5;
				break;
			case 245: // postamble
				goto done_reading;
			case 246: // no-op
				bytesused = 1;
				break;
			case 247:
				do_preamble(c, d, pos, &bytesused);
				break;
			default:
				de_err(c, "Unsupported command: %d at %d", (int)flagbyte, (int)pos);
				goto done;
			}

			if(dlen>0 && flagbyte>=240 && flagbyte<=244) {
				de_dbg_indent(c, 1);
				de_dbg_hexdump(c, c->infile, dpos, dlen, 256, NULL, 0x1);
				de_dbg_indent(c, -1);
			}
		}
		else {
			chars_in_file++;
			if(!do_char_descr(c, d, pos, &bytesused)) goto done;
		}

		if(bytesused<1) break;
		pos += bytesused;
	}

done_reading:
	de_dbg(c, "number of characters: %d (%d processed)", (int)chars_in_file,
		(int)d->font->num_chars);

	scan_and_fixup_font(c, d);
	de_font_bitmap_font_to_image(c, d->font, NULL, 0);

done:
	if(d->font) {
		if(d->font->char_array) {
			for(i=0; i<d->font->num_chars; i++) {
				de_free(c, d->font->char_array[i].bitmap);
			}
			de_free(c, d->font->char_array);
		}
		de_destroy_bitmap_font(c, d->font);
	}
	de_free(c, d);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl $0x10, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x16f6f0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movb $0x1, 0x10(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x109441
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165060
movb %al, -0x31(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movl %eax, -0x58(%rbp)
movzbl -0x31(%rbp), %eax
movl %eax, -0x54(%rbp)
movzbl -0x31(%rbp), %edi
callq 0x109580
movq -0x60(%rbp), %rdi
movl -0x58(%rbp), %edx
movl -0x54(%rbp), %ecx
movq %rax, %r8
leaq 0xb997a(%rip), %rsi     # 0x1c2b6f
movb $0x0, %al
callq 0x15b0d0
movq $0x0, -0x28(%rbp)
movzbl -0x31(%rbp), %eax
cmpl $0xf0, %eax
jl 0x1093fd
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movzbl -0x31(%rbp), %eax
addl $0xffffff10, %eax       # imm = 0xFFFFFF10
movl %eax, %ecx
movq %rcx, -0x68(%rbp)
subl $0x7, %eax
ja 0x109376
movq -0x68(%rbp), %rax
leaq 0xb98da(%rip), %rcx     # 0x1c2b20
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0x109397
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x1651d0
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x109397
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
movl $0x3, %edx
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x165a80
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
jmp 0x109397
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x165470
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x28(%rbp)
jmp 0x109397
movq $0x4, -0x50(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq $0x5, -0x28(%rbp)
jmp 0x109397
jmp 0x109443
movq $0x1, -0x28(%rbp)
jmp 0x109397
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x109650
jmp 0x109397
movq -0x8(%rbp), %rdi
movzbl -0x31(%rbp), %edx
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq 0xb9801(%rip), %rsi     # 0x1c2b8c
movb $0x0, %al
callq 0x15bfb0
jmp 0x10948b
cmpq $0x0, -0x50(%rbp)
jle 0x1093fb
movzbl -0x31(%rbp), %eax
cmpl $0xf0, %eax
jl 0x1093fb
movzbl -0x31(%rbp), %eax
cmpl $0xf4, %eax
jg 0x1093fb
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x109427
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x1096f0
cmpl $0x0, %eax
jne 0x109425
jmp 0x10948b
jmp 0x109427
cmpq $0x1, -0x28(%rbp)
jge 0x109430
jmp 0x109441
movq -0x28(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x109198
jmp 0x109443
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl %eax, %ecx
leaq 0xb9749(%rip), %rsi     # 0x1c2baa
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x109b40
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x16fe80
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x10950e
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x20(%rax)
je 0x1094fe
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x1094ea
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x30(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1094ab
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x16f730
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)