// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-png.c
// Function: write_png_chunk_IDATs
static int write_png_chunk_IDATs(struct deark_png_encode_info *pei, dbuf *cdbuf)
{
	int y;
	int retval = 0;
	deark *c = pei->c;
	struct fmtutil_tdefl_ctx *tdctx = NULL;
	static const unsigned int my_s_tdefl_num_probes[11] = { 0, 1, 6, 32,  16, 32, 128, 256,  512, 768, 1500 };
	dbuf *outf_IDAT = NULL;
	struct IDAT_write_userdata_struct iwu;

	de_zeromem(&iwu, sizeof(struct IDAT_write_userdata_struct));
	iwu.pei = pei;
	iwu.cdbuf = cdbuf;

	outf_IDAT = dbuf_create_custom_dbuf(c, 0, 0);
	outf_IDAT->userdata_for_customwrite = (void*)&iwu;
	outf_IDAT->customwrite_fn = my_IDAT_write_cb;

	// compress image data
	tdctx = fmtutil_tdefl_create(c, outf_IDAT,
		my_s_tdefl_num_probes[MY_MZ_MIN(10, pei->level)] | MY_TDEFL_WRITE_ZLIB_HEADER);

	if(pei->encode_as_bwimg) {
		pei->dst_rowspan = ((size_t)pei->width+7)/8;
	}
	else {
		pei->dst_rowspan = (size_t)pei->width * (size_t)pei->num_chans;
		if(pei->imglo) pei->dst_rowspan *= 2;
	}

	for (y = 0; y<pei->height; y++) {
		compress_png_row(pei, tdctx, (pei->flip ? (pei->height - 1 - y) : y));
	}

	if (fmtutil_tdefl_compress_buffer(tdctx, NULL, 0, FMTUTIL_TDEFL_FINISH) !=
		FMTUTIL_TDEFL_STATUS_DONE)
	{
		goto done;
	}

	if(cdbuf->len>0 || iwu.IDAT_count==0) {
		write_png_chunk_from_cdbuf(pei, cdbuf, CODE_IDAT);
	}

	retval = 1;

done:
	fmtutil_tdefl_destroy(tdctx);
	dbuf_close(outf_IDAT);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x19140
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x169220
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
leaq -0x48(%rbp), %rcx
movq %rcx, 0xa8(%rax)
movq -0x30(%rbp), %rax
leaq 0x1ee(%rip), %rcx       # 0x19b6f0
movq %rcx, 0xb0(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rcx
movl $0xa, %eax
cmpl 0x38(%rcx), %eax
jae 0x19b531
movl $0xa, %eax
movl %eax, -0x5c(%rbp)
jmp 0x19b53b
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
movl -0x5c(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x424ef(%rip), %rax     # 0x1dda40
movl (%rax,%rcx,4), %edx
orl $0x1000, %edx           # imm = 0x1000
callq 0x198180
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x62(%rax)
je 0x19b587
movq -0x8(%rbp), %rax
movslq 0x20(%rax), %rcx
addq $0x7, %rcx
shrq $0x3, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x78(%rax)
jmp 0x19b5bf
movq -0x8(%rbp), %rax
movslq 0x20(%rax), %rcx
movq -0x8(%rbp), %rax
movslq 0x2c(%rax), %rax
imulq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x19b5bd
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rcx
shlq %rcx
movq %rcx, 0x78(%rax)
jmp 0x19b5bf
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jge 0x19b61f
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x19b5fe
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
subl $0x1, %eax
subl -0x14(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0x19b604
movl -0x14(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdi
movl -0x74(%rbp), %edx
callq 0x19b800
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x19b5c6
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x4, %ecx
movq %rdx, %rsi
callq 0x198220
cmpl $0x1, %eax
je 0x19b63b
jmp 0x19b665
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jg 0x19b64c
cmpl $0x0, -0x38(%rbp)
jne 0x19b65e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x49444154, %edx       # imm = 0x49444154
callq 0x19b690
movl $0x1, -0x18(%rbp)
movq -0x28(%rbp), %rdi
callq 0x198340
movq -0x30(%rbp), %rdi
callq 0x1676a0
movl -0x18(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)