// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %r14
leaq 0x7a384(%rip), %rsi     # 0x139293
movq %rbx, %rdi
callq 0xea6cb
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
movl %ecx, 0x50(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef0d5
cmpb $0x36, %al
je 0xbef45
movzbl %al, %eax
cmpl $0x72, %eax
jne 0xbf275
movl $0x2, %edx
jmp 0xbef4a
movl $0x1, %edx
movl %edx, (%r14)
leaq 0x7a35d(%rip), %rsi     # 0x1392b1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpl $0x2, (%r14)
jne 0xbf0db
leaq 0x7a372(%rip), %rsi     # 0x1392e1
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef37e
movl %eax, 0x4(%r14)
leaq 0x7a35b(%rip), %rsi     # 0x1392fc
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movl 0x4(%r14), %edx
testl %edx, %edx
je 0xbefc6
leaq 0x7a338(%rip), %rsi     # 0x1392f4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
movq 0x18(%rbx), %rdi
movl $0x8, %esi
callq 0xef37e
movq %rax, 0x10(%r14)
leaq 0x68757(%rip), %rsi     # 0x127736
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0xc, %esi
callq 0xef37e
movl %eax, 0x8(%r14)
leaq 0x675fa(%rip), %rsi     # 0x1265fe
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movl 0x8(%r14), %eax
andl $0x1, %eax
movl %eax, 0x40(%r14)
leaq 0x68ff7(%rip), %rax     # 0x128026
leaq 0x77d38(%rip), %rdx     # 0x136d6e
cmoveq %rax, %rdx
leaq 0x7a2d4(%rip), %rsi     # 0x139315
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x10, %esi
callq 0xef37e
movq %rax, 0x18(%r14)
leaq 0x61195(%rip), %rsi     # 0x120206
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x14, %esi
callq 0xef37e
movq %rax, 0x30(%r14)
leaq 0x7a295(%rip), %rsi     # 0x13932b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x18, %esi
callq 0xef37e
movq %rax, 0x28(%r14)
movq 0x18(%rbx), %rdi
movl $0x1c, %esi
callq 0xef37e
movq %rax, 0x20(%r14)
movl 0x28(%r14), %ecx
leaq 0x7a26e(%rip), %rsi     # 0x13933f
movq %rbx, %rdi
movl %eax, %edx
jmp 0xbf1ce
leaq 0x7a276(%rip), %rsi     # 0x139358
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq $0x4, 0x10(%r14)
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xef0d5
movb %al, 0xc(%r14)
movzbl %al, %edx
leaq 0x8c616(%rip), %rsi     # 0x14b735
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movzbl 0xc(%r14), %edx
andl $0x1, %edx
shll $0x8, %edx
addl $0x100, %edx            # imm = 0x100
movq %rdx, 0x18(%r14)
leaq 0x610b4(%rip), %rsi     # 0x120206
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movzbl 0xc(%r14), %eax
andl $0x2, %eax
movl %eax, %ecx
shrl %ecx
testl %eax, %eax
movl %ecx, 0x40(%r14)
leaq 0x68eb1(%rip), %rax     # 0x128026
leaq 0x77bf2(%rip), %rdx     # 0x136d6e
cmoveq %rax, %rdx
leaq 0x7a18e(%rip), %rsi     # 0x139315
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x3, %esi
callq 0xef0d5
movzbl %al, %ecx
movq %rcx, 0x30(%r14)
movq %rcx, 0x28(%r14)
movq $0x8, 0x20(%r14)
leaq 0x7a179(%rip), %rsi     # 0x13933f
movq %rbx, %rdi
movl $0x8, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%r14), %rax
movq 0x30(%r14), %rcx
movq %rax, %rdx
imulq %rcx, %rdx
movq %rdx, 0x38(%r14)
cmpl $0x0, 0x40(%r14)
je 0xbf219
movq 0x10(%r14), %rsi
addq %rdx, %rsi
movq %rsi, 0x48(%r14)
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rsi
jl 0xbf219
movl $0x0, 0x40(%r14)
addq 0x10(%r14), %rdx
movq 0x18(%rbx), %rsi
cmpq 0x18(%rsi), %rdx
setg %dl
testq %rcx, %rcx
setle %cl
orb %dl, %cl
jne 0xbf26c
movq $-0x101, %rcx           # imm = 0xFEFF
movq 0x20(%r14), %rdx
addq %rcx, %rdx
cmpq $-0x100, %rdx
jb 0xbf26c
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 0xbf2a3
leaq 0x7a04e(%rip), %rsi     # 0x1392c1
jmp 0xbf27c
leaq 0x7a026(%rip), %rsi     # 0x1392a2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0xf57ec
movq %rax, %r15
movb $0x1, 0x10(%rax)
movq 0x20(%r14), %r12
movl %r12d, (%rax)
movl 0x28(%r14), %eax
movl %eax, 0x4(%r15)
movq 0x18(%r14), %rax
leaq 0x7(%r12), %rcx
addq $0xe, %r12
testq %rcx, %rcx
cmovnsq %rcx, %r12
movq %rax, 0x18(%r15)
movq %rax, 0x58(%r14)
cmpl $0x0, 0x50(%r14)
je 0xbf2ef
leaq 0x7d0(%rax), %rcx
movq %rcx, 0x58(%r14)
movq %rax, 0x60(%r14)
movq $0x0, 0x68(%r14)
movq 0x58(%r14), %rsi
movl $0x28, %edx
movq %rbx, %rdi
callq 0xea259
movq %rax, 0x20(%r15)
movq 0x38(%r14), %rsi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r13
movq 0x10(%r14), %rdx
movq 0x38(%r14), %rcx
leaq 0x7a03d(%rip), %rsi     # 0x13936b
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq 0x10(%r14), %rdx
movq 0x38(%r14), %rcx
movq %r13, %rsi
callq 0xeeee8
movq 0x58(%r14), %rax
testq %rax, %rax
jle 0xbf3ac
sarq $0x3, %r12
movl (%r15), %ecx
movl 0x4(%r15), %edx
movq 0x20(%r15), %rsi
movq 0x18(%r14), %rdi
xorl %r8d, %r8d
movl $0xfffffff, %r9d        # imm = 0xFFFFFFF
movl %ecx, 0x8(%rsi)
movl %edx, 0xc(%rsi)
movq %r12, 0x18(%rsi)
movl $0xfffffff, %r10d       # imm = 0xFFFFFFF
cmpq %rdi, %r8
cmovll %r8d, %r10d
movl %r10d, (%rsi)
movl %r9d, 0x4(%rsi)
jge 0xbf3a0
movq 0x30(%r14), %r10
imulq %r8, %r10
addq %r13, %r10
movq %r10, 0x20(%rsi)
incq %r8
addq $0x28, %rsi
cmpq %r8, %rax
jne 0xbf371
cmpl $0x0, 0x40(%r14)
je 0xbf675
movq %r13, 0x20(%rsp)
movq %r15, 0x10(%rsp)
cmpl $0x2, (%r14)
jne 0xbf543
movl 0x48(%r14), %edx
leaq 0x79fdb(%rip), %rsi     # 0x1393b1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x48(%r14), %rbp
xorl %r12d, %r12d
cmpq 0x18(%r14), %r12
jge 0xbf509
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rcx
subq %rbp, %rcx
jle 0xbf509
movl $0xff, %esi
movq %rbp, %rdx
leaq 0x28(%rsp), %r8
callq 0xf0057
testl %eax, %eax
je 0xbf509
movq 0x28(%rsp), %r15
subq %rbp, %r15
movl $0xc8, %eax
cmpq %rax, %r15
movl $0xc8, %r13d
cmovlq %r15, %r13
testq %r13, %r13
movl $0x0, %eax
cmovleq %rax, %r13
movq 0x18(%rbx), %rdi
leaq 0x40(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0xeeee8
testq %r15, %r15
jle 0xbf520
leaq (%r12,%r12,4), %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
leaq (%rsp,%rbp), %rdi
addq $0x40, %rdi
movq %r13, %rsi
subq %rbp, %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0xec857
testl %eax, %eax
je 0xbf518
movl 0x1c(%rsp), %r8d
movq %rbx, %rdi
testq %r15, %r15
je 0xbf4ba
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %r12, %rcx
callq 0xbf749
jmp 0xbf4e4
leaq 0x79f04(%rip), %rsi     # 0x1393c5
movl %r12d, %edx
movl %r8d, %ecx
xorl %eax, %eax
callq 0xe93cf
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
movl $0x1, %eax
cmpq %r13, %rbp
jge 0xbf51b
leaq 0x1(%r15), %rcx
cmpq $0x7d0, %r15            # imm = 0x7D0
movq %rcx, %r15
jb 0xbf47a
jmp 0xbf51b
xorl %eax, %eax
testb %al, %al
jne 0xbf3f4
jmp 0xbf657
movq %r15, %rax
testq %rax, %rax
jne 0xbf534
movq %rbx, %rdi
leaq 0x79ead(%rip), %rsi     # 0x1393d7
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9b27
movq 0x28(%rsp), %rbp
incq %rbp
incq %r12
movb $0x1, %al
jmp 0xbf50b
movl 0x48(%r14), %edx
leaq 0x79e63(%rip), %rsi     # 0x1393b1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
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 %r15d, %r15d
cmpq 0x18(%r14), %rbp
jge 0xbf657
leaq 0x1(%r12), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jge 0xbf657
movq %r12, %rsi
callq 0xef1ca
movq %rax, %r13
addq $0x2, %r12
cmpl $0xfffe, %r13d          # imm = 0xFFFE
je 0xbf5c4
cmpl $0xffff, %r13d          # imm = 0xFFFF
jne 0xbf5ca
jmp 0xbf635
movl $0x1, %r15d
testl %r15d, %r15d
movl $0x1, %r15d
jne 0xbf584
testb $0x1, 0x8(%rsp)
je 0xbf612
movl $0x0, 0x8(%rsp)
movq %rbx, %rdi
leaq 0x79dd7(%rip), %rsi     # 0x1393c5
movl %ebp, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0xe93cf
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x30(%rsp), %rcx
movl %r13d, 0x4(%rax,%rcx,8)
jmp 0xbf581
movq %rbx, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %rbp, %rcx
movl %r13d, %r8d
callq 0xbf749
movl $0x0, 0x8(%rsp)
jmp 0xbf581
testb $0x1, 0x8(%rsp)
je 0xbf64f
movq %rbx, %rdi
leaq 0x79d91(%rip), %rsi     # 0x1393d7
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9b27
incq %rbp
jmp 0xbf56b
movq 0x10(%rsp), %r15
movw $0x101, 0x11(%r15)      # imm = 0x101
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x20(%rsp), %r13
movq 0x68(%r14), %rdx
testq %rdx, %rdx
jle 0xbf6af
movq 0x60(%r14), %rax
addq %rdx, %rax
movq %rax, 0x18(%r15)
leaq 0x79cf5(%rip), %rsi     # 0x139385
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x18(%r15), %edx
leaq 0x79cf7(%rip), %rsi     # 0x13939c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf5c29
movq 0x20(%r15), %rsi
movq %rbx, %rdi
callq 0xe9752
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf5801
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe9752
jmp 0xbf286