// File: /workspace/github_c_makefile_star2_O3/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, 0x28(%rsp)
movq %rcx, %rbx
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r12
movq %rcx, 0x30(%rsp)
movb $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
callq 0xea504
movq 0x30(%r15), %rdx
testq %rdx, %rdx
je 0x7d927
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0x7d927
movl $0x1, 0x78(%rax)
cvtsi2sd %rdx, %xmm0
movsd %xmm0, 0x88(%rax)
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x80(%rax)
movq %rax, 0x20(%rsp)
cmpb $0x1, 0x50(%r15)
movl $0x4, %ecx
sbbl $0x0, %ecx
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
movq %r12, %rdi
callq 0xf266a
movq %rax, %r14
movq 0x28(%r15), %rax
testq %rax, %rax
jle 0x7da6e
addq %rbx, 0x28(%rsp)
movq 0x20(%r15), %rcx
movq $0x0, 0x10(%rsp)
leaq 0x30(%rsp), %rbx
movq %r12, 0x18(%rsp)
testq %rcx, %rcx
jle 0x7da40
xorl %r12d, %r12d
movq 0x28(%rsp), %rax
cmpq %rax, 0x30(%rsp)
jg 0x7da58
cmpl $0x0, 0x48(%r15)
je 0x7d9bd
xorl %ebp, %ebp
movq %r13, %rdi
movq %rbx, %rsi
callq 0xeeb4b
movl 0x94(%r15,%rbp,4), %ecx
movb %al, 0x8(%rsp,%rcx)
incq %rbp
movl 0x48(%r15), %eax
cmpq %rax, %rbp
jb 0x7d99a
cmpb $0x0, 0x50(%r15)
je 0x7d9f9
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 0x7da17
movl %ecx, %edi
callq 0xf3d94
movl %eax, %ecx
jmp 0x7da17
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 %r14, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rdx
callq 0xf24bf
incq %r12
movq 0x20(%r15), %rcx
cmpq %rcx, %r12
jl 0x7d981
movq 0x28(%r15), %rax
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rsi
incq %rsi
movq %rsi, 0x10(%rsp)
cmpq %rax, %rsi
jl 0x7d975
jmp 0x7da6e
leaq 0xabdce(%rip), %rsi     # 0x12982d
movq 0x18(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0xe8faa
movzbl 0x8(%r15), %eax
testl %eax, %eax
je 0x7da90
cmpl $0x2, %eax
movq 0x20(%rsp), %rbx
jne 0x7da9d
movq %r14, %rdi
movl $0x6, %esi
callq 0xf38c4
jmp 0x7da9d
movq %r14, %rdi
callq 0xf383e
movq 0x20(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf22d0
movq %r14, %rdi
callq 0xf228d
movq %r12, %rdi
movq %rbx, %rsi
callq 0xea50e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop