// File: /workspace/github_c_makefile_star2_O0/hughbarney[P]pEmacs/search.c
// Function: isearch
static int
isearch(int dir)
{
	LINE 	*clp;		/* Saved line pointer */
	int		 c;
	int		 cbo;		/* Saved offset */
	int		 success;
	int		 pptr;
	char	 opat[NPAT];

	for (cip = 0; cip < NSRCH; cip++)
		cmds[cip].s_code = SRCH_NOPR;

	(void)strlcpy(opat, pat, sizeof(opat));
	cip = 0;
	pptr = -1;
	clp = curwp->w_dotp;
	cbo = curwp->w_doto;
	is_lpush();
	is_cpush(SRCH_BEGIN);
	success = TRUE;
	is_prompt(dir, TRUE, success);

	for (;;) {
		update();
		c = ttgetc();

		switch (c) {
		case ESC:
			/*
			 * If new characters come in the next 300 msec,
			 * we can assume that they belong to a longer
			 * escaped sequence so we should ungetkey the
			 * ESC to avoid writing out garbage.
			 *
			 * BUG: The Mg code had these lines, however
			 * I was not able to get ttwait() to indicate that
			 * chars had arrived in the input buffer as it 
			 * always returned TRUE. So it made no difference.
			 *
			 * if (ttwait(300) == FALSE)
			 *   ungetkey(c);
			 *
			 * What will happen is that if the user hits
			 * up-arrow during an isearch then it terminates
			 * and [A gets output at the last search position.
			 * The same issue can also be observed in uEmacs/Pk
			 */

			/* FALLTHRU */
		case CTRL_M:
			srch_lastdir = dir;
			curwp->w_markp = clp;
			curwp->w_marko = cbo;
			setmark(0,0);
			return (TRUE);

		case CTRL_G:
			if (success != TRUE) {
				while (is_peek() == SRCH_ACCM)
					is_undo(&pptr, &dir);
				success = TRUE;
				is_prompt(dir, pptr < 0, success);
				break;
			}
			curwp->w_dotp = clp;
			curwp->w_doto = cbo;
			curwp->w_flag |= WFMOVE;
			srch_lastdir = dir;
			(void)strlcpy(pat, opat, NPAT);
			(void)ctrlg(FFRAND, 0);
			return (ABORT);
		case CTRL_S:
			if (dir == SRCH_BACK) {
				dir = SRCH_FORW;
				is_lpush();
				is_cpush(SRCH_FORW);
				success = TRUE;
			}
			if (success == FALSE && dir == SRCH_FORW) {
				/* wrap the search to beginning */
				curwp->w_dotp = bfirstlp(curbp);
				curwp->w_doto = 0;
				if (is_find(dir) != FALSE) {
					is_cpush(SRCH_MARK);
					success = TRUE;
				}
				mlwrite("Overwrapped I-search: %s", pat);
				break;
			}

			is_lpush();
			pptr = strlen(pat);
			(void)forwchar(FFRAND, 1);
			if (is_find(SRCH_FORW) != FALSE)
				is_cpush(SRCH_MARK);
			else {
				(void)backchar(FFRAND, 1);
				(*term.t_beep) ();
				success = FALSE;
				mlwrite("Failed I-search: %s", pat);
			}
			is_prompt(dir, pptr < 0, success);
			break;
		case CTRL_R:
			if (dir == SRCH_FORW) {
				dir = SRCH_BACK;
				is_lpush();
				is_cpush(SRCH_BACK);
				success = TRUE;
			}
			if (success == FALSE && dir == SRCH_BACK) {
				/* wrap the search to end */
				curwp->w_dotp = blastlp(curbp);
				curwp->w_doto = llength(curwp->w_dotp);
				if (is_find(dir) != FALSE) {
					is_cpush(SRCH_MARK);
					success = TRUE;
				}
				mlwrite("Overwrapped I-search: %s", pat);
				break;
			}
			is_lpush();
			pptr = strlen(pat);
			(void)backchar(FFRAND, 1);
			if (is_find(SRCH_BACK) != FALSE)
				is_cpush(SRCH_MARK);
			else {
				(void)forwchar(FFRAND, 1);
				(*term.t_beep) ();
				success = FALSE;
			}
			is_prompt(dir, pptr < 0, success);
			break;
		case CTRL_H:
		case BACKSPACE:
			is_undo(&pptr, &dir);
			if (is_peek() != SRCH_ACCM)
				success = TRUE;
			is_prompt(dir, pptr < 0, success);
			break;
		default:
			if (ISCTRL(c)) {
			  /* ungetkey(c);  not required as we allow any CTRL key to exit isearch */
				curwp->w_markp = clp;
				curwp->w_marko = cbo;
				setmark(0,0);
				curwp->w_flag |= WFMOVE;
				return (TRUE);
			}
			/* FALLTHRU */
		case CTRL_I:
		  //addchar:
			if (pptr == -1)
				pptr = 0;
			if (pptr == 0)
				success = TRUE;
			if (pptr == NPAT - 1)
				(*term.t_beep) ();
			else {
				pat[pptr++] = c;
				pat[pptr] = '\0';
			}
			is_lpush();
			if (success != FALSE) {
				if (is_find(dir) != FALSE)
					is_cpush(c);
				else {
					success = FALSE;
					(*term.t_beep) ();
					is_cpush(SRCH_ACCM);
				}
			} else
				is_cpush(SRCH_ACCM);
			is_prompt(dir, FALSE, success);
		}
	}
	/* NOTREACHED */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x8(%rbp)
movl $0x0, 0x7838(%rip)      # 0x10b50
cmpl $0x80, 0x782e(%rip)     # 0x10b50
jge 0x9350
movslq 0x7825(%rip), %rcx      # 0x10b50
leaq 0x782e(%rip), %rax      # 0x10b60
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0xfffffffd, (%rax)     # imm = 0xFFFFFFFD
movl 0x780b(%rip), %eax      # 0x10b50
addl $0x1, %eax
movl %eax, 0x7802(%rip)      # 0x10b50
jmp 0x9318
leaq -0x70(%rbp), %rdi
leaq 0x7735(%rip), %rsi      # 0x10a90
movl $0x50, %edx
callq 0x9220
movl $0x0, 0x77e1(%rip)      # 0x10b50
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
leaq 0x76db(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x10(%rbp)
leaq 0x76c9(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq 0x20(%rax), %rax
movl %eax, -0x18(%rbp)
callq 0xa5d0
xorl %edi, %edi
callq 0xa660
movl $0x1, -0x1c(%rbp)
movl -0x8(%rbp), %edi
movl -0x1c(%rbp), %edx
movl $0x1, %esi
callq 0xa6b0
xorl %eax, %eax
movb %al, -0x75(%rbp)
callq 0x46b0
movb -0x75(%rbp), %al
callq 0xaf00
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x74(%rbp)
subl $0x7, %eax
je 0x9481
jmp 0x93e2
movl -0x74(%rbp), %eax
subl $0x8, %eax
je 0x977f
jmp 0x93f0
movl -0x74(%rbp), %eax
subl $0x9, %eax
je 0x9814
jmp 0x93fe
movl -0x74(%rbp), %eax
subl $0xd, %eax
je 0x943f
jmp 0x9408
movl -0x74(%rbp), %eax
subl $0x12, %eax
je 0x965c
jmp 0x9416
movl -0x74(%rbp), %eax
subl $0x13, %eax
je 0x9533
jmp 0x9424
movl -0x74(%rbp), %eax
subl $0x1b, %eax
je 0x943f
jmp 0x942e
movl -0x74(%rbp), %eax
subl $0x7f, %eax
je 0x977f
jmp 0x97b9
movl -0x8(%rbp), %eax
movl %eax, 0x7428(%rip)      # 0x10870
movq -0x10(%rbp), %rcx
leaq 0x7605(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x28(%rax)
movslq -0x18(%rbp), %rcx
leaq 0x75f3(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x30(%rax)
xorl %esi, %esi
movl %esi, %edi
callq 0x2cb0
movl $0x1, -0x4(%rbp)
jmp 0x98cb
cmpl $0x1, -0x1c(%rbp)
je 0x94c5
jmp 0x9489
callq 0xa740
cmpl $-0x4, %eax
jne 0x94a2
leaq -0x20(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0xa760
jmp 0x9489
movl $0x1, -0x1c(%rbp)
movl -0x8(%rbp), %edi
cmpl $0x0, -0x20(%rbp)
setl %al
andb $0x1, %al
movzbl %al, %esi
movl -0x1c(%rbp), %edx
callq 0xa6b0
jmp 0x98c6
movq -0x10(%rbp), %rcx
leaq 0x7588(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x18(%rax)
movslq -0x18(%rbp), %rcx
leaq 0x7576(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x20(%rax)
leaq 0x7568(%rip), %rax      # 0x10a58
movq (%rax), %rax
movsbl 0x3b(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x3b(%rax)
movl -0x8(%rbp), %eax
movl %eax, 0x736a(%rip)      # 0x10870
leaq -0x70(%rbp), %rsi
leaq 0x757f(%rip), %rdi      # 0x10a90
movl $0x50, %edx
callq 0x9220
movl $0x8, %edi
xorl %esi, %esi
callq 0x83d0
movl $0x2, -0x4(%rbp)
jmp 0x98cb
cmpl $-0x2, -0x8(%rbp)
jne 0x9556
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
callq 0xa5d0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xa660
movl $0x1, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x95cb
cmpl $-0x1, -0x8(%rbp)
jne 0x95cb
leaq 0x74df(%rip), %rax      # 0x10a48
movq (%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rcx
leaq 0x74de(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x18(%rax)
leaq 0x74d0(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq $0x0, 0x20(%rax)
movl -0x8(%rbp), %edi
callq 0xa840
cmpl $0x0, %eax
je 0x95b1
movl $0xfffffffb, %edi       # imm = 0xFFFFFFFB
callq 0xa660
movl $0x1, -0x1c(%rbp)
leaq 0x3135(%rip), %rdi      # 0xc6ed
leaq 0x74d1(%rip), %rsi      # 0x10a90
movb $0x0, %al
callq 0x56d0
jmp 0x98c6
callq 0xa5d0
leaq 0x74b9(%rip), %rdi      # 0x10a90
callq 0x20e0
movl %eax, -0x20(%rbp)
movl $0x8, %edi
movl $0x1, %esi
callq 0x25b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xa840
cmpl $0x0, %eax
je 0x9609
movl $0xfffffffb, %edi       # imm = 0xFFFFFFFB
callq 0xa660
jmp 0x9640
movl $0x8, %edi
movl $0x1, %esi
callq 0x24c0
leaq 0x7259(%rip), %rcx      # 0x10878
movb $0x0, %al
callq *0x50(%rcx)
movl $0x0, -0x1c(%rbp)
leaq 0x30d4(%rip), %rdi      # 0xc706
leaq 0x7457(%rip), %rsi      # 0x10a90
movb $0x0, %al
callq 0x56d0
movl -0x8(%rbp), %edi
cmpl $0x0, -0x20(%rbp)
setl %al
andb $0x1, %al
movzbl %al, %esi
movl -0x1c(%rbp), %edx
callq 0xa6b0
jmp 0x98c6
cmpl $-0x1, -0x8(%rbp)
jne 0x967f
movl $0xfffffffe, -0x8(%rbp) # imm = 0xFFFFFFFE
callq 0xa5d0
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
callq 0xa660
movl $0x1, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x9703
cmpl $-0x2, -0x8(%rbp)
jne 0x9703
leaq 0x73b6(%rip), %rax      # 0x10a48
movq (%rax), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rcx
leaq 0x73b4(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x18(%rax)
leaq 0x73a6(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x14(%rax), %rcx
leaq 0x7394(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x20(%rax)
movl -0x8(%rbp), %edi
callq 0xa840
cmpl $0x0, %eax
je 0x96e9
movl $0xfffffffb, %edi       # imm = 0xFFFFFFFB
callq 0xa660
movl $0x1, -0x1c(%rbp)
leaq 0x2ffd(%rip), %rdi      # 0xc6ed
leaq 0x7399(%rip), %rsi      # 0x10a90
movb $0x0, %al
callq 0x56d0
jmp 0x98c6
callq 0xa5d0
leaq 0x7381(%rip), %rdi      # 0x10a90
callq 0x20e0
movl %eax, -0x20(%rbp)
movl $0x8, %edi
movl $0x1, %esi
callq 0x24c0
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
callq 0xa840
cmpl $0x0, %eax
je 0x9741
movl $0xfffffffb, %edi       # imm = 0xFFFFFFFB
callq 0xa660
jmp 0x9763
movl $0x8, %edi
movl $0x1, %esi
callq 0x25b0
leaq 0x7121(%rip), %rcx      # 0x10878
movb $0x0, %al
callq *0x50(%rcx)
movl $0x0, -0x1c(%rbp)
movl -0x8(%rbp), %edi
cmpl $0x0, -0x20(%rbp)
setl %al
andb $0x1, %al
movzbl %al, %esi
movl -0x1c(%rbp), %edx
callq 0xa6b0
jmp 0x98c6
leaq -0x20(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0xa760
callq 0xa740
cmpl $-0x4, %eax
je 0x979d
movl $0x1, -0x1c(%rbp)
movl -0x8(%rbp), %edi
cmpl $0x0, -0x20(%rbp)
setl %al
andb $0x1, %al
movzbl %al, %esi
movl -0x1c(%rbp), %edx
callq 0xa6b0
jmp 0x98c6
cmpl $0x0, -0x14(%rbp)
jl 0x9812
cmpl $0x1f, -0x14(%rbp)
jg 0x9812
movq -0x10(%rbp), %rcx
leaq 0x7288(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x28(%rax)
movslq -0x18(%rbp), %rcx
leaq 0x7276(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x30(%rax)
xorl %esi, %esi
movl %esi, %edi
callq 0x2cb0
leaq 0x725f(%rip), %rax      # 0x10a58
movq (%rax), %rax
movsbl 0x3b(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x3b(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x98cb
jmp 0x9814
cmpl $-0x1, -0x20(%rbp)
jne 0x9821
movl $0x0, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x982e
movl $0x1, -0x1c(%rbp)
cmpl $0x4f, -0x20(%rbp)
jne 0x9842
leaq 0x703d(%rip), %rcx      # 0x10878
movb $0x0, %al
callq *0x50(%rcx)
jmp 0x986e
movl -0x14(%rbp), %eax
movb %al, %dl
movl -0x20(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x20(%rbp)
movslq %eax, %rcx
leaq 0x7234(%rip), %rax      # 0x10a90
movb %dl, (%rax,%rcx)
movslq -0x20(%rbp), %rcx
leaq 0x7226(%rip), %rax      # 0x10a90
movb $0x0, (%rax,%rcx)
callq 0xa5d0
cmpl $0x0, -0x1c(%rbp)
je 0x98af
movl -0x8(%rbp), %edi
callq 0xa840
cmpl $0x0, %eax
je 0x9890
movl -0x14(%rbp), %edi
callq 0xa660
jmp 0x98ad
movl $0x0, -0x1c(%rbp)
leaq 0x6fda(%rip), %rcx      # 0x10878
movb $0x0, %al
callq *0x50(%rcx)
movl $0xfffffffc, %edi       # imm = 0xFFFFFFFC
callq 0xa660
jmp 0x98b9
movl $0xfffffffc, %edi       # imm = 0xFFFFFFFC
callq 0xa660
movl -0x8(%rbp), %edi
movl -0x1c(%rbp), %edx
xorl %esi, %esi
callq 0xa6b0
jmp 0x93bc
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)