// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/cdiimage.c
// Function: do_cdi_imag_model3
static int do_cdi_imag_model3(deark *c, struct cdi_imag_ctx *d, struct de_iffctx *ictx,
	de_bitmap *img)
{
	int retval = 0;
	i64 i, j;
	i64 pos;
	UI prev[3];
	static const u8 dtbl[16] = { 0, 1, 4, 9, 16, 27, 44, 79,
		128, 177, 212, 229, 240, 247, 252, 255 };

	for(j=0; j<d->h; j++) {
		pos = ictx->chunkctx->dpos + j*d->rowspan;
		prev[0] = (UI)d->dyuv_start[0];
		prev[1] = (UI)d->dyuv_start[1];
		prev[2] = (UI)d->dyuv_start[2];
		for(i=0; i<d->pdwidth; i+=2) {
			u8 b[2];
			UI ysamp[2];
			UI usamp, vsamp;
			de_color clr;

			b[0] = dbuf_getbyte_p(ictx->f, &pos);
			b[1] = dbuf_getbyte_p(ictx->f, &pos);

			// Each sample is a 4-bit code, which is first translated to an
			// 8-bit value using dtbl[], then added to the previous sample
			// value to get the real sample value.
			ysamp[0] = (prev[0] + (UI)dtbl[(UI)(b[0] & 0x0f)])&0xff;
			prev[0] = ysamp[0];
			ysamp[1] = (prev[0] + (UI)dtbl[(UI)(b[1] & 0x0f)])&0xff;
			prev[0] = ysamp[1];
			usamp = (prev[1] + (UI)dtbl[((UI)b[0] & 0xf0)>>4])&0xff;
			prev[1] = usamp;
			vsamp = (prev[2] + (UI)dtbl[((UI)b[1] & 0xf0)>>4])&0xff;
			prev[2] = vsamp;

			// Each U and V sample is used for two pixels. The spec says we
			// should interpolate to improve the image quality. But we're not
			// going to bother.
			yuv_to_rgb(ysamp[0], usamp, vsamp, &clr);
			de_bitmap_setpixel_rgb(img, i+0, j, clr);
			yuv_to_rgb(ysamp[1], usamp, vsamp, &clr);
			de_bitmap_setpixel_rgb(img, i+1, j, clr);
		}
	}
	retval = 1;

	if(retval) {
		de_info(c, "Note: Converting colorspace; image quality may be affected");
	}
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x887c7
movq -0x18(%rbp), %rax
movq 0x128(%rax), %rax
movq 0x40(%rax), %rax
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rdx
imulq 0x18(%rdx), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x2a(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x2b(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x2c(%rax), %eax
movl %eax, -0x44(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x887b4
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165170
movb %al, -0x4e(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165170
movb %al, -0x4d(%rbp)
movl -0x4c(%rbp), %eax
movzbl -0x4e(%rbp), %ecx
andl $0xf, %ecx
movl %ecx, %ecx
movl %ecx, %edx
leaq 0x12660c(%rip), %rcx    # 0x1aecc0
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
andl $0xff, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movzbl -0x4d(%rbp), %ecx
andl $0xf, %ecx
movl %ecx, %ecx
movl %ecx, %edx
leaq 0x1265e3(%rip), %rcx    # 0x1aecc0
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
andl $0xff, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
movzbl -0x4e(%rbp), %ecx
andl $0xf0, %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl %ecx, %edx
leaq 0x1265b4(%rip), %rcx    # 0x1aecc0
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
andl $0xff, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
movzbl -0x4d(%rbp), %ecx
andl $0xf0, %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl %ecx, %edx
leaq 0x126585(%rip), %rcx    # 0x1aecc0
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
andl $0xff, %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x58(%rbp), %edi
movl -0x5c(%rbp), %esi
movl -0x60(%rbp), %edx
leaq -0x64(%rbp), %rcx
callq 0x888d0
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x0, %rsi
movq -0x38(%rbp), %rdx
movl -0x64(%rbp), %ecx
callq 0x16b310
movl -0x54(%rbp), %edi
movl -0x5c(%rbp), %esi
movl -0x60(%rbp), %edx
leaq -0x64(%rbp), %rcx
callq 0x888d0
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x1, %rsi
movq -0x38(%rbp), %rdx
movl -0x64(%rbp), %ecx
callq 0x16b310
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
jmp 0x88665
jmp 0x887b6
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x88607
movl $0x1, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x887e6
movq -0x8(%rbp), %rdi
leaq 0x1263e3(%rip), %rsi    # 0x1aebc2
movb $0x0, %al
callq 0x15c0c0
movl -0x24(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop