// File: /workspace/github_c_makefile_star2_O3/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, %r15
movl $0x58, %esi
callq 0xe8b2b
movq %rax, %r14
leaq 0x82c30(%rip), %rsi     # 0x13758a
movq %r15, %rdi
movl $0x1, %edx
callq 0xe9bd0
movb %al, 0x4(%r14)
leaq 0x82c25(%rip), %rsi     # 0x137597
movq %r15, %rdi
movl $0x1, %edx
callq 0xe9bd0
movb %al, 0x5(%r14)
leaq 0x82c1d(%rip), %rsi     # 0x1375a7
movq %r15, %rdi
xorl %edx, %edx
callq 0xe9bd0
movb %al, 0x6(%r14)
leaq 0x7faec(%rip), %rsi     # 0x13448b
movq %r15, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r15), %rdi
callq 0xb4e1b
movl %eax, (%r14)
movq %r15, %rdi
movq %r14, %rsi
callq 0xb4e76
cmpl $0x1, (%r14)
jne 0xb49d4
cmpb $0x0, 0x5(%r14)
je 0xb49d4
movb $0x1, 0xa(%r14)
movq %r14, 0x20(%rsp)
movq 0x18(%r15), %rdi
cmpq $0x9, 0x18(%rdi)
movq %r15, 0x10(%rsp)
jl 0xb4d81
leaq 0x40(%rsp), %r14
movl $0x8, %r12d
leaq 0xd21f1(%rip), %r13     # 0x186bf0
movl $0x0, 0x1c(%rsp)
xorl %ebx, %ebx
pxor %xmm0, %xmm0
movdqu %xmm0, 0x30(%r14)
movdqu %xmm0, 0x20(%r14)
movdqu %xmm0, 0x10(%r14)
movdqu %xmm0, (%r14)
movdqu %xmm0, -0x10(%r14)
movq %r12, 0x70(%rsp)
leaq 0x8(%r12), %rbp
movq %rbp, 0x28(%rsp)
movq %r12, %rsi
callq 0xeed0d
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rcx
addq %rcx, %rax
addq $0x4, %rax
movq 0x18(%r15), %rdi
cmpq 0x18(%rdi), %rax
jg 0xb4d6b
leaq 0x4(%r12), %rsi
movq %r14, %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0xf1762
movq 0x20(%rsp), %rax
movl (%rax), %eax
xorl %r14d, %r14d
cmpl $0x2, %eax
sete %r14b
incl %r14d
cmpl $0x3, %eax
movl $0x4, %eax
cmovel %eax, %r14d
xorl %r15d, %r15d
leaq 0x90(%rsp), %rdi
movl (%r15,%r13), %eax
cmpl 0x44(%rsp), %eax
jne 0xb4b04
testl %r14d, 0x4(%r15,%r13)
je 0xb4b04
cmpl $0x68745350, %eax       # imm = 0x68745350
jne 0xb4b13
cmpq $0x17, 0x30(%rsp)
jle 0xb4b04
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x28(%rsp), %rdx
movl $0x10, %ecx
leaq 0x80(%rsp), %rsi
callq 0xee8d4
leaq 0x90(%rsp), %rdi
movdqa 0x80(%rsp), %xmm0
pcmpeqb 0x829d7(%rip), %xmm0    # 0x1374d0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0xb4b13
addq $0x18, %r15
cmpq $0x5b8, %r15            # imm = 0x5B8
jne 0xb4aa0
jmp 0xb4b1b
addq %r13, %r15
movq %r15, 0x38(%rsp)
movl 0x44(%rsp), %eax
cmpl $0x49444154, %eax       # imm = 0x49444154
jne 0xb4b42
cmpl $0x0, 0x1c(%rsp)
je 0xb4b42
movl $0x1, %r12d
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %r15
jmp 0xb4c17
cmpl $0x49444154, %eax       # imm = 0x49444154
movq 0x20(%rsp), %r14
jne 0xb4b81
cmpl $0x49444154, %ebx       # imm = 0x49444154
jne 0xb4b81
movq 0x10(%rsp), %rax
cmpl $0x1, (%rax)
jg 0xb4b81
movq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x82a6f(%rip), %rsi     # 0x1375de
xorl %eax, %eax
callq 0xe8617
movl $0x1, %r12d
jmp 0xb4c17
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0xb4bac
movq 0x8(%rax), %rcx
testq %rcx, %rcx
je 0xb4bbd
movl $0x50, %esi
movq %rdi, %r14
leaq 0x7726b(%rip), %rdx     # 0x12be0e
xorl %eax, %eax
callq 0xe8193
jmp 0xb4bd1
movl $0x50, %edx
movq %rdi, %r14
leaq 0x82a3d(%rip), %rsi     # 0x1375f8
jmp 0xb4bcc
movl $0x50, %edx
movq %rdi, %r14
leaq 0x904e4(%rip), %rsi     # 0x1450b0
callq 0xe8219
movq 0x10(%rsp), %r15
movl 0x30(%rsp), %eax
movl %eax, (%rsp)
movq %r15, %rdi
leaq 0x82a16(%rip), %rsi     # 0x1375fd
leaq 0x50(%rsp), %rdx
movq %r14, %rcx
movl %r12d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0xe8617
cmpl $0x49444154, 0x44(%rsp) # imm = 0x49444154
movl $0x0, %eax
movl 0x1c(%rsp), %r12d
cmovnel %eax, %r12d
movq 0x20(%rsp), %r14
movq %r15, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0xb4c46
movq 0x10(%rax), %rax
testq %rax, %rax
je 0xb4c72
movq %r15, %rdi
movq %r14, %rsi
leaq 0x28(%rsp), %rdx
callq *%rax
jmp 0xb4c72
cmpl $0x2, (%r15)
jl 0xb4c72
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x18(%r15), %rsi
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %r15, %rdi
xorl %r9d, %r9d
callq 0xe8bea
addq 0x30(%rsp), %rbp
cmpb $0x0, 0x4(%r14)
je 0xb4ce6
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0xb4c92
callq 0xeb7fe
movq 0x10(%r14), %rdi
jmp 0xb4ca6
movq %r15, %rdi
movl $0x10, %esi
callq 0xeb499
movq %rax, %rdi
movq %rax, 0x10(%r14)
movq 0x18(%r15), %rsi
movq 0x30(%rsp), %rcx
movq 0x70(%rsp), %rdx
addq $0x4, %rdx
addq $0x4, %rcx
callq 0xeb944
movq 0x10(%r14), %rdi
callq 0xeb865
movl %eax, 0x7c(%rsp)
testl %r12d, %r12d
jne 0xb4ce6
movq %r15, %rdi
leaq 0x6bb0a(%rip), %rsi     # 0x1207e7
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r15), %rdi
movq %rbp, %rsi
callq 0xeed0d
movl %eax, 0x78(%rsp)
testl %r12d, %r12d
jne 0xb4d0e
movq %r15, %rdi
leaq 0x773d8(%rip), %rsi     # 0x12c0dd
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl %r12d, 0x1c(%rsp)
cmpb $0x0, 0x4(%r14)
je 0xb4d3e
movl 0x78(%rsp), %ecx
movl 0x7c(%rsp), %r8d
cmpl %r8d, %ecx
je 0xb4d3e
movq 0x70(%rsp), %rdx
movq %r15, %rdi
leaq 0x828e9(%rip), %rsi     # 0x137620
xorl %eax, %eax
callq 0xe8faa
addq $0x4, %rbp
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movl 0x44(%rsp), %ebx
movq 0x18(%r15), %rdi
movq %rbp, %r12
cmpq 0x18(%rdi), %rbp
leaq 0x40(%rsp), %r14
jl 0xb4a09
jmp 0xb4d81
leaq 0x82845(%rip), %rsi     # 0x1375b7
movq 0x10(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8faa
movq 0x20(%rsp), %rbx
cmpq $0x0, 0x40(%rbx)
je 0xb4d95
movq %rbx, %rdi
callq 0xb4ed6
movq 0x38(%rbx), %rdi
callq 0xf052b
movq 0x48(%rbx), %rdi
callq 0xf052b
movq 0x50(%rbx), %rdi
callq 0xf052b
movq 0x10(%rbx), %rdi
callq 0xeb858
movq 0x18(%rbx), %rdi
callq 0xeb858
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0xe8be2
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq