// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/misc2.c
// Function: do_fastgraph_internal
static void do_fastgraph_internal(deark *c, struct fastgraph_ctx *d)
{
	dbuf *unc_pixels = NULL;
	de_bitmap *img = NULL;
	const char *s;

	if(d->w==0) {
		s = de_get_ext_option(c, "width");
		if(s) {
			d->w = de_atoi64(s);
		}
	}
	if(d->h==0) {
		s = de_get_ext_option(c, "height");
		if(s) {
			d->h = de_atoi64(s);
		}
	}

	if(d->w==0) {
		de_err(c, "Image width unknown. Try \"-opt width=...\".");
		goto done;
	}

	if(d->h>0) {
		de_dbg_dimensions(c, d->w, d->h);
	}
	else {
		de_dbg(c, "width: %"I64_FMT, d->w);
	}

	if(d->w<1 || d->w>c->max_image_dimension ||
		d->h<0 || d->h>c->max_image_dimension)
	{
		de_err(c, "Bad image dimensions");
		goto done;
	}

	if(d->h==0) {
		d->max_unc_bytes = DE_MAX_SANE_OBJECT_SIZE;
		unc_pixels = dbuf_create_membuf(c, 0, 0);
	}
	else {
		d->max_unc_bytes = d->w * d->h;
		unc_pixels = dbuf_create_membuf(c, d->max_unc_bytes, 0x1);
	}

	if(d->is_ppr) {
		decompress_fastgraph_ppr(c, d, unc_pixels, d->img_startpos);
	}
	else {
		decompress_fastgraph_spr(c, d, unc_pixels, d->img_startpos);
	}

	de_dbg(c, "decompressed %"I64_FMT" pixels", unc_pixels->len);
	if(d->h==0) {
		d->h = de_pad_to_n(unc_pixels->len, d->w) / d->w;
		de_dbg(c, "height: %"I64_FMT, d->h);
	}

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

	img = de_bitmap_create(c, d->w, d->h, d->pal_is_set?3:1);
	if(!d->pal_is_set) {
		de_info(c, "Note: Color map unknown. Rendering as grayscale.");
		de_make_grayscale_palette(d->pal, 1+(i64)d->max_color_used, 0);
	}

	de_convert_image_paletted(unc_pixels, 0, 8, d->w, d->pal, img, 0);
	de_bitmap_write_to_file(img, NULL, DE_CREATEFLAG_FLIP_IMAGE |
		DE_CREATEFLAG_OPT_IMAGE);

done:
	dbuf_close(unc_pixels);
	de_bitmap_destroy(img);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
cmpq $0x0, 0x8(%rsi)
jne 0x692d4
leaq 0xaf3cc(%rip), %rsi     # 0x118687
movq %r14, %rdi
callq 0xdfa87
testq %rax, %rax
je 0x692d4
movq %rax, %rdi
callq 0xdfb3b
movq %rax, 0x8(%rbx)
cmpq $0x0, 0x10(%rbx)
jne 0x692fb
leaq 0xaf3c9(%rip), %rsi     # 0x1186ab
movq %r14, %rdi
callq 0xdfa87
testq %rax, %rax
je 0x692fb
movq %rax, %rdi
callq 0xdfb3b
movq %rax, 0x10(%rbx)
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x6931a
movq 0x10(%rbx), %rdx
testq %rdx, %rdx
jle 0x69323
movq %r14, %rdi
movq %rax, %rsi
callq 0xdf038
jmp 0x69337
leaq 0xaf2b4(%rip), %rsi     # 0x1185d5
jmp 0x69367
leaq 0xaf229(%rip), %rsi     # 0x118553
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x8(%rbx), %rax
testq %rax, %rax
jle 0x69360
movq 0xa8(%r14), %rcx
cmpq %rcx, %rax
jg 0x69360
movq 0x10(%rbx), %rsi
testq %rsi, %rsi
setns %dl
cmpq %rcx, %rsi
setle %cl
testb %cl, %dl
jne 0x69396
leaq 0xaf299(%rip), %rsi     # 0x118600
xorl %r15d, %r15d
movq %r14, %rdi
xorl %eax, %eax
callq 0xdf2a5
xorl %r12d, %r12d
movq %r15, %rdi
callq 0xe5591
movq %r12, %rdi
callq 0xe7084
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rsi, %rsi
je 0x693ab
imulq %rax, %rsi
movq %rsi, 0x20(%rbx)
pushq $0x1
popq %rdx
movq %r14, %rdi
jmp 0x693ba
movq $0x5f5e100, 0x20(%rbx)  # imm = 0x5F5E100
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe59cd
movq %rax, %r15
cmpb $0x0, (%rbx)
movq 0x18(%rbx), %rcx
je 0x693db
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x69533
jmp 0x69452
leaq 0x10(%rsp), %rax
movq %rcx, (%rax)
movb $0x1, 0x428(%rbx)
xorl %r12d, %r12d
movq 0x18(%r14), %rdi
cmpq 0x18(%rdi), %rcx
jge 0x6944a
cmpq 0x20(%rbx), %r12
jge 0x6944a
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0xe3f2a
movl %eax, %ebp
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %r13d
testb %r13b, %r13b
je 0x69440
cmpb 0x428(%rbx), %bpl
jbe 0x69431
movb %bpl, 0x428(%rbx)
movzbl %bpl, %esi
movq %r15, %rdi
movq %r13, %rdx
callq 0xe5e40
addq %r13, %r12
movq 0x10(%rsp), %rcx
jmp 0x693ed
movq %r15, %rdi
callq 0xe58e8
movq 0x18(%r15), %rdx
leaq 0xaf1b8(%rip), %rsi     # 0x118615
movq %r14, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x10(%rbx), %rdx
testq %rdx, %rdx
jne 0x6949f
movq 0x18(%r15), %rdi
movq 0x8(%rbx), %rsi
callq 0xdfbb6
cqto
idivq 0x8(%rbx)
movq %rax, 0x10(%rbx)
leaq 0xaf19f(%rip), %rsi     # 0x11862d
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x10(%rbx), %rdx
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0xe6be1
testl %eax, %eax
je 0x69374
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
xorl %eax, %eax
cmpb $0x0, 0x1(%rbx)
setne %al
leal 0x1(,%rax,2), %ecx
movq %r14, %rdi
callq 0xe7437
movq %rax, %r12
cmpb $0x0, 0x1(%rbx)
jne 0x69502
leaq 0xaf156(%rip), %rsi     # 0x118639
movq %r14, %rdi
xorl %eax, %eax
callq 0xdf37f
leaq 0x28(%rbx), %rdi
movzbl 0x428(%rbx), %esi
incq %rsi
xorl %edx, %edx
callq 0xe87a8
movq 0x8(%rbx), %rcx
addq $0x28, %rbx
andl $0x0, (%rsp)
pushq $0x8
popq %rdx
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %r8
movq %r12, %r9
callq 0xe7cbc
pushq $0x6
popq %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0xe70b7
jmp 0x69377