// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pcf.c
// Function: do_make_font_image
static void do_make_font_image(deark *c, lctx *d)
{
	struct de_bitmap_font *font = NULL;
	i64 k;
	int max_full_width = 1;
	int max_ascent = 0;
	int max_descent = 0;
	struct de_encconv_state es;

	if(!d->chars) goto done;
	if(!d->bitmaps_data) goto done;

	font = de_create_bitmap_font(c);

	font->num_chars = d->num_chars;

	font->has_nonunicode_codepoints = 1;
	if(d->is_unicode || d->can_translate_to_unicode) {
		font->has_unicode_codepoints = 1;
		font->prefer_unicode = 1;
	}

	font->char_array = de_mallocarray(c, d->num_chars, sizeof(struct de_bitmap_font_char));
	de_encconv_init(&es, d->src_encoding); // 'es' might not get used, but that's ok.

	// First, scan the characters
	for(k=0; k<font->num_chars; k++) {
		struct char_info *ci = &d->chars[k];
		int full_width;

		if(ci->codepoint == DE_CODEPOINT_INVALID) continue;

		full_width = (int)ci->extraspace_l + ci->width_raw + (int)ci->extraspace_r;
		if(full_width > max_full_width) max_full_width = full_width;
		if(ci->ascent > max_ascent) max_ascent = ci->ascent;
		if(ci->height_raw - ci->ascent > max_descent) max_descent = ci->height_raw - ci->ascent;
	}

	font->nominal_width = max_full_width;
	font->nominal_height = max_ascent + max_descent;
	if(font->nominal_height<1) font->nominal_height = 1;

	for(k=0; k<font->num_chars; k++) {
		struct de_bitmap_font_char *ch = &font->char_array[k];
		struct char_info *ci = &d->chars[k];
		i64 bitmap_len;

		if(ci->codepoint == DE_CODEPOINT_INVALID) continue;
		ch->codepoint_nonunicode = ci->codepoint;
		if(d->is_unicode) {
			ch->codepoint_unicode = ci->codepoint;
		}
		else if(d->can_translate_to_unicode) {
			ch->codepoint_unicode = de_char_to_unicode_ex(ci->codepoint, &es);
		}

		ch->width = ci->width_raw;
		ch->height = ci->height_raw;
		if(ch->width<0) ch->width=0;
		if(ch->height<0) ch->height=0;
		ch->v_offset = max_ascent - ci->ascent;
		ch->extraspace_l = ci->extraspace_l;
		ch->extraspace_r = ci->extraspace_r;

		ch->rowspan = de_pad_to_n((i64)((ci->width_raw+7)/8), (i64)d->bitmaps_fmt.glyph_padding_value);
		bitmap_len = ch->rowspan * ci->height_raw;
		if(ci->bitmap_offset + bitmap_len <= d->bitmaps_data_len) {
			ch->bitmap = &d->bitmaps_data[ci->bitmap_offset];
		}
		else {
			continue;
		}
	}

	de_font_bitmap_font_to_image(c, font, NULL, 0);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x11b650
jmp 0x11b973
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x11b660
jmp 0x11b973
movq -0x8(%rbp), %rdi
callq 0x16f6f0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x10(%rax)
movq -0x10(%rbp), %rax
movzbl 0x51(%rax), %eax
cmpl $0x0, %eax
jne 0x11b69f
movq -0x10(%rbp), %rax
movzbl 0x52(%rax), %eax
cmpl $0x0, %eax
je 0x11b6af
movq -0x18(%rbp), %rax
movb $0x1, 0x11(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x12(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movl $0x28, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0x54(%rax), %esi
leaq -0x50(%rbp), %rdi
callq 0x160150
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x11b794
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0xfffffff, 0x4(%rax)   # imm = 0xFFFFFFF
jne 0x11b71d
jmp 0x11b783
movq -0x58(%rbp), %rax
movswl 0x14(%rax), %eax
movq -0x58(%rbp), %rcx
addl 0x8(%rcx), %eax
movq -0x58(%rbp), %rcx
movswl 0x16(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x11b747
movl -0x5c(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0x28(%rbp), %eax
jle 0x11b75d
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0x10(%rcx), %eax
cmpl -0x2c(%rbp), %eax
jle 0x11b781
movq -0x58(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x2c(%rbp)
jmp 0x11b783
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x11b6e8
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jge 0x11b7bf
movq -0x18(%rbp), %rax
movl $0x1, 0x4(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x11b960
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpl $0xfffffff, 0x4(%rax)   # imm = 0xFFFFFFF
jne 0x11b813
jmp 0x11b94f
movq -0x70(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x51(%rax)
je 0x11b83a
movq -0x70(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x11b85f
movq -0x10(%rbp), %rax
cmpb $0x0, 0x52(%rax)
je 0x11b85d
movq -0x70(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x50(%rbp), %rsi
callq 0x160a30
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x11b85f
movq -0x70(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x70(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x68(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jge 0x11b890
movq -0x68(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x68(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jge 0x11b8a5
movq -0x68(%rbp), %rax
movl $0x0, 0xc(%rax)
movl -0x28(%rbp), %ecx
movq -0x70(%rbp), %rax
subl 0x10(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x70(%rbp), %rax
movw 0x14(%rax), %cx
movq -0x68(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x70(%rbp), %rax
movw 0x16(%rax), %cx
movq -0x68(%rbp), %rax
movw %cx, 0x16(%rax)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x7, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movslq %eax, %rdi
movq -0x10(%rbp), %rax
movl 0x3c(%rax), %eax
movl %eax, %esi
callq 0x15ce90
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x70(%rbp), %rcx
movslq 0xc(%rcx), %rcx
imulq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movl (%rax), %eax
addq -0x78(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jg 0x11b94b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x70(%rbp), %rax
movl (%rax), %eax
addq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x11b94d
jmp 0x11b94f
jmp 0x11b94f
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x11b7c7
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x16fe80
cmpq $0x0, -0x18(%rbp)
je 0x11b998
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x16f730
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)