// File: /workspace/github_c_makefile_star2_O1/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 0x24(%rsp), %rsi
callq 0xe958c
movl $0x478, %esi            # imm = 0x478
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
leaq 0x735ba(%rip), %rsi     # 0x13b4e7
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0xc7f76
movq %rax, %r15
xorl %r12d, %r12d
leaq 0xbf269(%rip), %r13     # 0x1871b0
movq 0x8(%r12,%r13), %rsi
movq %r15, %rdi
callq 0x181a0
testl %eax, %eax
je 0xc7f67
addq $0x10, %r12
cmpq $0x80, %r12
jne 0xc7f47
jmp 0xc7f76
movups (%r12,%r13), %xmm0
movups %xmm0, 0x28(%r14)
movb $0x1, 0x22(%r14)
leaq 0x5b222(%rip), %rsi     # 0x12319f
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef32a
movq %rax, (%r14)
movq 0x18(%rbx), %rdi
movl $0x8, %esi
callq 0xef32a
movq %rax, 0x8(%r14)
movq (%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xe9b05
movq 0x18(%rbx), %rdi
movl $0xc, %esi
callq 0xef32a
movl %eax, 0x18(%r14)
leaq 0x5bf9a(%rip), %rsi     # 0x123f7a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x10, %esi
callq 0xef32a
movq %rax, 0x38(%r14)
movq 0x18(%rbx), %rdi
movl $0x14, %esi
callq 0xef32a
movl %eax, 0x1c(%r14)
cmpl $0x5, %eax
ja 0xc8030
movl %eax, %ecx
leaq 0x733d6(%rip), %rdx     # 0x13b3f4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq 0x724a0(%rip), %rcx     # 0x13a4ce
jmp 0xc8074
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0xc8052
leaq 0x734ec(%rip), %rcx     # 0x13b52a
jmp 0xc8074
leaq 0x82147(%rip), %rcx     # 0x14a18e
jmp 0xc8074
leaq 0x5d022(%rip), %rcx     # 0x125072
jmp 0xc8074
leaq 0x63e10(%rip), %rcx     # 0x12be69
jmp 0xc8074
leaq 0x7753e(%rip), %rcx     # 0x13f5a0
jmp 0xc8074
leaq 0x6cbea(%rip), %rcx     # 0x134c55
jmp 0xc8074
leaq 0x6065c(%rip), %rcx     # 0x1286d0
movq 0x38(%r14), %r8
leaq 0x73475(%rip), %rsi     # 0x13b4f4
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movl 0x1c(%r14), %eax
cmpl $0x3, %eax
je 0xc80a0
cmpl $0x2, %eax
jne 0xc80a5
movb $0x1, 0x20(%r14)
jmp 0xc80a5
movb $0x1, 0x21(%r14)
movq 0x18(%rbx), %rdi
movl $0x18, %esi
callq 0xef32a
movl %eax, 0x40(%r14)
movq 0x18(%rbx), %rdi
movl $0x1c, %esi
callq 0xef32a
movq %rax, 0x48(%r14)
movl 0x40(%r14), %edx
cmpq $0x2, %rdx
ja 0xc80e3
leaq 0x73332(%rip), %rsi     # 0x13b40c
movslq (%rsi,%rdx,4), %rcx
addq %rsi, %rcx
jmp 0xc80ea
leaq 0x63d7f(%rip), %rcx     # 0x12be69
leaq 0x7341f(%rip), %rsi     # 0x13b510
xorl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %r8
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%rbx), %rax
cmpq $0x21, 0x18(%rax)
jl 0xc862e
cmpq $0x0, 0x48(%r14)
jle 0xc813a
leaq 0x732ff(%rip), %rsi     # 0x13b42a
movl $0x20, %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movl 0x40(%r14), %edx
testl %edx, %edx
je 0xc822c
cmpl $0x1, %edx
jne 0xc82f0
cmpl $0x8, 0x18(%r14)
ja 0xc8311
movb $0x1, 0x60(%r14)
movq 0x48(%r14), %rax
cmpq $0x3, %rax
jl 0xc8255
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
movq %rdx, %rcx
shrq %rcx
movl $0x100, %eax            # imm = 0x100
cmpq %rax, %rcx
cmovlq %rcx, %rax
addq $0x20, %rcx
movq %rcx, 0x18(%rsp)
andq $-0x2, %rdx
addq $0x20, %rdx
movq %rdx, 0x10(%rsp)
cmpq $0x2, %rax
movl $0x1, %r15d
cmovgeq %rax, %r15
xorl %r12d, %r12d
movq 0x18(%rbx), %rdi
leaq 0x20(%r12), %rsi
callq 0xef0d5
movl %eax, %ebp
movq 0x18(%rbx), %rdi
movq 0x18(%rsp), %rax
leaq (%rax,%r12), %rsi
callq 0xef0d5
movl %eax, %r13d
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rax
leaq (%rax,%r12), %rsi
callq 0xef0d5
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 0xe9d68
incq %r12
cmpq %r12, %r15
jne 0xc81c0
jmp 0xc8255
movl 0x18(%r14), %ecx
cmpq $0x8, %rcx
ja 0xc8255
movb $0x1, 0x61(%r14)
movl $0x1, %esi
shlq %cl, %rsi
leaq 0x64(%r14), %rdi
xorl %edx, %edx
cmpq $0x1, %rcx
sete %dl
callq 0xf41f4
movq 0x48(%r14), %r12
addq $0x20, %r12
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jge 0xc8309
leaq 0x72aa0(%rip), %rsi     # 0x13ad1f
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movl 0x18(%r14), %edi
imulq (%r14), %rdi
movl $0x10, %esi
callq 0xea80b
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 0xc832a
leaq 0x73179(%rip), %rsi     # 0x13b45e
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r8d, %edx
jmp 0xc82fd
leaq 0x73143(%rip), %rsi     # 0x13b43a
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xc862e
xorl %r15d, %r15d
jmp 0xc862e
leaq 0x6cb6b(%rip), %rsi     # 0x134e83
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xc862e
orl $0x2, %r8d
cmpl $0x3, %r8d
jne 0xc834e
movq 0x38(%r14), %rdx
cmpq %rcx, %rdx
je 0xc834e
leaq 0x73143(%rip), %rsi     # 0x13b487
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
cmpb $0x0, 0x20(%r14)
je 0xc841c
movq 0x58(%r14), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf0faf
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0xf0e3f
movq %r12, %r13
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r15
cmpq %r15, %r12
jge 0xc8401
leaq 0x1(%r12), %rbp
movq %r12, %rsi
callq 0xef0d5
cmpb $-0x80, %al
jne 0xc83e0
movq 0x18(%rbx), %rdi
leaq 0x2(%r12), %r13
movq %rbp, %rsi
callq 0xef0d5
testb %al, %al
je 0xc83f2
movl %eax, %ebp
movq 0x18(%rbx), %rdi
leaq 0x3(%r12), %rax
movq %rax, 0x18(%rsp)
movq %r13, %rsi
callq 0xef0d5
movzbl %bpl, %edx
incq %rdx
movzbl %al, %esi
movq 0x10(%rsp), %rdi
callq 0xf14bd
movq 0x18(%rsp), %r13
jmp 0xc8401
movzbl %al, %esi
movq 0x10(%rsp), %rdi
callq 0xf11be
movq %rbp, %r13
jmp 0xc8401
movq 0x10(%rsp), %rdi
movl $0x80, %esi
callq 0xf11be
cmpq %r15, %r12
movq %r13, %r12
jl 0xc837a
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0xf0ea4
jmp 0xc8432
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
subq %r12, %rdx
movq %r12, %rsi
callq 0xf1988
movq %rax, %r15
movl 0x18(%r14), %r13d
cmpq $0x20, %r13
ja 0xc8602
movabsq $0x101010112, %rax      # imm = 0x101010112
btq %r13, %rax
jae 0xc8602
cmpl $0x10, %r13d
je 0xc84a6
cmpl $0x20, %r13d
jne 0xc84b7
cmpb $0x0, 0x22(%r14)
jne 0xc84a0
leaq 0x730f3(%rip), %rsi     # 0x13b561
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
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)
cmpl $0x10, %r13d
jne 0xc84b7
leaq 0x7310b(%rip), %rsi     # 0x13b5b8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xf241d
testl %eax, %eax
je 0xc85a3
movl 0x18(%r14), %eax
movl %eax, %ecx
shrl $0x3, %ecx
movq %rcx, 0x468(%r14)
movl $0x3, %r8d
cmpb $0x0, 0x60(%r14)
jne 0xc8512
movl $0x1, %r8d
cmpb $0x0, 0x61(%r14)
jne 0xc8512
movl $0x3, %r8d
cmpl $0x20, %eax
jne 0xc8512
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 0xf2ce6
movq %rax, %r12
movl 0x18(%r14), %edx
cmpq $0x10, %rdx
jne 0xc85a8
cmpq $0x0, 0x8(%r14)
jle 0xc85d9
xorl %r13d, %r13d
cmpq $0x0, 0x10(%r14)
jle 0xc8598
xorl %ebp, %ebp
movq 0x50(%r14), %rax
imulq %r13, %rax
movq 0x468(%r14), %rsi
imulq %rbp, %rsi
addq %rax, %rsi
movq %r15, %rdi
callq 0xef1ca
movl %eax, %edi
callq 0xece9d
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xf2b02
incq %rbp
cmpq 0x10(%r14), %rbp
jl 0xc855a
incq %r13
cmpq 0x8(%r14), %r13
jl 0xc8551
jmp 0xc85d9
xorl %r12d, %r12d
jmp 0xc8619
cmpb $0x0, 0x60(%r14)
jne 0xc85ba
cmpb $0x0, 0x61(%r14)
je 0xc865c
movq 0x50(%r14), %rcx
movq %r14, %r8
addq $0x64, %r8
movl $0x0, (%rsp)
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %r9
callq 0xf35b8
cmpl $0x20, 0x18(%r14)
jne 0xc85f4
cmpb $0x2, 0x2c(%r14)
jne 0xc85f4
movq %r12, %rdi
movl $0x1, %esi
callq 0xf3f11
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf2923
jmp 0xc8619
leaq 0x72f3d(%rip), %rsi     # 0x13b546
xorl %r12d, %r12d
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9df7
movq %r12, %rdi
callq 0xf28d4
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %r15, %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movl 0x24(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x8(%r14)
jle 0xc85d9
xorl %r13d, %r13d
cmpq $0x0, 0x10(%r14)
jle 0xc8739
xorl %ebp, %ebp
movl 0x18(%r14), %eax
cmpl $0x20, %eax
je 0xc86c0
cmpl $0x18, %eax
jne 0xc872c
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 0xefa60
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xf2afd
jmp 0xc872c
movq 0x50(%r14), %rax
imulq %r13, %rax
movq 0x468(%r14), %rdx
imulq %rbp, %rdx
addq %rax, %rdx
movl $0x4, %ecx
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0xeeee8
movzbl 0xc(%rsp), %edx
movb 0x28(%r14), %cl
movb 0x29(%r14), %al
shll %cl, %edx
movzbl 0xd(%rsp), %esi
movl %eax, %ecx
shll %cl, %esi
movzbl 0xe(%rsp), %edi
movb 0x2a(%r14), %cl
shll %cl, %edi
movzbl 0xf(%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 0xf2b02
incq %rbp
cmpq 0x10(%r14), %rbp
jl 0xc8677
incq %r13
cmpq 0x8(%r14), %r13
jl 0xc866a
jmp 0xc85d9