// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x50
popq %rcx
pushq $0x1
popq %r8
pushq $0x5
popq %r9
movq %r13, %rsi
movq %rcx, %rdx
callq 0xe495c
movq %rax, %r14
cmpl $0x0, 0x34(%rax)
je 0xaecfa
movq 0x18(%r14), %rdi
callq 0xeb877
leaq 0x7bba8(%rip), %rsi     # 0x12a76e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq (%r14), %r13
movq %r13, 0x8(%rsp)
movq 0x8(%r14), %rsi
leaq 0x10(%rsp), %r13
pushq $0x64
popq %rdx
movq %r13, %rdi
callq 0xde492
leaq 0x59f17(%rip), %rsi     # 0x108b0d
movq %r13, %rdi
callq 0xde4cb
testl %eax, %eax
je 0xaec17
leaq 0x7bb78(%rip), %rsi     # 0x12a781
leaq 0x10(%rsp), %rdi
callq 0xde4cb
testl %eax, %eax
jne 0xaec1c
movb $0x0, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x180e0
cmpq $0x5, %rax
jb 0xaec4d
movq %rax, %r13
leaq 0x59ed7(%rip), %rsi     # 0x108b0d
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
callq 0xdfcb6
testl %eax, %eax
je 0xaec4d
movb $0x0, -0x4(%r13,%rbp)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xe3f2a
testb %al, %al
jne 0xaed1d
movq 0x8(%r12), %r13
addq (%r12), %r13
movq 0x8(%rsp), %rdx
subq %rdx, %r13
leaq 0x7bb12(%rip), %rsi     # 0x12a78d
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r12
cmpb $0x0, 0xd0(%rbx)
je 0xaecb9
cmpb $0x0, 0x10(%rsp)
je 0xaecb9
leaq 0x10(%rsp), %rdx
pushq $0x5
popq %r8
movq %rbx, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0xdffbd
leaq 0x59e4d(%rip), %rsi     # 0x108b0d
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xe4e62
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 0xf4638
jmp 0xaecff
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0xe5591
movq %rbx, %rdi
movq %r12, %rsi
callq 0xdfd24
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe4b94
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq