// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/png.c
// Function: handler_text
static void handler_text(deark *c, lctx *d, struct handler_params *hp)
{
	i64 pos;
	i64 endpos;
	i64 field_bytes_consumed;
	int is_compressed = 0;
	de_encoding encoding;
	int ret;
	struct text_chunk_ctx tcc;

	de_zeromem(&tcc, sizeof(struct text_chunk_ctx));

	endpos = hp->dpos+hp->dlen;
	pos = hp->dpos;

	// Keyword
	ret = do_text_field(c, d, &tcc, FIELD_KEYWORD, pos, endpos-pos,
		1, 0, DE_ENCODING_LATIN1, &field_bytes_consumed);
	if(!ret) goto done;
	pos += field_bytes_consumed;
	pos += 1;

	// Compression flag
	if(hp->chunk4cc.id==CODE_iTXt) {
		is_compressed = (int)de_getbyte(pos++);
		de_dbg(c, "compression flag: %d", (int)is_compressed);
	}
	else if(hp->chunk4cc.id==CODE_zTXt) {
		is_compressed = 1;
	}

	// Compression method
	if(hp->chunk4cc.id==CODE_zTXt || hp->chunk4cc.id==CODE_iTXt) {
		u8 cmpr_method;
		cmpr_method = de_getbyte(pos++);
		if(is_compressed && cmpr_method!=0) {
			de_warn(c, "Unsupported text compression type: %d", (int)cmpr_method);
			goto done;
		}
	}

	if(hp->chunk4cc.id==CODE_iTXt) {
		// Language tag
		ret = do_text_field(c, d, &tcc, FIELD_LANG, pos, endpos-pos,
			1, 0, DE_ENCODING_ASCII, &field_bytes_consumed);
		if(!ret) goto done;
		pos += field_bytes_consumed;
		pos += 1;

		// Translated keyword
		ret = do_text_field(c, d, &tcc, FIELD_XKEYWORD, pos, endpos-pos,
			1, 0, DE_ENCODING_UTF8, &field_bytes_consumed);
		if(!ret) goto done;
		pos += field_bytes_consumed;
		pos += 1;
	}

	if(hp->chunk4cc.id==CODE_iTXt)
		encoding = DE_ENCODING_UTF8;
	else
		encoding = DE_ENCODING_LATIN1;

	do_text_field(c, d, &tcc, FIELD_MAIN, pos, endpos-pos,
		0, is_compressed, encoding, &field_bytes_consumed);

done:
	;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r13
movq %rdi, %rbx
leaq 0x10(%rsp), %rdx
andq $0x0, 0x10(%rdx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdx)
movq (%r13), %r14
movq 0x8(%r13), %r15
movq %rsp, %rax
pushq $0x1
popq %r12
movq %rsi, 0x8(%rsp)
movl %r12d, %ecx
movq %r14, %r8
movq %r15, %r9
pushq %rax
pushq $0x5
pushq $0x0
pushq $0x1
callq 0xaf5a0
addq $0x20, %rsp
testl %eax, %eax
je 0xaeefa
addq %r14, %r15
movq (%rsp), %rbp
leaq (%r14,%rbp), %rsi
incq %rsi
movl 0x1c(%r13), %eax
cmpl $0x7a545874, %eax       # imm = 0x7A545874
je 0xaedf0
xorl %r12d, %r12d
cmpl $0x69545874, %eax       # imm = 0x69545874
jne 0xaedd7
addq %r14, %rbp
movq 0x18(%rbx), %rdi
addq $0x2, %rbp
callq 0xe3eb4
movzbl %al, %r12d
leaq 0x7b9f2(%rip), %rsi     # 0x12a7b5
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
movl 0x1c(%r13), %eax
movq %rbp, %rsi
cmpl $0x7a545874, %eax       # imm = 0x7A545874
je 0xaedf0
cmpl $0x69545874, %eax       # imm = 0x69545874
movq %rbx, %rbp
je 0xaedf3
movq %rsi, %r8
jmp 0xaeecd
movq %rbx, %rbp
movq 0x18(%rbp), %rdi
movq %rsi, %rbx
callq 0xe3eb4
testl %r12d, %r12d
je 0xaee2a
testb %al, %al
je 0xaee2a
movzbl %al, %edx
leaq 0x7b9b8(%rip), %rsi     # 0x12a7ca
movq %rbp, %rdi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdf05a
leaq 0x1(%rbx), %r8
cmpl $0x69545874, 0x1c(%r13) # imm = 0x69545874
jne 0xaeecd
movq %r15, %r9
subq %r8, %r9
pushq $0x1
popq %rax
leaq 0x10(%rsp), %rdx
pushq $0x2
popq %rcx
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rsp, %r10
pushq %r10
pushq %rax
pushq $0x0
pushq %rax
callq 0xaf5a0
addq $0x20, %rsp
testl %eax, %eax
je 0xaeefa
movq (%rsp), %rax
leaq (%rbx,%rax), %r14
addq $0x2, %r14
movq %r15, %r9
subq %r14, %r9
leaq 0x10(%rsp), %rdx
pushq $0x3
popq %rcx
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %r8
movq %rsp, %rax
pushq %rax
pushq $0x2
pushq $0x0
pushq $0x1
callq 0xaf5a0
addq $0x20, %rsp
testl %eax, %eax
je 0xaeefa
movq (%rsp), %rax
leaq (%r14,%rax), %r8
incq %r8
xorl %eax, %eax
cmpl $0x69545874, 0x1c(%r13) # imm = 0x69545874
setne %al
leal (%rax,%rax,2), %r10d
addl $0x2, %r10d
jmp 0xaeed1
pushq $0x5
popq %r10
subq %r8, %r15
leaq 0x10(%rsp), %rdx
pushq $0x4
popq %rcx
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %r9
movq %rsp, %rax
pushq %rax
pushq %r10
pushq %r12
pushq $0x0
callq 0xaf5a0
addq $0x20, %rsp
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq