// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rcx, %rbx
movq %rdx, %r13
movq %rsi, %r12
movq %rcx, 0x30(%rsp)
movb $0x0, 0x4(%rsp)
movl $0x0, (%rsp)
movq %rdi, 0x18(%rsp)
callq 0xea9a9
movq 0x30(%r12), %rdx
testq %rdx, %rdx
je 0x7df3a
movq 0x38(%r12), %rcx
testq %rcx, %rcx
je 0x7df3a
movl $0x1, 0x78(%rax)
cvtsi2sd %rdx, %xmm0
movsd %xmm0, 0x88(%rax)
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x80(%rax)
movq %rax, 0x28(%rsp)
cmpb $0x1, 0x50(%r12)
movl $0x4, %ecx
sbbl $0x0, %ecx
movq 0x20(%r12), %rsi
movq 0x28(%r12), %rdx
movq 0x18(%rsp), %rdi
callq 0xf2cab
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x28(%r12)
jle 0x7e082
addq %rbx, %r15
leaq 0x30(%rsp), %r14
movq $0x0, 0x20(%rsp)
movq %r15, 0x8(%rsp)
cmpq $0x0, 0x20(%r12)
jle 0x7e06a
xorl %ebp, %ebp
movq 0x30(%rsp), %rbx
cmpq %r15, %rbx
jle 0x7dfb8
movq 0x18(%rsp), %rdi
leaq 0xab651(%rip), %rsi     # 0x1295fd
xorl %eax, %eax
callq 0xe9b27
jmp 0x7e057
cmpl $0x0, 0x48(%r12)
je 0x7dfe6
xorl %r15d, %r15d
movq %r13, %rdi
movq %r14, %rsi
callq 0xef14d
movl 0x94(%r12,%r15,4), %ecx
movb %al, (%rsp,%rcx)
incq %r15
movl 0x48(%r12), %eax
cmpq %rax, %r15
jb 0x7dfc3
cmpb $0x0, 0x50(%r12)
je 0x7e023
movzbl 0x3(%rsp), %eax
shll $0x18, %eax
movzbl (%rsp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl 0x1(%rsp), %eax
shll $0x8, %eax
orl %ecx, %eax
movzbl 0x2(%rsp), %ecx
orl %eax, %ecx
cmpb $0x0, 0x52(%r12)
je 0x7e040
movl %ecx, %edi
callq 0xf429c
movl %eax, %ecx
jmp 0x7e040
movl (%rsp), %eax
shll $0x10, %eax
movzbl 0x1(%rsp), %edx
shll $0x8, %edx
orl %eax, %edx
movzbl 0x2(%rsp), %ecx
orl %edx, %ecx
orl $0xff000000, %ecx       # imm = 0xFF000000
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq 0x20(%rsp), %rdx
callq 0xf2b02
cmpq %r15, %rbx
jg 0x7e082
incq %rbp
cmpq 0x20(%r12), %rbp
jl 0x7df96
movq 0x20(%rsp), %rcx
incq %rcx
movq %rcx, 0x20(%rsp)
cmpq 0x28(%r12), %rcx
jl 0x7df88
movzbl 0x8(%r12), %eax
testl %eax, %eax
je 0x7e0aa
cmpl $0x2, %eax
movq 0x28(%rsp), %rbx
movq 0x10(%rsp), %r14
jne 0x7e0bc
movq %r14, %rdi
movl $0x6, %esi
callq 0xf3f11
jmp 0x7e0bc
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0xf3e98
movq 0x28(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf2917
movq %r14, %rdi
callq 0xf28d4
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0xea9b3
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq