// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/exectext.c
// Function: asc2com_filter_and_write
static void asc2com_filter_and_write(deark *c, lctx *d,
	i64 ipos1, i64 endpos, dbuf *outf)
{
	i64 ipos;
	u8 n;
	static struct ecnv_ctx *ecnv = NULL;

	if(d->proctype==ET_PROCTYPE_FMTCONV_AND_ENCCONV) {
		ecnv = ecnv_create(c, d->proctype, DE_EXTENC_MAKE(d->input_encoding,
			DE_ENCSUBTYPE_PRINTABLE), outf);

		if(c->write_bom) {
			dbuf_write_uchar_as_utf8(outf, 0xfeff);
		}
	}

	if(!ecnv) {
		// This object won't necessarily be used, but that's ok.
		ecnv = ecnv_create(c, d->proctype, DE_ENCODING_UNKNOWN, outf);
	}

	ipos = ipos1;
	while(ipos < endpos) {
		n = dbuf_getbyte_p(d->inf, &ipos);
		if(d->proctype==ET_PROCTYPE_FMTCONV_AND_ENCCONV) {
			exectext_convert_and_write_slice(c, d, ipos, (i64)n, ecnv);
			ecnv_add_rune(ecnv, 13);
			ecnv_add_rune(ecnv, 10);
		}
		else if(d->proctype==ET_PROCTYPE_FMTCONV_ONLY) {
			exectext_convert_and_write_slice(c, d, ipos, (i64)n, ecnv);
			ecnv_add_byte(ecnv, 13);
			ecnv_add_byte(ecnv, 10);
		}
		else { // ET_PROCTYPE_RAW
			dbuf_copy(d->inf, ipos, (i64)n, outf);
			dbuf_write(outf, (const u8*)"\x0d\x0a", 2);
		}
		ipos += (i64)n;
	}

	if(ecnv) {
		ecnv_hard_flush(c, ecnv);
		ecnv_destroy(c, ecnv);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x3, 0x18(%rax)
jne 0x8eef1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
andl $0xff, %edx
orl $0x400, %edx            # imm = 0x400
movq -0x28(%rbp), %rcx
callq 0x8e260
movq %rax, 0x196d4c(%rip)    # 0x225c20
movq -0x8(%rbp), %rax
cmpb $0x0, 0xcc(%rax)
je 0x8eeef
movq -0x28(%rbp), %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0x160cc0
jmp 0x8eef1
cmpq $0x0, 0x196d27(%rip)    # 0x225c20
jne 0x8ef18
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
movq -0x28(%rbp), %rcx
xorl %edx, %edx
callq 0x8e260
movq %rax, 0x196d08(%rip)    # 0x225c20
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x8f01d
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movb %al, -0x31(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x3, 0x18(%rax)
jne 0x8ef8e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movzbl -0x31(%rbp), %eax
movl %eax, %ecx
movq 0x196cbb(%rip), %r8     # 0x225c20
callq 0x8e2f0
movq 0x196caf(%rip), %rdi    # 0x225c20
movl $0xd, %esi
callq 0x8e560
movq 0x196c9e(%rip), %rdi    # 0x225c20
movl $0xa, %esi
callq 0x8e560
jmp 0x8f00c
movq -0x10(%rbp), %rax
cmpl $0x2, 0x18(%rax)
jne 0x8efda
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movzbl -0x31(%rbp), %eax
movl %eax, %ecx
movq 0x196c6f(%rip), %r8     # 0x225c20
callq 0x8e2f0
movq 0x196c63(%rip), %rdi    # 0x225c20
movl $0xd, %esi
callq 0x8e5b0
movq 0x196c52(%rip), %rdi    # 0x225c20
movl $0xa, %esi
callq 0x8e5b0
jmp 0x8f00a
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x30(%rbp), %rsi
movzbl -0x31(%rbp), %eax
movl %eax, %edx
movq -0x28(%rbp), %rcx
callq 0x166070
movq -0x28(%rbp), %rdi
leaq 0x113817(%rip), %rsi    # 0x1a2817
movl $0x2, %edx
callq 0x166170
jmp 0x8f00c
movzbl -0x31(%rbp), %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x8ef20
cmpq $0x0, 0x196bfb(%rip)    # 0x225c20
je 0x8f047
movq -0x8(%rbp), %rdi
movq 0x196bee(%rip), %rsi    # 0x225c20
callq 0x8e4e0
movq -0x8(%rbp), %rdi
movq 0x196bde(%rip), %rsi    # 0x225c20
callq 0x8e520
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)