// File: /workspace/github_c_makefile_star2_O2/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 0x462c
xorl %ebx, %ebx
movl %ebx, %edi
callq 0x25e7
movb 0xa4fc(%rip), %al       # 0xd253
movb %al, 0xa75b(%rip)       # 0xd4b8
movb 0xa4f1(%rip), %al       # 0xd254
movb %al, 0xa750(%rip)       # 0xd4b9
movb 0xa4e2(%rip), %al       # 0xd251
movb %al, 0xa745(%rip)       # 0xd4ba
leaq 0xa5d4(%rip), %rdi      # 0xd350
callq 0x21b0
andl $0x0, 0xa69c(%rip)      # 0xd424
andl $0x0, 0xa71d(%rip)      # 0xd4ac
andl $0x0, 0xa71e(%rip)      # 0xd4b4
andq $0x0, 0xa68e(%rip)      # 0xd42c
andl $0x0, 0xa68f(%rip)      # 0xd434
andl $0x0, 0xa710(%rip)      # 0xd4bc
andl $0x0, 0xa665(%rip)      # 0xd418
movl 0x5473(%rip), %eax      # 0x822c
andl $0x0, 0xa660(%rip)      # 0xd420
movl %eax, 0xa6e2(%rip)      # 0xd4a8
movl $0x3e8, %r14d           # imm = 0x3E8
leaq 0x23a9(%rip), %r15      # 0x517c
movl $0xffff, %r12d          # imm = 0xFFFF
movl %ebx, %edi
callq 0x32f7
testl %eax, %eax
je 0x2e52
callq 0x269c
movl %eax, %r13d
movb %al, 0xa62a(%rip)       # 0xd41c
callq 0x2030
cmpb 0xa6ba(%rip), %r13b     # 0xd4b8
je 0x2e13
cmpb $0x8, %r13b
je 0x2e13
movzbl %r13b, %ecx
cmpl $0x1f, %ecx
jne 0x2f38
testb $0x1, 0xa6a2(%rip)      # 0xd4bc
jne 0x3286
cmpl $0x0, 0xa5fd(%rip)      # 0xd424
jle 0x3286
movq %r15, %rdi
callq 0x2798
decl 0xa5e9(%rip)            # 0xd424
andl $0x0, 0xa67a(%rip)      # 0xd4bc
andl $0x0, 0xa5cf(%rip)      # 0xd418
andl $0x0, 0xa5d0(%rip)      # 0xd420
jmp 0x2dd9
cmpl $0x0, 0xa667(%rip)      # 0xd4c0
je 0x2f2b
callq 0x3d50
testl %eax, %eax
je 0x2e75
callq 0x3d5c
testl %eax, %eax
je 0x2f2b
movl %ebx, %edi
callq 0x3dc3
movl %eax, %r13d
leaq 0x22b6(%rip), %rdi      # 0x513c
callq 0x27bb
movl %r13d, %edi
callq 0x275f
callq 0x3d50
testl %eax, %eax
leaq 0x22ce(%rip), %rdi      # 0x516f
leaq 0x22c4(%rip), %rax      # 0x516c
cmoveq %rax, %rdi
callq 0x2798
andl %r12d, %r13d
movl %r13d, %edi
callq 0x3d77
movl %eax, %r13d
pushq $0x2
popq %rbx
movl %ebx, %edi
movl %eax, %esi
callq 0x2ae6
leaq 0x22a6(%rip), %rdi      # 0x5178
callq 0x2798
movw %r13w, 0xa549(%rip)     # 0xd428
andl %r12d, %r13d
movl %ebx, %edi
movl %r13d, %esi
callq 0x2b88
leaq 0x227f(%rip), %rdi      # 0x5172
callq 0x2798
movl %r13d, %edi
callq 0x3d77
movl %eax, %r13d
movl %eax, -0x2c(%rbp)
movl %ebx, %edi
xorl %ebx, %ebx
movl %eax, %esi
callq 0x2ae6
movl %r13d, 0xa58c(%rip)     # 0xd4a4
leaq 0x2258(%rip), %rdi      # 0x5177
callq 0x2798
andl $0x0, 0xa595(%rip)      # 0xd4c0
movl %r14d, %edi
callq 0x23e0
jmp 0x2dd9
cmpb 0xa57a(%rip), %r13b     # 0xd4b9
je 0x3292
cmpb 0xa56e(%rip), %r13b     # 0xd4ba
je 0x329e
movq (%rax), %rax
movsbq %r13b, %rcx
movl (%rax,%rcx,4), %r14d
movsbl %r13b, %edi
callq 0x26dc
movl 0xa550(%rip), %eax      # 0xd4bc
testb $0x1, %al
jne 0x2f81
movb 0xa4a6(%rip), %cl       # 0xd41c
andb $-0x21, %cl
addb $-0x41, %cl
cmpb $0x19, %cl
jbe 0x2fad
movsbl %r14b, %ecx
movl %ecx, %edx
addl $-0xa, %edx
cmpl $0x3d, %edx
ja 0x2fb7
movl %eax, %r14d
andl $0x1, %r14d
movl %edx, %ecx
leaq 0x2065(%rip), %rdx      # 0x5004
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
testl %r14d, %r14d
jne 0x2ff0
callq 0x2847
jmp 0x323b
movl %ecx, %edx
addl $-0x50, %edx
cmpl $0xf, %edx
ja 0x3000
movl %edx, %ecx
leaq 0x2132(%rip), %rdx      # 0x50fc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq -0x2c(%rbp), %rdi
callq 0x2a93
callq 0x45d5
movl $0x1, 0xa4d5(%rip)      # 0xd4c0
jmp 0x323b
callq 0x2818
movl $0x3e8, %r14d           # imm = 0x3E8
jmp 0x2dd9
cmpl $0x7c, %ecx
jne 0x32a3
leaq -0x2c(%rbp), %rdi
callq 0x29d3
testl %eax, %eax
je 0x3030
movl -0x2c(%rbp), %edi
callq 0x2a42
movsbl 0xa3f7(%rip), %eax      # 0xd41c
movl %eax, 0xa405(%rip)      # 0xd430
jmp 0x323b
cmpb $0x2d, 0xa3e5(%rip)     # 0xd41c
movl $0x3e8, %r14d           # imm = 0x3E8
jne 0x2e3b
movl $0x2d, 0xa3e3(%rip)     # 0xd430
jmp 0x2e3b
movl %ebx, %edi
callq 0x2bfb
testl %r14d, %r14d
jne 0x320b
movzwl 0xa447(%rip), %eax      # 0xd4b0
movw %ax, 0xa3b8(%rip)       # 0xd428
jmp 0x31cd
addl %r14d, %r14d
orl %r14d, %eax
orl $0x1, %eax
movl %eax, 0xa438(%rip)      # 0xd4bc
movl $0x3e8, %r14d           # imm = 0x3E8
jmp 0x2dd9
leaq -0x2c(%rbp), %rdi
callq 0x2a93
testb $0x1, 0xa41d(%rip)      # 0xd4bc
jne 0x3215
callq 0x45e6
jmp 0x321a
pushq $0x1
jmp 0x3203
pushq $0x1
popq %rdi
callq 0x2bfb
movzwl 0xa363(%rip), %eax      # 0xd428
incl %eax
jmp 0x31b7
leaq -0x2c(%rbp), %rdi
callq 0x2a93
testl %eax, %eax
jne 0x30e3
movzwl 0xa3e4(%rip), %eax      # 0xd4c4
movl %eax, -0x2c(%rbp)
testb $0x2, 0xa3d2(%rip)      # 0xd4bc
movl $0x3e8, %r14d           # imm = 0x3E8
je 0x30fd
movzwl -0x2c(%rbp), %eax
movw %ax, 0xa3c7(%rip)       # 0xd4c4
cmpl $0x0, 0xa31c(%rip)      # 0xd420
movzwl -0x2c(%rbp), %edi
je 0x3222
cmpl $0x0, 0xa303(%rip)      # 0xd418
jne 0x3222
callq 0x4584
jmp 0x3227
andl $0x0, 0xa2f8(%rip)      # 0xd424
testl %r14d, %r14d
jne 0x3236
callq 0x45ab
jmp 0x323b
pushq $0xa
popq %rdi
callq 0x26dc
pushq $0x1
popq %rdi
callq 0x2bfb
movl 0x50d7(%rip), %eax      # 0x822c
movl %eax, 0xa34d(%rip)      # 0xd4a8
jmp 0x323b
cmpl $0x0, 0xa2cd(%rip)      # 0xd434
je 0x3246
movl 0xa2b9(%rip), %esi      # 0xd42c
jmp 0x324d
movl %ebx, %edi
callq 0x2bfb
movzwl 0xa32a(%rip), %eax      # 0xd4b0
movw %ax, 0xa29b(%rip)       # 0xd428
pushq $0x2
jmp 0x31ec
movl %ebx, %edi
callq 0x2bfb
jmp 0x31cd
leaq 0x1f9b(%rip), %rdi      # 0x513c
callq 0x27bb
pushq $0x1
popq %rdi
callq 0x2bfb
movzwl 0xa273(%rip), %eax      # 0xd428
decl %eax
movw %ax, 0xa26a(%rip)       # 0xd428
movw %ax, 0xa2eb(%rip)       # 0xd4b0
movzwl %ax, %edi
callq 0x2be1
movl 0xa2d5(%rip), %edi      # 0xd4a8
jmp 0x31ed
movl %ebx, %edi
callq 0x2bfb
movzwl 0xa2cd(%rip), %eax      # 0xd4b0
movw %ax, 0xa23e(%rip)       # 0xd428
pushq $0x1
popq %rdi
callq 0x2c8d
jmp 0x323b
movl 0xa2aa(%rip), %edi      # 0xd4a4
callq 0x2a42
jmp 0x323b
pushq $0x2
popq %rdi
callq 0x2bae
jmp 0x323b
pushq $0x1
popq %rdi
callq 0x2cd5
jmp 0x323b
callq 0x4626
movl $0x3e8, %r14d           # imm = 0x3E8
jmp 0x3227
callq 0x44d4
movl $0x1, 0xa28f(%rip)      # 0xd4c0
jmp 0x2e3b
callq 0x45cf
movl $0x3e8, %r14d           # imm = 0x3E8
jmp 0x2e3b
movzwl 0xa1db(%rip), %esi      # 0xd428
movl $0x3e8, %r14d           # imm = 0x3E8
movq 0x4fc6(%rip), %rdi      # 0x8220
callq 0x28d1
andl $0x0, 0xa1be(%rip)      # 0xd424
leaq 0x1f0b(%rip), %rdi      # 0x5178
callq 0x2798
andq $0x0, 0xa1b2(%rip)      # 0xd42c
andl $0x0, 0xa1b3(%rip)      # 0xd434
jmp 0x2e3b
leaq 0x1eaf(%rip), %rdi      # 0x513c
callq 0x2801
leaq 0x1ee6(%rip), %rdi      # 0x517f
callq 0x2801
callq 0x259f
cmpl $0x4, %ecx
jne 0x32b8
leaq 0x1ed1(%rip), %rdi      # 0x5180
callq 0x2801
testb $0x2, %al
jne 0x32c4
leaq 0x1ec7(%rip), %rdi      # 0x5186
callq 0x2801
callq 0x2d1d
nopl (%rax)