// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/png.c
// Function: de_run_png
static void de_run_png(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos;
	i32 prev_chunk_id = 0;
	int suppress_idat_dbg = 0;

	d = de_malloc(c, sizeof(lctx));

	d->check_crcs = (u8)de_get_ext_option_bool(c, "png:checkcrc", 1);
	d->opt_extract_from_APNG = (u8)de_get_ext_option_bool(c, "png:extractapng", 1);
	d->opt_want_raw_zlib = (u8)de_get_ext_option_bool(c, "png:extractzlib", 0);

	de_dbg(c, "signature at %d", 0);
	d->fmt = do_identify_png_internal(c);
	declare_png_fmt(c, d);

	if(d->fmt==DE_PNGFMT_PNG && d->opt_extract_from_APNG) {
		d->extract_from_APNG_enabled = 1;
	}

	pos = 8;
	while(pos < c->infile->len) {
		struct chunk_ctx cctx;
		char nbuf[80];

		de_zeromem(&cctx, sizeof(struct chunk_ctx));

		cctx.pos = pos;
		cctx.hp.dpos = pos + 8;
		cctx.hp.dlen = de_getu32be(pos);
		if(cctx.hp.dpos + cctx.hp.dlen + 4 > c->infile->len) {
			de_warn(c, "Truncated file, or invalid data at %"I64_FMT, pos);
			break;
		}
		dbuf_read_fourcc(c->infile, pos+4, &cctx.hp.chunk4cc, 4, 0x0);

		get_chunk_type_info(c, d, &cctx.hp);

		if(cctx.hp.chunk4cc.id==CODE_IDAT && suppress_idat_dbg) {
			;
		}
		else if(cctx.hp.chunk4cc.id==CODE_IDAT && prev_chunk_id==CODE_IDAT && c->debug_level<2) {
			de_dbg(c, "(more IDAT chunks follow)");
			suppress_idat_dbg = 1;
		}
		else {
			if(cctx.hp.cti) {
				if(cctx.hp.cti->name) {
					de_snprintf(nbuf, sizeof(nbuf), " (%s)", cctx.hp.cti->name);
				}
				else {
					de_strlcpy(nbuf, "", sizeof(nbuf));
				}
			}
			else {
				de_strlcpy(nbuf, " (?)", sizeof(nbuf));
			}

			de_dbg(c, "chunk '%s'%s at %d dpos=%d dlen=%d",
				cctx.hp.chunk4cc.id_dbgstr, nbuf,
				(int)pos, (int)(pos+8), (int)cctx.hp.dlen);
			if(cctx.hp.chunk4cc.id!=CODE_IDAT) suppress_idat_dbg = 0;
		}

		pos += 8;

		de_dbg_indent(c, 1);

		if(cctx.hp.cti) {
			if(cctx.hp.cti->handler_fn) {
				cctx.hp.cti->handler_fn(c, d, &cctx.hp);
			}
		}
		else {
			if(c->debug_level>=2) {
				handler_hexdump(c, d, &cctx.hp);
			}
		}
		pos += cctx.hp.dlen;

		if(d->check_crcs) {
			do_check_chunk_crc(c, d, &cctx, suppress_idat_dbg);
		}

		cctx.crc_reported = (u32)de_getu32be(pos);
		if(!suppress_idat_dbg) {
			de_dbg(c, "crc32 (reported): 0x%08x", (unsigned int)cctx.crc_reported);
		}
		pos += 4;
		if(d->check_crcs && (cctx.crc_reported != cctx.crc_calc)) {
			de_warn(c, "CRC-32 check failed for chunk at %"I64_FMT" "
				"(reported=0x%08x, calculated=0x%08x)", cctx.pos,
				(unsigned int)cctx.crc_reported, (unsigned int)cctx.crc_calc);
		}

		de_dbg_indent(c, -1);

		prev_chunk_id = cctx.hp.chunk4cc.id;
	}

	if(d) {
		if(d->curr_APNG_frame) {
			finish_APNG_frame(c, d);
		}
		dbuf_close(d->APNG_prefix);
		dbuf_close(d->IDAT_prefix);
		dbuf_close(d->raw_zlib);
		de_crcobj_destroy(d->crco);
		de_crcobj_destroy(d->crco_for_write);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %rbx
pushq $0x58
popq %rsi
callq 0xdecaf
movq %rax, %r14
leaq 0x7c8da(%rip), %rsi     # 0x12a2aa
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %edx
callq 0xdfae5
movb %al, 0x4(%r14)
leaq 0x7c8cf(%rip), %rsi     # 0x12a2b7
movq %rbx, %rdi
movl %ebp, %edx
callq 0xdfae5
movb %al, 0x5(%r14)
leaq 0x7c8ca(%rip), %rsi     # 0x12a2c7
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
movb %al, 0x6(%r14)
leaq 0x797a1(%rip), %rsi     # 0x1271b3
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
callq 0xade51
movl %eax, (%r14)
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xadeb2
cmpl $0x1, (%r14)
jne 0xada4b
cmpb $0x0, 0x5(%r14)
je 0xada4b
movb $0x1, 0xa(%r14)
leaq 0x38(%rsp), %r15
pushq $0x8
popq %r12
leaq 0xdc155(%rip), %rbp     # 0x189bb0
xorl %eax, %eax
movl $0x0, 0x18(%rsp)
movq 0x10(%rsp), %rbx
movq %r14, 0x78(%rsp)
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r12
jge 0xaddc2
movl %eax, 0x1c(%rsp)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x30(%r15)
movdqu %xmm0, 0x20(%r15)
movdqu %xmm0, 0x10(%r15)
movdqu %xmm0, (%r15)
movdqu %xmm0, -0x10(%r15)
movq %r12, 0x68(%rsp)
leaq 0x8(%r12), %r13
movq %r13, 0x20(%rsp)
movq %r12, %rsi
callq 0xe404f
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rcx
addq %rcx, %rax
addq $0x4, %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0xaddac
leaq 0x4(%r12), %rsi
movq %r15, %rdx
movq %r14, %r15
pushq $0x4
popq %r14
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0xe657c
movl (%r15), %eax
xorl %r15d, %r15d
cmpl $0x2, %eax
sete %r15b
incl %r15d
cmpl $0x3, %eax
cmovel %r14d, %r15d
xorl %r14d, %r14d
cmpq $0x5b8, %r14            # imm = 0x5B8
je 0xadb7d
movl (%r14,%rbp), %eax
cmpl 0x3c(%rsp), %eax
jne 0xadb6f
testl %r15d, 0x4(%r14,%rbp)
je 0xadb6f
cmpl $0x68745350, %eax       # imm = 0x68745350
jne 0xadb75
cmpq $0x17, 0x28(%rsp)
jle 0xadb6f
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x20(%rsp), %rdx
leaq 0x80(%rsp), %rsi
pushq $0x10
popq %rcx
callq 0xe3cb7
movdqa 0x80(%rsp), %xmm0
pcmpeqb 0x7c68c(%rip), %xmm0    # 0x12a1f0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0xadb75
addq $0x18, %r14
jmp 0xadb0c
addq %rbp, %r14
movq %r14, 0x30(%rsp)
movl 0x3c(%rsp), %eax
cmpl $0x49444154, %eax       # imm = 0x49444154
movq 0x78(%rsp), %r14
jne 0xadb9c
pushq $0x1
popq %r15
cmpl $0x0, 0x18(%rsp)
jne 0xadc65
cmpl $0x49444154, %eax       # imm = 0x49444154
jne 0xadbd3
cmpl $0x49444154, 0x1c(%rsp) # imm = 0x49444154
jne 0xadbd3
movq 0x10(%rsp), %rax
cmpl $0x1, (%rax)
jg 0xadbd3
movq 0x10(%rsp), %rdi
leaq 0x7c73b(%rip), %rsi     # 0x12a2fe
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %r15
jmp 0xadc65
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0xadc04
movq 0x8(%rax), %rcx
testq %rcx, %rcx
leaq 0x90(%rsp), %r15
movq %r15, %rdi
je 0xadc18
pushq $0x50
popq %rsi
leaq 0x70fa3(%rip), %rdx     # 0x11eb9e
xorl %eax, %eax
callq 0xde40c
jmp 0xadc27
leaq 0x90(%rsp), %r15
movq %r15, %rdi
leaq 0x7c702(%rip), %rsi     # 0x12a318
jmp 0xadc1f
leaq 0x8a041(%rip), %rsi     # 0x137c60
pushq $0x50
popq %rdx
callq 0xde492
movq 0x10(%rsp), %rdi
movl 0x28(%rsp), %eax
movl %eax, (%rsp)
leaq 0x7c6e3(%rip), %rsi     # 0x12a31d
leaq 0x48(%rsp), %rdx
movq %r15, %rcx
movl %r12d, %r8d
movl %r13d, %r9d
xorl %eax, %eax
callq 0xde896
cmpl $0x49444154, 0x3c(%rsp) # imm = 0x49444154
movl $0x0, %eax
movl 0x18(%rsp), %r15d
cmovnel %eax, %r15d
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0xadc97
movq 0x10(%rax), %rax
testq %rax, %rax
je 0xadcc2
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x20(%rsp), %rdx
callq *%rax
jmp 0xadcc2
cmpl $0x2, (%rbx)
jl 0xadcc2
movq 0x18(%rbx), %rsi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
xorl %r9d, %r9d
callq 0xded3a
addq 0x28(%rsp), %r13
cmpb $0x0, 0x4(%r14)
je 0xadd34
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0xadce2
callq 0xe0e44
movq 0x10(%r14), %rdi
jmp 0xadcf4
movq %rbx, %rdi
pushq $0x10
popq %rsi
callq 0xe0ae9
movq %rax, %rdi
movq %rax, 0x10(%r14)
movq 0x18(%rbx), %rsi
movq 0x28(%rsp), %rcx
movq 0x68(%rsp), %rdx
addq $0x4, %rdx
addq $0x4, %rcx
callq 0xe0f33
movq 0x10(%r14), %rdi
callq 0xe0e95
movl %eax, 0x74(%rsp)
testl %r15d, %r15d
jne 0xadd34
movq %rbx, %rdi
leaq 0x659ca(%rip), %rsi     # 0x1136f5
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe404f
movl %eax, 0x70(%rsp)
testl %r15d, %r15d
jne 0xadd5c
movq %rbx, %rdi
leaq 0x7111a(%rip), %rsi     # 0x11ee6d
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
cmpb $0x0, 0x4(%r14)
je 0xadd87
movl 0x70(%rsp), %ecx
movl 0x74(%rsp), %r8d
cmpl %r8d, %ecx
je 0xadd87
movq 0x68(%rsp), %rdx
movq %rbx, %rdi
leaq 0x7c5c0(%rip), %rsi     # 0x12a340
xorl %eax, %eax
callq 0xdf05a
addq $0x4, %r13
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movl 0x3c(%rsp), %eax
movq %r13, %r12
movl %r15d, 0x18(%rsp)
leaq 0x38(%rsp), %r15
jmp 0xada6f
leaq 0x7c524(%rip), %rsi     # 0x12a2d7
movq 0x10(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xdf05a
cmpq $0x0, 0x40(%r14)
je 0xaddd1
movq %r14, %rdi
callq 0xadf12
movq 0x38(%r14), %rdi
callq 0xe5591
movq 0x48(%r14), %rdi
callq 0xe5591
movq 0x50(%r14), %rdi
callq 0xe5591
movq 0x10(%r14), %rdi
callq 0xe0e8d
movq 0x18(%r14), %rdi
callq 0xe0e8d
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0xded32
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq