// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/ilbm.c
// Function: deep_decode_image_unc
static void deep_decode_image_unc(deark *c, struct deep_ctx *d,
	dbuf *f, i64 pos1, i64 len)
{
	i64 i, j;
	i64 pos = pos1;
	UI k;
	UI dst_samples_per_pixel;
	de_bitmap *img = NULL;
	de_finfo *fi = NULL;
	u8 s[5] = {0,0,0,0,0};

	fi = de_finfo_create(c);
	if(d->x_aspect && d->y_aspect) {
		fi->density.code = DE_DENSITY_UNK_UNITS;
		fi->density.ydens = (double)d->x_aspect;
		fi->density.xdens = (double)d->y_aspect;
	}

	dst_samples_per_pixel = d->have_alpha ? 4 : 3;
	img = de_bitmap_create(c, d->width, d->height, dst_samples_per_pixel);

	for(j=0; j<d->height; j++) {
		for(i=0; i<d->width; i++) {
			de_color clr;

			if(pos > pos1+len) {
				de_warn(c, "Premature end of image");
				goto after_image;
			}

			for(k=0; k<(UI)d->num_components; k++) {
				s[d->sample_map[k]] =  dbuf_getbyte_p(f, &pos);
			}
			if(d->have_alpha) {
				clr = DE_MAKE_RGBA(s[0], s[1], s[2], s[3]);
				if(d->is_assoc_alpha) {
					clr = de_unpremultiply_alpha_clr(clr);
				}
			}
			else {
				clr = DE_MAKE_RGB(s[0], s[1], s[2]);
			}
			de_bitmap_setpixel_rgba(img, i, j, clr);
		}
	}

after_image:
	if(d->trans_setting==TRANS_AUTO) {
		de_bitmap_optimize_alpha(img, (0x4|0x02));
	}
	else if(d->trans_setting==TRANS_REMOVE) {
		de_bitmap_remove_alpha(img);
	}
	de_bitmap_write_to_file_finfo(img, fi, DE_CREATEFLAG_OPT_IMAGE);

	de_bitmap_destroy(img);
	de_finfo_destroy(c, fi);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, 0x20(%rsp)
movq %rcx, %rbx
movq %rdx, %rbp
movq %rsi, %r15
movq %rdi, %r12
movq %rcx, 0x28(%rsp)
movb $0x0, 0xc(%rsp)
andl $0x0, 0x8(%rsp)
callq 0xdfd1a
movq 0x30(%r15), %rdx
testq %rdx, %rdx
je 0x78fb6
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0x78fb6
movl $0x1, 0x78(%rax)
cvtsi2sd %rdx, %xmm0
movsd %xmm0, 0x88(%rax)
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x80(%rax)
movq %rax, 0x30(%rsp)
cmpb $0x1, 0x50(%r15)
pushq $0x4
popq %rcx
sbbl $0x0, %ecx
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
movq %r12, %rdi
callq 0xe7437
movq %rax, 0x10(%rsp)
addq %rbx, 0x20(%rsp)
xorl %r14d, %r14d
leaq 0x28(%rsp), %rbx
movq %r12, 0x18(%rsp)
cmpq 0x28(%r15), %r14
jge 0x790d1
xorl %r13d, %r13d
cmpq 0x20(%r15), %r13
jge 0x790ae
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
jg 0x790bb
xorl %r12d, %r12d
movl 0x48(%r15), %eax
cmpq %rax, %r12
jae 0x7903c
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xe3f2a
movl 0x94(%r15,%r12,4), %ecx
movb %al, 0x8(%rsp,%rcx)
incq %r12
jmp 0x79017
cmpb $0x0, 0x50(%r15)
je 0x79078
movzbl 0xb(%rsp), %eax
shll $0x18, %eax
movzbl 0x8(%rsp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl 0x9(%rsp), %eax
shll $0x8, %eax
orl %ecx, %eax
movzbl 0xa(%rsp), %ecx
orl %eax, %ecx
cmpb $0x0, 0x52(%r15)
je 0x79096
movl %ecx, %edi
callq 0xe8851
movl %eax, %ecx
jmp 0x79096
movl 0x8(%rsp), %eax
shll $0x10, %eax
movzbl 0x9(%rsp), %edx
shll $0x8, %edx
orl %eax, %edx
movzbl 0xa(%rsp), %ecx
orl %edx, %ecx
orl $0xff000000, %ecx       # imm = 0xFF000000
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0xe728c
incq %r13
jmp 0x78ffa
incq %r14
movq 0x18(%rsp), %r12
jmp 0x78fed
leaq 0xa352b(%rip), %rsi     # 0x11c5ed
movq 0x18(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0xdf05a
movzbl 0x8(%r15), %eax
testl %eax, %eax
je 0x790f1
cmpl $0x2, %eax
movq 0x10(%rsp), %r14
jne 0x790fe
pushq $0x6
popq %rsi
movq %r14, %rdi
callq 0xe84da
jmp 0x790fe
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0xe8472
pushq $0x2
popq %rdx
movq %r14, %rdi
movq 0x30(%rsp), %rbx
movq %rbx, %rsi
callq 0xe70ab
movq %r14, %rdi
callq 0xe7084
movq %r12, %rdi
movq %rbx, %rsi
callq 0xdfd24
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop