// File: /workspace/github_c_makefile_star2_O3/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 0xb6782
movq %r9, %r15
movq %r8, %rbp
movq %rcx, %r13
movl %edx, %ebx
movq %rsi, %r12
cmpl $0x4, %edx
jne 0xb673f
cmpl $0x0, 0x4(%r12)
je 0xb673f
leaq 0x813c3(%rip), %rcx     # 0x137ade
movl $0x1, %r14d
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xefd48
xorl %esi, %esi
jmp 0xb6b59
movl 0x88(%rsp), %r9d
cmpl $0x0, 0x80(%rsp)
je 0xb678a
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movl $0x1, %r8d
callq 0xef87c
movq %rax, %rsi
cmpl $0x0, 0x34(%rax)
je 0xb67f9
movq (%rsi), %rax
decq %rax
movq %rax, (%r14)
jmp 0xb67ad
xorl %r14d, %r14d
jmp 0xb6b63
movq %r15, (%r14)
movl $0x1f4, %ecx            # imm = 0x1F4
cmpq %rcx, %r15
cmovbq %r15, %rcx
movq %r13, %rdi
movq %rbp, %rsi
movq %rcx, %rdx
xorl %r8d, %r8d
callq 0xef87c
movq %rax, %rsi
cmpl $0x1, %ebx
movq %r12, 0x10(%rsp)
jne 0xb67e6
movq %rsi, %r12
movq 0x8(%rsi), %rdi
leaq 0x8130b(%rip), %rsi     # 0x137ad0
callq 0x181a0
leaq 0x8131c(%rip), %r14     # 0x137aed
testl %eax, %eax
jne 0xb67e1
movq 0x10(%rsp), %rax
movl $0x1, 0x4(%rax)
movq %r12, %rsi
jmp 0xb6856
cmpl $0x2, %ebx
je 0xb6801
cmpl $0x3, %ebx
jne 0xb680a
leaq 0x812eb(%rip), %r14     # 0x137ae2
jmp 0xb6856
xorl %r14d, %r14d
jmp 0xb6b59
leaq 0x6b38a(%rip), %r14     # 0x121b92
jmp 0xb6856
leaq 0x764ea(%rip), %r14     # 0x12ccfb
cmpl $0x4, %ebx
jne 0xb6856
movq 0x10(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0xb6851
movq 0x10(%rax), %rax
testq %rax, %rax
leaq 0x75922(%rip), %rdx     # 0x12c151
cmovneq %rax, %rdx
movq %rsi, %r12
leaq 0x812b8(%rip), %rsi     # 0x137af5
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0xe8617
movq %r12, %rsi
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jne 0xb68c4
movq 0x18(%rsi), %rdi
movq %rsi, %r12
callq 0xf705c
leaq 0x758c1(%rip), %rsi     # 0x12c12a
movq 0x8(%rsp), %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
cmpl $0x1, %ebx
jne 0xb68b2
movq %r12, %r15
movq 0x8(%r12), %rbx
leaq 0x8127f(%rip), %rsi     # 0x137b0e
movl $0x11, %edx
movq %rbx, %rdi
callq 0x18050
movl $0x1, %r14d
testl %eax, %eax
je 0xb69c7
movq %r15, %rsi
jmp 0xb6b59
movl $0x1, %r14d
cmpl $0x4, %ebx
movq %r12, %rsi
jne 0xb6b59
movq 0x10(%rsp), %r12
cmpl $0x0, 0x8(%r12)
je 0xb6a9e
movq %rsi, 0x18(%rsp)
movq 0x8(%rsp), %rdi
movl $0x1, %esi
callq 0xe8a15
addq %rbp, %r15
movq %rbp, %rcx
negq %rcx
movl $0x3, %r14d
leaq 0x20(%rsp), %rbx
movq $0x0, 0x20(%rsp)
addq %r15, %rcx
movq %r13, %rdi
movl $0xa, %esi
movq %rbp, %rdx
movq %rbx, %r8
callq 0xefa77
testl %eax, %eax
je 0xb6b3f
movq 0x20(%rsp), %rcx
leaq 0x1(%rcx), %rbp
notq %rcx
decl %r14d
jne 0xb68fd
addq %rcx, %r15
movl 0xc(%r12), %eax
decl %eax
cmpl $0x3, %eax
ja 0xb6ad3
leaq 0x80bad(%rip), %rcx     # 0x1374fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rax
cmpl $0x2, 0x90(%rax)
jge 0xb6b02
movq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf09c5
movq %rax, %rbx
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xecc3c
movl 0xc(%r12), %eax
cmpl $0x2, %eax
je 0xb6aea
cmpl $0x1, %eax
jne 0xb6b37
movq 0x18(%rbx), %rcx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0xf7eb8
jmp 0xb6b37
movq 0x10(%rsp), %r12
movq $0x1, 0x8(%r12)
movq $0x0, 0x10(%r12)
movl $0x1, (%r12)
addq $0x11, %rbx
movq %rbx, %rdi
callq 0x180e0
leaq 0x20(%rsp), %r14
movl $0x20, %ecx
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xec9c7
movl $0x6d696238, %eax       # imm = 0x6D696238
xorl (%r14), %eax
movzbl 0x4(%r14), %ecx
orl %eax, %ecx
je 0xb6a5d
movl $0x63747069, %eax       # imm = 0x63747069
xorl 0x20(%rsp), %eax
movzbl 0x24(%rsp), %ecx
orl %eax, %ecx
movq %r15, %rsi
je 0xb6a77
movl 0x20(%rsp), %eax
cmpl $0x636369, %eax         # imm = 0x636369
je 0xb6a89
cmpl $0x706d78, %eax         # imm = 0x706D78
jne 0xb6aa9
movl $0x3, 0xc(%r12)
leaq 0x74fe3(%rip), %rax     # 0x12ba3e
jmp 0xb6a99
movl $0x1, 0xc(%r12)
leaq 0x7c4d1(%rip), %rax     # 0x132f3e
movq %rax, 0x10(%r12)
movq %r15, %rsi
jmp 0xb6a9e
movl $0x2, 0xc(%r12)
leaq 0x93a00(%rip), %rax     # 0x14a487
jmp 0xb6a99
movl $0x4, 0xc(%r12)
leaq 0x74fa0(%rip), %rax     # 0x12ba39
movq %rax, 0x10(%r12)
movl $0x1, %r14d
jmp 0xb6b59
movq 0x8(%rsp), %rax
cmpl $0x1, 0x90(%rax)
jg 0xb6a9e
movl $0x0, (%r12)
jmp 0xb6a9e
leaq 0x81016(%rip), %rsi     # 0x137ade
jmp 0xb6b09
leaq 0x5f0cc(%rip), %rsi     # 0x115b9d
jmp 0xb6b09
movq 0x8(%rsp), %rax
cmpl $0x2, 0x90(%rax)
jl 0xb6b3f
leaq 0x81038(%rip), %rsi     # 0x137b20
jmp 0xb6b09
movq 0x18(%rbx), %rcx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0xf7a74
jmp 0xb6b37
leaq 0x93969(%rip), %rsi     # 0x14a472
movq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
callq 0xefda1
movq %rax, %rbx
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xecc3c
movq %rbx, %rdi
callq 0xf052b
movq 0x8(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movl $0x1, %r14d
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0xefaca
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)