// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdx, %r12
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movq (%rdx), %rbp
movq 0x8(%rdx), %r14
movq 0x18(%rdi), %rcx
subq $0x8, %rsp
leaq 0x10(%rsp), %rax
movl $0x1, %edx
movq %rbp, %r8
movq %r14, %r9
pushq %rax
pushq $0x5
pushq $0x1
callq 0xb724a
addq $0x20, %rsp
movl %eax, %r13d
xorl %edi, %edi
callq 0xf0b13
testl %r13d, %r13d
je 0xb6ba9
movq 0x8(%rsp), %r13
leaq 0x1(,%rbp), %r15
addq %r13, %r15
movl 0x1c(%r12), %eax
cmpl $0x7a545874, %eax       # imm = 0x7A545874
je 0xb69c0
movb $0x1, %dl
cmpl $0x69545874, %eax       # imm = 0x69545874
jne 0xb69c2
addq %rbp, %r13
movq 0x18(%rbx), %rdi
addq $0x2, %r13
movq %r15, %rsi
callq 0xef0d5
movzbl %al, %r15d
leaq 0x80d65(%rip), %rsi     # 0x13770d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
testb %r15b, %r15b
sete %dl
movq %r13, %r15
jmp 0xb69c2
xorl %edx, %edx
movl 0x1c(%r12), %eax
cmpl $0x7a545874, %eax       # imm = 0x7A545874
leaq 0x8(%rsp), %r13
je 0xb69da
cmpl $0x69545874, %eax       # imm = 0x69545874
jne 0xb6a01
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movl %edx, %r13d
callq 0xef0d5
movl %r13d, %edx
testb %al, %al
sete %cl
orb %dl, %cl
je 0xb6b0a
incq %r15
leaq 0x8(%rsp), %r13
addq %rbp, %r14
cmpl $0x69545874, 0x1c(%r12) # imm = 0x69545874
jne 0xb6abe
movl %edx, 0x14(%rsp)
movq %r14, %r9
subq %r15, %r9
movq 0x18(%rbx), %rcx
subq $0x8, %rsp
movl $0x1, %eax
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
movl $0x2, %edx
movq %r15, %r8
pushq %r13
pushq %rax
pushq %rax
callq 0xb724a
addq $0x20, %rsp
movl %eax, %ebp
xorl %edi, %edi
callq 0xf0b13
testl %ebp, %ebp
je 0xb6ba9
movq %r13, %r10
movq 0x8(%rsp), %rax
leaq (%r15,%rax), %r13
incq %r13
movq %r14, %r9
subq %r13, %r9
movq 0x18(%rbx), %rcx
subq $0x8, %rsp
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
movl $0x3, %edx
movq %r13, %r8
pushq %r10
pushq $0x2
pushq $0x1
movq %r10, %r15
callq 0xb724a
addq $0x20, %rsp
movl %eax, %ebp
xorl %edi, %edi
callq 0xf0b13
testl %ebp, %ebp
je 0xb6ba9
movq %r15, %rcx
movq 0x8(%rsp), %rax
leaq (%rax,%r13), %r15
incq %r15
movq %rcx, %r13
movl 0x14(%rsp), %edx
xorl %eax, %eax
cmpl $0x69545874, 0x1c(%r12) # imm = 0x69545874
setne %al
leal (%rax,%rax,2), %ebp
addl $0x2, %ebp
subq %r15, %r14
testb %dl, %dl
je 0xb6b2c
movq 0x18(%rbx), %rcx
subq $0x8, %rsp
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
movl $0x4, %edx
movq %r15, %r8
movq %r14, %r9
pushq %r13
pushq %rbp
pushq $0x0
callq 0xb724a
addq $0x20, %rsp
xorl %r12d, %r12d
jmp 0xb6ba1
movzbl %al, %edx
leaq 0x80c0e(%rip), %rsi     # 0x137722
movq %rbx, %rdi
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9b27
movq %r14, 0x8(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %rax, %r12
movq 0x18(%rbx), %rdi
xorl %eax, %eax
movq 0x18(%rsp), %rcx
cmpb $0x0, 0x7(%rcx)
sete %al
subq $0x8, %rsp
movq %r15, %rsi
movq %r14, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rax
callq 0x100d18
addq $0x10, %rsp
testl %eax, %eax
je 0xb6ba1
movq 0x18(%r12), %r9
subq $0x8, %rsp
leaq 0x48(%rsp), %rax
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
movl $0x4, %edx
movq %r12, %rcx
xorl %r8d, %r8d
pushq %rax
pushq %rbp
pushq $0x0
callq 0xb724a
addq $0x20, %rsp
movq %r12, %rdi
callq 0xf0b13
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq