// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl $0x430, %esi            # imm = 0x430
callq 0xdecaf
movq %rax, %r14
movb $0x1, (%rax)
movq %rbx, %rdi
callq 0x69610
testl %eax, %eax
je 0x6735c
movq 0x18(%rbx), %rdi
pushq $0x9
popq %rsi
callq 0xe3eb4
movzbl %al, %eax
shll $0x8, %eax
movq %rax, 0x8(%r14)
movq 0x18(%rbx), %rdi
pushq $0xc
popq %rsi
callq 0xe3eb4
movzbl %al, %eax
addq %rax, 0x8(%r14)
movq 0x18(%rbx), %rdi
pushq $0xf
popq %rsi
callq 0xe3eb4
movzbl %al, %eax
shll $0x8, %eax
movq %rax, 0x10(%r14)
movq 0x18(%rbx), %rdi
pushq $0x12
popq %rsi
callq 0xe3eb4
movzbl %al, %edx
addq 0x10(%r14), %rdx
movq %rdx, 0x10(%r14)
movq $0x18, 0x18(%r14)
movq 0x8(%r14), %rsi
jmp 0x67376
movq $0x140, 0x8(%r14)       # imm = 0x140
movq $0xc8, 0x10(%r14)
movl $0x140, %esi            # imm = 0x140
movl $0xc8, %edx
movq %rbx, %rdi
callq 0xdf038
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %rbx, %rdi
callq 0xe6be1
testl %eax, %eax
je 0x67449
movq 0x10(%r14), %rsi
imulq 0x8(%r14), %rsi
movq %rsi, 0x20(%r14)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0xe59cd
movq %rax, %r15
movq %rax, %rdi
callq 0xe589c
movq 0x18(%r14), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x69533
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r12
movl $0x1, 0x78(%rax)
movaps 0xae88c(%rip), %xmm0    # 0x115c70
movups %xmm0, 0x80(%rax)
movq %r14, %rbp
addq $0x28, %rbp
pushq $0x14
popq %rdi
pushq $0x10
popq %r8
xorl %esi, %esi
xorl %edx, %edx
movq %rbp, %rcx
xorl %r9d, %r9d
callq 0xe1b11
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
pushq $0x3
popq %rcx
movq %rbx, %rdi
callq 0xe7437
movq %rax, %r13
movq 0x8(%r14), %rcx
andl $0x0, (%rsp)
pushq $0x8
popq %rdx
movq %r15, %rdi
xorl %esi, %esi
movq %rbp, %r8
movq %rax, %r9
callq 0xe7cbc
pushq $0x6
popq %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0xe70ab
jmp 0x67452
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xe5591
movq %r13, %rdi
callq 0xe7084
movq %rbx, %rdi
movq %r12, %rsi
callq 0xdfd24
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xded32