// File: /workspace/github_c_makefile_star2_O0/hughbarney[P]pEmacs/complete.c
// Function: getfilename
int getfilename(char *prompt, char *buf, int nbuf)
{
	int cpos = 0;	/* current character position in string */
	int c;
	int ocpos, nskip = 0, didtry = 0;
	int eolchar = '\n';
	int result = 0;

	static char tmp[] = "/tmp/meXXXXXX";
	FILE *tmpf = NULL;

	/* prompt the user for the input string */
	mlwrite(prompt);

	for (;;) {
		if (!didtry)
			nskip = -1;
		didtry = 0;

		/* get a character from the user */
		c = ttgetc();

		/* If it is a <ret>, change it to a <NL> */
		if (c == CTRL_M)
			c = '\n';

		/* if they hit the line terminate, wrap it up */
		if (c == eolchar) {
			buf[cpos++] = 0;

			/* clear the message line */
			mlwrite("");
			ttflush();

			/* if we default the buffer, return FALSE */
			if (buf[0] == 0)
				return FALSE;

			return TRUE;
		}

		if (c == CTRL_G) {
			/* Abort the input? */
			ctrlg(FALSE, 0);
			ttflush();
			return ABORT;
		} else if ((c == 0x7F || c == 0x08)) {
			/* rubout/erase */
			if (cpos != 0) {
				outstring("\b \b");
				--ttcol;
				if (buf[--cpos] < 0x20) {
					outstring("\b \b");
					--ttcol;
				}
				if (buf[cpos] == '\n') {
					outstring("\b\b  \b\b");
					ttcol -= 2;
				}
				ttflush();
			}
		} else if (c == 0x15) {
			/* C-U, kill */
			while (cpos != 0) {
				outstring("\b \b");
				--ttcol;

				if (buf[--cpos] < 0x20) {
					outstring("\b \b");
					--ttcol;
				}
				if (buf[cpos] == '\n') {
					outstring("\b\b  \b\b");
					ttcol -= 2;
				}
			}
			ttflush();
		} else if ((c == 0x09 || c == ' ')) {
			/* TAB, complete file name */
			char ffbuf[255];
			int n, iswild = 0;

			didtry = 1;
			ocpos = cpos;
			while (cpos != 0) {
				outstring("\b \b");
				--ttcol;

				if (buf[--cpos] < 0x20) {
					outstring("\b \b");
					--ttcol;
				}
				if (buf[cpos] == '\n') {
					outstring("\b\b  \b\b");
					ttcol -= 2;
				}
				if (buf[cpos] == '*' || buf[cpos] == '?')
					iswild = 1;
			}
			ttflush();
			if (nskip < 0) {
				buf[ocpos] = 0;
				if (tmpf != NULL)
					fclose(tmpf);
				strcpy(tmp, "/tmp/meXXXXXX");
				strcpy(ffbuf, "echo ");
				strcat(ffbuf, buf);
				if (!iswild)
					strcat(ffbuf, "*");
				strcat(ffbuf, " >");
				result = mkstemp(tmp);
				if (result == -1)
				{
				  printf("Failed to create temp file\n");
				  exit(1);
				}
				strcat(ffbuf, tmp);
				strcat(ffbuf, " 2>&1");
				result = system(ffbuf);
				tmpf = fopen(tmp, "r");
				nskip = 0;
			}
			c = ' ';
			for (n = nskip; n > 0; n--)
				while ((c = getc(tmpf)) != EOF
				       && c != ' ');
			nskip++;

			if (c != ' ') {
				(*term.t_beep) ();
				nskip = 0;
			}
			while ((c = getc(tmpf)) != EOF && c != '\n'
			       && c != ' ' && c != '*')
			{
				if (cpos < nbuf - 1)
					buf[cpos++] = c;
			}
			if (c == '*')
				(*term.t_beep) ();

			for (n = 0; n < cpos; n++) {
				c = buf[n];
				if ((c < ' ') && (c != '\n')) {
					outstring("^");
					++ttcol;
					c ^= 0x40;
				}

				if (c != '\n') {
					ttputc(c);
				} else {	/* put out <NL> for <ret> */
					outstring("<NL>");
					ttcol += 3;
				}
				++ttcol;
			}
			ttflush();
			rewind(tmpf);
			unlink(tmp);
		} else {
			if (cpos < nbuf - 1) {
				/* if a control char */
				if ((c < ' ') && (c != '\n')) {
				  (*term.t_beep) ();
				} else {
				  buf[cpos++] = c;
				  ttputc(c);
				  ++ttcol;
				  ttflush();
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0xa, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movb $0x0, %al
callq 0x56d0
cmpl $0x0, -0x30(%rbp)
jne 0xb729
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x30(%rbp)
movb $0x0, %al
callq 0xaf00
movl %eax, -0x24(%rbp)
cmpl $0xd, -0x24(%rbp)
jne 0xb747
movl $0xa, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0xb79e
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x20(%rbp)
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
leaq 0x116d(%rip), %rdi      # 0xc8d9
movb $0x0, %al
callq 0x56d0
movb $0x0, %al
callq 0xaee0
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xb792
movl $0x0, -0x4(%rbp)
jmp 0xbd8e
movl $0x1, -0x4(%rbp)
jmp 0xbd8e
cmpl $0x7, -0x24(%rbp)
jne 0xb7c2
xorl %esi, %esi
movl %esi, %edi
movb $0x0, %al
callq 0x83d0
movb $0x0, %al
callq 0xaee0
movl $0x2, -0x4(%rbp)
jmp 0xbd8e
cmpl $0x7f, -0x24(%rbp)
je 0xb7d2
cmpl $0x8, -0x24(%rbp)
jne 0xb875
cmpl $0x0, -0x20(%rbp)
je 0xb870
leaq 0x10ec(%rip), %rdi      # 0xc8cf
callq 0xbda0
leaq 0x4985(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x4979(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x20(%rbp)
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jge 0xb837
leaq 0x10b2(%rip), %rdi      # 0xc8cf
callq 0xbda0
leaq 0x494b(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x493f(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0xb869
leaq 0x1084(%rip), %rdi      # 0xc8d3
callq 0xbda0
leaq 0x4919(%rip), %rax      # 0x10174
movl (%rax), %ecx
subl $0x2, %ecx
leaq 0x490d(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movb $0x0, %al
callq 0xaee0
jmp 0xbd87
cmpl $0x15, -0x24(%rbp)
jne 0xb929
jmp 0xb881
cmpl $0x0, -0x20(%rbp)
je 0xb91d
leaq 0x103d(%rip), %rdi      # 0xc8cf
callq 0xbda0
leaq 0x48d6(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x48ca(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x20(%rbp)
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jge 0xb8e6
leaq 0x1003(%rip), %rdi      # 0xc8cf
callq 0xbda0
leaq 0x489c(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x4890(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0xb918
leaq 0xfd5(%rip), %rdi       # 0xc8d3
callq 0xbda0
leaq 0x486a(%rip), %rax      # 0x10174
movl (%rax), %ecx
subl $0x2, %ecx
leaq 0x485e(%rip), %rax      # 0x10174
movl %ecx, (%rax)
jmp 0xb881
movb $0x0, %al
callq 0xaee0
jmp 0xbd85
cmpl $0x9, -0x24(%rbp)
je 0xb939
cmpl $0x20, -0x24(%rbp)
jne 0xbd18
movl $0x0, -0x148(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0xba18
leaq 0xf6e(%rip), %rdi       # 0xc8cf
callq 0xbda0
leaq 0x4807(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x47fb(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x20(%rbp)
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jge 0xb9b5
leaq 0xf34(%rip), %rdi       # 0xc8cf
callq 0xbda0
leaq 0x47cd(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x47c1(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0xb9e7
leaq 0xf06(%rip), %rdi       # 0xc8d3
callq 0xbda0
leaq 0x479b(%rip), %rax      # 0x10174
movl (%rax), %ecx
subl $0x2, %ecx
leaq 0x478f(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2a, %eax
je 0xba09
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3f, %eax
jne 0xba13
movl $0x1, -0x148(%rbp)
jmp 0xb950
movb $0x0, %al
callq 0xaee0
cmpl $0x0, -0x2c(%rbp)
jge 0xbb2a
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
cmpq $0x0, -0x40(%rbp)
je 0xba45
movq -0x40(%rbp), %rdi
callq 0x20c0
leaq 0x4e8c(%rip), %rdi      # 0x108d8
leaq 0xe87(%rip), %rsi       # 0xc8da
callq 0x2080
leaq -0x140(%rbp), %rdi
leaq 0xe82(%rip), %rsi       # 0xc8e8
callq 0x2080
leaq -0x140(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2260
cmpl $0x0, -0x148(%rbp)
jne 0xba97
leaq -0x140(%rbp), %rdi
leaq 0x5b2(%rip), %rsi       # 0xc044
callq 0x2260
leaq -0x140(%rbp), %rdi
leaq 0xe49(%rip), %rsi       # 0xc8ee
callq 0x2260
leaq 0x4e27(%rip), %rdi      # 0x108d8
callq 0x21e0
movl %eax, -0x38(%rbp)
cmpl $-0x1, -0x38(%rbp)
jne 0xbad7
leaq 0xe2b(%rip), %rdi       # 0xc8f1
movb $0x0, %al
callq 0x2110
movl $0x1, %edi
callq 0x2280
leaq -0x140(%rbp), %rdi
leaq 0x4df3(%rip), %rsi      # 0x108d8
callq 0x2260
leaq -0x140(%rbp), %rdi
leaq 0xe15(%rip), %rsi       # 0xc90d
callq 0x2260
leaq -0x140(%rbp), %rdi
callq 0x2100
movl %eax, -0x38(%rbp)
leaq 0x4dc5(%rip), %rdi      # 0x108d8
leaq 0x7fc(%rip), %rsi       # 0xc316
callq 0x2250
movq %rax, -0x40(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x20, -0x24(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x144(%rbp)
cmpl $0x0, -0x144(%rbp)
jle 0xbb8e
jmp 0xbb45
movq -0x40(%rbp), %rdi
callq 0x22a0
movl %eax, %ecx
movl %ecx, -0x24(%rbp)
xorl %eax, %eax
cmpl $-0x1, %ecx
movb %al, -0x149(%rbp)
je 0xbb6d
cmpl $0x20, -0x24(%rbp)
setne %al
movb %al, -0x149(%rbp)
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0xbb79
jmp 0xbb7b
jmp 0xbb45
jmp 0xbb7d
movl -0x144(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0xbb3a
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x20, -0x24(%rbp)
je 0xbbb0
leaq 0x4cd4(%rip), %rcx      # 0x10878
movb $0x0, %al
callq *0x50(%rcx)
movl $0x0, -0x2c(%rbp)
jmp 0xbbb2
movq -0x40(%rbp), %rdi
callq 0x22a0
movl %eax, %ecx
movl %ecx, -0x24(%rbp)
xorl %eax, %eax
cmpl $-0x1, %ecx
movb %al, -0x14a(%rbp)
je 0xbbf6
xorl %eax, %eax
cmpl $0xa, -0x24(%rbp)
movb %al, -0x14a(%rbp)
je 0xbbf6
xorl %eax, %eax
cmpl $0x20, -0x24(%rbp)
movb %al, -0x14a(%rbp)
je 0xbbf6
cmpl $0x2a, -0x24(%rbp)
setne %al
movb %al, -0x14a(%rbp)
movb -0x14a(%rbp), %al
testb $0x1, %al
jne 0xbc02
jmp 0xbc2b
movl -0x20(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xbc29
movl -0x24(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0xbbb2
cmpl $0x2a, -0x24(%rbp)
jne 0xbc3d
leaq 0x4c40(%rip), %rcx      # 0x10878
movb $0x0, %al
callq *0x50(%rcx)
movl $0x0, -0x144(%rbp)
movl -0x144(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xbcfa
movq -0x18(%rbp), %rax
movslq -0x144(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x24(%rbp)
cmpl $0x20, -0x24(%rbp)
jge 0xbc9e
cmpl $0xa, -0x24(%rbp)
je 0xbc9e
leaq 0xc98(%rip), %rdi       # 0xc913
callq 0xbda0
leaq 0x44ed(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x44e1(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movl -0x24(%rbp), %eax
xorl $0x40, %eax
movl %eax, -0x24(%rbp)
cmpl $0xa, -0x24(%rbp)
je 0xbcb0
movl -0x24(%rbp), %edi
movb $0x0, %al
callq 0xaeb0
jmp 0xbcd1
leaq 0xc5e(%rip), %rdi       # 0xc915
callq 0xbda0
leaq 0x44b1(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $0x3, %ecx
leaq 0x44a5(%rip), %rax      # 0x10174
movl %ecx, (%rax)
leaq 0x449c(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x4490(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0xbc47
movb $0x0, %al
callq 0xaee0
movq -0x40(%rbp), %rdi
callq 0x2120
leaq 0x4bc7(%rip), %rdi      # 0x108d8
callq 0x2060
jmp 0xbd83
movl -0x20(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xbd81
cmpl $0x20, -0x24(%rbp)
jge 0xbd3f
cmpl $0xa, -0x24(%rbp)
je 0xbd3f
leaq 0x4b40(%rip), %rcx      # 0x10878
movb $0x0, %al
callq *0x50(%rcx)
jmp 0xbd7f
movl -0x24(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %edi
movb $0x0, %al
callq 0xaeb0
leaq 0x440a(%rip), %rax      # 0x10174
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x43fe(%rip), %rax      # 0x10174
movl %ecx, (%rax)
movb $0x0, %al
callq 0xaee0
jmp 0xbd81
jmp 0xbd83
jmp 0xbd85
jmp 0xbd87
jmp 0xbd89
jmp 0xb71c
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw (%rax,%rax)