// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/sunras.c
// Function: de_run_sunras
static void de_run_sunras(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	dbuf *unc_pixels = NULL;
	i64 pos;
	i64 bits_per_row;
	int saved_indent_level;
	de_dbg_indent_save(c, &saved_indent_level);

	d = de_malloc(c, sizeof(lctx));
	handle_options(c, d);

	pos = 0;
	read_header(c, d, pos);
	pos += 32;

	if(pos >= c->infile->len) goto done;

	if(d->maplen > 0)
		de_dbg(c, "colormap at %"I64_FMT, pos);

	de_dbg_indent(c, 1);

	if(d->maptype==RMT_EQUAL_RGB) {
		if(d->depth<=8) {
			d->is_paletted = 1;
			do_read_palette(c, d, pos);
		}
		else {
			de_err(c, "This type of image is not supported");
			goto done;
		}
	}
	else if(d->maptype==RMT_NONE) {
		if(d->depth<=8) {
			d->is_grayscale = 1;
			de_make_grayscale_palette(d->pal, ((i64)1)<<d->depth, d->depth==1 ? 1 : 0);
		}
	}
	else {
		// TODO: Support RMT_RAW
		de_err(c, "Colormap type (%u) is not supported", d->maptype);
		goto done;
	}
	pos += d->maplen;
	de_dbg_indent(c, -1);

	if(pos >= c->infile->len) goto done;
	de_dbg(c, "image data at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	bits_per_row = de_pad_to_n(d->npwidth * (i64)d->depth, 16);
	d->rowspan = bits_per_row / 8;
	d->pdwidth = bits_per_row / (i64)d->depth;
	d->unc_pixels_size = d->rowspan * d->height;

	if(d->imgtype>5) {
		de_err(c, "This type of image (%u) is not supported", d->imgtype);
		goto done;
	}

	if((d->imgtype==RT_STANDARD || d->imgtype==RT_FORMAT_RGB) && d->imglen!=d->unc_pixels_size) {
		de_warn(c, "Inconsistent image length: reported=%"I64_FMT", calculated=%"I64_FMT,
			d->imglen, d->unc_pixels_size);
	}

	if(d->is_compressed) {
		unc_pixels = dbuf_create_membuf(c, d->unc_pixels_size, 0x1);
		dbuf_enable_wbuffer(unc_pixels);
		do_decompress_image(c, d, pos, c->infile->len - pos, unc_pixels);
		dbuf_flush(unc_pixels);
	}
	else {
		unc_pixels = dbuf_open_input_subfile(c->infile, pos, c->infile->len - pos);
	}

	do_image(c, d, unc_pixels);
	de_dbg_indent(c, -1);

done:
	dbuf_close(unc_pixels);
	de_free(c, d);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x14(%rsp), %rsi
callq 0xe8a1c
movl $0x478, %esi            # imm = 0x478
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r14
leaq 0x7449e(%rip), %rsi     # 0x13b89f
movq %rbx, %rdi
callq 0xe9b74
testq %rax, %rax
je 0xc744a
movq %rax, %r15
xorl %r12d, %r12d
leaq 0xbfd95(%rip), %r13     # 0x1871b0
movq 0x8(%r12,%r13), %rsi
movq %r15, %rdi
callq 0x181a0
testl %eax, %eax
je 0xc743b
addq $0x10, %r12
cmpq $0x80, %r12
jne 0xc741b
jmp 0xc744a
movups (%r12,%r13), %xmm0
movups %xmm0, 0x28(%r14)
movb $0x1, 0x22(%r14)
leaq 0x5bf2e(%rip), %rsi     # 0x12337f
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xeed0d
movq %rax, (%r14)
movq 0x18(%rbx), %rdi
movl $0x8, %esi
callq 0xeed0d
movq %rax, 0x8(%r14)
movq (%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xe8f88
movq 0x18(%rbx), %rdi
movl $0xc, %esi
callq 0xeed0d
movl %eax, 0x18(%r14)
leaq 0x5cce8(%rip), %rsi     # 0x12419c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x10, %esi
callq 0xeed0d
movq %rax, 0x38(%r14)
movq 0x18(%rbx), %rdi
movl $0x14, %esi
callq 0xeed0d
movl %eax, 0x1c(%r14)
cmpl $0x5, %eax
ja 0xc7504
movl %eax, %ecx
leaq 0x742ba(%rip), %rdx     # 0x13b7ac
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq 0x7334c(%rip), %rcx     # 0x13a84e
jmp 0xc7548
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0xc7526
leaq 0x743d0(%rip), %rcx     # 0x13b8e2
jmp 0xc7548
leaq 0x83223(%rip), %rcx     # 0x14a73e
jmp 0xc7548
leaq 0x5dd7e(%rip), %rcx     # 0x1252a2
jmp 0xc7548
leaq 0x64c24(%rip), %rcx     # 0x12c151
jmp 0xc7548
leaq 0x7846a(%rip), %rcx     # 0x13f9a0
jmp 0xc7548
leaq 0x6daa2(%rip), %rcx     # 0x134fe1
jmp 0xc7548
leaq 0x613b8(%rip), %rcx     # 0x128900
movq 0x38(%r14), %r8
leaq 0x74359(%rip), %rsi     # 0x13b8ac
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl 0x1c(%r14), %eax
cmpl $0x3, %eax
je 0xc7574
cmpl $0x2, %eax
jne 0xc7579
movb $0x1, 0x20(%r14)
jmp 0xc7579
movb $0x1, 0x21(%r14)
movq 0x18(%rbx), %rdi
movl $0x18, %esi
callq 0xeed0d
movl %eax, 0x40(%r14)
movq 0x18(%rbx), %rdi
movl $0x1c, %esi
callq 0xeed0d
movq %rax, 0x48(%r14)
movl 0x40(%r14), %edx
cmpq $0x2, %rdx
ja 0xc75b7
leaq 0x74216(%rip), %rsi     # 0x13b7c4
movslq (%rsi,%rdx,4), %rcx
addq %rsi, %rcx
jmp 0xc75be
leaq 0x64b93(%rip), %rcx     # 0x12c151
leaq 0x74303(%rip), %rsi     # 0x13b8c8
xorl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %r8
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x18(%rbx), %rax
cmpq $0x21, 0x18(%rax)
jl 0xc7ada
cmpq $0x0, 0x48(%r14)
jle 0xc760e
leaq 0x741e3(%rip), %rsi     # 0x13b7e2
movl $0x20, %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl 0x40(%r14), %edx
testl %edx, %edx
je 0xc76ef
cmpl $0x1, %edx
jne 0xc77b3
cmpl $0x8, 0x18(%r14)
ja 0xc77d4
movb $0x1, 0x60(%r14)
movq 0x48(%r14), %rax
cmpq $0x3, %rax
jl 0xc7718
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
movq %rdx, %r15
shrq %r15
movl $0x100, %eax            # imm = 0x100
cmpq %rax, %r15
cmovbq %r15, %rax
movq %rax, 0x18(%rsp)
addq $0x20, %r15
andq $-0x2, %rdx
addq $0x20, %rdx
movq %rdx, 0x20(%rsp)
xorl %r12d, %r12d
movq 0x18(%rbx), %rdi
leaq 0x20(%r12), %rsi
callq 0xeead3
movl %eax, %ebp
movq 0x18(%rbx), %rdi
leaq (%r15,%r12), %rsi
callq 0xeead3
movl %eax, %r13d
movq 0x18(%rbx), %rdi
movq 0x20(%rsp), %rax
leaq (%rax,%r12), %rsi
callq 0xeead3
movzbl %bpl, %ecx
shll $0x10, %ecx
movzbl %r13b, %esi
shll $0x8, %esi
orl %ecx, %esi
movzbl %al, %edx
orl %esi, %edx
orl $0xff000000, %edx       # imm = 0xFF000000
movl %edx, 0x64(%r14,%r12,4)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe91fc
incq %r12
cmpq %r12, 0x18(%rsp)
jne 0xc7686
jmp 0xc7718
movl 0x18(%r14), %ecx
cmpq $0x8, %rcx
ja 0xc7718
movb $0x1, 0x61(%r14)
movl $0x1, %esi
shlq %cl, %rsi
leaq 0x64(%r14), %rdi
xorl %edx, %edx
cmpq $0x1, %rcx
sete %dl
callq 0xf3bdb
movq 0x48(%r14), %r12
addq $0x20, %r12
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jge 0xc77cc
leaq 0x73975(%rip), %rsi     # 0x13b0b7
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl 0x18(%r14), %edi
imulq (%r14), %rdi
movl $0x10, %esi
callq 0xe9cb4
leaq 0x7(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
sarq $0x3, %rcx
movq %rcx, 0x50(%r14)
movl 0x18(%r14), %esi
movl 0x1c(%r14), %r8d
cqto
idivq %rsi
movq %rax, 0x10(%r14)
imulq 0x8(%r14), %rcx
movq %rcx, 0x58(%r14)
cmpl $0x6, %r8d
jb 0xc77ed
leaq 0x7406e(%rip), %rsi     # 0x13b816
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r8d, %edx
jmp 0xc77c0
leaq 0x74038(%rip), %rsi     # 0x13b7f2
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0xc7ada
xorl %r15d, %r15d
jmp 0xc7ada
leaq 0x6da34(%rip), %rsi     # 0x13520f
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0xc7ada
orl $0x2, %r8d
cmpl $0x3, %r8d
jne 0xc7811
movq 0x38(%r14), %rdx
cmpq %rcx, %rdx
je 0xc7811
leaq 0x74038(%rip), %rsi     # 0x13b83f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
cmpb $0x0, 0x20(%r14)
je 0xc78c5
movq 0x58(%r14), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf09c5
movq %rax, %r15
movq %rax, %rdi
callq 0xf0855
movq 0x18(%rbx), %rdi
cmpq %r12, 0x18(%rdi)
jle 0xc78bb
leaq 0x1(%r12), %rbp
movq %r12, %rsi
callq 0xeead3
cmpb $-0x80, %al
jne 0xc7891
movq 0x18(%rbx), %rdi
leaq 0x2(%r12), %r13
movq %rbp, %rsi
callq 0xeead3
testb %al, %al
je 0xc78a1
movl %eax, %ebp
movq 0x18(%rbx), %rdi
addq $0x3, %r12
movq %r13, %rsi
callq 0xeead3
movzbl %bpl, %edx
incq %rdx
movzbl %al, %esi
movq %r15, %rdi
callq 0xf0eba
movq %r12, %r13
jmp 0xc78ae
movzbl %al, %esi
movq %r15, %rdi
callq 0xf0bd6
movq %rbp, %r13
jmp 0xc78ae
movq %r15, %rdi
movl $0x80, %esi
callq 0xf0bd6
movq 0x18(%rbx), %rdi
movq %r13, %r12
cmpq 0x18(%rdi), %r13
jl 0xc7842
movq %r15, %rdi
callq 0xf08ba
jmp 0xc78db
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
subq %r12, %rdx
movq %r12, %rsi
callq 0xf1388
movq %rax, %r15
movl 0x18(%r14), %edx
cmpq $0x20, %rdx
ja 0xc7ab1
movl $0x1000112, %eax        # imm = 0x1000112
btq %rdx, %rax
jae 0xc79f5
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xf1db1
testl %eax, %eax
je 0xc7a52
movl 0x18(%r14), %eax
movl %eax, %ecx
shrl $0x3, %ecx
movq %rcx, 0x468(%r14)
movl $0x3, %r8d
cmpb $0x0, 0x60(%r14)
jne 0xc7953
movl $0x1, %r8d
cmpb $0x0, 0x61(%r14)
jne 0xc7953
movl $0x3, %r8d
cmpl $0x20, %eax
jne 0xc7953
cmpb $0x1, 0x2c(%r14)
movl $0x4, %r8d
sbbl $0x0, %r8d
xorl %eax, %eax
cmpb $0x0, 0x21(%r14)
sete %al
movl %eax, 0x470(%r14)
movq 0x10(%r14), %rdx
movq (%r14), %rsi
movq 0x8(%r14), %rcx
movq %rbx, %rdi
callq 0xf26a5
movq %rax, %r12
movl 0x18(%r14), %edx
cmpq $0x10, %rdx
jne 0xc7a57
movq 0x8(%r14), %rcx
testq %rcx, %rcx
jle 0xc7aa3
movq 0x10(%r14), %rax
xorl %r13d, %r13d
testq %rax, %rax
jle 0xc79e8
xorl %ebp, %ebp
movq 0x50(%r14), %rax
imulq %r13, %rax
movq 0x468(%r14), %rsi
imulq %rbp, %rsi
addq %rax, %rsi
movq %r15, %rdi
callq 0xeebc8
movl %eax, %edi
callq 0xec844
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xf24bf
incq %rbp
movq 0x10(%r14), %rax
cmpq %rax, %rbp
jl 0xc79a3
movq 0x8(%r14), %rcx
incq %r13
cmpq %rcx, %r13
jl 0xc799c
jmp 0xc7a88
cmpq $0x10, %rdx
je 0xc7b08
cmpq $0x20, %rdx
jne 0xc7ab1
cmpb $0x0, 0x22(%r14)
jne 0xc78f8
leaq 0x73efe(%rip), %rsi     # 0x13b919
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
movb $0x18, 0x28(%r14)
movb $0x8, 0x2a(%r14)
cmpb $0x0, 0x21(%r14)
setne %al
sete %cl
shlb $0x4, %al
shlb $0x4, %cl
movb %al, 0x29(%r14)
movb %cl, 0x2b(%r14)
movb $0x2, 0x2c(%r14)
jmp 0xc78f8
xorl %r12d, %r12d
jmp 0xc7ac5
cmpb $0x0, 0x60(%r14)
jne 0xc7a69
cmpb $0x0, 0x61(%r14)
je 0xc7b1e
movq 0x50(%r14), %rcx
movq %r14, %r8
addq $0x64, %r8
movl $0x0, (%rsp)
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %r9
callq 0xf2f79
cmpl $0x20, 0x18(%r14)
jne 0xc7aa3
cmpb $0x2, 0x2c(%r14)
jne 0xc7aa3
movq %r12, %rdi
movl $0x1, %esi
callq 0xf38c4
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf22dc
jmp 0xc7ac5
leaq 0x73e46(%rip), %rsi     # 0x13b8fe
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %r12, %rdi
callq 0xf228d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq %r15, %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x73e61(%rip), %rsi     # 0x13b970
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
jmp 0xc78f8
movq 0x8(%r14), %rcx
testq %rcx, %rcx
jle 0xc7a88
movq 0x10(%r14), %rax
xorl %r13d, %r13d
testq %rax, %rax
jle 0xc7c06
xorl %ebp, %ebp
movl 0x18(%r14), %eax
cmpl $0x20, %eax
je 0xc7b86
cmpl $0x18, %eax
jne 0xc7bf2
movq 0x50(%r14), %rax
imulq %r13, %rax
movq 0x468(%r14), %rsi
imulq %rbp, %rsi
addq %rax, %rsi
movl 0x470(%r14), %edx
movq %r15, %rdi
callq 0xef42f
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xf24ba
jmp 0xc7bf2
movq 0x50(%r14), %rax
imulq %r13, %rax
movq 0x468(%r14), %rdx
imulq %rbp, %rdx
addq %rax, %rdx
movl $0x4, %ecx
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
callq 0xee8d4
movzbl 0x10(%rsp), %edx
movb 0x28(%r14), %cl
movb 0x29(%r14), %al
shll %cl, %edx
movzbl 0x11(%rsp), %esi
movl %eax, %ecx
shll %cl, %esi
movzbl 0x12(%rsp), %edi
movb 0x2a(%r14), %cl
shll %cl, %edi
movzbl 0x13(%rsp), %eax
movb 0x2b(%r14), %cl
shll %cl, %eax
orl %edx, %esi
orl %edi, %eax
orl %esi, %eax
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xf24bf
incq %rbp
movq 0x10(%r14), %rax
cmpq %rax, %rbp
jl 0xc7b3d
movq 0x8(%r14), %rcx
incq %r13
cmpq %rcx, %r13
jl 0xc7b32
jmp 0xc7a88