// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/exectext.c
// Function: doc2com_output
static void doc2com_output(deark *c, lctx *d)
{
	dbuf *tmpdbuf = NULL;

	exectext_check_tpos(c, d);
	if(d->errflag) goto done;

	if(d->is_encrypted) {
		u8 this_byte = 0;
		u8 next_byte = 0;
		u8 init_flag = 0;
		i64 i;

		tmpdbuf = dbuf_create_membuf(c, d->tlen, 0);
		dbuf_enable_wbuffer(tmpdbuf);

		for(i=0; i<d->tlen; i++) {
			u8 b;

			if(init_flag) {
				this_byte = next_byte;
			}
			else {
				this_byte = de_getbyte(d->tpos+i);
				init_flag = 1;
			}

			if(i+1 < d->tlen) {
				next_byte = de_getbyte(d->tpos+i+1);
			}
			else {
				next_byte = 0xff;
			}

			b = this_byte ^ next_byte;
			dbuf_writebyte(tmpdbuf, b);
		}

		dbuf_flush(tmpdbuf);
		d->inf = tmpdbuf;
		d->tpos = 0;
	}

	// Notes:
	//
	// - By default, DOC2COM doesn't support most control characters and
	// extended ASCII characters. It just displays them as spaces.
	// But with the /e option, it supports these characters the way that
	// most programs do.
	// Any undisplayed characters are still in the COM file. While we could
	// detect the non-use of /e, and do something differently, I think it's
	// best to behave as if /e were always used.
	//
	// - V1.3+ has the ability to define arbitrary characters to be special
	// codes that change the colors. A color-change code is just a single
	// character like "^". Doubling a code (e.g. "^^") escapes it. If we're
	// translating to UTF-8, we replace these codes with the Unicode
	// replacement char.

	exectext_extract_default(c, d);

done:
	dbuf_close(tmpdbuf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x8e1d0
movq -0x10(%rbp), %rax
cmpb $0x0, 0x12(%rax)
je 0x8f5b4
jmp 0x8f6c7
movq -0x10(%rbp), %rax
cmpb $0x0, 0x15(%rax)
je 0x8f6ba
movb $0x0, -0x19(%rbp)
movb $0x0, -0x1a(%rbp)
movb $0x0, -0x1b(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
xorl %edx, %edx
callq 0x168020
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x167b90
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jge 0x8f699
cmpb $0x0, -0x1b(%rbp)
je 0x8f616
movb -0x1a(%rbp), %al
movb %al, -0x19(%rbp)
jmp 0x8f636
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
addq -0x28(%rbp), %rsi
callq 0x165060
movb %al, -0x19(%rbp)
movb $0x1, -0x1b(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq -0x10(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jge 0x8f66a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
addq -0x28(%rbp), %rsi
addq $0x1, %rsi
callq 0x165060
movb %al, -0x1a(%rbp)
jmp 0x8f66e
movb $-0x1, -0x1a(%rbp)
movzbl -0x19(%rbp), %eax
movzbl -0x1a(%rbp), %ecx
xorl %ecx, %eax
movb %al, -0x29(%rbp)
movq -0x18(%rbp), %rdi
movzbl -0x29(%rbp), %esi
callq 0x168380
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x8f5f6
movq -0x18(%rbp), %rdi
callq 0x167c30
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x8df30
movq -0x18(%rbp), %rdi
callq 0x1676a0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)