// File: /workspace/github_c_makefile_star2_O2/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 0xdebae
movl $0x478, %esi            # imm = 0x478
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r14
leaq 0x6f1a6(%rip), %rsi     # 0x12e5af
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
je 0xbf454
movq %rax, %r15
pushq $-0x10
popq %rcx
leaq 0xcad4d(%rip), %r12     # 0x18a170
leaq 0x10(%rcx), %r13
cmpq $0x80, %r13
je 0xbf454
movq 0x18(%rcx,%r12), %rsi
movq %r15, %rdi
callq 0x181a0
movq %r13, %rcx
testl %eax, %eax
jne 0xbf423
movups (%r13,%r12), %xmm0
movups %xmm0, 0x28(%r14)
movb $0x1, 0x22(%r14)
leaq 0x56d64(%rip), %rsi     # 0x1161bf
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rdi
pushq $0x4
popq %rsi
callq 0xe404f
movq %rax, (%r14)
movq 0x18(%rbx), %rdi
pushq $0x8
popq %rsi
callq 0xe404f
movq %rax, 0x8(%r14)
movq (%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xdf038
movq 0x18(%rbx), %rdi
pushq $0xc
popq %rsi
callq 0xe404f
movl %eax, 0x18(%r14)
leaq 0x57ae4(%rip), %rsi     # 0x116f9a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x10
popq %rsi
callq 0xe404f
movq %rax, 0x38(%r14)
movq 0x18(%rbx), %rdi
pushq $0x14
popq %rsi
callq 0xe404f
movl %eax, 0x1c(%r14)
cmpl $0x5, %eax
ja 0xbf502
movl %eax, %ecx
leaq 0x6efcc(%rip), %rdx     # 0x12e4bc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq 0x6e05e(%rip), %rcx     # 0x12d55e
jmp 0xbf546
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0xbf524
leaq 0x6f0e2(%rip), %rcx     # 0x12e5f2
jmp 0xbf546
leaq 0x7dd55(%rip), %rcx     # 0x13d26e
jmp 0xbf546
leaq 0x58b80(%rip), %rcx     # 0x1180a2
jmp 0xbf546
leaq 0x5f9b6(%rip), %rcx     # 0x11eee1
jmp 0xbf546
leaq 0x7313c(%rip), %rcx     # 0x132670
jmp 0xbf546
leaq 0x687c4(%rip), %rcx     # 0x127d01
jmp 0xbf546
leaq 0x5c17a(%rip), %rcx     # 0x11b6c0
movq 0x38(%r14), %r8
leaq 0x6f06b(%rip), %rsi     # 0x12e5bc
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movl 0x1c(%r14), %eax
cmpl $0x3, %eax
je 0xbf572
cmpl $0x2, %eax
jne 0xbf577
movb $0x1, 0x20(%r14)
jmp 0xbf577
movb $0x1, 0x21(%r14)
movq 0x18(%rbx), %rdi
pushq $0x18
popq %rsi
callq 0xe404f
movl %eax, 0x40(%r14)
movq 0x18(%rbx), %rdi
pushq $0x1c
popq %rsi
callq 0xe404f
movq %rax, 0x48(%r14)
movl 0x40(%r14), %edx
cmpq $0x2, %rdx
ja 0xbf5b1
leaq 0x6ef2c(%rip), %rsi     # 0x12e4d4
movslq (%rsi,%rdx,4), %rcx
addq %rsi, %rcx
jmp 0xbf5b8
leaq 0x5f929(%rip), %rcx     # 0x11eee1
leaq 0x6f019(%rip), %rsi     # 0x12e5d8
xorl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %r8
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rax
cmpq $0x21, 0x18(%rax)
jl 0xbfa7d
cmpq $0x0, 0x48(%r14)
jle 0xbf604
leaq 0x6eefb(%rip), %rsi     # 0x12e4f2
pushq $0x20
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movl 0x40(%r14), %edx
testl %edx, %edx
je 0xbf6dc
cmpl $0x1, %edx
jne 0xbf79c
cmpl $0x8, 0x18(%r14)
ja 0xbf7bd
movb $0x1, 0x60(%r14)
movq 0x48(%r14), %rax
pushq $0x3
popq %rcx
cqto
idivq %rcx
movl $0x100, %r15d           # imm = 0x100
cmpq %r15, %rax
cmovlq %rax, %r15
leaq 0x20(,%rax,2), %rcx
movq %rcx, 0x18(%rsp)
addq $0x20, %rax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
testq %r15, %r15
cmovleq %r13, %r15
cmpq %r13, %r15
je 0xbf703
movq 0x18(%rbx), %rdi
leaq 0x20(%r13), %rsi
callq 0xe3eb4
movl %eax, %ebp
movq 0x18(%rbx), %rdi
movq 0x20(%rsp), %rax
leaq (%rax,%r13), %rsi
callq 0xe3eb4
movl %eax, %r12d
movq 0x18(%rbx), %rdi
movq 0x18(%rsp), %rax
leaq (%rax,%r13), %rsi
callq 0xe3eb4
movzbl %bpl, %ecx
shll $0x10, %ecx
movzbl %r12b, %esi
shll $0x8, %esi
orl %ecx, %esi
movzbl %al, %edx
orl %esi, %edx
orl $0xff000000, %edx       # imm = 0xFF000000
movl %edx, 0x64(%r14,%r13,4)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xdf23b
incq %r13
jmp 0xbf66d
movl 0x18(%r14), %ecx
cmpq $0x8, %rcx
ja 0xbf703
movb $0x1, 0x61(%r14)
pushq $0x1
popq %rsi
shlq %cl, %rsi
leaq 0x64(%r14), %rdi
xorl %edx, %edx
cmpq $0x1, %rcx
sete %dl
callq 0xe87a8
movq 0x48(%r14), %r13
addq $0x20, %r13
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r13
jge 0xbf7b5
leaq 0x6e69c(%rip), %rsi     # 0x12ddc7
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movl 0x18(%r14), %edi
imulq (%r14), %rdi
pushq $0x10
popq %rsi
callq 0xdfbb6
movq %rax, %rsi
cqto
pushq $0x8
popq %rcx
idivq %rcx
movq %rax, %rcx
movq %rax, 0x50(%r14)
movl 0x18(%r14), %edi
movl 0x1c(%r14), %r8d
movq %rsi, %rax
cqto
idivq %rdi
movq %rax, 0x10(%r14)
imulq 0x8(%r14), %rcx
movq %rcx, 0x58(%r14)
cmpl $0x6, %r8d
jb 0xbf7d6
leaq 0x6ed95(%rip), %rsi     # 0x12e526
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r8d, %edx
jmp 0xbf7a9
leaq 0x6ed5f(%rip), %rsi     # 0x12e502
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0xbfa7d
xorl %r15d, %r15d
jmp 0xbfa7d
leaq 0x6876b(%rip), %rsi     # 0x127f2f
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0xbfa7d
orl $0x2, %r8d
cmpl $0x3, %r8d
jne 0xbf7fa
movq 0x38(%r14), %rdx
cmpq %rcx, %rdx
je 0xbf7fa
leaq 0x6ed5f(%rip), %rsi     # 0x12e54f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
cmpb $0x0, 0x20(%r14)
je 0xbf8a3
movq 0x58(%r14), %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0xe59cd
movq %rax, %r15
movq %rax, %rdi
callq 0xe589c
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r13
jge 0xbf896
leaq 0x1(%r13), %r12
movq %r13, %rsi
callq 0xe3eb4
cmpb $-0x80, %al
jne 0xbf874
movq 0x18(%rbx), %rdi
leaq 0x2(%r13), %rbp
movq %r12, %rsi
callq 0xe3eb4
testb %al, %al
je 0xbf884
movl %eax, %r12d
movq 0x18(%rbx), %rdi
addq $0x3, %r13
movq %rbp, %rsi
callq 0xe3eb4
movzbl %r12b, %edx
incq %rdx
movzbl %al, %esi
movq %r15, %rdi
callq 0xe5e40
jmp 0xbf81f
movzbl %al, %esi
movq %r15, %rdi
callq 0xe5bc5
movq %r12, %r13
jmp 0xbf81f
movq %r15, %rdi
movl $0x80, %esi
callq 0xe5bc5
movq %rbp, %r13
jmp 0xbf81f
movq %r15, %rdi
callq 0xe58e8
pushq $0x1
popq %rbp
jmp 0xbf8b9
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
subq %r13, %rdx
movq %r13, %rsi
callq 0xe6248
movq %rax, %r15
movl 0x18(%r14), %edx
cmpq $0x20, %rdx
ja 0xbfa56
movl $0x1000112, %eax        # imm = 0x1000112
btq %rdx, %rax
jae 0xbf903
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xe6be1
testl %eax, %eax
je 0xbf95c
movl 0x18(%r14), %eax
movl %eax, %ecx
shrl $0x3, %ecx
movq %rcx, 0x468(%r14)
pushq $0x3
popq %rcx
cmpb $0x0, 0x60(%r14)
je 0xbf964
movl %ecx, %ebp
jmp 0xbf97d
cmpq $0x10, %rdx
je 0xbfaab
cmpq $0x20, %rdx
jne 0xbfa56
cmpb $0x0, 0x22(%r14)
jne 0xbf8d2
leaq 0x6ed04(%rip), %rsi     # 0x12e629
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
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 0xbf8d2
xorl %r12d, %r12d
jmp 0xbfa6a
cmpb $0x0, 0x61(%r14)
jne 0xbf97d
movl %ecx, %ebp
cmpl $0x20, %eax
jne 0xbf97d
cmpb $0x1, 0x2c(%r14)
pushq $0x4
popq %rbp
sbbl $0x0, %ebp
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
movl %ebp, %r8d
callq 0xe746f
movq %rax, %r12
movl 0x18(%r14), %edx
cmpq $0x10, %rdx
jne 0xbfa01
xorl %r13d, %r13d
cmpq 0x8(%r14), %r13
jge 0xbfa2f
xorl %ebp, %ebp
cmpq 0x10(%r14), %rbp
jge 0xbf9fc
movq 0x50(%r14), %rax
imulq %r13, %rax
movq 0x468(%r14), %rsi
imulq %rbp, %rsi
addq %rax, %rsi
movq %r15, %rdi
callq 0xe3fa3
movl %eax, %edi
callq 0xe1da6
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xe728c
incq %rbp
jmp 0xbf9bc
incq %r13
jmp 0xbf9b4
cmpb $0x0, 0x60(%r14)
jne 0xbfa13
cmpb $0x0, 0x61(%r14)
je 0xbfac1
movq 0x50(%r14), %rcx
movq %r14, %r8
addq $0x64, %r8
andl $0x0, (%rsp)
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %r9
callq 0xe7cbc
cmpl $0x20, 0x18(%r14)
jne 0xbfa48
cmpb $0x2, 0x2c(%r14)
jne 0xbfa48
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0xe84da
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe70b7
jmp 0xbfa6a
leaq 0x6ebb1(%rip), %rsi     # 0x12e60e
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %r12, %rdi
callq 0xe7084
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %r15, %rdi
callq 0xe5591
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6ebce(%rip), %rsi     # 0x12e680
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
jmp 0xbf8d2
xorl %r13d, %r13d
cmpq 0x8(%r14), %r13
jge 0xbfa2f
xorl %ebp, %ebp
cmpq 0x10(%r14), %rbp
jge 0xbfb95
movl 0x18(%r14), %eax
cmpl $0x20, %eax
je 0xbfb23
cmpl $0x18, %eax
jne 0xbfb8d
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 0xe45a4
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xe7287
jmp 0xbfb8d
movq 0x50(%r14), %rax
imulq %r13, %rax
movq 0x468(%r14), %rdx
imulq %rbp, %rdx
addq %rax, %rdx
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
pushq $0x4
popq %rcx
callq 0xe3cb7
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 0xe728c
incq %rbp
jmp 0xbfad0
incq %r13
jmp 0xbfac4