// File: /workspace/github_c_makefile_star2_O2/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 0xaea5c
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq (%rdx), %rsi
callq 0xaf545
cmpb $0x0, 0xd(%rbx)
je 0xaea5c
cmpq $0x0, 0x20(%rbx)
je 0xaea5c
cmpq $0x0, 0x28(%rbx)
je 0xaea5c
cmpb $0x0, 0xa(%rbx)
je 0xaea5c
cmpq $0x0, 0x38(%rbx)
je 0xaea58
cmpq $0x0, 0x30(%rbx)
je 0xaea58
cmpq $0x0, 0x18(%rbx)
jne 0xae931
pushq $0x10
popq %rsi
movq %r15, %rdi
callq 0xe0ae9
movq %rax, 0x18(%rbx)
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
jne 0xae9d9
leaq 0x6cbab(%rip), %rsi     # 0x11b4f0
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, 0x40(%rbx)
movq 0x38(%rbx), %rdi
movq 0x20(%rbx), %rdx
movq 0x30(%rbx), %rsi
addq $0x8, %rsi
callq 0xaf566
movq 0x38(%rbx), %rdi
movq 0x28(%rbx), %rdx
movq 0x30(%rbx), %rsi
addq $0xc, %rsi
callq 0xaf566
movq 0x18(%rbx), %rdi
callq 0xe0e44
movq 0x38(%rbx), %rsi
movq 0x18(%rbx), %rdi
movq 0x30(%rbx), %rdx
addq $0x4, %rdx
pushq $0x11
popq %rcx
callq 0xe0f33
movq 0x38(%rbx), %r12
movq 0x18(%rbx), %rdi
movq 0x30(%rbx), %r13
addq $0x15, %r13
callq 0xe0e95
movl %eax, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0xaf566
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %rcx
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xe45f4
movq 0x40(%rbx), %rdi
movq 0x8(%r14), %r12
addq $-0x4, %r12
movq %r12, %rsi
callq 0xe5f65
movq 0x18(%rbx), %rdi
callq 0xe0e44
movq 0x18(%rbx), %rdx
movq 0x40(%rbx), %rdi
leaq 0x378c0(%rip), %rsi     # 0xe62c1
callq 0xe629a
movq 0x40(%rbx), %rdi
movl $0x49444154, %esi       # imm = 0x49444154
callq 0xe5f65
movq 0x18(%r15), %rdi
movq (%r14), %rsi
addq $0x4, %rsi
movq 0x40(%rbx), %rcx
movq %r12, %rdx
callq 0xe45f4
movq 0x40(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe629a
movq 0x18(%rbx), %rdi
movq 0x40(%rbx), %rbx
callq 0xe0e95
movl %eax, %esi
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xe5f65
movb $0x0, 0xa(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq