// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x28(%rbp), %rax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movq $0x0, -0x50(%rbp)
movq 0x28(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, 0x10(%rbp)
jge 0x10d44d
movl $0x0, -0x4(%rbp)
jmp 0x10d6d8
cmpl $0x4, -0x24(%rbp)
jne 0x10d48c
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x10d48c
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq 0x10(%rbp), %rdx
leaq 0xb5f56(%rip), %rcx     # 0x1c33c6
xorl %eax, %eax
movl %eax, %r8d
movl $0x1, %r9d
callq 0x166be0
movl $0x1, -0x44(%rbp)
jmp 0x10d6c5
cmpl $0x0, 0x18(%rbp)
je 0x10d4d9
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq 0x10(%rbp), %rdx
movl 0x20(%rbp), %r9d
movl $0x1f4, %ecx            # imm = 0x1F4
movl $0x1, %r8d
callq 0x1664c0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0x10d4c5
jmp 0x10d6c5
movq -0x50(%rbp), %rax
movq (%rax), %rcx
subq $0x1, %rcx
movq 0x28(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10d51e
movq 0x10(%rbp), %rcx
movq 0x28(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x1f4, -0x58(%rbp)     # imm = 0x1F4
jle 0x10d4fe
movq $0x1f4, -0x58(%rbp)     # imm = 0x1F4
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x58(%rbp), %rcx
movl 0x20(%rbp), %r9d
xorl %r8d, %r8d
callq 0x1664c0
movq %rax, -0x50(%rbp)
cmpl $0x1, -0x24(%rbp)
jne 0x10d54a
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xb5e85(%rip), %rsi     # 0x1c33b8
callq 0x191a0
cmpl $0x0, %eax
jne 0x10d548
movq -0x20(%rbp), %rax
movl $0x1, 0x4(%rax)
jmp 0x10d54a
movl -0x24(%rbp), %eax
movl %eax, -0x5c(%rbp)
subl $0x1, %eax
je 0x10d56b
jmp 0x10d557
movl -0x5c(%rbp), %eax
subl $0x2, %eax
je 0x10d578
jmp 0x10d561
movl -0x5c(%rbp), %eax
subl $0x3, %eax
je 0x10d585
jmp 0x10d592
leaq 0xb5e63(%rip), %rax     # 0x1c33d5
movq %rax, -0x40(%rbp)
jmp 0x10d59d
leaq 0xa01bc(%rip), %rax     # 0x1ad73b
movq %rax, -0x40(%rbp)
jmp 0x10d59d
leaq 0xb5e3e(%rip), %rax     # 0x1c33ca
movq %rax, -0x40(%rbp)
jmp 0x10d59d
leaq 0xab23e(%rip), %rax     # 0x1b87d7
movq %rax, -0x40(%rbp)
cmpl $0x4, -0x24(%rbp)
jne 0x10d5f1
movq -0x20(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x10d5f1
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x10d5ce
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x10d5db
leaq 0xaa658(%rip), %rax     # 0x1b7c2d
movq %rax, -0x70(%rbp)
jmp 0x10d5db
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rdx
leaq 0xb5df3(%rip), %rsi     # 0x1c33dd
movb $0x0, %al
callq 0x15b0d0
cmpl $0x4, -0x24(%rbp)
jne 0x10d600
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x10d636
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172500
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rdx
movq %rax, %rcx
leaq 0xaa5d7(%rip), %rsi     # 0x1b7c06
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x44(%rbp)
cmpl $0x1, -0x24(%rbp)
jne 0x10d678
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xb5da4(%rip), %rsi     # 0x1c33f6
movl $0x11, %edx
callq 0x19050
cmpl $0x0, %eax
jne 0x10d676
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x10d6f0
jmp 0x10d678
cmpl $0x4, -0x24(%rbp)
jne 0x10d6c3
movq -0x20(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x10d6c3
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq 0x10(%rbp), %r9
callq 0x10d860
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x10d6c5
jmp 0x10d6c5
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x166830
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)