// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/exectext.c
// Function: asc2com_find_special_chars
static void asc2com_find_special_chars(deark *c, lctx *d,
	struct asc2com_detection_data *idd)
{
	u8 sctype = 0;
	i64 pos;
	u8 b;
	struct asc2com_ctx *a2cc = (struct asc2com_ctx*)d->userdata;
	de_ucstring *tmpstr = NULL;

	if(a2cc->lister==4) {
		// The 'print' lister doesn't do special chars.
		// TODO: Investigate how tabs and other control chars are handled.
		d->chartypes[9] = ETCT_CONTROL;
		goto done;
	}

	if(a2cc->version<0x165) goto done;

	// Tabs. (Sigh.)
	// Before v1.75, they're just graphics characters.
	// v1.75-1.76 attempts to rewrite files so that tabs in the COM file must
	// be printed as a full 8 spaces. (The rewrite step is buggy, but that's
	// not our problem.)
	// v2.00-2.05 just seems to always interpret tabs as 8 spaces.
	if(a2cc->version>=0x175) {
		d->chartypes[9] = ETCT_8SPACES;
	}

	if(a2cc->version>=0x165 && a2cc->version<=0x166) {
		sctype = 1;
	}
	else if(a2cc->version>=0x175 && a2cc->version<=0x176) {
		sctype = 2;
	}
	else if(a2cc->version>=0x200 && a2cc->version<=0x205) {
		sctype = 3;
	}

	if(sctype==0) goto done;

	tmpstr = ucstring_create(c);

	// "TagLine" feature.
	// In v1.75+, these codes are quasi-configurable, but for our purposes
	// they're not. They always get changed to 0x00 and 0xff in the document
	// itself.
	d->chartypes[0x00] = ETCT_SPECIAL;
	d->chartypes[0xff] = ETCT_SPECIAL;
	ucstring_append_sz(tmpstr, " 00 ff", DE_ENCODING_LATIN1);

	if(sctype==2) {
		// Three codes are configurable, and are stored in the COM file outside
		// the document.
		for(pos=8; pos<=12; pos+=2) {
			b = de_getbyte(pos);
			d->chartypes[(UI)b] = ETCT_SPECIAL;
			ucstring_printf(tmpstr, DE_ENCODING_LATIN1, " %02x", (UI)b);
		}
	}
	else if(sctype==3) {
		// (The original TagLine codes are stored in the file, at offset 78-79.
		// We don't use them for anything. I guess that, if we're not translating
		// to UTF-8, they could be used to help construct something a little
		// closer to the original source document.)

		// Four configurable codes:
		for(pos=80; pos<=83; pos++) {
			b = de_getbyte(pos);
			d->chartypes[(UI)b] = ETCT_SPECIAL;
			ucstring_printf(tmpstr, DE_ENCODING_LATIN1, " %02x", (UI)b);
		}
	}

done:
	if(ucstring_isnonempty(tmpstr)) {
		de_dbg(c, "special chars:%s", ucstring_getpsz(tmpstr));
	}
	ucstring_destroy(tmpstr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x4, 0x4(%rax)
jne 0x8ea82
movq -0x10(%rbp), %rax
movb $0x1, 0x41(%rax)
jmp 0x8ec16
movq -0x38(%rbp), %rax
cmpl $0x165, (%rax)          # imm = 0x165
jae 0x8ea93
jmp 0x8ec16
movq -0x38(%rbp), %rax
cmpl $0x175, (%rax)          # imm = 0x175
jb 0x8eaa7
movq -0x10(%rbp), %rax
movb $0x64, 0x41(%rax)
movq -0x38(%rbp), %rax
cmpl $0x165, (%rax)          # imm = 0x165
jb 0x8eac5
movq -0x38(%rbp), %rax
cmpl $0x166, (%rax)          # imm = 0x166
ja 0x8eac5
movb $0x1, -0x19(%rbp)
jmp 0x8eb03
movq -0x38(%rbp), %rax
cmpl $0x175, (%rax)          # imm = 0x175
jb 0x8eae3
movq -0x38(%rbp), %rax
cmpl $0x176, (%rax)          # imm = 0x176
ja 0x8eae3
movb $0x2, -0x19(%rbp)
jmp 0x8eb01
movq -0x38(%rbp), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jb 0x8eaff
movq -0x38(%rbp), %rax
cmpl $0x205, (%rax)          # imm = 0x205
ja 0x8eaff
movb $0x3, -0x19(%rbp)
jmp 0x8eb01
jmp 0x8eb03
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0x8eb11
jmp 0x8ec16
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movb $0x2, 0x38(%rax)
movq -0x10(%rbp), %rax
movb $0x2, 0x137(%rax)
movq -0x40(%rbp), %rdi
leaq 0x120972(%rip), %rsi    # 0x1af4ae
movl $0x5, %edx
callq 0x1715e0
movzbl -0x19(%rbp), %eax
cmpl $0x2, %eax
jne 0x8ebac
movq $0x8, -0x28(%rbp)
cmpq $0xc, -0x28(%rbp)
jg 0x8ebaa
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165060
movb %al, -0x29(%rbp)
movq -0x10(%rbp), %rax
movzbl -0x29(%rbp), %ecx
movl %ecx, %ecx
movb $0x2, 0x38(%rax,%rcx)
movq -0x40(%rbp), %rdi
movzbl -0x29(%rbp), %ecx
movl $0x5, %esi
leaq 0x120920(%rip), %rdx    # 0x1af4b5
movb $0x0, %al
callq 0x171660
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0x8eb57
jmp 0x8ec14
movzbl -0x19(%rbp), %eax
cmpl $0x3, %eax
jne 0x8ec12
movq $0x50, -0x28(%rbp)
cmpq $0x53, -0x28(%rbp)
jg 0x8ec10
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165060
movb %al, -0x29(%rbp)
movq -0x10(%rbp), %rax
movzbl -0x29(%rbp), %ecx
movl %ecx, %ecx
movb $0x2, 0x38(%rax,%rcx)
movq -0x40(%rbp), %rdi
movzbl -0x29(%rbp), %ecx
movl $0x5, %esi
leaq 0x1208ba(%rip), %rdx    # 0x1af4b5
movb $0x0, %al
callq 0x171660
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x8ebbd
jmp 0x8ec12
jmp 0x8ec14
jmp 0x8ec16
movq -0x40(%rbp), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x8ec4a
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x172500
movq -0x48(%rbp), %rdi
movq %rax, %rdx
leaq 0x120878(%rip), %rsi    # 0x1af4bb
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rdi
callq 0x171750
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)