// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0xc0(%rbp), %rsi
movl $0x50, %ecx
movl $0x1, %r8d
movl $0x5, %r9d
movq %rcx, %rdx
callq 0x1664c0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0x10bf68
jmp 0x10c146
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0xc8(%rbp), %rdi
movq %rax, %rdx
leaq 0xb73a5(%rip), %rsi     # 0x1c3336
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
movq (%rax), %rax
addq -0xc0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0xb0(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
movl $0x64, %edx
callq 0x15aa30
leaq -0xb0(%rbp), %rdi
leaq 0x95a11(%rip), %rsi     # 0x1a19e5
callq 0x15aaa0
cmpl $0x0, %eax
je 0x10bff6
leaq -0xb0(%rbp), %rdi
leaq 0xb735d(%rip), %rsi     # 0x1c3349
callq 0x15aaa0
cmpl $0x0, %eax
jne 0x10bffd
movb $0x0, -0xb0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x190e0
movq %rax, -0xb8(%rbp)
cmpq $0x5, -0xb8(%rbp)
jb 0x10c047
leaq -0xb0(%rbp), %rdi
leaq 0x959bd(%rip), %rsi     # 0x1a19e5
callq 0x15d130
cmpl $0x0, %eax
je 0x10c045
movq -0xb8(%rbp), %rax
subq $0x4, %rax
movb $0x0, -0xb0(%rbp,%rax)
jmp 0x10c047
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x165170
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
je 0x10c06c
jmp 0x10c169
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x8(%rcx), %rax
subq -0xc0(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0xc0(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq 0xb72b9(%rip), %rsi     # 0x1c3355
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movzbl 0xd0(%rax), %eax
cmpl $0x0, %eax
je 0x10c0e8
movsbl -0xb0(%rbp), %eax
cmpl $0x0, %eax
je 0x10c0e8
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0x15d4c0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0x958ee(%rip), %rsi     # 0x1a19e5
movl $0x1, %ecx
callq 0x166c60
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0xc0(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movzbl 0x7(%rax), %r9d
movl $0x1, %eax
xorl %r8d, %r8d
cmpl $0x0, %r9d
cmovnel %r8d, %eax
xorl %r8d, %r8d
movl %r8d, %r9d
movq %r9, %r8
movl %eax, (%rsp)
callq 0x17f4f0
movq -0x30(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x166830
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)