// File: /workspace/github_c_makefile_star2_O1/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 %rdi, 0x8(%rsp)
movq 0x90(%rsp), %r14
movq $0x0, (%r14)
testq %r9, %r9
js 0xb72fd
movq %r9, %r15
movq %r8, %rbp
movq %rcx, %r12
movl %edx, %ebx
movq %rsi, %r13
cmpl $0x4, %edx
jne 0xb72ba
cmpl $0x0, 0x4(%r13)
je 0xb72ba
leaq 0x804c0(%rip), %rcx     # 0x137756
movl $0x1, %r14d
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xf0321
xorl %esi, %esi
jmp 0xb769f
movl 0x88(%rsp), %r9d
cmpl $0x0, 0x80(%rsp)
je 0xb7305
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movl $0x1, %r8d
callq 0xefe67
movq %rax, %rsi
cmpl $0x0, 0x34(%rax)
je 0xb749b
movq (%rsi), %rax
decq %rax
movq %rax, (%r14)
jmp 0xb7328
xorl %r14d, %r14d
jmp 0xb76a9
movq %r15, (%r14)
movl $0x1f4, %ecx            # imm = 0x1F4
cmpq %rcx, %r15
cmovlq %r15, %rcx
movq %r12, %rdi
movq %rbp, %rsi
movq %rcx, %rdx
xorl %r8d, %r8d
callq 0xefe67
movq %rax, %rsi
cmpl $0x1, %ebx
movq %rsi, 0x10(%rsp)
jne 0xb7353
movq 0x8(%rsi), %rdi
leaq 0x8040b(%rip), %rsi     # 0x137748
callq 0x181a0
movq 0x10(%rsp), %rsi
testl %eax, %eax
jne 0xb7353
movl $0x1, 0x4(%r13)
leal -0x1(%rbx), %eax
cmpl $0x2, %eax
ja 0xb736d
movl %eax, %eax
leaq 0x7fe80(%rip), %rcx     # 0x1371e4
movslq (%rcx,%rax,4), %r14
addq %rcx, %r14
jmp 0xb7374
leaq 0x7569f(%rip), %r14     # 0x12ca13
cmpl $0x4, %ebx
jne 0xb73b1
cmpl $0x0, 0x8(%r13)
je 0xb73aa
movq 0x10(%r13), %rax
testq %rax, %rax
leaq 0x74adb(%rip), %rdx     # 0x12be69
cmovneq %rax, %rdx
leaq 0x803d4(%rip), %rsi     # 0x13776d
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x10(%rsp), %rsi
cmpl $0x0, (%r13)
jne 0xb73d8
movq 0x18(%rsi), %rdi
callq 0xf74bd
leaq 0x74a81(%rip), %rsi     # 0x12be42
movq 0x8(%rsp), %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9226
movq 0x10(%rsp), %rsi
cmpl $0x1, %ebx
jne 0xb74e1
movq 0x8(%rsi), %rdi
leaq 0x8039a(%rip), %rsi     # 0x137786
movl $0x11, %edx
callq 0x18050
movq 0x10(%rsp), %rsi
testl %eax, %eax
jne 0xb74e1
movq $0x1, 0x8(%r13)
movq $0x0, 0x10(%r13)
movl $0x1, (%r13)
movq 0x8(%rsi), %r14
addq $0x11, %r14
movq %r14, %rdi
callq 0x180e0
leaq 0x20(%rsp), %rdx
movl $0x20, %ecx
movq %r14, %rdi
movq %rax, %rsi
movq %rdx, %r14
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xed004
movl $0x6d696238, %eax       # imm = 0x6D696238
xorl (%r14), %eax
movzbl 0x4(%r14), %ecx
orl %eax, %ecx
je 0xb74a3
movl $0x63747069, %eax       # imm = 0x63747069
xorl 0x20(%rsp), %eax
movzbl 0x24(%rsp), %ecx
orl %eax, %ecx
movq 0x10(%rsp), %rsi
je 0xb74bd
movl 0x20(%rsp), %eax
cmpl $0x636369, %eax         # imm = 0x636369
je 0xb74ce
cmpl $0x706d78, %eax         # imm = 0x706D78
jne 0xb76bb
movl $0x3, 0xc(%r13)
leaq 0x742d5(%rip), %rax     # 0x12b76e
jmp 0xb74dd
xorl %r14d, %r14d
jmp 0xb769f
movl $0x1, 0xc(%r13)
leaq 0x7b694(%rip), %rax     # 0x132b46
movq %rax, 0x10(%r13)
movq 0x10(%rsp), %rsi
jmp 0xb74e1
movl $0x2, 0xc(%r13)
leaq 0x92a0b(%rip), %rax     # 0x149ed7
jmp 0xb74dd
movl $0x4, 0xc(%r13)
leaq 0x7428c(%rip), %rax     # 0x12b769
movq %rax, 0x10(%r13)
movl $0x1, %r14d
cmpl $0x4, %ebx
jne 0xb769f
cmpl $0x0, 0x8(%r13)
je 0xb769f
movq 0x8(%rsp), %rdi
movl $0x1, %esi
callq 0xe9585
addq %rbp, %r15
movq %rbp, %rcx
negq %rcx
movl $0x3, %r14d
leaq 0x20(%rsp), %rbx
movq $0x0, 0x20(%rsp)
addq %r15, %rcx
movq %r12, %rdi
movl $0xa, %esi
movq %rbp, %rdx
movq %rbx, %r8
callq 0xf0057
testl %eax, %eax
je 0xb7685
movq 0x20(%rsp), %rcx
leaq 0x1(%rcx), %rbp
notq %rcx
decl %r14d
jne 0xb751e
movl 0xc(%r13), %eax
movb $0x1, %dil
decl %eax
cmpl $0x3, %eax
ja 0xb75ae
leaq 0x7fc01(%rip), %rdx     # 0x13716c
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movb $0x1, %al
xorl %edi, %edi
xorl %esi, %esi
jmp 0xb75ca
leaq 0x801d3(%rip), %rsi     # 0x137756
jmp 0xb758c
leaq 0x5e561(%rip), %rsi     # 0x115aed
xorl %eax, %eax
jmp 0xb75ca
xorl %esi, %esi
movq 0x8(%rsp), %rax
cmpl $0x2, 0x90(%rax)
setge %dil
setl %al
leaq 0x92916(%rip), %rdx     # 0x149ec2
jmp 0xb75c6
xorl %esi, %esi
movq 0x8(%rsp), %rax
cmpl $0x2, 0x90(%rax)
setl %al
leaq 0x801d2(%rip), %rdx     # 0x137798
cmovgeq %rdx, %rsi
addq %rcx, %r15
testb %al, %al
jne 0xb7611
movq 0x8(%rsp), %r14
movq %rdi, 0x18(%rsp)
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
callq 0xf037a
movq %rax, %rbx
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xed29c
movq %rbx, %rdi
callq 0xf0b13
movq 0x18(%rsp), %rdi
testb %dil, %dil
jne 0xb7685
movq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %rax, %rbx
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xed29c
movl 0xc(%r13), %eax
cmpl $0x2, %eax
je 0xb7667
cmpl $0x1, %eax
jne 0xb767d
movq 0x18(%rbx), %rcx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0xf8388
jmp 0xb767d
movq 0x18(%rbx), %rcx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0xf7eb8
movq %rbx, %rdi
callq 0xf0b13
movq 0x8(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl $0x1, %r14d
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0xf00aa
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
cmpl $0x1, 0x90(%rax)
jg 0xb74e1
movl $0x0, (%r13)
jmp 0xb74e1
nop