// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/png.c
// Function: handler_IDAT
static void handler_IDAT(deark *c, lctx *d, struct handler_params *hp)
{
	if(!d->found_IDAT) {
		d->found_IDAT = 1;
		// In case format declaration was deferred, do it now.
		declare_png_fmt(c, d);

		prepare_PNG_extraction_from_APNG(c, d);

		if(d->fmt==DE_PNGFMT_PNG && !d->is_CgBI && !d->IDAT_prefix) {
			d->IDAT_prefix = dbuf_create_membuf(c, 8, 0x1);
		}

		if(d->opt_want_raw_zlib && d->fmt==DE_PNGFMT_PNG && !d->is_CgBI &&
			!d->raw_zlib)
		{
			d->raw_zlib = dbuf_create_output_file(c, "zlib", NULL, 0);
		}
	}

	// Collect at least the first 2 bytes of IDAT data for analysis.
	// We allow for the possibility that the bytes are not all in the same chunk.
	if(d->IDAT_prefix && d->IDAT_prefix->len<2) {
		i64 n;

		n = de_min_int(2, hp->dlen);
		dbuf_copy(c->infile, hp->dpos, n, d->IDAT_prefix);
		if(d->IDAT_prefix->len>=2) {
			decode_zlib_header(c, d);
		}
	}

	if(d->raw_zlib) {
		dbuf_copy(c->infile, hp->dpos, hp->dlen, d->raw_zlib);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
cmpb $0x0, 0xc(%rsi)
je 0xb5b9a
movq 0x48(%r15), %rax
testq %rax, %rax
je 0xb5b6f
cmpq $0x1, 0x18(%rax)
jg 0xb5b6f
movq 0x8(%rbx), %rsi
movl $0x2, %edi
callq 0xea792
movq 0x18(%r14), %rdi
movq (%rbx), %rsi
movq 0x48(%r15), %rcx
movq %rax, %rdx
callq 0xefabc
movq 0x48(%r15), %rdi
testq %rdi, %rdi
je 0xb5b6f
cmpq $0x2, 0x18(%rdi)
jl 0xb5b6f
xorl %esi, %esi
callq 0xef0d5
movl %eax, %ebp
movq 0x48(%r15), %rdi
movl $0x1, %esi
callq 0xef0d5
movl %eax, %r12d
shrb $0x4, %bpl
addb $0x8, %bpl
movl $0x1, %edx
movl %ebp, %ecx
shll %cl, %edx
leaq 0x81973(%rip), %rsi     # 0x1374bf
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9226
shrb $0x6, %r12b
movzbl %r12b, %edx
leaq 0x8196f(%rip), %rsi     # 0x1374d4
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x50(%r15), %rcx
testq %rcx, %rcx
je 0xb5db7
movq 0x18(%r14), %rdi
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xefabc
movb $0x1, 0xc(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0xb5a04
cmpb $0x0, 0x8(%r15)
je 0xb5de8
cmpb $0x0, 0xa(%r15)
je 0xb5de8
cmpb $0x0, 0xb(%r15)
jne 0xb5de8
cmpq $0x0, 0x38(%r15)
jne 0xb5de8
movb $0x1, 0xb(%r15)
movq $0x0, 0x10(%rsp)
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %rax, 0x38(%r15)
movl $0xfa1, %esi            # imm = 0xFA1
movq %rax, %rdi
callq 0xf1066
movq 0x38(%r15), %rdi
leaq 0x81570(%rip), %rbp     # 0x13717c
movl $0x8, %r12d
movl $0x8, %edx
movq %rbp, %rsi
callq 0xefb82
leaq 0x8186b(%rip), %rsi     # 0x137491
movq %r14, %rdi
xorl %eax, %eax
callq 0xe93cf
cmpb $0x0, 0xd(%r15)
leaq 0x81877(%rip), %rax     # 0x1374b3
leaq 0x728bd(%rip), %rsi     # 0x128500
cmoveq %rax, %rsi
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movl $0x8, %edx
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
callq 0xefb82
leaq 0xc(%r12), %rax
movq 0x18(%r14), %rdi
cmpq 0x18(%rdi), %rax
jg 0xb5ca2
movq %r12, %rsi
callq 0xef32a
movq %rax, %rbp
movq 0x18(%r14), %rdi
leaq 0x4(%r12), %rsi
callq 0xef32a
leaq (%r12,%rbp), %rsi
addq $0xc, %rsi
movq 0x18(%r14), %rdi
cmpq 0x18(%rdi), %rsi
jle 0xb5caf
xorl %r13d, %r13d
testb %r13b, %r13b
jne 0xb5c68
jmp 0xb5dc6
cmpl $0x49444154, %eax       # imm = 0x49444154
movq 0x10(%rsp), %rdx
movl $0x1, %ecx
cmovel %ecx, %edx
cmpb $0x0, 0xa(%r15)
movb $0x1, %cl
je 0xb5d2e
testl %edx, %edx
jne 0xb5d2e
cmpl $0x67414d40, %eax       # imm = 0x67414D40
jle 0xb5cf3
cmpl $0x73424953, %eax       # imm = 0x73424953
jle 0xb5d1e
cmpl $0x73424954, %eax       # imm = 0x73424954
je 0xb5d2c
cmpl $0x74524e53, %eax       # imm = 0x74524E53
je 0xb5d2c
cmpl $0x73524742, %eax       # imm = 0x73524742
je 0xb5d2c
jmp 0xb5d2e
cmpl $0x624b4743, %eax       # imm = 0x624B4743
jg 0xb5d0e
cmpl $0x49484452, %eax       # imm = 0x49484452
je 0xb5d99
cmpl $0x504c5445, %eax       # imm = 0x504C5445
je 0xb5d2c
jmp 0xb5d2e
cmpl $0x624b4744, %eax       # imm = 0x624B4744
je 0xb5d2c
cmpl $0x6348524d, %eax       # imm = 0x6348524D
je 0xb5d2c
jmp 0xb5d2e
cmpl $0x67414d41, %eax       # imm = 0x67414D41
je 0xb5d2c
cmpl $0x70485973, %eax       # imm = 0x70485973
jne 0xb5d2e
xorl %ecx, %ecx
addq $0xc, %rbp
cmpl $0x6163544c, %eax       # imm = 0x6163544C
movq %rdx, 0x10(%rsp)
je 0xb5d6a
cmpl $0x6663544c, %eax       # imm = 0x6663544C
je 0xb5d6a
cmpl $0x66644154, %eax       # imm = 0x66644154
je 0xb5d6a
movq %rsi, (%rsp)
movq %r12, %rsi
movq %rbp, %rdx
movl %ecx, %r13d
movq 0x8(%rsp), %rcx
callq 0xefabc
movl %r13d, %ecx
movq (%rsp), %rsi
movb $0x1, %r13b
testb %cl, %cl
je 0xb5d79
movq %rsi, %r12
jmp 0xb5ca5
movq 0x18(%r14), %rdi
movq 0x38(%r15), %rcx
movq %rsi, (%rsp)
movq %r12, %rsi
movq %rbp, %rdx
callq 0xefabc
movq (%rsp), %r12
jmp 0xb5ca5
cmpq $0xd, %rbp
jne 0xb5d2e
cmpq $0x0, 0x30(%r15)
jne 0xb5d2e
movq 0x38(%r15), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, 0x30(%r15)
jmp 0xb5d2c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38(%r15), %rax
testq %rax, %rax
je 0xb5dde
cmpq $0xfa1, 0x18(%rax)      # imm = 0xFA1
jl 0xb5dde
movb $0x0, 0xa(%r15)
movq 0x8(%rsp), %rdi
callq 0xf0b13
cmpl $0x1, (%r15)
jne 0xb5e12
cmpb $0x0, 0x7(%r15)
jne 0xb5e12
cmpq $0x0, 0x48(%r15)
jne 0xb5e12
movl $0x8, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0xf0faf
movq %rax, 0x48(%r15)
cmpb $0x0, 0x6(%r15)
je 0xb5ad1
cmpl $0x1, (%r15)
jne 0xb5ad1
cmpb $0x0, 0x7(%r15)
jne 0xb5ad1
cmpq $0x0, 0x50(%r15)
jne 0xb5ad1
leaq 0x813e6(%rip), %rsi     # 0x13722a
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, 0x50(%r15)
jmp 0xb5ad1