// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl $0x58, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xb871c(%rip), %rsi     # 0x1c2e72
movl $0x1, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x8(%rbp), %rdi
leaq 0xb870b(%rip), %rsi     # 0x1c2e7f
movl $0x1, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x5(%rax)
movq -0x8(%rbp), %rdi
leaq 0xb86fd(%rip), %rsi     # 0x1c2e8f
xorl %edx, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x6(%rax)
movq -0x8(%rbp), %rdi
leaq 0xb5725(%rip), %rsi     # 0x1bfed2
xorl %edx, %edx
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
callq 0x10abd0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x10ac80
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x10a7f2
movq -0x18(%rbp), %rax
movzbl 0x5(%rax), %eax
cmpl $0x0, %eax
je 0x10a7f2
movq -0x18(%rbp), %rax
movb $0x1, 0xa(%rax)
movq $0x8, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x10aacb
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x19140
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165470
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
addq $0x4, %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x10a87e
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0xb862d(%rip), %rsi     # 0x1c2e9f
movb $0x0, %al
callq 0x15bc10
jmp 0x10aacb
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
leaq -0x80(%rbp), %rdx
addq $0x18, %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x10ad30
cmpl $0x49444154, -0x64(%rbp) # imm = 0x49444154
jne 0x10a8c8
cmpl $0x0, -0x28(%rbp)
je 0x10a8c8
jmp 0x10a9bb
cmpl $0x49444154, -0x64(%rbp) # imm = 0x49444154
jne 0x10a901
cmpl $0x49444154, -0x24(%rbp) # imm = 0x49444154
jne 0x10a901
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jge 0x10a901
movq -0x8(%rbp), %rdi
leaq 0xb85d8(%rip), %rsi     # 0x1c2ec6
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x28(%rbp)
jmp 0x10a9b9
cmpq $0x0, -0x70(%rbp)
je 0x10a951
movq -0x70(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x10a937
leaq -0xd0(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x50, %esi
leaq 0xacfbc(%rip), %rdx     # 0x1b78ea
movb $0x0, %al
callq 0x15a980
jmp 0x10a94f
leaq -0xd0(%rbp), %rdi
leaq 0xc628b(%rip), %rsi     # 0x1d0bd0
movl $0x50, %edx
callq 0x15aa30
jmp 0x10a969
leaq -0xd0(%rbp), %rdi
leaq 0xb8581(%rip), %rsi     # 0x1c2ee0
movl $0x50, %edx
callq 0x15aa30
movq -0x8(%rbp), %rdi
leaq -0x80(%rbp), %rdx
addq $0x18, %rdx
addq $0x10, %rdx
leaq -0xd0(%rbp), %rcx
movq -0x20(%rbp), %rax
movl %eax, %r8d
movq -0x20(%rbp), %rax
addq $0x8, %rax
movl %eax, %r9d
movq -0x78(%rbp), %rax
leaq 0xb8548(%rip), %rsi     # 0x1c2ee5
movl %eax, (%rsp)
movb $0x0, %al
callq 0x15b0d0
cmpl $0x49444154, -0x64(%rbp) # imm = 0x49444154
je 0x10a9b7
movl $0x0, -0x28(%rbp)
jmp 0x10a9b9
jmp 0x10a9bb
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
cmpq $0x0, -0x70(%rbp)
je 0x10a9ff
movq -0x70(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x10a9fd
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq *%rax
jmp 0x10aa1b
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x10aa19
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x10ae00
jmp 0x10aa1b
movq -0x78(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x10aa45
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x28(%rbp), %ecx
leaq -0x80(%rbp), %rdx
callq 0x10ae50
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165470
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x10aa74
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %edx
leaq 0xad14c(%rip), %rsi     # 0x1b7bb9
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0x10aab2
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
je 0x10aab2
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %r8d
leaq 0xb845d(%rip), %rsi     # 0x1c2f08
movb $0x0, %al
callq 0x15bc10
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x64(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x10a7fa
cmpq $0x0, -0x18(%rbp)
je 0x10ab38
movq -0x18(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x10aaea
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x10af10
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x1676a0
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x1676a0
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x1676a0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x15f2e0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x15f2e0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)