// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc2.c
// Function: do_fp_art_hires
static void do_fp_art_hires(deark *c, struct fp_art_ctx *d)
{
	struct fp_art_stdhdr_data *hd = &d->hd;
	i64 pos = 2;
	UI unk1;
	dbuf *unc_pixels = NULL;
	de_finfo *fi = NULL;
	i64 xdpi, ydpi;
	i64 min_rowspan, max_rowspan;
	i64 cmpr_size;
	i64 cmpr_pos;
	i64 max_unc_size;

	fi = de_finfo_create(c);
	xdpi = de_getu16le_p(&pos);
	ydpi = de_getu16le_p(&pos);
	fi->density.code = DE_DENSITY_DPI;
	fi->density.xdens = (double)xdpi;
	fi->density.ydens = (double)ydpi;
	hd->w = de_getu16le_p(&pos);
	hd->h = de_getu16le_p(&pos);
	de_dbg_dimensions(c, hd->w, hd->h);
	unk1 = (UI)de_getu16le_p(&pos);
	if(unk1!=1) {
		d->need_errmsg = 1;
		goto done;
	}
	cmpr_pos = pos;
	if(!de_good_image_dimensions(c, hd->w, hd->h)) goto done;

	// We don't know the bytes/row yet, but it should be in this range.
	min_rowspan = ((hd->w+7)/8);
	max_rowspan = min_rowspan+3; // (+2 may be sufficient)
	max_unc_size = hd->h * max_rowspan +1;
	unc_pixels = dbuf_create_membuf(c, max_unc_size, 0x1);
	dbuf_enable_wbuffer(unc_pixels);
	cmpr_size = c->infile->len - cmpr_pos;
	fmtutil_decompress_packbits(c->infile, cmpr_pos, cmpr_size, unc_pixels, NULL);
	dbuf_flush(unc_pixels);
	de_dbg(c, "decompressed %"I64_FMT" bytes to %"I64_FMT, cmpr_size, unc_pixels->len);

	// I don't know if there's any better way to figure out the bytes/row.
	// It's weird.
	if((unc_pixels->len % hd->h) != 0) {
		d->need_errmsg = 1;
		goto done;
	}
	hd->rowspan = unc_pixels->len / hd->h;
	if(hd->rowspan<min_rowspan || hd->rowspan>max_rowspan) {
		d->need_errmsg = 1;
		goto done;
	}
	de_dbg(c, "bytes/row: %"I64_FMT, hd->rowspan);
	de_dbg2(c, "padding bytes/row: %d", (int)(hd->rowspan-min_rowspan));

	de_convert_and_write_image_bilevel2(unc_pixels, 0, hd->w, hd->h, hd->rowspan,
		0, fi, 0);

done:
	dbuf_close(unc_pixels);
	de_finfo_destroy(c, fi);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq $0x2, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movl $0x2, 0x78(%rax)
cvtsi2sdq -0x40(%rbp), %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, 0x80(%rax)
cvtsi2sdq -0x48(%rbp), %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, 0x88(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x24(%rbp)
cmpl $0x1, -0x24(%rbp)
je 0x9b1f1
movq -0x10(%rbp), %rax
movb $0x1, 0x21(%rax)
jmp 0x9b3a7
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x9b21c
jmp 0x9b3a7
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
subq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x30(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x177e60
movq -0x30(%rbp), %rdi
callq 0x167c30
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0x103a7b(%rip), %rsi    # 0x19ed43
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
cqto
idivq 0x10(%rcx)
cmpq $0x0, %rdx
je 0x9b2f4
movq -0x10(%rbp), %rax
movb $0x1, 0x21(%rax)
jmp 0x9b3a7
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
cqto
idivq 0x10(%rcx)
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x50(%rbp), %rax
jl 0x9b32d
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x58(%rbp), %rax
jle 0x9b337
movq -0x10(%rbp), %rax
movb $0x1, 0x21(%rax)
jmp 0x9b3a7
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x11558d(%rip), %rsi    # 0x1b08d7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
subq -0x50(%rbp), %rax
movl %eax, %edx
leaq 0x11557c(%rip), %rsi    # 0x1b08e6
movb $0x0, %al
callq 0x15b350
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %r8
movq -0x38(%rbp), %rax
xorl %esi, %esi
xorl %r9d, %r9d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x16c000
movq -0x30(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15d260
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)