// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/grasp.c
// Function: de_run_graspfont_newfmt
static void de_run_graspfont_newfmt(deark *c)
{
	struct de_bitmap_font *font = NULL;
	de_ucstring *fontname = NULL;
	i64 k;
	i64 glyph_offsets_table_pos;
	i64 widths_table_pos;
	i64 glyph_rowspan;
	int tmp_width;
	int ch_max_width = 0;

	de_dbg(c, "header at %d", 0);
	de_dbg_indent(c, 1);

	font = de_create_bitmap_font(c);
	font->has_nonunicode_codepoints = 1;

	fontname = ucstring_create(c);
	dbuf_read_to_ucstring(c->infile, 1, 13, fontname, DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_ASCII);
	de_dbg(c, "name: \"%s\"", ucstring_getpsz(fontname));

	font->num_chars = (i64)de_getbyte(16);
	de_dbg(c, "number of glyphs: %d", (int)font->num_chars);

	tmp_width = (int)de_getbyte(19);
	de_dbg(c, "font width: %d", tmp_width);
	font->nominal_height = (int)de_getbyte(20);
	de_dbg(c, "font height: %d", font->nominal_height);

	glyph_rowspan = (i64)de_getbyte(21);

	de_dbg_indent(c, -1);

	glyph_offsets_table_pos = 59;
	widths_table_pos = glyph_offsets_table_pos +2*font->num_chars;
	if(widths_table_pos<249)
		widths_table_pos = 249;
	de_dbg(c, "glyph offsets table at %d, width table at %d", (int)glyph_offsets_table_pos,
		(int)widths_table_pos);
	de_dbg_indent(c, 1);

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

	for(k=0; k<font->num_chars; k++) {
		i64 ch_offset;
		i64 bitmapsize;
		struct de_bitmap_font_char *ch = &font->char_array[k];

		ch->codepoint_nonunicode = (i32)(33 + k);

		ch_offset = de_getu16le(glyph_offsets_table_pos + 2 + 2*k);

		ch->width = (int)de_getbyte(widths_table_pos + 1 + k);
		de_dbg2(c, "ch[%d]: codepoint=%d, width=%d, glyph_offs=%d", (int)k,
			(int)ch->codepoint_nonunicode,
			(int)ch->width, (int)ch_offset);

		if(ch->width<1) continue;

		if(ch->width > ch_max_width) ch_max_width = ch->width;
		ch->height = font->nominal_height;
		ch->rowspan = glyph_rowspan;
		bitmapsize = ch->rowspan * ch->height;
		ch->bitmap = de_malloc(c, bitmapsize);
		de_read(ch->bitmap, ch_offset, bitmapsize);
	}

	de_dbg_indent(c, -1);

	de_dbg(c, "calculated maximum width: %d", (int)ch_max_width);
	font->nominal_width = ch_max_width;

	de_font_bitmap_font_to_image(c, font, NULL, 0);

	if(font) {
		if(font->char_array) {
			for(k=0; k<font->num_chars; k++) {
				de_free(c, font->char_array[k].bitmap);
			}
			de_free(c, font->char_array);
		}
		de_destroy_bitmap_font(c, font);
	}

	ucstring_destroy(fontname);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x14ee80(%rip), %rsi    # 0x1c4f8e
xorl %edx, %edx
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
callq 0x16f6f0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, 0x10(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0xd, %edx
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0x172500
movq -0x60(%rbp), %rdi
movq %rax, %rdx
leaq 0x138046(%rip), %rsi    # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x10, %esi
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x135c8b(%rip), %rsi    # 0x1abe50
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x13, %esi
callq 0x165060
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %edx
leaq 0x135c73(%rip), %rsi    # 0x1abe65
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x14, %esi
callq 0x165060
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
leaq 0x12cd4b(%rip), %rsi    # 0x1a2f72
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x15, %esi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq $0x3b, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpq $0xf9, -0x30(%rbp)
jge 0x76285
movq $0xf9, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
movq -0x30(%rbp), %rax
movl %eax, %ecx
leaq 0x135bd8(%rip), %rsi    # 0x1abe74
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movl $0x28, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x7641d
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
addq $0x21, %rax
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x2, %rsi
movq -0x20(%rbp), %rax
shlq %rax
addq %rax, %rsi
callq 0x165280
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0x1, %rsi
addq -0x20(%rbp), %rsi
callq 0x165060
movzbl %al, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
movq -0x58(%rbp), %rax
movl (%rax), %ecx
movq -0x58(%rbp), %rax
movl 0x8(%rax), %r8d
movq -0x48(%rbp), %rax
movl %eax, %r9d
leaq 0x135b25(%rip), %rsi    # 0x1abea1
movb $0x0, %al
callq 0x15b350
movq -0x58(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jge 0x7638f
jmp 0x7640c
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x40(%rbp), %eax
jle 0x763a5
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x58(%rbp), %rcx
movslq 0xc(%rcx), %rcx
imulq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x15b780
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x164d10
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x762da
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %edx
leaq 0x135a96(%rip), %rsi    # 0x1abecf
movb $0x0, %al
callq 0x15b0d0
movl -0x40(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x16fe80
cmpq $0x0, -0x10(%rbp)
je 0x764cd
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x764c0
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x764af
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x76476
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x16f730
movq -0x18(%rbp), %rdi
callq 0x171750
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)