// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x34(%rbp)
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x19140
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x8(%rcx), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
subq -0x20(%rbp), %r9
leaq -0x58(%rbp), %rdx
movl $0x1, %ecx
xorl %eax, %eax
leaq -0x30(%rbp), %rax
movl $0x1, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x5, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x10d2a0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x10c21e
jmp 0x10c43c
movq -0x30(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x69545874, 0x1c(%rax) # imm = 0x69545874
jne 0x10c27c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
callq 0x165060
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
leaq 0xb710a(%rip), %rsi     # 0x1c337d
movb $0x0, %al
callq 0x15b0d0
jmp 0x10c292
movq -0x18(%rbp), %rax
cmpl $0x7a545874, 0x1c(%rax) # imm = 0x7A545874
jne 0x10c290
movl $0x1, -0x34(%rbp)
jmp 0x10c292
movq -0x18(%rbp), %rax
cmpl $0x7a545874, 0x1c(%rax) # imm = 0x7A545874
je 0x10c2ac
movq -0x18(%rbp), %rax
cmpl $0x69545874, 0x1c(%rax) # imm = 0x69545874
jne 0x10c2f7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
callq 0x165060
movb %al, -0x59(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x10c2f5
movzbl -0x59(%rbp), %eax
cmpl $0x0, %eax
je 0x10c2f5
movq -0x8(%rbp), %rdi
movzbl -0x59(%rbp), %edx
leaq 0xb70a9(%rip), %rsi     # 0x1c3392
movb $0x0, %al
callq 0x15bc10
jmp 0x10c43c
jmp 0x10c2f7
movq -0x18(%rbp), %rax
cmpl $0x69545874, 0x1c(%rax) # imm = 0x69545874
jne 0x10c3d9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
subq -0x20(%rbp), %r9
leaq -0x58(%rbp), %rdx
movl $0x2, %ecx
xorl %eax, %eax
leaq -0x30(%rbp), %rax
movl $0x1, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x10d2a0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x10c35a
jmp 0x10c43c
movq -0x30(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
subq -0x20(%rbp), %r9
leaq -0x58(%rbp), %rdx
movl $0x3, %ecx
xorl %eax, %eax
leaq -0x30(%rbp), %rax
movl $0x1, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x2, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x10d2a0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x10c3c1
jmp 0x10c43c
movq -0x30(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x69545874, 0x1c(%rax) # imm = 0x69545874
jne 0x10c3ef
movl $0x2, -0x38(%rbp)
jmp 0x10c3f6
movl $0x5, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
subq -0x20(%rbp), %r9
movl -0x34(%rbp), %r11d
movl -0x38(%rbp), %r10d
leaq -0x58(%rbp), %rdx
movl $0x4, %ecx
xorl %eax, %eax
leaq -0x30(%rbp), %rax
movl $0x0, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x10d2a0
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)