// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc2.c
// Function: de_run_yp
static void de_run_yp(deark *c, de_module_params *mparams)
{
	struct fastgraph_ctx *d = NULL;
	de_bitmap *img = NULL;
	de_finfo *fi = NULL;
	dbuf *unc_pixels = NULL;

	d = de_malloc(c, sizeof(struct fastgraph_ctx));
	// TODO?: Maybe we should call do_fastgraph_internal() instead of
	// just decompress_fastgraph_ppr(), but it would be a bit messy.
	d->is_ppr = 1;

	if(has_yp_sig(c)) {
		d->w = (i64)de_getbyte(9) * 256;
		d->w += (i64)de_getbyte(12);
		d->h = (i64)de_getbyte(15) * 256;
		d->h += (i64)de_getbyte(18);
		d->img_startpos = 24; // (Not actually necessary)
	}
	else {
		d->w = 320;
		d->h = 200;
	}

	de_dbg_dimensions(c, d->w, d->h);
	if(!de_good_image_dimensions(c, d->w, d->h)) goto done;

	d->max_unc_bytes = d->w * d->h;
	unc_pixels = dbuf_create_membuf(c, d->max_unc_bytes, 0x1);
	dbuf_enable_wbuffer(unc_pixels);
	decompress_fastgraph_ppr(c, d, unc_pixels, d->img_startpos);

	fi = de_finfo_create(c);
	fi->density.code = DE_DENSITY_UNK_UNITS;
	fi->density.xdens = 6.0;
	fi->density.ydens = 5.0;

	de_copy_std_palette(DE_PALID_PC16, 0, 0, d->pal, 16, 0);
	img = de_bitmap_create(c, d->w, d->h, 3);
	de_convert_image_paletted(unc_pixels, 0, 8, d->w, d->pal, img, 0);
	de_bitmap_write_to_file_finfo(img, fi, DE_CREATEFLAG_FLIP_IMAGE |
		DE_CREATEFLAG_OPT_IMAGE);

done:
	dbuf_close(unc_pixels);
	de_bitmap_destroy(img);
	de_finfo_destroy(c, fi);
	de_free(c, d);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0x430, %esi            # imm = 0x430
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movb $0x1, (%rax)
movq -0x8(%rbp), %rdi
callq 0x9c070
cmpl $0x0, %eax
je 0x99aa5
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x9, %esi
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
shlq $0x8, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0xc, %esi
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0xf, %esi
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
shlq $0x8, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x12, %esi
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq $0x18, 0x18(%rax)
jmp 0x99abd
movq -0x18(%rbp), %rax
movq $0x140, 0x8(%rax)       # imm = 0x140
movq -0x18(%rbp), %rax
movq $0xc8, 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), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x99af9
jmp 0x99c13
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
imulq 0x10(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
callq 0x9be30
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x1, 0x78(%rax)
movq -0x28(%rbp), %rax
movsd 0x114d16(%rip), %xmm0   # 0x1ae888
movsd %xmm0, 0x80(%rax)
movq -0x28(%rbp), %rax
movsd 0x114cfa(%rip), %xmm0   # 0x1ae880
movsd %xmm0, 0x88(%rax)
movq -0x18(%rbp), %rcx
addq $0x28, %rcx
movl $0x14, %edi
xorl %r9d, %r9d
xorl %eax, %eax
movl %eax, %edx
movl $0x10, %r8d
movl %r9d, %esi
callq 0x161320
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x3, %ecx
callq 0x16b750
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %r8
addq $0x28, %r8
movq -0x20(%rbp), %r9
xorl %eax, %eax
movl %eax, %esi
movl $0x8, %edx
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x6, %edx
callq 0x16afa0
movq -0x30(%rbp), %rdi
callq 0x1676a0
movq -0x20(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)