// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/psf.c
// Function: de_run_psf
static void de_run_psf(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	u8 b;
	const char *s;

	d = de_malloc(c, sizeof(lctx));

	s = de_get_ext_option(c, "font:noaliases");
	if(s)
		d->read_extra_codepoints = 0;
	else
		d->read_extra_codepoints = 1;

	b = de_getbyte(0);
	if(b==0x36) {
		d->version=1;
	}
	else if(b==0x72) {
		d->version=2;
	}
	else {
		de_err(c, "Not a PSF file");
		goto done;
	}

	de_dbg(c, "PSF version: %d", (int)d->version);

	if(d->version==2)
		do_psf2_header(c, d);
	else
		do_psf1_header(c, d);

	d->font_data_size = d->bytes_per_glyph * d->num_glyphs;
	if(d->has_unicode_table) {
		d->unicode_table_pos = d->headersize + d->font_data_size;
		if(d->unicode_table_pos >= c->infile->len) {
			d->has_unicode_table = 0;
		}
	}

	if((d->headersize+d->font_data_size > c->infile->len) ||
		d->bytes_per_glyph<1 ||
		d->glyph_width<1 || d->glyph_width>256 ||
		d->glyph_height<1 || d->glyph_height>256 ||
		d->num_glyphs<1 || d->num_glyphs>2000000)
	{
		de_err(c, "Invalid or unsupported PSF file");
		goto done;
	}

	do_glyphs(c, d);

done:
	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %rbx
movl $0x70, %esi
callq 0xe8b2b
movq %rax, %r14
leaq 0x7b3c8(%rip), %rsi     # 0x139623
movq %rbx, %rdi
callq 0xe9b74
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
movl %ecx, 0x50(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeead3
cmpb $0x36, %al
je 0xbe291
movzbl %al, %eax
cmpl $0x72, %eax
jne 0xbe56a
movl $0x2, %edx
jmp 0xbe296
movl $0x1, %edx
movl %edx, (%r14)
leaq 0x7b3a1(%rip), %rsi     # 0x139641
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
cmpl $0x2, (%r14)
jne 0xbe427
leaq 0x7b3b6(%rip), %rsi     # 0x139671
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xeed61
movl %eax, 0x4(%r14)
leaq 0x7b39f(%rip), %rsi     # 0x13968c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl 0x4(%r14), %edx
testl %edx, %edx
je 0xbe312
leaq 0x7b37c(%rip), %rsi     # 0x139684
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
movq 0x18(%rbx), %rdi
movl $0x8, %esi
callq 0xeed61
movq %rax, 0x10(%r14)
leaq 0x6963b(%rip), %rsi     # 0x127966
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0xc, %esi
callq 0xeed61
movl %eax, 0x8(%r14)
leaq 0x684de(%rip), %rsi     # 0x12682e
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl 0x8(%r14), %eax
andl $0x1, %eax
movl %eax, 0x40(%r14)
leaq 0x69edb(%rip), %rax     # 0x128256
leaq 0x78db6(%rip), %rdx     # 0x137138
cmoveq %rax, %rdx
leaq 0x7b318(%rip), %rsi     # 0x1396a5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x18(%rbx), %rdi
movl $0x10, %esi
callq 0xeed61
movq %rax, 0x18(%r14)
leaq 0x61f71(%rip), %rsi     # 0x12032e
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x14, %esi
callq 0xeed61
movq %rax, 0x30(%r14)
leaq 0x7b2d9(%rip), %rsi     # 0x1396bb
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x18, %esi
callq 0xeed61
movq %rax, 0x28(%r14)
movq 0x18(%rbx), %rdi
movl $0x1c, %esi
callq 0xeed61
movq %rax, 0x20(%r14)
movl 0x28(%r14), %ecx
leaq 0x7b2b2(%rip), %rsi     # 0x1396cf
movq %rbx, %rdi
movl %eax, %edx
jmp 0xbe51a
leaq 0x7b2ba(%rip), %rsi     # 0x1396e8
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq $0x4, 0x10(%r14)
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xeead3
movb %al, 0xc(%r14)
movzbl %al, %edx
leaq 0x8d8e6(%rip), %rsi     # 0x14bd51
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movzbl 0xc(%r14), %edx
andl $0x1, %edx
shll $0x8, %edx
addl $0x100, %edx            # imm = 0x100
movq %rdx, 0x18(%r14)
leaq 0x61e90(%rip), %rsi     # 0x12032e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movzbl 0xc(%r14), %eax
andl $0x2, %eax
movl %eax, %ecx
shrl %ecx
testl %eax, %eax
movl %ecx, 0x40(%r14)
leaq 0x69d95(%rip), %rax     # 0x128256
leaq 0x78c70(%rip), %rdx     # 0x137138
cmoveq %rax, %rdx
leaq 0x7b1d2(%rip), %rsi     # 0x1396a5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x18(%rbx), %rdi
movl $0x3, %esi
callq 0xeead3
movzbl %al, %ecx
movq %rcx, 0x30(%r14)
movq %rcx, 0x28(%r14)
movq $0x8, 0x20(%r14)
leaq 0x7b1bd(%rip), %rsi     # 0x1396cf
movq %rbx, %rdi
movl $0x8, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x30(%r14), %rcx
movq 0x10(%r14), %rdx
movq 0x18(%r14), %rax
movq %rax, %rdi
imulq %rcx, %rdi
movq %rdi, 0x38(%r14)
cmpl $0x0, 0x40(%r14)
je 0xbe573
addq %rdi, %rdx
movq %rdx, 0x48(%r14)
movq 0x18(%rbx), %rsi
movq 0x18(%rsi), %rsi
cmpq %rsi, %rdx
jl 0xbe57e
movl $0x0, 0x40(%r14)
jmp 0xbe57e
leaq 0x7b0c1(%rip), %rsi     # 0x139632
jmp 0xbe5cf
movq 0x18(%rbx), %rsi
movq 0x18(%rsi), %rsi
addq %rdi, %rdx
cmpq %rsi, %rdx
setg %dl
testq %rcx, %rcx
setle %cl
orb %dl, %cl
jne 0xbe5c8
movq $-0x101, %rcx           # imm = 0xFEFF
movq 0x20(%r14), %rdx
addq %rcx, %rdx
cmpq $-0x100, %rdx
jb 0xbe5c8
addq 0x28(%r14), %rcx
cmpq $-0x100, %rcx
setb %cl
addq $-0x1e8481, %rax        # imm = 0xFFE17B7F
cmpq $-0x1e8480, %rax        # imm = 0xFFE17B80
setb %al
orb %cl, %al
cmpb $0x1, %al
jne 0xbe5f6
leaq 0x7b082(%rip), %rsi     # 0x139651
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0xf5358
movq %rax, %r12
movb $0x1, 0x10(%rax)
movq 0x20(%r14), %r15
movl %r15d, (%rax)
movl 0x28(%r14), %eax
movl %eax, 0x4(%r12)
movq 0x18(%r14), %rax
movq %rax, 0x18(%r12)
leaq 0x7(%r15), %rcx
addq $0xe, %r15
testq %rcx, %rcx
cmovnsq %rcx, %r15
movq %rax, 0x58(%r14)
cmpl $0x0, 0x50(%r14)
movq %rax, %rsi
je 0xbe646
leaq 0x7d0(%rax), %rsi
movq %rsi, 0x58(%r14)
movq %rax, 0x60(%r14)
movq $0x0, 0x68(%r14)
movl $0x28, %edx
movq %rbx, %rdi
callq 0xe96f7
movq %rax, 0x20(%r12)
movq 0x38(%r14), %rsi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r13
movq 0x10(%r14), %rdx
movq 0x38(%r14), %rcx
leaq 0x7b079(%rip), %rsi     # 0x1396fb
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq 0x10(%r14), %rdx
movq 0x38(%r14), %rcx
movq %r13, %rsi
callq 0xee8d4
movq 0x58(%r14), %rax
testq %rax, %rax
jle 0xbe6f6
sarq $0x3, %r15
movq 0x20(%r12), %rcx
movsd (%r12), %xmm0
movq 0x18(%r14), %rdx
xorl %esi, %esi
movlps %xmm0, 0x8(%rcx)
movq %r15, 0x18(%rcx)
movl $0xfffffff, %edi        # imm = 0xFFFFFFF
cmpq %rdx, %rsi
jge 0xbe6e1
movq 0x30(%r14), %rdi
imulq %rsi, %rdi
addq %r13, %rdi
movq %rdi, 0x20(%rcx)
movl %esi, %edi
movl %edi, (%rcx)
movl $0xfffffff, 0x4(%rcx)   # imm = 0xFFFFFFF
incq %rsi
addq $0x28, %rcx
cmpq %rsi, %rax
jne 0xbe6be
cmpl $0x0, 0x40(%r14)
je 0xbe89c
movq %r13, 0x20(%rsp)
movq %r12, 0x10(%rsp)
cmpl $0x2, (%r14)
jne 0xbe90f
movl 0x48(%r14), %edx
leaq 0x7b021(%rip), %rsi     # 0x139741
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpq $0x0, 0x18(%r14)
jle 0xbe87d
movq 0x48(%r14), %rbp
xorl %r12d, %r12d
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rcx
subq %rbp, %rcx
jle 0xbe87d
movl $0xff, %esi
movq %rbp, %rdx
leaq 0x28(%rsp), %r8
callq 0xefa77
testl %eax, %eax
je 0xbe87d
movq 0x28(%rsp), %r13
subq %rbp, %r13
movl $0xc8, %eax
cmpq %rax, %r13
movl $0xc8, %r15d
cmovlq %r13, %r15
testq %r15, %r15
movl $0x0, %eax
cmovleq %rax, %r15
movq 0x18(%rbx), %rdi
leaq 0x40(%rsp), %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0xee8d4
testq %r13, %r13
jle 0xbe854
leaq (%r12,%r12,4), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
leaq (%rsp,%rbp), %rdi
addq $0x40, %rdi
movq %r15, %rsi
subq %rbp, %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0xec1ff
testl %eax, %eax
je 0xbe84f
movl 0x1c(%rsp), %r8d
movq %rbx, %rdi
testq %r13, %r13
je 0xbe805
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %r12, %rcx
callq 0xbea87
jmp 0xbe82f
leaq 0x7af49(%rip), %rsi     # 0x139755
movl %r12d, %edx
movl %r8d, %ecx
xorl %eax, %eax
callq 0xe87e4
movl 0x1c(%rsp), %eax
movq 0x10(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq 0x8(%rsp), %rdx
movl %eax, 0x4(%rcx,%rdx,8)
addq 0x38(%rsp), %rbp
cmpq %r15, %rbp
jge 0xbe868
leaq 0x1(%r13), %rax
cmpq $0x7cf, %r13            # imm = 0x7CF
movq %rax, %r13
jbe 0xbe7c5
jmp 0xbe868
testq %r13, %r13
jne 0xbe868
movq %rbx, %rdi
leaq 0x7af09(%rip), %rsi     # 0x139767
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8faa
movq 0x28(%rsp), %rbp
incq %rbp
incq %r12
cmpq 0x18(%r14), %r12
jl 0xbe749
movq 0x10(%rsp), %r12
movw $0x101, 0x11(%r12)      # imm = 0x101
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x20(%rsp), %r13
movq 0x68(%r14), %rdx
testq %rdx, %rdx
jle 0xbe8d8
movq 0x60(%r14), %rax
addq %rdx, %rax
movq %rax, 0x18(%r12)
leaq 0x7ae5d(%rip), %rsi     # 0x139715
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x18(%r12), %edx
leaq 0x7ae5e(%rip), %rsi     # 0x13972c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf576f
movq 0x20(%r12), %rsi
movq %rbx, %rdi
callq 0xe8be2
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf536d
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe8be2
jmp 0xbe5d9
movl 0x48(%r14), %edx
leaq 0x7ae27(%rip), %rsi     # 0x139741
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x48(%r14), %r12
xorl %ebp, %ebp
movb $0x1, %al
movl %eax, 0x8(%rsp)
leaq (,%rbp,4), %rax
addq %rbp, %rax
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
cmpq 0x18(%r14), %rbp
jge 0xbe87d
leaq 0x1(%r12), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jge 0xbe87d
movq %r12, %rsi
callq 0xeebc8
movq %rax, %r15
addq $0x2, %r12
cmpl $0xfffe, %r15d          # imm = 0xFFFE
je 0xbe990
cmpl $0xffff, %r15d          # imm = 0xFFFF
jne 0xbe996
jmp 0xbea01
movl $0x1, %r13d
testl %r13d, %r13d
movl $0x1, %r13d
jne 0xbe950
testb $0x1, 0x8(%rsp)
je 0xbe9de
movl $0x0, 0x8(%rsp)
movq %rbx, %rdi
leaq 0x7ad9b(%rip), %rsi     # 0x139755
movl %ebp, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0xe87e4
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x30(%rsp), %rcx
movl %r15d, 0x4(%rax,%rcx,8)
jmp 0xbe94d
movq %rbx, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %rbp, %rcx
movl %r15d, %r8d
callq 0xbea87
movl $0x0, 0x8(%rsp)
jmp 0xbe94d
testb $0x1, 0x8(%rsp)
je 0xbea1b
movq %rbx, %rdi
leaq 0x7ad55(%rip), %rsi     # 0x139767
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8faa
incq %rbp
jmp 0xbe937