// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x4, 0x8(%rax)
jge 0x10bae4
jmp 0x10bd3e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
callq 0x10d150
movq -0x10(%rbp), %rax
cmpb $0x0, 0xd(%rax)
jne 0x10bb07
jmp 0x10bd3e
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x10bb1d
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x10bb22
jmp 0x10bd3e
movq -0x10(%rbp), %rax
cmpb $0x0, 0xa(%rax)
jne 0x10bb31
jmp 0x10bd3e
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x10bb47
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x10bb54
movq -0x10(%rbp), %rax
movb $0x0, 0xa(%rax)
jmp 0x10bd3e
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x10bb78
movq -0x8(%rbp), %rdi
movl $0x10, %esi
callq 0x15eac0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x10bc84
movq -0x8(%rbp), %rdi
leaq 0xa8346(%rip), %rsi     # 0x1b3ed8
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x166c60
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
addq $0x8, %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
callq 0x10d260
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
addq $0x8, %rsi
addq $0x4, %rsi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
callq 0x10d260
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x15f250
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
addq $0x4, %rdx
movl $0x11, %ecx
callq 0x15f500
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
addq $0x8, %rax
addq $0xd, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x15f340
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl %eax, %eax
movl %eax, %edx
callq 0x10d260
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x166070
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
subq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x168b80
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x15f250
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x5d607(%rip), %rsi     # 0x1692d0
callq 0x169280
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movl $0x49444154, %esi       # imm = 0x49444154
callq 0x168b80
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
addq $0x4, %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rcx
callq 0x166070
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x169280
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x15f340
movq -0x38(%rbp), %rdi
movl %eax, %eax
movl %eax, %esi
callq 0x168b80
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)