// File: /workspace/github_c_makefile_star2_O1/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 0x4b34
xorl %r12d, %r12d
movl %r12d, %edi
callq 0x270b
movb 0xa245(%rip), %al       # 0xd253
movb %al, 0xa4a4(%rip)       # 0xd4b8
movb 0xa23a(%rip), %al       # 0xd254
movb %al, 0xa499(%rip)       # 0xd4b9
movb 0xa22b(%rip), %al       # 0xd251
movb %al, 0xa48e(%rip)       # 0xd4ba
leaq 0xa31d(%rip), %rdi      # 0xd350
callq 0x21b0
movl %r12d, 0xa3e5(%rip)     # 0xd424
movl %r12d, 0xa466(%rip)     # 0xd4ac
movl %r12d, 0xa467(%rip)     # 0xd4b4
movq $0x0, 0xa3d4(%rip) # 0xd42c
movl %r12d, 0xa3d5(%rip)     # 0xd434
movl %r12d, 0xa456(%rip)     # 0xd4bc
movl 0x51c0(%rip), %eax      # 0x822c
movl %eax, 0xa436(%rip)      # 0xd4a8
movl %r12d, 0xa39f(%rip)     # 0xd418
movl %r12d, 0xa3a0(%rip)     # 0xd420
leaq 0x20f3(%rip), %r13      # 0x517a
leaq 0x20f0(%rip), %rbx      # 0x517e
movl %r12d, %edi
callq 0x378b
testl %eax, %eax
je 0x3139
movl %r12d, %edi
leaq -0x2d(%rbp), %rsi
movl $0x1, %edx
callq 0x2180
movsbq -0x2d(%rbp), %r14
movb %r14b, 0xa361(%rip)     # 0xd41c
callq 0x2030
cmpb 0xa3f1(%rip), %r14b     # 0xd4b8
je 0x30dd
movl %r14d, %ecx
movzbl %cl, %edx
cmpl $0x8, %edx
je 0x30dd
cmpl $0x1f, %edx
jne 0x31b7
testb $0x1, 0xa3d8(%rip)      # 0xd4bc
jne 0x3715
cmpl $0x0, 0xa333(%rip)      # 0xd424
jle 0x3715
movb $0x8, %cl
movl $0x1, %eax
movq %rax, %r14
movsbl %cl, %edi
callq 0x280e
movb (%r14,%rbx), %cl
incq %r14
movq %r14, %rax
cmpq $0x4, %r14
jne 0x30fe
decl 0xa305(%rip)            # 0xd424
movl %r12d, 0xa396(%rip)     # 0xd4bc
movl %r12d, 0xa2eb(%rip)     # 0xd418
movl %r12d, 0xa2ec(%rip)     # 0xd420
jmp 0x308e
cmpl $0x0, 0xa380(%rip)      # 0xd4c0
je 0x339a
callq 0x41bc
testl %eax, %eax
je 0x315c
callq 0x41c8
testl %eax, %eax
je 0x339a
movl %r12d, %edi
callq 0x422f
movl %eax, %r14d
movl %eax, -0x2c(%rbp)
movl $0xa, %edi
callq 0x280e
movl %r14d, %edi
callq 0x288a
callq 0x41bc
testl %eax, %eax
je 0x3295
movb $0x3c, %al
movl %r12d, %ecx
movq %rcx, %r15
leaq 0x1(%rcx), %r12
movsbl %al, %edi
callq 0x280e
leaq 0x1fcd(%rip), %rax      # 0x5171
movb 0x1(%r15,%rax), %al
movq %r12, %rcx
cmpq $0x2, %r12
jne 0x318e
jmp 0x32be
cmpb 0xa2fc(%rip), %cl       # 0xd4b9
je 0x372f
cmpb 0xa2f1(%rip), %cl       # 0xd4ba
je 0x3738
movq (%rax), %rax
movl (%rax,%r14,4), %r14d
movsbl %cl, %edi
callq 0x280e
movl 0xa2d8(%rip), %eax      # 0xd4bc
testb $0x1, %al
jne 0x3216
movb 0xa22e(%rip), %cl       # 0xd41c
movl %ecx, %edx
andb $-0x21, %dl
addb $-0x41, %dl
cmpb $0x19, %dl
ja 0x3216
movslq 0xa222(%rip), %rax      # 0xd424
leaq 0xa077(%rip), %rsi      # 0xd280
movb %cl, (%rax,%rsi)
incl %eax
movl %eax, 0xa210(%rip)      # 0xd424
jmp 0x3266
movsbl %r14b, %ecx
movl %ecx, %edx
cmpl $0x4f, %ecx
jg 0x33a9
addl $-0xa, %edx
cmpl $0x3d, %edx
ja 0x373d
movl %edx, %ecx
leaq 0x1dca(%rip), %rdx      # 0x5004
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
testb $0x1, %al
jne 0x33d6
movb 0xa1cb(%rip), %al       # 0xd41c
movslq 0xa1cc(%rip), %rcx      # 0xd424
leaq 0xa021(%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, 0xa19a(%rip)      # 0xd424
cltq
movb $0x0, (%rax,%rsi)
jmp 0x311f
movb $0x3e, %al
movl %r12d, %ecx
movq %rcx, %r15
leaq 0x1(%rcx), %r12
movsbl %al, %edi
callq 0x280e
leaq 0x1ebe(%rip), %rax      # 0x516e
movb 0x1(%r15,%rax), %al
movq %r12, %rcx
cmpq $0x2, %r12
jne 0x329a
movzwl %r14w, %edi
callq 0x41e3
movl %eax, %r14d
movl %eax, -0x2c(%rbp)
movl $0x2, %edi
movl %eax, %esi
callq 0x2cc3
movb $0x20, %cl
movl $0x1, %eax
movq %rax, %r15
movsbl %cl, %edi
callq 0x280e
movb (%r15,%r13), %cl
incq %r15
movq %r15, %rax
cmpq $0x4, %r15
jne 0x32e0
movzwl %r14w, %esi
movl %esi, -0x2c(%rbp)
movw %si, 0xa11f(%rip)       # 0xd428
movl $0x2, %edi
callq 0x2da9
movb $0x2f, %al
xorl %ecx, %ecx
leaq 0x1e56(%rip), %r13      # 0x5174
movq %rcx, %r15
leaq 0x1(%rcx), %r12
movsbl %al, %edi
callq 0x280e
movb 0x1(%r15,%r13), %al
movq %r12, %rcx
cmpq $0x4, %r12
jne 0x331e
movzwl %r14w, %edi
callq 0x41e3
movl %eax, %r14d
movl %eax, -0x2c(%rbp)
movl $0x2, %edi
movl %eax, %esi
callq 0x2cc3
movl %r14d, 0xa147(%rip)     # 0xd4a4
movb $0x20, %al
xorl %r12d, %r12d
movl %r12d, %ecx
leaq 0x1e0d(%rip), %r13      # 0x5179
movq %rcx, %r14
leaq 0x1(%rcx), %r15
movsbl %al, %edi
callq 0x280e
movb 0x1(%r14,%r13), %al
movq %r15, %rcx
cmpq $0x4, %r15
jne 0x336c
movl $0x0, 0xa12d(%rip)      # 0xd4c0
leaq 0x1de0(%rip), %r13      # 0x517a
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x23f0
jmp 0x308e
addl $-0x50, %edx
cmpl $0xf, %edx
ja 0x3404
movl %edx, %ecx
leaq 0x1d42(%rip), %rdx      # 0x50fc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq -0x2c(%rbp), %rdi
callq 0x2c60
callq 0x4abf
jmp 0x3690
movl 0x4e4c(%rip), %eax      # 0x8228
imull 0xa035(%rip), %eax      # 0xd418
movsbl 0xa032(%rip), %ecx      # 0xd41c
addl %ecx, %eax
addl $-0x30, %eax
movl %eax, 0xa023(%rip)      # 0xd418
movl $0x1, 0xa021(%rip)      # 0xd420
jmp 0x308e
cmpl $0x7c, %ecx
jne 0x374b
leaq -0x2c(%rbp), %rdi
callq 0x2b58
testl %eax, %eax
je 0x3434
movl -0x2c(%rbp), %edi
callq 0x2c0f
movsbl 0x9ff3(%rip), %eax      # 0xd41c
movl %eax, 0xa001(%rip)      # 0xd430
jmp 0x311f
cmpb $0x2d, 0x9fe1(%rip)     # 0xd41c
jne 0x311f
movl $0x2d, 0x9fe5(%rip)     # 0xd430
jmp 0x311f
movl $0xa, %edi
callq 0x280e
movl $0x1, %r14d
movl %r14d, %edi
callq 0x2e68
movzwl 0x9fb9(%rip), %eax      # 0xd428
decl %eax
movw %ax, 0x9fb0(%rip)       # 0xd428
movw %ax, 0xa031(%rip)       # 0xd4b0
movl 0xa023(%rip), %edi      # 0xd4a8
movzwl %ax, %esi
callq 0x2da9
movb $0x2f, -0x2e(%rbp)
movl %r14d, %edi
leaq -0x2e(%rbp), %rsi
jmp 0x35ab
movl %r12d, %edi
callq 0x2e68
movzwl 0xa004(%rip), %eax      # 0xd4b0
movw %ax, 0x9f75(%rip)       # 0xd428
movl $0x1, %edi
jmp 0x35bb
movl 0x9fe1(%rip), %edi      # 0xd4a4
callq 0x2c0f
jmp 0x311f
movl %r12d, %edi
callq 0x2e68
movzwl 0x9fd4(%rip), %eax      # 0xd4b0
movw %ax, 0x9f45(%rip)       # 0xd428
movl $0x2, %edi
jmp 0x35bb
movl %r12d, %edi
callq 0x2e68
jmp 0x35b5
movl $0x2, %edi
jmp 0x35ef
movl $0x0, 0x9f16(%rip)      # 0xd424
testb $0x1, %al
jne 0x366b
callq 0x4a95
jmp 0x311f
movb $0xa, -0x30(%rbp)
movl $0x1, %r14d
movl %r14d, %edi
leaq -0x30(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
movl %r14d, %edi
callq 0x2e68
movl 0x4ce3(%rip), %eax      # 0x822c
movl %eax, 0x9f59(%rip)      # 0xd4a8
jmp 0x311f
testb $0x1, %al
je 0x3561
orl $0x2, %eax
movl %eax, 0x9f5b(%rip)      # 0xd4bc
orb $0x1, 0x9f54(%rip)      # 0xd4bc
jmp 0x308e
movl $0x1, %r14d
movl %r14d, %edi
callq 0x2e68
movzwl 0x9ea6(%rip), %eax      # 0xd428
incl %eax
movw %ax, 0x9e9d(%rip)       # 0xd428
movw %ax, 0x9f1e(%rip)       # 0xd4b0
movl 0x9f10(%rip), %edi      # 0xd4a8
movzwl %ax, %esi
callq 0x2da9
movb $0x2f, -0x2f(%rbp)
movl %r14d, %edi
leaq -0x2f(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
movl 0x9eed(%rip), %edi      # 0xd4a8
callq 0x2efa
jmp 0x311f
movl %eax, %r14d
movl %r12d, %edi
callq 0x2e68
testb $0x1, %r14b
jne 0x3675
movzwl 0x9ecf(%rip), %eax      # 0xd4b0
movw %ax, 0x9e40(%rip)       # 0xd428
jmp 0x35b5
movl $0x1, %edi
callq 0x2ded
jmp 0x311f
leaq -0x2c(%rbp), %rdi
callq 0x2c60
testb $0x1, 0x9eb3(%rip)      # 0xd4bc
jne 0x3684
callq 0x4ad0
jmp 0x3690
leaq -0x2c(%rbp), %rdi
callq 0x2c60
testl %eax, %eax
jne 0x3629
movzwl 0x9e9e(%rip), %eax      # 0xd4c4
movl %eax, -0x2c(%rbp)
testb $0x2, 0x9e8c(%rip)      # 0xd4bc
je 0x363d
movzwl -0x2c(%rbp), %eax
movw %ax, 0x9e87(%rip)       # 0xd4c4
cmpl $0x0, 0x9ddc(%rip)      # 0xd420
movzwl -0x2c(%rbp), %edi
je 0x368b
cmpl $0x0, 0x9dc7(%rip)      # 0xd418
jne 0x368b
callq 0x4a6e
jmp 0x3690
cmpl $0x0, 0x9dd3(%rip)      # 0xd434
je 0x369f
movl 0x9dc3(%rip), %esi      # 0xd42c
jmp 0x36a6
callq 0x4ab9
jmp 0x311f
movl $0x1, %edi
callq 0x2f66
jmp 0x311f
callq 0x4b2e
jmp 0x3690
callq 0x49be
movl $0x1, 0x9e26(%rip)      # 0xd4c0
jmp 0x311f
movzwl 0x9d82(%rip), %esi      # 0xd428
movq 0x4b73(%rip), %rdi      # 0x8220
callq 0x2a42
movl $0x0, 0x9d68(%rip)      # 0xd424
movb $0x20, %cl
movl $0x1, %eax
movq %rax, %r14
movsbl %cl, %edi
callq 0x280e
movb (%r14,%r13), %cl
incq %r14
movq %r14, %rax
cmpq $0x4, %r14
jne 0x36c3
movq $0x0, 0x9d43(%rip) # 0xd42c
movl $0x0, 0x9d41(%rip)      # 0xd434
jmp 0x311f
testb $0x2, %al
je 0x374b
xorl %ebx, %ebx
movl %ebx, %eax
movzwl %ax, %r14d
movl %r14d, %edi
movl %ebx, %esi
callq 0x41d0
movl %r14d, %eax
incl %eax
jmp 0x3700
leaq 0x1a20(%rip), %rdi      # 0x513c
callq 0x28c3
leaq 0x9c28(%rip), %rdi      # 0xd350
xorl %esi, %esi
callq 0x2290
leaq 0x1a4b(%rip), %rdi      # 0x5181
jmp 0x371c
callq 0x26c1
cmpl $0x4, %ecx
jne 0x374b
leaq 0x1a39(%rip), %rdi      # 0x5182
jmp 0x371c
leaq 0x1a36(%rip), %rdi      # 0x5188
jmp 0x371c