// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x5a00
xorl %edi, %edi
callq 0x2690
movb 0xb2c2(%rip), %al       # 0xe523
movb %al, 0xb521(%rip)       # 0xe788
movb 0xb2b7(%rip), %al       # 0xe524
movb %al, 0xb516(%rip)       # 0xe789
movb 0xb2a8(%rip), %al       # 0xe521
movb %al, 0xb50b(%rip)       # 0xe78a
leaq 0xb39a(%rip), %rdi      # 0xe620
callq 0x21b0
movl $0x0, 0xb45f(%rip)      # 0xe6f4
movl $0x0, 0xb4dd(%rip)      # 0xe77c
movl $0x0, 0xb4db(%rip)      # 0xe784
callq 0x2da0
movl $0x0, 0xb4d4(%rip)      # 0xe78c
movl 0x5f8e(%rip), %eax      # 0x924c
movl %eax, 0xb4b4(%rip)      # 0xe778
movl $0x0, 0xb41a(%rip)      # 0xe6e8
movl $0x0, 0xb418(%rip)      # 0xe6f0
xorl %edi, %edi
callq 0x3960
cmpl $0x0, %eax
je 0x32f4
callq 0x2770
movb %al, 0xb3fd(%rip)       # 0xe6ec
jmp 0x33fd
cmpl $0x0, 0xb495(%rip)      # 0xe790
je 0x33ee
callq 0x49a0
cmpl $0x0, %eax
je 0x3319
callq 0x49b0
cmpl $0x0, %eax
je 0x33ee
xorl %edi, %edi
callq 0x4a70
movl %eax, -0x18(%rbp)
leaq 0x3074(%rip), %rdi      # 0x639e
callq 0x2940
movl -0x18(%rbp), %edi
callq 0x28b0
callq 0x49a0
cmpl $0x0, %eax
jne 0x334f
leaq 0x2ed0(%rip), %rdi      # 0x6218
callq 0x2900
jmp 0x335b
leaq 0x2ec5(%rip), %rdi      # 0x621b
callq 0x2900
movl -0x18(%rbp), %eax
movzwl %ax, %edi
callq 0x49f0
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %esi
movl $0x2, %edi
callq 0x2ee0
leaq 0x2ea7(%rip), %rdi      # 0x6224
callq 0x2900
movl -0x18(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movw %ax, 0xb361(%rip)       # 0xe6f8
movl $0x2, %edi
movzwl 0xb355(%rip), %esi      # 0xe6f8
callq 0x2fe0
leaq 0x2e6f(%rip), %rdi      # 0x621e
callq 0x2900
movl -0x18(%rbp), %eax
movzwl %ax, %edi
callq 0x49f0
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %esi
movl $0x2, %edi
callq 0x2ee0
movl -0x18(%rbp), %eax
movl %eax, 0xb39c(%rip)      # 0xe774
leaq 0x2e44(%rip), %rdi      # 0x6223
callq 0x2900
movl $0x0, 0xb3a2(%rip)      # 0xe790
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x2410
jmp 0x32d8
movsbl 0xb2e8(%rip), %edi      # 0xe6ec
callq 0x2090
movb %al, -0x11(%rbp)
movsbl 0xb2d9(%rip), %eax      # 0xe6ec
movsbl 0xb36e(%rip), %ecx      # 0xe788
cmpl %ecx, %eax
je 0x3436
movsbl 0xb2c7(%rip), %eax      # 0xe6ec
cmpl $0x8, %eax
je 0x3436
movsbl 0xb2bb(%rip), %eax      # 0xe6ec
cmpl $0x1f, %eax
jne 0x3479
movl 0xb350(%rip), %eax      # 0xe78c
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x344d
cmpl $0x0, 0xb2a9(%rip)      # 0xe6f4
jg 0x3459
leaq 0x2f4a(%rip), %rdi      # 0x639e
callq 0x29c0
leaq 0x2dc8(%rip), %rdi      # 0x6228
callq 0x2900
movl 0xb289(%rip), %eax      # 0xe6f4
addl $-0x1, %eax
movl %eax, 0xb280(%rip)      # 0xe6f4
jmp 0x38e3
movsbl 0xb26c(%rip), %eax      # 0xe6ec
movsbl 0xb302(%rip), %ecx      # 0xe789
cmpl %ecx, %eax
jne 0x349c
leaq 0x2d99(%rip), %rdi      # 0x622b
callq 0x29c0
jmp 0x38e1
movsbl 0xb249(%rip), %eax      # 0xe6ec
movsbl 0xb2e0(%rip), %ecx      # 0xe78a
cmpl %ecx, %eax
jne 0x34b3
jmp 0x3906
movsbl 0xb232(%rip), %edi      # 0xe6ec
callq 0x27d0
movl 0xb2c7(%rip), %eax      # 0xe78c
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x3507
movsbl 0xb218(%rip), %eax      # 0xe6ec
cmpl $0x41, %eax
jl 0x34e5
movsbl 0xb20c(%rip), %eax      # 0xe6ec
cmpl $0x5a, %eax
jle 0x34fd
movsbl 0xb200(%rip), %eax      # 0xe6ec
cmpl $0x61, %eax
jl 0x3507
movsbl 0xb1f4(%rip), %eax      # 0xe6ec
cmpl $0x7a, %eax
jg 0x3507
callq 0x2a20
jmp 0x38dd
movsbl -0x11(%rbp), %eax
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x78, %eax
ja 0x38cf
movq -0x20(%rbp), %rax
leaq 0x2adc(%rip), %rcx      # 0x6004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2cf4(%rip), %rdi      # 0x622c
callq 0x29c0
jmp 0x38db
callq 0x2a20
jmp 0x38db
movl 0xb23a(%rip), %eax      # 0xe78c
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3564
callq 0x29f0
jmp 0x3901
callq 0x2a20
jmp 0x38db
leaq -0x18(%rbp), %rdi
callq 0x2e70
cmpl $0x0, %eax
jne 0x3586
movzwl 0xb211(%rip), %eax      # 0xe794
movl %eax, -0x18(%rbp)
movl 0xb200(%rip), %eax      # 0xe78c
andl $0x2, %eax
cmpl $0x0, %eax
je 0x35a3
movl -0x18(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movw %ax, 0xb1f1(%rip)       # 0xe794
cmpl $0x0, 0xb146(%rip)      # 0xe6f0
je 0x35c2
cmpl $0x0, 0xb135(%rip)      # 0xe6e8
jne 0x35c2
movl -0x18(%rbp), %eax
movzwl %ax, %edi
callq 0x58f0
jmp 0x35cd
movl -0x18(%rbp), %eax
movzwl %ax, %edi
callq 0x5820
movl $0x1, 0xb1b9(%rip)      # 0xe790
jmp 0x38db
leaq -0x18(%rbp), %rdi
callq 0x2e70
callq 0x5970
movl $0x1, 0xb19c(%rip)      # 0xe790
jmp 0x38db
leaq -0x18(%rbp), %rdi
callq 0x2e70
movl 0xb184(%rip), %eax      # 0xe78c
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3617
callq 0x59f0
jmp 0x361c
callq 0x5990
movl $0x1, 0xb16a(%rip)      # 0xe790
jmp 0x38db
movl $0x0, 0xb0bf(%rip)      # 0xe6f4
movl 0xb151(%rip), %eax      # 0xe78c
andl $0x1, %eax
cmpl $0x0, %eax
je 0x364a
callq 0x5960
jmp 0x364f
callq 0x5930
jmp 0x38db
movl 0xb11a(%rip), %edi      # 0xe774
callq 0x2dd0
jmp 0x38db
movl 0xb122(%rip), %eax      # 0xe78c
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3679
callq 0x31f0
jmp 0x3685
leaq 0x2bb2(%rip), %rdi      # 0x6232
callq 0x29c0
jmp 0x38db
movl 0xb0fc(%rip), %eax      # 0xe78c
andl $0x1, %eax
cmpl $0x0, %eax
je 0x36a7
movl 0xb0ee(%rip), %eax      # 0xe78c
orl $0x2, %eax
movl %eax, 0xb0e5(%rip)      # 0xe78c
movl 0xb0df(%rip), %eax      # 0xe78c
orl $0x1, %eax
movl %eax, 0xb0d6(%rip)      # 0xe78c
jmp 0x3901
movq 0x5b7e(%rip), %rax      # 0x9240
movq %rax, -0x28(%rbp)
cmpl $0x0, 0xb037(%rip)      # 0xe704
je 0x36da
movl 0xb027(%rip), %eax      # 0xe6fc
movl %eax, -0x2c(%rbp)
jmp 0x36e4
movzwl 0xb017(%rip), %eax      # 0xe6f8
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x2b00
movl $0x0, 0xaffa(%rip)      # 0xe6f4
leaq 0x2b23(%rip), %rdi      # 0x6224
callq 0x2900
callq 0x2da0
jmp 0x38db
leaq -0x18(%rbp), %rdi
callq 0x2d10
cmpl $0x0, %eax
jne 0x3739
movsbl 0xafc7(%rip), %eax      # 0xe6ec
cmpl $0x2d, %eax
jne 0x3734
movl $0x2d, 0xafcc(%rip)     # 0xe700
jmp 0x38db
movl -0x18(%rbp), %edi
callq 0x2dd0
movsbl 0xafa4(%rip), %eax      # 0xe6ec
movl %eax, 0xafb2(%rip)      # 0xe700
jmp 0x38db
movl 0xb033(%rip), %eax      # 0xe78c
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3774
xorl %edi, %edi
callq 0x3090
movl $0x1, %edi
callq 0x31a0
jmp 0x3794
xorl %edi, %edi
callq 0x3090
movw 0xaffe(%rip), %ax       # 0xe780
movw %ax, 0xaf6f(%rip)       # 0xe6f8
movl 0xafe9(%rip), %edi      # 0xe778
callq 0x3150
jmp 0x38db
xorl %edi, %edi
callq 0x3090
movl 0xafd2(%rip), %edi      # 0xe778
callq 0x3150
jmp 0x38db
xorl %edi, %edi
callq 0x3090
movw 0xafc2(%rip), %ax       # 0xe780
movw %ax, 0xaf33(%rip)       # 0xe6f8
movl $0x1, %edi
callq 0x3150
jmp 0x38db
xorl %edi, %edi
callq 0x3090
movw 0xaf9e(%rip), %ax       # 0xe780
movw %ax, 0xaf0f(%rip)       # 0xe6f8
movl $0x2, %edi
callq 0x3150
jmp 0x38db
leaq 0x2b9f(%rip), %rdi      # 0x639e
callq 0x2940
movl $0x1, %edi
callq 0x3090
movzwl 0xaee3(%rip), %eax      # 0xe6f8
subl $0x1, %eax
andl $0xffff, %eax           # imm = 0xFFFF
movw %ax, 0xaed4(%rip)       # 0xe6f8
movw 0xaecd(%rip), %ax       # 0xe6f8
movw %ax, 0xaf4e(%rip)       # 0xe780
movzwl 0xaf47(%rip), %edi      # 0xe780
callq 0x3060
movl 0xaf34(%rip), %edi      # 0xe778
callq 0x3150
jmp 0x38db
movl $0x1, %edi
callq 0x3090
movzwl 0xae99(%rip), %eax      # 0xe6f8
addl $0x1, %eax
andl $0xffff, %eax           # imm = 0xFFFF
movw %ax, 0xae8a(%rip)       # 0xe6f8
movw 0xae83(%rip), %ax       # 0xe6f8
movw %ax, 0xaf04(%rip)       # 0xe780
movzwl 0xaefd(%rip), %edi      # 0xe780
callq 0x3060
movl 0xaeea(%rip), %edi      # 0xe778
callq 0x3150
jmp 0x38db
movl $0xa, %edi
callq 0x27d0
movl $0x1, %edi
callq 0x3090
movl 0x599d(%rip), %eax      # 0x924c
movl %eax, 0xaec3(%rip)      # 0xe778
jmp 0x38db
movl $0x2, %edi
callq 0x3020
jmp 0x38db
movl $0x1, %edi
callq 0x3020
jmp 0x38db
leaq 0x295c(%rip), %rdi      # 0x6232
callq 0x29c0
jmp 0x38dd
jmp 0x38df
jmp 0x38e1
jmp 0x38e3
movl $0x0, 0xae9f(%rip)      # 0xe78c
movl $0x0, 0xadf1(%rip)      # 0xe6e8
movl $0x0, 0xadef(%rip)      # 0xe6f0
jmp 0x32d8
callq 0x2610
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)