// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/png.c
// Function: do_unc_text_field
static int do_unc_text_field(deark *c, lctx *d,
	struct text_chunk_ctx *tcc, int which_field,
	dbuf *srcdbuf, i64 pos, i64 bytes_avail,
	int is_nul_terminated, de_encoding encoding, i64 *bytes_consumed)
{
	const char *name;
	int retval = 0;
	struct de_stringreaderdata *srd = NULL;

	*bytes_consumed = 0;
	if(bytes_avail<0) return 0;

	if(which_field==FIELD_MAIN && tcc->is_xmp) {
		// The main field is never NUL terminated, so we can do this right away.
		dbuf_create_file_from_slice(srcdbuf, pos, bytes_avail, "xmp",
			NULL, DE_CREATEFLAG_IS_AUX);
		retval = 1;
		goto done;
	}

	if(is_nul_terminated) {
		srd = dbuf_read_string(srcdbuf, pos, bytes_avail, DE_DBG_MAX_STRLEN,
			DE_CONVFLAG_STOP_AT_NUL, encoding);

		if(!srd->found_nul) goto done;
		*bytes_consumed = srd->bytes_consumed - 1;
	}
	else {
		i64 bytes_to_scan;

		*bytes_consumed = bytes_avail;

		bytes_to_scan = bytes_avail;
		if(bytes_to_scan>DE_DBG_MAX_STRLEN) bytes_to_scan = DE_DBG_MAX_STRLEN;
		srd = dbuf_read_string(srcdbuf, pos, bytes_to_scan, bytes_to_scan, 0, encoding);
	}

	if(which_field==FIELD_KEYWORD) {
		if(!de_strcmp(srd->sz, "XML:com.adobe.xmp")) {
			tcc->is_xmp = 1;
		}
	}

	switch(which_field) {
	case FIELD_KEYWORD: name="keyword"; break;
	case FIELD_LANG: name="language"; break;
	case FIELD_XKEYWORD: name="translated keyword"; break;
	default: name="text";
	}

	if(which_field==FIELD_MAIN && tcc->is_im_generic_profile) {
		de_dbg(c, "generic profile type: %s",
			tcc->im_generic_profile_type_name?tcc->im_generic_profile_type_name:"?");
	}

	if(!(which_field==FIELD_MAIN && tcc->suppress_debugstr)) {
		de_dbg(c, "%s: \"%s\"", name, ucstring_getpsz(srd->str));
	}
	retval = 1;

	if(which_field==FIELD_KEYWORD) {
		if(!de_strncmp(srd->sz, "Raw profile type ", 17)) {
			on_im_generic_profile_keyword(c, d, tcc, srd);
		}
	}

	if(which_field==FIELD_MAIN && tcc->is_im_generic_profile) {
		de_dbg_indent(c, 1);
		on_im_generic_profile_main(c, d, tcc, srcdbuf, pos, bytes_avail);
		de_dbg_indent(c, -1);
		goto done;
	}

done:
	de_destroy_stringreaderdata(c, srd);
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq 0x90(%rsp), %r15
andq $0x0, (%r15)
testq %r9, %r9
js 0xaf750
movq %r9, %r12
movq %r8, %rbx
movq %rcx, %r13
movl %edx, %r14d
movq %rsi, %rbp
cmpl $0x4, %edx
jne 0xaf70a
cmpl $0x0, 0x4(%rbp)
je 0xaf70a
movq %rdi, %r14
leaq 0x7b115(%rip), %rcx     # 0x12a7fe
pushq $0x1
popq %rbp
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %r8d, %r8d
movl %ebp, %r9d
callq 0xe4e0b
movq %r14, %rdi
xorl %esi, %esi
jmp 0xaf8ed
movq %rdi, 0x8(%rsp)
movl 0x88(%rsp), %r9d
cmpl $0x0, 0x80(%rsp)
je 0xaf757
pushq $0x1
popq %r8
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xe495c
movq %rax, %rsi
cmpl $0x0, 0x34(%rax)
je 0xaf7c9
movq (%rsi), %rax
decq %rax
movq %rax, (%r15)
jmp 0xaf77a
xorl %ebp, %ebp
jmp 0xaf8f2
movq %r12, (%r15)
movl $0x1f4, %ecx            # imm = 0x1F4
cmpq %rcx, %r12
cmovbq %r12, %rcx
movq %r13, %rdi
movq %rbx, %rsi
movq %rcx, %rdx
xorl %r8d, %r8d
callq 0xe495c
movq %rax, %rsi
cmpl $0x1, %r14d
movq %rbp, 0x10(%rsp)
jne 0xaf7b4
movq %rsi, %r15
movq 0x8(%rsi), %rdi
leaq 0x7b05d(%rip), %rsi     # 0x12a7f0
callq 0x181a0
leaq 0x7b06e(%rip), %rbp     # 0x12a80d
testl %eax, %eax
jne 0xaf7af
movq 0x10(%rsp), %rax
movl $0x1, 0x4(%rax)
movq %r15, %rsi
jmp 0xaf827
cmpl $0x2, %r14d
je 0xaf7d0
cmpl $0x3, %r14d
jne 0xaf7d9
leaq 0x7b03b(%rip), %rbp     # 0x12a802
jmp 0xaf827
xorl %ebp, %ebp
jmp 0xaf8e8
leaq 0x652cb(%rip), %rbp     # 0x114aa2
jmp 0xaf827
leaq 0x702ab(%rip), %rbp     # 0x11fa8b
cmpl $0x4, %r14d
jne 0xaf827
movq 0x10(%rsp), %r15
cmpl $0x0, 0x8(%r15)
je 0xaf821
movq 0x10(%r15), %rax
testq %rax, %rax
leaq 0x6f6e1(%rip), %rdx     # 0x11eee1
cmovneq %rax, %rdx
movq %rsi, 0x18(%rsp)
leaq 0x7b005(%rip), %rsi     # 0x12a815
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rsp), %rsi
cmpl $0x0, (%r15)
jne 0xaf881
movq 0x18(%rsi), %rdi
movq %rsi, %r15
callq 0xeb7e4
leaq 0x6f680(%rip), %rsi     # 0x11eeba
movq 0x8(%rsp), %rdi
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
cmpl $0x1, %r14d
jne 0xaf878
movq %r15, %r12
movq 0x8(%r15), %rbx
leaq 0x7afce(%rip), %rsi     # 0x12a82e
pushq $0x11
popq %rdx
movq %rbx, %rdi
callq 0x18050
testl %eax, %eax
je 0xaf903
movq %r12, %rsi
jmp 0xaf8e5
cmpl $0x4, %r14d
movq %r15, %rsi
jne 0xaf8e5
movq 0x10(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0xaf8e5
movq %rsi, 0x18(%rsp)
pushq $0x1
popq %rsi
movq 0x8(%rsp), %rdi
callq 0xdeba7
addq %rbx, %r12
pushq $0x3
popq %rbp
pushq $0xa
popq %r14
leaq 0x20(%rsp), %r15
subl $0x1, %ebp
jb 0xaf9b2
andq $0x0, 0x20(%rsp)
movq %r12, %rcx
subq %rbx, %rcx
movq %r13, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movq %r15, %r8
callq 0xe4b21
testl %eax, %eax
je 0xafb28
movq 0x20(%rsp), %rbx
incq %rbx
jmp 0xaf8ad
pushq $0x1
popq %rbp
movq 0x8(%rsp), %rdi
callq 0xe4b94
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %r15
movq $0x1, 0x8(%r15)
andq $0x0, 0x10(%r15)
movl $0x1, (%r15)
addq $0x11, %rbx
movq %rbx, %rdi
callq 0x180e0
leaq 0x20(%rsp), %r14
pushq $0x20
popq %rcx
pushq $0x1
popq %rbp
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
xorl %r8d, %r8d
movl %ebp, %r9d
callq 0xe1f1b
leaq 0x76313(%rip), %rsi     # 0x125c61
pushq $0x5
popq %rdx
movq %r14, %rdi
callq 0x18230
testl %eax, %eax
je 0xafa3f
leaq 0x8d63a(%rip), %rsi     # 0x13cfa2
leaq 0x20(%rsp), %rdi
pushq $0x5
popq %rdx
callq 0x18230
testl %eax, %eax
je 0xafa54
movl 0x20(%rsp), %eax
cmpl $0x636369, %eax         # imm = 0x636369
movq %r12, %rsi
je 0xafa73
cmpl $0x706d78, %eax         # imm = 0x706D78
jne 0xafa8f
movq 0x10(%rsp), %rcx
movl $0x3, 0xc(%rcx)
leaq 0x6ee21(%rip), %rax     # 0x11e7ce
jmp 0xafa86
subq %rbx, %r12
movq 0x10(%rsp), %rbp
movl 0xc(%rbp), %eax
decl %eax
cmpl $0x3, %eax
ja 0xafac0
leaq 0x7a84d(%rip), %rcx     # 0x12a21c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq 0x8(%rsp), %r15
jmpq *%rax
cmpl $0x2, 0x90(%r15)
jge 0xafaf2
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe59cd
movq %rax, %r14
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xe214f
movl 0xc(%rbp), %eax
cmpl $0x2, %eax
je 0xafadc
cmpl $0x1, %eax
jne 0xafb20
movq 0x18(%r14), %rcx
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0xec5fa
jmp 0xafb20
movl $0x1, 0xc(%r15)
leaq 0x76218(%rip), %rax     # 0x125c66
movq %rax, 0x10(%r15)
jmp 0xafa6b
movq 0x10(%rsp), %rcx
movl $0x2, 0xc(%rcx)
leaq 0x8d550(%rip), %rax     # 0x13cfb7
movq %rax, 0x10(%rcx)
movq %r12, %rsi
jmp 0xaf8e8
movq 0x10(%rsp), %rcx
movl $0x4, 0xc(%rcx)
leaq 0x6ed43(%rip), %rax     # 0x11e7c9
movq %rax, 0x10(%rcx)
jmp 0xaf8e8
movq 0x8(%rsp), %rdi
cmpl $0x1, 0x90(%rdi)
jg 0xaf8ed
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
jmp 0xaf8ed
leaq 0x7ad49(%rip), %rsi     # 0x12a7fe
jmp 0xafaf9
leaq 0x5904f(%rip), %rsi     # 0x108b0d
jmp 0xafaf9
movq 0x8(%rsp), %rax
cmpl $0x2, 0x90(%rax)
jl 0xafb28
leaq 0x7ad6b(%rip), %rsi     # 0x12a840
movq 0x8(%rsp), %r15
jmp 0xafaf9
movq 0x18(%r14), %rcx
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0xec1bf
jmp 0xafb20
leaq 0x8d4a9(%rip), %rsi     # 0x13cfa2
pushq $0x1
popq %rcx
movq %r15, %rdi
xorl %edx, %edx
callq 0xe4e62
movq %rax, %r14
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xe214f
movq %r14, %rdi
callq 0xe5591
pushq $-0x1
popq %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
pushq $0x1
popq %rbp
jmp 0xaf8ed