// File: /workspace/github_c_makefile_star2_O1/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), %rsi
movq %rsi, 0x8(%rsp)
movq 0x18(%rdi), %rdi
movl $0x50, %edx
movl $0x50, %ecx
movl $0x1, %r8d
movl $0x5, %r9d
callq 0xefe67
movq %rax, %r14
cmpl $0x0, 0x34(%rax)
je 0xb68c7
movq 0x18(%r14), %rdi
callq 0xf7557
leaq 0x80f39(%rip), %rsi     # 0x1376c6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq (%r14), %rax
addq %rax, 0x8(%rsp)
movq 0x8(%r14), %rsi
leaq 0x10(%rsp), %r13
movl $0x64, %edx
movq %r13, %rdi
callq 0xe8ded
leaq 0x5f32e(%rip), %rsi     # 0x115aed
movq %r13, %rdi
callq 0xe8e26
testl %eax, %eax
je 0xb67e0
leaq 0x80f07(%rip), %rsi     # 0x1376d9
leaq 0x10(%rsp), %rdi
callq 0xe8e26
testl %eax, %eax
jne 0xb67e5
movb $0x0, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x180e0
cmpq $0x5, %rax
jb 0xb6816
movq %rax, %r13
leaq 0x5f2ee(%rip), %rsi     # 0x115aed
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
callq 0xea913
testl %eax, %eax
je 0xb6816
movb $0x0, -0x4(%r13,%rbp)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef14d
testb %al, %al
jne 0xb68ea
movq 0x8(%r12), %r13
addq (%r12), %r13
movq 0x8(%rsp), %rdx
subq %rdx, %r13
leaq 0x80ea1(%rip), %rsi     # 0x1376e5
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r12
cmpb $0x0, 0xd0(%rbx)
je 0xb6884
cmpb $0x0, 0x10(%rsp)
je 0xb6884
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0xeac7c
leaq 0x5f262(%rip), %rsi     # 0x115aed
movq %rbx, %rdi
movq %r12, %rdx
movl $0x1, %ecx
callq 0xf037a
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 0x100d18
jmp 0xb68cc
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r12, %rsi
callq 0xea9b3
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf00aa
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq