// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/png.c
// Function: handler_fdAT
static void handler_fdAT(deark *c, lctx *d, struct handler_params *hp)
{
	i64 IDAT_dlen;

	if(hp->dlen<4) return;
	do_APNG_seqno(c, d, hp->dpos);

	if(!d->found_fcTL) return;
	if(d->curr_fcTL_width==0 || d->curr_fcTL_height==0) return;
	if(!d->extract_from_APNG_enabled) return;
	if(!d->APNG_prefix || d->APNG_prefix_IHDR_pos==0) {
		d->extract_from_APNG_enabled = 0;
		return;
	}

	// Convert the fdAT chunk to an IDAT chunk, and write it to d->curr_APNG_frame.

	if(!d->crco_for_write) {
		d->crco_for_write = de_crcobj_create(c, DE_CRCOBJ_CRC32_IEEE);
	}

	if(!d->curr_APNG_frame) {
		d->curr_APNG_frame = dbuf_create_output_file(c, "png", NULL, 0);

		// Update the width & height in the APNG_prefix membuf, in-place.

		writeu32be_at(d->APNG_prefix, d->APNG_prefix_IHDR_pos+8, d->curr_fcTL_width);
		writeu32be_at(d->APNG_prefix, d->APNG_prefix_IHDR_pos+8+4, d->curr_fcTL_height);

		de_crcobj_reset(d->crco_for_write);
		de_crcobj_addslice(d->crco_for_write, d->APNG_prefix, d->APNG_prefix_IHDR_pos+4, 4+13);
		writeu32be_at(d->APNG_prefix, d->APNG_prefix_IHDR_pos+8+13,
			(i64)de_crcobj_getval(d->crco_for_write));

		dbuf_copy(d->APNG_prefix, 0, d->APNG_prefix->len, d->curr_APNG_frame);
	}

	IDAT_dlen = hp->dlen-4;
	dbuf_writeu32be(d->curr_APNG_frame, IDAT_dlen);

	de_crcobj_reset(d->crco_for_write);
	dbuf_set_writelistener(d->curr_APNG_frame, de_writelistener_for_crc, (void*)d->crco_for_write);

	dbuf_writeu32be(d->curr_APNG_frame, (i64)CODE_IDAT);
	dbuf_copy(c->infile, hp->dpos+4, IDAT_dlen, d->curr_APNG_frame);
	dbuf_set_writelistener(d->curr_APNG_frame, NULL, NULL);
	dbuf_writeu32be(d->curr_APNG_frame, (i64)de_crcobj_getval(d->crco_for_write));
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpq $0x4, 0x8(%rdx)
jl 0xb5aa0
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq (%rdx), %rsi
movq 0x18(%rdi), %rdi
callq 0xeed0d
leaq 0x820ef(%rip), %rsi     # 0x1379fe
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
cmpb $0x0, 0xd(%rbx)
je 0xb5aa0
cmpq $0x0, 0x20(%rbx)
je 0xb5aa0
cmpq $0x0, 0x28(%rbx)
je 0xb5aa0
cmpb $0x0, 0xa(%rbx)
je 0xb5aa0
cmpq $0x0, 0x38(%rbx)
je 0xb5a9c
cmpq $0x0, 0x30(%rbx)
je 0xb5a9c
cmpq $0x0, 0x18(%rbx)
jne 0xb5973
movq %r15, %rdi
movl $0x10, %esi
callq 0xeb499
movq %rax, 0x18(%rbx)
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
jne 0xb5a1d
leaq 0x72da9(%rip), %rsi     # 0x128730
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, 0x40(%rbx)
movq 0x38(%rbx), %rdi
movq 0x20(%rbx), %rdx
movq 0x30(%rbx), %rsi
addq $0x8, %rsi
callq 0xb6692
movq 0x38(%rbx), %rdi
movq 0x28(%rbx), %rdx
movq 0x30(%rbx), %rsi
addq $0xc, %rsi
callq 0xb6692
movq 0x18(%rbx), %rdi
callq 0xeb7fe
movq 0x38(%rbx), %rsi
movq 0x18(%rbx), %rdi
movq 0x30(%rbx), %rdx
addq $0x4, %rdx
movl $0x11, %ecx
callq 0xeb944
movq 0x38(%rbx), %r12
movq 0x18(%rbx), %rdi
movq 0x30(%rbx), %r13
addq $0x15, %r13
callq 0xeb865
movl %eax, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0xb6692
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %rcx
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xef481
movq 0x40(%rbx), %rdi
movq 0x8(%r14), %r12
addq $-0x4, %r12
movq %r12, %rsi
callq 0xf1026
movq 0x18(%rbx), %rdi
callq 0xeb7fe
movq 0x18(%rbx), %rdx
movq 0x40(%rbx), %rdi
leaq 0x3ba0c(%rip), %rsi     # 0xf1451
callq 0xf1412
movq 0x40(%rbx), %rdi
movl $0x49444154, %esi       # imm = 0x49444154
callq 0xf1026
movq 0x18(%r15), %rdi
movq (%r14), %rsi
addq $0x4, %rsi
movq 0x40(%rbx), %rcx
movq %r12, %rdx
callq 0xef481
movq 0x40(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf1412
movq 0x18(%rbx), %rdi
movq 0x40(%rbx), %rbx
callq 0xeb865
movl %eax, %esi
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xf1026
movb $0x0, 0xa(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq