// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/psf.c
// Function: do_glyphs
static void do_glyphs(deark *c, lctx *d)
{
	struct de_bitmap_font *font = NULL;
	u8 *font_data = NULL;
	i64 i;
	i64 glyph_rowspan;

	font = de_create_bitmap_font(c);
	font->has_nonunicode_codepoints = 1;
	font->nominal_width = (int)d->glyph_width;
	font->nominal_height = (int)d->glyph_height;
	font->num_chars = d->num_glyphs; // This may increase later
	glyph_rowspan = (d->glyph_width+7)/8;

	d->num_chars_alloc = d->num_glyphs;
	if(d->read_extra_codepoints)
		d->num_chars_alloc += MAX_EXTRA_CODEPOINTS;

	d->index_of_first_extra_codepoint = d->num_glyphs;
	d->num_extra_codepoints = 0;

	font->char_array = de_mallocarray(c, d->num_chars_alloc, sizeof(struct de_bitmap_font_char));

	font_data = de_malloc(c, d->font_data_size);
	de_read(font_data, d->headersize, d->font_data_size);

	for(i=0; i<d->num_chars_alloc; i++) {
		font->char_array[i].width = font->nominal_width;
		font->char_array[i].height = font->nominal_height;
		font->char_array[i].rowspan = glyph_rowspan;
		if(i<d->num_glyphs)
			font->char_array[i].codepoint_nonunicode = (i32)i;
		else
			font->char_array[i].codepoint_nonunicode = DE_CODEPOINT_INVALID;
		font->char_array[i].codepoint_unicode = DE_CODEPOINT_INVALID;
		if(i<d->num_glyphs)
			font->char_array[i].bitmap = &font_data[i*d->bytes_per_glyph];
	}

	if(d->has_unicode_table) {
		if(d->version==2)
			do_psf2_unicode_table(c, d, font);
		else
			do_psf1_unicode_table(c, d, font);
	}

	if(d->num_extra_codepoints>0) {
		font->num_chars = d->index_of_first_extra_codepoint + d->num_extra_codepoints;
		de_dbg(c, "codepoints aliases: %d", (int)d->num_extra_codepoints);
		de_dbg(c, "total characters: %d", (int)font->num_chars);
	}

	de_font_bitmap_font_to_image(c, font, NULL, 0);

	if(font) {
		de_free(c, font->char_array);
		de_destroy_bitmap_font(c, font);
	}
	de_free(c, font_data);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x16f6f0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movb $0x1, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x119b3d
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rcx
addq $0x7d0, %rcx            # imm = 0x7D0
movq %rcx, 0x58(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x68(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
movl $0x28, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
callq 0x164d10
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jge 0x119cb3
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x28(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x28(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x28(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x119c3d
movq -0x28(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x28(%rbp), %rdx
addq %rdx, %rax
movl %ecx, (%rax)
jmp 0x119c53
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
movl $0xfffffff, (%rax)      # imm = 0xFFFFFFF
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
movl $0xfffffff, 0x4(%rax)   # imm = 0xFFFFFFF
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x119ca0
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rdx
imulq 0x30(%rdx), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x28(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x20(%rax)
jmp 0x119ca2
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x119bb8
movq -0x10(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0x119cec
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x119cd9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x119da0
jmp 0x119cea
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x11a010
jmp 0x119cec
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jle 0x119d47
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x10(%rbp), %rax
addq 0x68(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movl %eax, %edx
leaq 0xab277(%rip), %rsi     # 0x1c4f9b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0xab272(%rip), %rsi     # 0x1c4fb2
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x16fe80
cmpq $0x0, -0x18(%rbp)
je 0x119d7f
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x16f730
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)