// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/png.c
// Function: on_im_generic_profile_main
static void on_im_generic_profile_main(deark *c, lctx *d,
	struct text_chunk_ctx *tcc, dbuf *inf, i64 pos1, i64 len)
{
	int k;
	i64 pos = pos1;
	i64 dlen;
	int dump_to_file = 0;
	int decode_to_membuf = 0;
	const char *ext = NULL;

	// Skip the first three lines
	for(k=0; k<3; k++) {
		int ret;
		i64 foundpos = 0;
		ret = dbuf_search_byte(inf, 0x0a, pos, pos1+len-pos, &foundpos);
		if(!ret) goto done;
		pos = foundpos+1;
	}
	dlen = pos1+len-pos;

	if(tcc->im_generic_profile_type==PROFILETYPE_XMP) {
		dump_to_file = 1;
		ext = "xmp";
	}
	else if(tcc->im_generic_profile_type==PROFILETYPE_8BIM) {
		decode_to_membuf = 1;
	}
	else if(tcc->im_generic_profile_type==PROFILETYPE_IPTC) {
		if(c->extract_level>=2) {
			dump_to_file = 1;
			ext = "iptc";
		}
		else {
			decode_to_membuf = 1;
		}
	}
	else if(tcc->im_generic_profile_type==PROFILETYPE_ICC) {
		dump_to_file = 1;
		ext = "icc";
	}
	else {
		if(c->extract_level>=2) {
			dump_to_file = 1;
			ext = "profile.bin";
		}
	}

	if(dump_to_file) {
		dbuf *outf;
		outf = dbuf_create_output_file(c, ext?ext:"bin", NULL, DE_CREATEFLAG_IS_AUX);
		de_decode_base16(c, inf, pos, dlen, outf, 0);
		dbuf_close(outf);
	}

	if(decode_to_membuf) {
		dbuf *tmpf;

		tmpf = dbuf_create_membuf(c, 0, 0);
		de_decode_base16(c, inf, pos, dlen, tmpf, 0);

		if(tcc->im_generic_profile_type==PROFILETYPE_8BIM) {
			fmtutil_handle_photoshop_rsrc(c, tmpf, 0, tmpf->len, 0x0);
		}
		else if(tcc->im_generic_profile_type==PROFILETYPE_IPTC) {
			fmtutil_handle_iptc(c, tmpf, 0, tmpf->len, 0x0);
		}

		dbuf_close(tmpf);
	}

done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x10d8fd
movq $0x0, -0x68(%rbp)
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq -0x30(%rbp), %rcx
subq -0x40(%rbp), %rcx
movl $0xa, %esi
leaq -0x68(%rbp), %r8
callq 0x1667a0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jne 0x10d8e6
jmp 0x10dac2
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x10d8a8
movq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x3, 0xc(%rax)
jne 0x10d92e
movl $0x1, -0x4c(%rbp)
leaq 0xb5aa1(%rip), %rax     # 0x1c33c6
movq %rax, -0x58(%rbp)
jmp 0x10d9ba
movq -0x18(%rbp), %rax
cmpl $0x1, 0xc(%rax)
jne 0x10d941
movl $0x1, -0x50(%rbp)
jmp 0x10d9b8
movq -0x18(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x10d975
movq -0x8(%rbp), %rax
cmpl $0x2, 0x90(%rax)
jl 0x10d96c
movl $0x1, -0x4c(%rbp)
leaq 0xc85bc(%rip), %rax     # 0x1d5f22
movq %rax, -0x58(%rbp)
jmp 0x10d973
movl $0x1, -0x50(%rbp)
jmp 0x10d9b6
movq -0x18(%rbp), %rax
cmpl $0x4, 0xc(%rax)
jne 0x10d993
movl $0x1, -0x4c(%rbp)
leaq 0x94058(%rip), %rax     # 0x1a19e5
movq %rax, -0x58(%rbp)
jmp 0x10d9b4
movq -0x8(%rbp), %rax
cmpl $0x2, 0x90(%rax)
jl 0x10d9b2
movl $0x1, -0x4c(%rbp)
leaq 0xb5a5a(%rip), %rax     # 0x1c3408
movq %rax, -0x58(%rbp)
jmp 0x10d9b4
jmp 0x10d9b6
jmp 0x10d9b8
jmp 0x10d9ba
cmpl $0x0, -0x4c(%rbp)
je 0x10da2e
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x10d9dc
movq -0x58(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x10d9ec
leaq 0xb3824(%rip), %rax     # 0x1c1207
movq %rax, -0x88(%rbp)
jmp 0x10d9ec
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x166c60
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x70(%rbp), %r8
xorl %r9d, %r9d
callq 0x162030
movq -0x70(%rbp), %rdi
callq 0x1676a0
cmpl $0x0, -0x50(%rbp)
je 0x10dac0
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x168020
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x78(%rbp), %r8
xorl %r9d, %r9d
callq 0x162030
movq -0x18(%rbp), %rax
cmpl $0x1, 0xc(%rax)
jne 0x10da8f
movq -0x8(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rcx
xorl %eax, %eax
movl %eax, %edx
xorl %r8d, %r8d
callq 0x173bd0
jmp 0x10dab7
movq -0x18(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x10dab5
movq -0x8(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rcx
xorl %eax, %eax
movl %eax, %edx
xorl %r8d, %r8d
callq 0x173700
jmp 0x10dab7
movq -0x78(%rbp), %rdi
callq 0x1676a0
jmp 0x10dac2
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)