// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
cmpl $0x3, 0x18(%rsi)
jne 0x63a23
movzbl 0x8(%r12), %edx
orl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
movl $0x3, %esi
movq %r14, %rcx
callq 0x635ac
movq %rax, 0x12b77c(%rip)    # 0x18f188
cmpb $0x0, 0xcc(%r13)
je 0x63a2a
movq %r14, %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0xec1c4
movq 0x12b75e(%rip), %rax    # 0x18f188
testq %rax, %rax
jne 0x63a48
movl 0x18(%r12), %esi
movq %r13, %rdi
xorl %edx, %edx
movq %r14, %rcx
callq 0x635ac
movq %rax, 0x12b740(%rip)    # 0x18f188
movq %rbx, 0x8(%rsp)
cmpq %r15, %rbx
jge 0x63b46
movq %r13, 0x10(%rsp)
leaq 0x8(%rsp), %r13
leaq 0xb2f94(%rip), %rbp     # 0x1169fb
movq 0x20(%r12), %rdi
movq %r13, %rsi
callq 0xeeb4b
movl 0x18(%r12), %ecx
cmpl $0x2, %ecx
je 0x63ac1
cmpl $0x3, %ecx
jne 0x63aff
movq 0x8(%rsp), %rsi
movzbl %al, %ebx
movq 0x12b6f6(%rip), %rcx    # 0x18f188
movq %r12, %rdi
movq %rbx, %rdx
callq 0x63603
movq 0x12b6e4(%rip), %rdi    # 0x18f188
movl $0xd, %esi
callq 0x6378e
movq 0x12b6d3(%rip), %rdi    # 0x18f188
movl $0xa, %esi
callq 0x6378e
jmp 0x63b27
movq 0x8(%rsp), %rsi
movzbl %al, %ebx
movq 0x12b6b8(%rip), %rcx    # 0x18f188
movq %r12, %rdi
movq %rbx, %rdx
callq 0x63603
movq 0x12b6a6(%rip), %rdi    # 0x18f188
movl $0xd, %esi
callq 0x637dc
movq 0x12b695(%rip), %rdi    # 0x18f188
movl $0xa, %esi
callq 0x637dc
jmp 0x63b27
movq 0x20(%r12), %rdi
movq 0x8(%rsp), %rsi
movzbl %al, %ebx
movq %rbx, %rdx
movq %r14, %rcx
callq 0xef481
movl $0x2, %edx
movq %r14, %rdi
movq %rbp, %rsi
callq 0xef547
addq 0x8(%rsp), %rbx
movq %rbx, 0x8(%rsp)
cmpq %r15, %rbx
jl 0x63a67
movq 0x12b647(%rip), %rax    # 0x18f188
movq 0x10(%rsp), %r13
testq %rax, %rax
je 0x63b62
movq %rax, %rdi
callq 0x63739
movq 0x12b62e(%rip), %rsi    # 0x18f188
movq %r13, %rdi
callq 0x63764
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq