// File: /workspace/github_c_makefile_star2_O1/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
movl $0x58, %esi
callq 0xe969b
movq %rax, %r14
leaq 0x81d04(%rip), %rsi     # 0x137202
movq %rbx, %rdi
movl $0x1, %edx
callq 0xea727
movb %al, 0x4(%r14)
leaq 0x81cf9(%rip), %rsi     # 0x13720f
movq %rbx, %rdi
movl $0x1, %edx
callq 0xea727
movb %al, 0x5(%r14)
leaq 0x81cf1(%rip), %rsi     # 0x13721f
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
movb %al, 0x6(%r14)
leaq 0x7eb50(%rip), %rsi     # 0x134093
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
callq 0xb59a5
movl %eax, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb5a04
cmpl $0x1, (%r14)
jne 0xb5577
cmpb $0x0, 0x5(%r14)
je 0xb5577
movb $0x1, 0xa(%r14)
movl $0x8, %r12d
leaq 0xd162c(%rip), %r13     # 0x186bb0
leaq 0x90(%rsp), %rbp
movl $0x0, 0xc(%rsp)
xorl %r15d, %r15d
movq %r14, 0x78(%rsp)
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r12
jge 0xb5916
pxor %xmm0, %xmm0
movdqa %xmm0, 0x60(%rsp)
movdqa %xmm0, 0x20(%rsp)
movdqa %xmm0, 0x30(%rsp)
movdqa %xmm0, 0x40(%rsp)
movdqa %xmm0, 0x50(%rsp)
movq $0x0, 0x70(%rsp)
movq %r12, 0x68(%rsp)
leaq 0x8(%r12), %rax
movq %rax, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movq %r12, %rsi
callq 0xef32a
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rcx
addq %rcx, %rax
addq $0x4, %rax
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rcx
movq %rax, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
cmpq %rcx, %rax
jle 0xb5638
movq %rbx, %rdi
leaq 0x81c06(%rip), %rsi     # 0x13722f
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9b27
jmp 0xb5900
movl %r15d, 0x1c(%rsp)
movq %rbp, %r15
leaq 0x4(%r12), %rsi
leaq 0x38(%rsp), %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0xf1d74
movl (%r14), %eax
xorl %ebp, %ebp
cmpl $0x2, %eax
sete %bpl
incl %ebp
cmpl $0x3, %eax
movl $0x4, %eax
cmovel %eax, %ebp
xorl %r14d, %r14d
movl (%r14,%r13), %eax
cmpl 0x3c(%rsp), %eax
jne 0xb56c5
testl %ebp, 0x4(%r14,%r13)
je 0xb56c5
cmpl $0x68745350, %eax       # imm = 0x68745350
jne 0xb56d4
cmpq $0x18, 0x28(%rsp)
jl 0xb56c5
movq 0x18(%rbx), %rdi
movq 0x20(%rsp), %rdx
movl $0x10, %ecx
movq %r15, %rsi
callq 0xeeee8
movdqa 0x90(%rsp), %xmm0
pcmpeqb 0x81a86(%rip), %xmm0    # 0x137140
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0xb56d4
addq $0x18, %r14
cmpq $0x5b8, %r14            # imm = 0x5B8
jne 0xb5673
jmp 0xb56dc
addq %r13, %r14
movq %r14, 0x30(%rsp)
movl 0x3c(%rsp), %eax
cmpl $0x49444154, %eax       # imm = 0x49444154
movq %r15, %rbp
movl 0x1c(%rsp), %r15d
jne 0xb5709
testl %r15d, %r15d
je 0xb5709
movl $0x1, %r15d
movq 0x78(%rsp), %r14
movq 0x10(%rsp), %r12
jmp 0xb57c9
cmpl $0x49444154, %eax       # imm = 0x49444154
movq 0x78(%rsp), %r14
jne 0xb573d
cmpl $0x49444154, 0xc(%rsp)  # imm = 0x49444154
jne 0xb573d
cmpl $0x1, (%rbx)
jg 0xb573d
movq %rbx, %rdi
leaq 0x81b28(%rip), %rsi     # 0x137256
xorl %eax, %eax
callq 0xe9226
movl $0x1, %r15d
jmp 0xb56ff
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0xb5768
movq 0x8(%rax), %rcx
testq %rcx, %rcx
je 0xb5779
movl $0x50, %esi
movq %rbp, %rdi
leaq 0x763c7(%rip), %rdx     # 0x12bb26
xorl %eax, %eax
callq 0xe8d67
jmp 0xb578d
movl $0x50, %edx
movq %rbp, %rdi
leaq 0x81af9(%rip), %rsi     # 0x137270
jmp 0xb5788
movl $0x50, %edx
movq %rbp, %rdi
leaq 0x8f448(%rip), %rsi     # 0x144bd0
callq 0xe8ded
movl 0x28(%rsp), %eax
movl %eax, (%rsp)
movq %rbx, %rdi
leaq 0x81ad7(%rip), %rsi     # 0x137275
leaq 0x48(%rsp), %rdx
movq %rbp, %rcx
movl %r12d, %r8d
movq 0x10(%rsp), %r12
movl %r12d, %r9d
xorl %eax, %eax
callq 0xe9226
cmpl $0x49444154, 0x3c(%rsp) # imm = 0x49444154
movl $0x0, %eax
cmovnel %eax, %r15d
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0xb57f8
movq 0x10(%rax), %rax
testq %rax, %rax
je 0xb5823
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x20(%rsp), %rdx
callq *%rax
jmp 0xb5823
cmpl $0x2, (%rbx)
jl 0xb5823
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 0xe975a
addq 0x28(%rsp), %r12
cmpb $0x0, 0x4(%r14)
je 0xb5894
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0xb583f
callq 0xebdc3
jmp 0xb5850
movq %rbx, %rdi
movl $0x10, %esi
callq 0xeba56
movq %rax, 0x10(%r14)
movq 0x10(%r14), %rdi
movq 0x18(%rbx), %rsi
movq 0x28(%rsp), %rcx
movq 0x68(%rsp), %rdx
addq $0x4, %rdx
addq $0x4, %rcx
callq 0xebf09
movq 0x10(%r14), %rdi
callq 0xebe2a
movl %eax, 0x74(%rsp)
testl %r15d, %r15d
jne 0xb5894
movq %rbx, %rdi
leaq 0x6ae34(%rip), %rsi     # 0x1206bf
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef32a
movl %eax, 0x70(%rsp)
testl %r15d, %r15d
jne 0xb58bc
movq %rbx, %rdi
leaq 0x76542(%rip), %rsi     # 0x12bdf5
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
cmpb $0x0, 0x4(%r14)
je 0xb58e7
movl 0x70(%rsp), %ecx
movl 0x74(%rsp), %r8d
cmpl %r8d, %ecx
je 0xb58e7
movq 0x68(%rsp), %rdx
movq %rbx, %rdi
leaq 0x819b8(%rip), %rsi     # 0x137298
xorl %eax, %eax
callq 0xe9b27
addq $0x4, %r12
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl 0x3c(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x80(%rsp), %rax
cmpq %rax, 0x88(%rsp)
jle 0xb559c
cmpq $0x0, 0x40(%r14)
je 0xb5925
movq %r14, %rdi
callq 0xb5a64
movq 0x38(%r14), %rdi
callq 0xf0b13
movq 0x48(%r14), %rdi
callq 0xf0b13
movq 0x50(%r14), %rdi
callq 0xf0b13
movq 0x10(%r14), %rdi
callq 0xebe1d
movq 0x18(%r14), %rdi
callq 0xebe1d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq