// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/cdiimage.c
// Function: do_cdi_imag_IHDR
static void do_cdi_imag_IHDR(deark *c, struct cdi_imag_ctx *d, struct de_iffctx *ictx)
{
	i64 pos = ictx->chunkctx->dpos;
	if(ictx->chunkctx->dlen<10) return;
	d->found_IHDR = 1;
	d->npwidth = dbuf_getu16be_p(ictx->f, &pos);
	d->rowspan = dbuf_getu16be_p(ictx->f, &pos);
	d->h = dbuf_getu16be_p(ictx->f, &pos);
	de_dbg_dimensions(c, d->npwidth, d->h);
	de_dbg(c, "bytes/row: %u", (UI)d->rowspan);
	d->model = (UI)dbuf_getu16be_p(ictx->f, &pos);
	de_dbg(c, "model: %u (%s)", d->model, get_cdi_imag_model_name(d->model));
	d->depth = (UI)dbuf_getu16be_p(ictx->f, &pos);
	de_dbg(c, "bits/pixel: %u", d->depth);

	if(d->model==3 && ictx->chunkctx->dlen>=14) {
		UI k;

		d->dyuv_kind = dbuf_getbyte_p(ictx->f, &pos);
		// 0 = IFF_DYUV_ONE, 1 = IFF_DYUV_EACH
		de_dbg(c, "dyuv kind: %u", (UI)d->dyuv_kind);
		for(k=0; k<3; k++) {
			d->dyuv_start[k] = dbuf_getbyte_p(ictx->f, &pos);
		}
		de_dbg(c, "dyuv start: %u,%u,%u", (UI)d->dyuv_start[0],
			(UI)d->dyuv_start[1], (UI)d->dyuv_start[2]);
	}

	if(d->depth==4 || d->depth==8) {
		d->pdwidth = (d->rowspan*8)/d->depth;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x128(%rax), %rax
movq 0x40(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x128(%rax), %rax
cmpq $0xa, 0x48(%rax)
jge 0x882ee
jmp 0x884f0
movq -0x10(%rbp), %rax
movb $0x1, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x1268c2(%rip), %rsi    # 0x1aec38
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %edi
callq 0x88bf0
movq -0x30(%rbp), %rdi
movl -0x28(%rbp), %edx
movq %rax, %rcx
leaq 0x126880(%rip), %rsi    # 0x1aec46
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x24(%rax), %edx
leaq 0x11c9de(%rip), %rsi    # 0x1a4dd7
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x3, 0x20(%rax)
jne 0x884b9
movq -0x18(%rbp), %rax
movq 0x128(%rax), %rax
cmpq $0xe, 0x48(%rax)
jl 0x884b9
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x29(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x29(%rax), %edx
leaq 0x126804(%rip), %rsi    # 0x1aec55
movb $0x0, %al
callq 0x15b0d0
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jae 0x8848e
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movb %dl, 0x2a(%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x8845f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2a(%rax), %edx
movq -0x10(%rbp), %rax
movzbl 0x2b(%rax), %ecx
movq -0x10(%rbp), %rax
movzbl 0x2c(%rax), %r8d
leaq 0x1267b1(%rip), %rsi    # 0x1aec63
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x4, 0x24(%rax)
je 0x884cd
movq -0x10(%rbp), %rax
cmpl $0x8, 0x24(%rax)
jne 0x884f0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shlq $0x3, %rax
movq -0x10(%rbp), %rcx
movl 0x24(%rcx), %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)