// File: /workspace/github_c_makefile_star2_O3/aap[P]rx-0/common/fe.c
// Function: threadmain
int
threadmain(int argc, char *argv[])
{
	char chu;
	Word t;

	initmach();

	raw(0);
	erasec = tiosaved.c_cc[VERASE];
	killc = tiosaved.c_cc[VKILL];
	intrc = tiosaved.c_cc[VINTR];

	setjmp(errjmp);
	nbuf = 0;
	opened = 0;
	regopened = 0;
	resetexp();
	flags = 0;
	curmode = permmode;
	number = 0;
	hasnum = 0;
//	linemode = 0;

	for(;;){
		if(hasinput(0)){
			ch = tyi();
		}else{
			if(started && (!isrunning() || isstopped())){
				t = examinereg(REG_PC);
				/* TODO: maybe do something different on stop? */
				typestrnl("\n");
				typenum(t);
				if(!isrunning())
					typestr(">>");
				else
					typestr("<<");
				t = examine(t);
				prword(MODE_SYM, t);
				typestr("   ");

				/* show E */
				t = t&ADDRMASK;
				dot = t;
				praddr(MODE_SYM, dot);
				typestr("/   ");
				t = examine(t);
				prword(MODE_SYM, t);
				q = t;
				typestr("    ");

				started = 0;
			}
			usleep(1000);
			continue;
		}
		chu = toupper(ch);
		if(ch == erasec || ch == CTL('H') || ch == CTL('?')){
			/* can't backspace in all cases */
			if((flags & CF) || nbuf <= 0)
				err("\n");
			typestr("\b \b");
			nbuf--;
		}else if(ch == killc)
			err("");
		else if(ch == intrc)
			break;
		else{
			tyo(ch);

			if((flags & CF) == 0 &&
			   (ch >= 'A' && ch <= 'Z' ||
			    ch >= 'a' && ch <= 'z')){
				ins();
			}else switch(chu){
			case CTL('D'):
				err("XXX? ");
				break;

			case '.': case '%': case '$':
				ins();
				break;

			case '0': case '1': case '2': case '3':
			case '4': case '5': case '6': case '7':
			case '8': case '9':
				if(flags & CF){
					num();
					goto keepflags;
				}
				ins();
				break;

			case 'G':
				if(!endword(&t))
					t = starta;
				if(flags & CCF)
					starta = t & ADDRMASK;
				if(hasnum && number == 0)
					cpu_setpc(t);
				else
					cpu_start(t);
				started = 1;
				break;
			case 'P':
				endword(&t);
				cpu_cont();
				started = 1;
				break;
			case CTL('N'):
				endword(&t);
				if(flags & CF)
					cpu_nextmem();
				else
					cpu_nextinst();
				started = 1;
				break;
			case CTL('Z'):
				nbuf = 0;
				if(flags & CF)
					cpu_stopmem();
				else
					cpu_stopinst();
				break;

			case 'Q':
				combine(q);
				break;

			case 'Z':
				if(flags & CCF)
					zerocore();
				else
					err(" ?? ");
				break;

			case ALT:
				if(flags & CF)
					flags |= CCF;
				flags |= CF;
				goto keepflags;

			case ':':
				defsym(bufstart, as.gotexp ? as.exp : dot);
				nbuf = 0;
				typestr("   ");
				resetexp();
				break;

			/* expressions */
			case ' ':
			case '+':
			case '-':
			case '*':
			case '|':
				if(!parse(&t)){
					if(ch == '-')
						as.op = '-';
					break;
				}
				combine(t);
				as.op = ch;
				break;

			/* opening */
			case '/':
				if(flags & CF){
					aclose(0);
					aropen(MODE_NUM);
				}else{
					aclose(0);
					dot = addr;
					aopen(curmode);
				}
				break;
			case '\\':
				aclose(0);
				aopen(curmode);
				break;
			case '[':
				aclose(0);
				dot = addr;
				aopen(MODE_NUM);
				break;
			case ']':
				aclose(0);
				dot = addr;
				aopen(MODE_SYM);
				break;
			case '^':
				typestrnl("\n");
				aclose(1);
				dot = (dot-1) & ADDRMASK;
				addr = dot;
				propen(addr);
				aopen(curmode);
				break;
			case CTL('J'):
				aclose(1);
				dot = (dot+1) & ADDRMASK;
				addr = dot;
				propen(addr);
				aopen(curmode);
				break;

			case CTL('M'):
				tyo('\n');
				aclose(1);
				curmode = permmode;
				break;

			/* typeout */
			case '_':
				typeout(MODE_SYM);
				break;
			case '=':
				typeout(MODE_NUM);
				break;

			default:
				err(" ?? ");
				break;
			}
		}
		flags = 0;
		number = 0;
		hasnum = 0;
keepflags:;
	}

	quit();

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x4aea
xorl %r12d, %r12d
movl %r12d, %edi
callq 0x25eb
movb 0xa38c(%rip), %al       # 0xd253
movb %al, 0xa5eb(%rip)       # 0xd4b8
movb 0xa381(%rip), %al       # 0xd254
movb %al, 0xa5e0(%rip)       # 0xd4b9
movb 0xa372(%rip), %al       # 0xd251
movb %al, 0xa5d5(%rip)       # 0xd4ba
leaq 0xa464(%rip), %rdi      # 0xd350
callq 0x21b0
movl %r12d, 0xa52c(%rip)     # 0xd424
movl %r12d, 0xa5ad(%rip)     # 0xd4ac
movl %r12d, 0xa5ae(%rip)     # 0xd4b4
movq $0x0, 0xa51b(%rip) # 0xd42c
movl %r12d, 0xa51c(%rip)     # 0xd434
movl %r12d, 0xa59d(%rip)     # 0xd4bc
movl 0x5307(%rip), %eax      # 0x822c
movl %eax, 0xa57d(%rip)      # 0xd4a8
movl %r12d, 0xa4e6(%rip)     # 0xd418
movl %r12d, 0xa4e7(%rip)     # 0xd420
leaq 0x2238(%rip), %r13      # 0x5178
leaq 0x2235(%rip), %rbx      # 0x517c
movl %r12d, %edi
callq 0x363b
testl %eax, %eax
je 0x2ff2
movl %r12d, %edi
leaq -0x2d(%rbp), %rsi
movl $0x1, %edx
callq 0x2180
movsbq -0x2d(%rbp), %r14
movb %r14b, 0xa4a8(%rip)     # 0xd41c
callq 0x2030
cmpb 0xa538(%rip), %r14b     # 0xd4b8
je 0x2f96
movl %r14d, %ecx
movzbl %cl, %edx
cmpl $0x8, %edx
je 0x2f96
cmpl $0x1f, %edx
jne 0x3070
testb $0x1, 0xa51f(%rip)      # 0xd4bc
jne 0x35c3
cmpl $0x0, 0xa47a(%rip)      # 0xd424
jle 0x35c3
movb $0x8, %cl
movl $0x1, %eax
movq %rax, %r14
movsbl %cl, %edi
callq 0x26ee
movb (%r14,%rbx), %cl
incq %r14
movq %r14, %rax
cmpq $0x4, %r14
jne 0x2fb7
decl 0xa44c(%rip)            # 0xd424
movl %r12d, 0xa4dd(%rip)     # 0xd4bc
movl %r12d, 0xa432(%rip)     # 0xd418
movl %r12d, 0xa433(%rip)     # 0xd420
jmp 0x2f47
cmpl $0x0, 0xa4c7(%rip)      # 0xd4c0
je 0x3250
callq 0x4168
testl %eax, %eax
je 0x3015
callq 0x4174
testl %eax, %eax
je 0x3250
movl %r12d, %edi
callq 0x41db
movl %eax, %r14d
movl %eax, -0x2c(%rbp)
movl $0xa, %edi
callq 0x26ee
movl %r14d, %edi
callq 0x276a
callq 0x4168
testl %eax, %eax
je 0x314e
movb $0x3c, %al
movl %r12d, %ecx
movq %rcx, %r15
leaq 0x1(%rcx), %r12
movsbl %al, %edi
callq 0x26ee
leaq 0x2112(%rip), %rax      # 0x516f
movb 0x1(%r15,%rax), %al
movq %r12, %rcx
cmpq $0x2, %r12
jne 0x3047
jmp 0x3177
cmpb 0xa443(%rip), %cl       # 0xd4b9
je 0x35dd
cmpb 0xa438(%rip), %cl       # 0xd4ba
je 0x35e6
movq (%rax), %rax
movl (%rax,%r14,4), %r14d
movsbl %cl, %edi
callq 0x26ee
movl 0xa41f(%rip), %eax      # 0xd4bc
testb $0x1, %al
jne 0x30c7
movb 0xa375(%rip), %cl       # 0xd41c
movl %ecx, %edx
andb $-0x21, %dl
addb $-0x41, %dl
cmpb $0x19, %dl
ja 0x30c7
movslq 0xa369(%rip), %rax      # 0xd424
leaq 0xa1be(%rip), %rsi      # 0xd280
movb %cl, (%rax,%rsi)
jmp 0x311d
movsbl %r14b, %ecx
movl %ecx, %edx
cmpl $0x4f, %ecx
jg 0x325f
addl $-0xa, %edx
cmpl $0x3d, %edx
ja 0x35eb
movl %eax, %r14d
andl $0x1, %r14d
movl %edx, %ecx
leaq 0x1f12(%rip), %rdx      # 0x5004
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
testl %r14d, %r14d
jne 0x328c
movb 0xa312(%rip), %al       # 0xd41c
movslq 0xa313(%rip), %rcx      # 0xd424
leaq 0xa168(%rip), %rsi      # 0xd280
movb %al, (%rcx,%rsi)
movl %ecx, %eax
incl %eax
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rcx
sarq $0x26, %rdx
addl %ecx, %edx
imull $0xc8, %edx, %ecx
subl %ecx, %eax
movl %eax, 0xa2e1(%rip)      # 0xd424
cltq
movb $0x0, (%rax,%rsi)
jmp 0x2fd8
movb $0x3e, %al
movl %r12d, %ecx
movq %rcx, %r15
leaq 0x1(%rcx), %r12
movsbl %al, %edi
callq 0x26ee
leaq 0x2003(%rip), %rax      # 0x516c
movb 0x1(%r15,%rax), %al
movq %r12, %rcx
cmpq $0x2, %r12
jne 0x3153
movzwl %r14w, %edi
callq 0x418f
movl %eax, %r14d
movl $0x2, %edi
movl %eax, %esi
callq 0x2b89
movb $0x20, %cl
movl $0x1, %eax
movq %rax, %r15
movsbl %cl, %edi
callq 0x26ee
movb (%r15,%r13), %cl
incq %r15
movq %r15, %rax
cmpq $0x4, %r15
jne 0x3196
movw %r14w, 0xa26f(%rip)     # 0xd428
movzwl %r14w, %r14d
movl $0x2, %edi
movl %r14d, %esi
callq 0x2c62
movb $0x2f, %al
xorl %ecx, %ecx
leaq 0x1f9d(%rip), %r13      # 0x5172
movq %rcx, %r15
leaq 0x1(%rcx), %r12
movsbl %al, %edi
callq 0x26ee
movb 0x1(%r15,%r13), %al
movq %r12, %rcx
cmpq $0x4, %r12
jne 0x31d5
movl %r14d, %edi
callq 0x418f
movl %eax, %r14d
movl %eax, -0x2c(%rbp)
movl $0x2, %edi
movl %eax, %esi
callq 0x2b89
movl %r14d, 0xa291(%rip)     # 0xd4a4
movb $0x20, %al
xorl %r12d, %r12d
movl %r12d, %ecx
leaq 0x1f55(%rip), %r13      # 0x5177
movq %rcx, %r14
leaq 0x1(%rcx), %r15
movsbl %al, %edi
callq 0x26ee
movb 0x1(%r14,%r13), %al
movq %r15, %rcx
cmpq $0x4, %r15
jne 0x3222
movl $0x0, 0xa277(%rip)      # 0xd4c0
leaq 0x1f28(%rip), %r13      # 0x5178
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x23e0
jmp 0x2f47
addl $-0x50, %edx
cmpl $0xf, %edx
ja 0x32ba
movl %edx, %ecx
leaq 0x1e8c(%rip), %rdx      # 0x50fc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq -0x2c(%rbp), %rdi
callq 0x2b2e
callq 0x4a75
jmp 0x353e
movl 0x4f96(%rip), %eax      # 0x8228
imull 0xa17f(%rip), %eax      # 0xd418
movsbl 0xa17c(%rip), %ecx      # 0xd41c
addl %ecx, %eax
addl $-0x30, %eax
movl %eax, 0xa16d(%rip)      # 0xd418
movl $0x1, 0xa16b(%rip)      # 0xd420
jmp 0x2f47
cmpl $0x7c, %ecx
jne 0x35f9
leaq -0x2c(%rbp), %rdi
callq 0x2a30
testl %eax, %eax
je 0x32ea
movl -0x2c(%rbp), %edi
callq 0x2add
movsbl 0xa13d(%rip), %eax      # 0xd41c
movl %eax, 0xa14b(%rip)      # 0xd430
jmp 0x2fd8
cmpb $0x2d, 0xa12b(%rip)     # 0xd41c
jne 0x2fd8
movl $0x2d, 0xa12f(%rip)     # 0xd430
jmp 0x2fd8
movl $0xa, %edi
callq 0x26ee
movl $0x1, %r14d
movl %r14d, %edi
callq 0x2d21
movzwl 0xa103(%rip), %eax      # 0xd428
decl %eax
movw %ax, 0xa0fa(%rip)       # 0xd428
movw %ax, 0xa17b(%rip)       # 0xd4b0
movl 0xa16d(%rip), %edi      # 0xd4a8
movzwl %ax, %esi
callq 0x2c62
movb $0x2f, -0x2e(%rbp)
movl %r14d, %edi
leaq -0x2e(%rbp), %rsi
jmp 0x345d
movl %r12d, %edi
callq 0x2d21
movzwl 0xa14e(%rip), %eax      # 0xd4b0
movw %ax, 0xa0bf(%rip)       # 0xd428
movl $0x1, %edi
jmp 0x346d
movl 0xa12b(%rip), %edi      # 0xd4a4
callq 0x2add
jmp 0x2fd8
movl %r12d, %edi
callq 0x2d21
movzwl 0xa11e(%rip), %eax      # 0xd4b0
movw %ax, 0xa08f(%rip)       # 0xd428
movl $0x2, %edi
jmp 0x346d
movl %r12d, %edi
callq 0x2d21
jmp 0x3467
movl $0x2, %edi
jmp 0x349d
movl $0x0, 0xa060(%rip)      # 0xd424
testl %r14d, %r14d
jne 0x3519
callq 0x4a4b
jmp 0x2fd8
movb $0xa, -0x30(%rbp)
movl $0x1, %r14d
movl %r14d, %edi
leaq -0x30(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
movl %r14d, %edi
callq 0x2d21
movl 0x4e2c(%rip), %eax      # 0x822c
movl %eax, 0xa0a2(%rip)      # 0xd4a8
jmp 0x2fd8
addl %r14d, %r14d
orl %r14d, %eax
orl $0x1, %eax
movl %eax, 0xa0a2(%rip)      # 0xd4bc
jmp 0x2f47
movl $0x1, %r14d
movl %r14d, %edi
callq 0x2d21
movzwl 0x9ff4(%rip), %eax      # 0xd428
incl %eax
movw %ax, 0x9feb(%rip)       # 0xd428
movw %ax, 0xa06c(%rip)       # 0xd4b0
movl 0xa05e(%rip), %edi      # 0xd4a8
movzwl %ax, %esi
callq 0x2c62
movb $0x2f, -0x2f(%rbp)
movl %r14d, %edi
leaq -0x2f(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
movl 0xa03b(%rip), %edi      # 0xd4a8
callq 0x2db3
jmp 0x2fd8
movl %r12d, %edi
callq 0x2d21
testl %r14d, %r14d
jne 0x3523
movzwl 0xa021(%rip), %eax      # 0xd4b0
movw %ax, 0x9f92(%rip)       # 0xd428
jmp 0x3467
movl $0x1, %edi
callq 0x2ca6
jmp 0x2fd8
leaq -0x2c(%rbp), %rdi
callq 0x2b2e
testb $0x1, 0xa005(%rip)      # 0xd4bc
jne 0x3532
callq 0x4a86
jmp 0x353e
leaq -0x2c(%rbp), %rdi
callq 0x2b2e
testl %eax, %eax
jne 0x34d7
movzwl 0x9ff0(%rip), %eax      # 0xd4c4
movl %eax, -0x2c(%rbp)
testb $0x2, 0x9fde(%rip)      # 0xd4bc
je 0x34eb
movzwl -0x2c(%rbp), %eax
movw %ax, 0x9fd9(%rip)       # 0xd4c4
cmpl $0x0, 0x9f2e(%rip)      # 0xd420
movzwl -0x2c(%rbp), %edi
je 0x3539
cmpl $0x0, 0x9f19(%rip)      # 0xd418
jne 0x3539
callq 0x4a24
jmp 0x353e
cmpl $0x0, 0x9f25(%rip)      # 0xd434
je 0x354d
movl 0x9f15(%rip), %esi      # 0xd42c
jmp 0x3554
callq 0x4a6f
jmp 0x2fd8
movl $0x1, %edi
callq 0x2e1f
jmp 0x2fd8
callq 0x4ae4
jmp 0x353e
callq 0x4974
movl $0x1, 0x9f78(%rip)      # 0xd4c0
jmp 0x2fd8
movzwl 0x9ed4(%rip), %esi      # 0xd428
movq 0x4cc5(%rip), %rdi      # 0x8220
callq 0x2922
movl $0x0, 0x9eba(%rip)      # 0xd424
movb $0x20, %cl
movl $0x1, %eax
movq %rax, %r14
movsbl %cl, %edi
callq 0x26ee
movb (%r14,%r13), %cl
incq %r14
movq %r14, %rax
cmpq $0x4, %r14
jne 0x3571
movq $0x0, 0x9e95(%rip) # 0xd42c
movl $0x0, 0x9e93(%rip)      # 0xd434
jmp 0x2fd8
testb $0x2, %al
je 0x35f9
xorl %ebx, %ebx
movl %ebx, %eax
movzwl %ax, %r14d
movl %r14d, %edi
movl %ebx, %esi
callq 0x417c
movl %r14d, %eax
incl %eax
jmp 0x35ae
leaq 0x1b72(%rip), %rdi      # 0x513c
callq 0x27a3
leaq 0x9d7a(%rip), %rdi      # 0xd350
xorl %esi, %esi
callq 0x2280
leaq 0x1b9b(%rip), %rdi      # 0x517f
jmp 0x35ca
callq 0x25a1
cmpl $0x4, %ecx
jne 0x35f9
leaq 0x1b89(%rip), %rdi      # 0x5180
jmp 0x35ca
leaq 0x1b86(%rip), %rdi      # 0x5186
jmp 0x35ca
nop