// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pkfont.c
// Function: do_char_descr
static int do_char_descr(deark *c, lctx *d, i64 pos, i64 *bytesused)
{
	u8 flagbyte;
	u8 lsb3;
#define CHAR_PREAMBLE_FORMAT_SHORT      1
#define CHAR_PREAMBLE_FORMAT_EXT_SHORT  2
#define CHAR_PREAMBLE_FORMAT_LONG       3
	int char_preamble_format;
	i64 pl;
	i64 tfm_offs;
	struct page_ctx *pg = NULL;
	int retval = 0;

	pg = de_malloc(c, sizeof(struct page_ctx));

	de_dbg(c, "character descriptor at %d", (int)pos);
	de_dbg_indent(c, 1);

	flagbyte = de_getbyte(pos);
	pg->dyn_f = ((i64)flagbyte)>>4;
	de_dbg(c, "dyn_f: %d", (int)pg->dyn_f);

	// Character preamble format: (lsb=...)
	// 0-3: short format
	// 4-6: extended short format
	// 7: long form
	lsb3 = flagbyte&0x7;

	pg->start_with_black = (flagbyte&0x8)?1:0;

	if(lsb3==7) {
		char_preamble_format = CHAR_PREAMBLE_FORMAT_LONG;
	}
	else if(lsb3>=4) {
		char_preamble_format = CHAR_PREAMBLE_FORMAT_EXT_SHORT;
	}
	else {
		char_preamble_format = CHAR_PREAMBLE_FORMAT_SHORT;
	}

	if(char_preamble_format==CHAR_PREAMBLE_FORMAT_SHORT) {
		pl = (i64)de_getbyte(pos+1);
		pl |= ((i64)(flagbyte&0x03))<<8;
		pg->cc = (i32)de_getbyte(pos+2);
		tfm_offs = 3;
		pg->tfm = do_getu24be(c->infile, pos+tfm_offs);
		pg->dm = (i64)de_getbyte(pos+6);
		pg->w = (int)de_getbyte(pos+7);
		pg->h = (int)de_getbyte(pos+8);
		pg->hoff = dbuf_geti8(c->infile, pos+9);
		pg->voff = dbuf_geti8(c->infile, pos+10);
		pg->raster_pos = pos + 11;
	}
	else if(char_preamble_format==CHAR_PREAMBLE_FORMAT_EXT_SHORT) {
		pl = de_getu16be(pos+1);
		pl |= ((i64)(flagbyte&0x03))<<16;
		pg->cc = (i32)de_getbyte(pos+3);
		tfm_offs = 4;
		pg->tfm = do_getu24be(c->infile, pos+tfm_offs);
		pg->dm = de_getu16be(pos+7);
		pg->w = (int)de_getu16be(pos+9);
		pg->h = (int)de_getu16be(pos+11);
		pg->hoff = de_geti16be(pos+13);
		pg->voff = de_geti16be(pos+15);
		pg->raster_pos = pos + 17;
	}
	else {
		de_err(c, "Unsupported character preamble format (%d)", (int)lsb3);
		goto done;
	}

	de_dbg(c, "pl=%d cc=%d tfm=%d dm=%d w=%d h=%d hoff=%d voff=%d",
		(int)pl, (int)pg->cc, (int)pg->tfm, (int)pg->dm, (int)pg->w, (int)pg->h,
		(int)pg->hoff, (int)pg->voff);

	pg->raster_len = (pos+tfm_offs+pl)-pg->raster_pos;
	do_read_raster(c, d, pg);

	*bytesused = tfm_offs + pl;
	retval = 1;

done:
	de_dbg_indent(c, -1);
	de_free(c, pg);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x68, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
movl $0x68, %esi
callq 0x15b780
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xb9527(%rip), %rsi     # 0x1c2c62
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165060
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
movl %eax, %ecx
sarq $0x4, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, %edx
leaq 0xb94f2(%rip), %rsi     # 0x1c2c7d
movb $0x0, %al
callq 0x15b0d0
movzbl -0x29(%rbp), %eax
andl $0x7, %eax
movb %al, -0x2a(%rbp)
movzbl -0x29(%rbp), %edx
andl $0x8, %edx
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x38(%rax)
movzbl -0x2a(%rbp), %eax
cmpl $0x7, %eax
jne 0x1097c9
movl $0x3, -0x30(%rbp)
jmp 0x1097e4
movzbl -0x2a(%rbp), %eax
cmpl $0x4, %eax
jl 0x1097db
movl $0x2, -0x30(%rbp)
jmp 0x1097e2
movl $0x1, -0x30(%rbp)
jmp 0x1097e4
cmpl $0x1, -0x30(%rbp)
jne 0x10991a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x38(%rbp)
movzbl -0x29(%rbp), %eax
andl $0x3, %eax
cltq
shlq $0x8, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x2, %rsi
callq 0x165060
movzbl %al, %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movq $0x3, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq -0x40(%rbp), %rsi
callq 0x109c60
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x6, %rsi
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x7, %rsi
callq 0x165060
movzbl %al, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x8, %rsi
callq 0x165060
movzbl %al, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x9, %rsi
callq 0x165140
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0xa, %rsi
callq 0x165140
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rcx
addq $0xb, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x109a63
cmpl $0x2, -0x30(%rbp)
jne 0x109a46
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x1651d0
movq %rax, -0x38(%rbp)
movzbl -0x29(%rbp), %eax
andl $0x3, %eax
cltq
shlq $0x10, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x3, %rsi
callq 0x165060
movzbl %al, %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movq $0x4, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq -0x40(%rbp), %rsi
callq 0x109c60
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x7, %rsi
callq 0x1651d0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x9, %rsi
callq 0x1651d0
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0xb, %rsi
callq 0x1651d0
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0xd, %rsi
callq 0x165310
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0xf, %rsi
callq 0x165310
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rcx
addq $0x11, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x109a61
movq -0x10(%rbp), %rdi
movzbl -0x2a(%rbp), %edx
leaq 0xb9232(%rip), %rsi     # 0x1c2c87
movb $0x0, %al
callq 0x15bfb0
jmp 0x109b0d
jmp 0x109a63
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x48(%rbp), %rax
movl (%rax), %ecx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %r8d
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %r9d
movq -0x48(%rbp), %rax
movl 0x4(%rax), %ebx
movq -0x48(%rbp), %rax
movl 0x8(%rax), %r11d
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, %r10d
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
leaq 0xb9200(%rip), %rsi     # 0x1c2cb2
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rcx
addq -0x40(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rax
subq 0x40(%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x109c90
movq -0x40(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x15b820
movl -0x4c(%rbp), %eax
addq $0x68, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)