// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/png.c
// Function: handler_iccp
static void handler_iccp(deark *c, lctx *d, struct handler_params *hp)
{
	u8 cmpr_type;
	i64 cmpr_len;
	dbuf *f = NULL;
	struct de_stringreaderdata *prof_name_srd = NULL;
	de_finfo *fi = NULL;
	char prof_name2[100];
	size_t prof_name2_strlen;
	i64 pos = hp->dpos;

	prof_name_srd = dbuf_read_string(c->infile, pos, 80, 80,
		DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_LATIN1);
	if(!prof_name_srd->found_nul) goto done;
	de_dbg(c, "profile name: \"%s\"", ucstring_getpsz_d(prof_name_srd->str));
	pos += prof_name_srd->bytes_consumed;

	// Our working copy, to use as part of the filename.
	de_strlcpy(prof_name2, prof_name_srd->sz, sizeof(prof_name2));
	if(!de_strcasecmp(prof_name2, "icc") ||
		!de_strcasecmp(prof_name2, "icc profile"))
	{
		prof_name2[0] = '\0'; // Ignore generic name.
	}

	prof_name2_strlen = de_strlen(prof_name2);
	if(prof_name2_strlen>=5) {
		if(de_sz_has_ext(prof_name2, "icc")) {
			// If the name already ends in ".icc", chop it off so that we don't end
			// up with a double ".icc.icc" file extension.
			prof_name2[prof_name2_strlen-4] = '\0';
		}
	}

	cmpr_type = de_getbyte_p(&pos);
	if(cmpr_type!=0) return;

	cmpr_len = hp->dpos + hp->dlen - pos;
	de_dbg(c, "compressed profile data at %"I64_FMT", len=%"I64_FMT, pos, cmpr_len);
	fi = de_finfo_create(c);
	if(c->filenames_from_file && prof_name2[0])
		de_finfo_set_name_from_sz(c, fi, prof_name2, 0, DE_ENCODING_LATIN1);
	f = dbuf_create_output_file(c, "icc", fi, DE_CREATEFLAG_IS_AUX);
	fmtutil_decompress_deflate(c->infile, pos, cmpr_len, f, 0, NULL,
		d->is_CgBI ? 0 : DE_DEFLATEFLAG_ISZLIB);

done:
	dbuf_close(f);
	de_finfo_destroy(c, fi);
	de_destroy_stringreaderdata(c, prof_name_srd);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movq (%rdx), %r13
movq %r13, 0x8(%rsp)
movq 0x18(%rdi), %rdi
movl $0x50, %edx
movl $0x50, %ecx
movq %r13, %rsi
movl $0x1, %r8d
movl $0x5, %r9d
callq 0xef87c
movq %rax, %r14
cmpl $0x0, 0x34(%rax)
je 0xb5d4f
movq 0x18(%r14), %rdi
callq 0xf70f6
leaq 0x81e39(%rip), %rsi     # 0x137a4e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq (%r14), %r13
movq %r13, 0x8(%rsp)
movq 0x8(%r14), %rsi
leaq 0x10(%rsp), %r13
movl $0x64, %edx
movq %r13, %rdi
callq 0xe8219
leaq 0x5ff56(%rip), %rsi     # 0x115b9d
movq %r13, %rdi
callq 0xe8252
testl %eax, %eax
je 0xb5c68
leaq 0x81e07(%rip), %rsi     # 0x137a61
leaq 0x10(%rsp), %rdi
callq 0xe8252
testl %eax, %eax
jne 0xb5c6d
movb $0x0, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x180e0
cmpq $0x5, %rax
jb 0xb5c9e
movq %rax, %r13
leaq 0x5ff16(%rip), %rsi     # 0x115b9d
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
callq 0xea46e
testl %eax, %eax
je 0xb5c9e
movb $0x0, -0x4(%r13,%rbp)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xeeb4b
testb %al, %al
jne 0xb5d72
movq 0x8(%r12), %r13
addq (%r12), %r13
movq 0x8(%rsp), %rdx
subq %rdx, %r13
leaq 0x81da1(%rip), %rsi     # 0x137a6d
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
callq 0xea504
movq %rax, %r12
cmpb $0x0, 0xd0(%rbx)
je 0xb5d0c
cmpb $0x0, 0x10(%rsp)
je 0xb5d0c
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0xea78f
leaq 0x5fe8a(%rip), %rsi     # 0x115b9d
movq %rbx, %rdi
movq %r12, %rdx
movl $0x1, %ecx
callq 0xefda1
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
xorl %eax, %eax
cmpb $0x0, 0x7(%r15)
sete %al
movl %eax, (%rsp)
movq %r13, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x100594
jmp 0xb5d54
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r12, %rsi
callq 0xea50e
movq %rbx, %rdi
movq %r14, %rsi
callq 0xefaca
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq