// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x9bb3c
movq -0x8(%rbp), %rdi
leaq 0x1151e1(%rip), %rsi    # 0x1b0cf7
callq 0x15cb30
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x9bb3a
movq -0x28(%rbp), %rdi
callq 0x15ccc0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x9bb3c
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x9bb78
movq -0x8(%rbp), %rdi
leaq 0x1151c9(%rip), %rsi    # 0x1b0d1b
callq 0x15cb30
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x9bb76
movq -0x28(%rbp), %rdi
callq 0x15ccc0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x9bb78
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x9bb9a
movq -0x8(%rbp), %rdi
leaq 0x1150b7(%rip), %rsi    # 0x1b0c45
movb $0x0, %al
callq 0x15bfb0
jmp 0x9be0d
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jle 0x9bbc0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x15bba0
jmp 0x9bbda
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x114ff0(%rip), %rsi    # 0x1b0bc3
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x1, 0x8(%rax)
jl 0x9bc1a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0xa8(%rcx), %rax
jg 0x9bc1a
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jl 0x9bc1a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0xa8(%rcx), %rax
jle 0x9bc31
movq -0x8(%rbp), %rdi
leaq 0x11504b(%rip), %rsi    # 0x1b0c70
movb $0x0, %al
callq 0x15bfb0
jmp 0x9be0d
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x9bc5d
movq -0x10(%rbp), %rax
movq $0x5f5e100, 0x20(%rax)  # imm = 0x5F5E100
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x168020
movq %rax, -0x18(%rbp)
jmp 0x9bc90
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
imulq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x9bcb4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
callq 0x9be30
jmp 0x9bccd
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
callq 0x9bf50
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x114fa5(%rip), %rsi    # 0x1b0c85
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x9bd36
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x15ce90
movq -0x10(%rbp), %rcx
cqto
idivq 0x8(%rcx)
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x114f6e(%rip), %rsi    # 0x1b0c9d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x9bd59
jmp 0x9be0d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %r8d
movl $0x1, %ecx
movl $0x3, %eax
cmpl $0x0, %r8d
cmovnel %eax, %ecx
callq 0x16b750
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x1(%rax)
jne 0x9bdcc
movq -0x8(%rbp), %rdi
leaq 0x114f04(%rip), %rsi    # 0x1b0ca9
movb $0x0, %al
callq 0x15c0c0
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
movq -0x10(%rbp), %rax
movzbl 0x428(%rax), %eax
movl %eax, %esi
addq $0x1, %rsi
xorl %edx, %edx
callq 0x16d580
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%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
xorl %eax, %eax
movl %eax, %esi
movl $0x6, %edx
callq 0x16afd0
movq -0x18(%rbp), %rdi
callq 0x1676a0
movq -0x20(%rbp), %rdi
callq 0x16af60
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)