// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rsi, %r12
movq %rdi, %rbx
cmpl $0x3, 0x18(%rsi)
jne 0x603a9
movzbl 0x8(%r12), %edx
orl $0x400, %edx            # imm = 0x400
pushq $0x3
popq %rsi
movq %rbx, %rdi
movq %r14, %rcx
callq 0x5ff37
movq %rax, 0x131df5(%rip)    # 0x192188
cmpb $0x0, 0xcc(%rbx)
je 0x603b0
movq %r14, %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0xe1790
movq 0x131dd8(%rip), %rax    # 0x192188
testq %rax, %rax
jne 0x603ce
movl 0x18(%r12), %esi
movq %rbx, %rdi
xorl %edx, %edx
movq %r14, %rcx
callq 0x5ff37
movq %rax, 0x131dba(%rip)    # 0x192188
movq %rbx, 0x10(%rsp)
leaq 0x8(%rsp), %rbp
pushq $0xa
popq %rbx
movq %r13, 0x8(%rsp)
cmpq %r15, %r13
jge 0x604a6
movq 0x20(%r12), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movl 0x18(%r12), %ecx
movzbl %al, %r13d
cmpl $0x2, %ecx
je 0x6043f
cmpl $0x3, %ecx
jne 0x60475
movq 0x8(%rsp), %rsi
movq 0x131d73(%rip), %rcx    # 0x192188
movq %r12, %rdi
movq %r13, %rdx
callq 0x5ff8c
movq 0x131d61(%rip), %rdi    # 0x192188
pushq $0xd
popq %rsi
callq 0x600ff
movq 0x131d52(%rip), %rdi    # 0x192188
movl %ebx, %esi
callq 0x600ff
jmp 0x6049c
movq 0x8(%rsp), %rsi
movq 0x131d3d(%rip), %rcx    # 0x192188
movq %r12, %rdi
movq %r13, %rdx
callq 0x5ff8c
movq 0x131d2b(%rip), %rdi    # 0x192188
pushq $0xd
popq %rsi
callq 0x60128
movq 0x131d1c(%rip), %rdi    # 0x192188
movl %ebx, %esi
callq 0x60128
jmp 0x6049c
movq 0x20(%r12), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0xe45f4
movq %r14, %rdi
leaq 0xa94d7(%rip), %rsi     # 0x10996b
pushq $0x2
popq %rdx
callq 0xe46ba
addq 0x8(%rsp), %r13
jmp 0x603db
movq 0x131cdb(%rip), %rdi    # 0x192188
testq %rdi, %rdi
je 0x604c8
callq 0x600bc
movq 0x131cca(%rip), %rsi    # 0x192188
movq 0x10(%rsp), %rdi
callq 0x600d5
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq