// File: /workspace/github_cpp_makefile_star2_O3/craigbarstow[P]cmd-line-text-editor/text_editor.cc
// Function: find_and_type(text_ed&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
bool find_and_type(text_ed & T, string cl, bool toggle) { //search area from first given line to second for a given word. Type all lines where word is found.
  bool error_state=false;
  string aline,m_string,n_string, word;
  int i = 0,m=0,n=0,p=1,m_begin, m_end, n_begin, n_end,document_length, word_start, word_end,count=0; 
  if (cl.find_first_not_of(" ",1)!=string::npos){ //section to isolate substring representing the first integer from the string
    m_begin= cl.find_first_not_of(" ",1);
    m_end = cl.find_first_of(" ", m_begin)-2;
    m_string=cl.substr(m_begin,m_end);
    if (istringstream(m_string) >> m) { //if substring can be converted to an integer, increment count to show the first integer is present
      count++;}
    if (cl.find_first_not_of(" ", m_end+2)!=string::npos){ //section to isolate substring representing the second integer from the string
      n_begin = cl.find_first_not_of(" ", m_end+2);
      n_end = cl.find_first_of("",n_begin);
      n_string=cl.substr(n_begin,n_end);
      if (istringstream(n_string) >> n){ //if substring can be converted to an integer, increment count to show the second integer is present
	count++;
      }
    }
    //SECTION TO MAKE SURE THE INTEGER VALUES MAKE SENSE
    document_length = T.get_last_line();
    if ((m<=0 || m>document_length) && count!=0){ //if first integer is less than the starting line number toggle error state on
      error_state=true;
    }
    if (n>document_length) { //if ending integer value is greater than the document length, toggle error state on
      error_state=true;
    }
    if (n<m && count==2){ //if the second integer is greater than the first, toggle error state on
      error_state=true;
    }
  }
  //section to isolate the substring representing the word to be searched for from the string
  if (cl.find_first_of("/")!=string::npos){ 
    word_start = cl.find_first_of("/")+1;
    word_end = cl.find_first_of("/",word_start);
    word = cl.substr(word_start,word_end-word_start); //select the correct substring from the string
  } else { //if word can't be found, return false, as there is no point in continuing
    return false;
  }

  if (!error_state) {
    switch (count) {
    case 0: //if no integers are present, search the whole document for the word
      n = T.get_last_line();
      for (i=1; i<=document_length; i++){
	if (T.get_line(aline,i)) {
	  if (aline.find(word)!=string::npos){
	    if (toggle) {  
	      cout << setw(2) << i << " ";
	    } else {
	      cout << " ";
	    }
	    cout << aline << endl;
	  }
	} else {
	  cout << "No line " << i << endl;
	  return false;
	}
      }
      break;
    case 1: //if 1 integer is present, search just that line for the given word
      if (T.get_line(aline,m)) {
	if (aline.find(word)!=string::npos){
	  if (toggle) {  
	    cout << setw(2) << m << " ";
	  } else {
	    cout << " ";
	  }
	  cout << aline << endl;
	} else {
	  cout << "No line " << i << endl;
	  return false;
	}
      }
      break;
    case 2: //if two integers are present, search from the starting int to the ending int for the word
      for (i = m; i<=n; i++){
	if (T.get_line(aline,i)) {
	  if (aline.find(word)!=string::npos){
	    if (toggle) {  
	      cout << setw(2) << i << " ";
	    } else {
	      cout << " ";
	    }
	    cout << aline << endl;
	  }
	} else {
	  cout << "No line " << i << endl;
	  return false;
	}
      }
    }
    return true; //return true if !error state
  } 
  return false; //return true if error state
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movl %edx, -0x34(%rbp)
movq %rsi, %r12
movq %rdi, -0x40(%rbp)
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
xorl %r15d, %r15d
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
movl %r15d, -0x30(%rbp)
movl %r15d, -0x2c(%rbp)
leaq 0x2d91(%rip), %rsi      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r12, %rdi
callq 0x2210
cmpq $-0x1, %rax
je 0x4867
leaq 0x2d6e(%rip), %rbx      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2210
movslq %eax, %r14
movl $0x1, %ecx
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x21e0
movq %rax, %rbx
shlq $0x20, %rbx
movabsq $-0x200000000, %rcx     # imm = 0xFFFFFFFE00000000
addq %rbx, %rcx
sarq $0x20, %rcx
leaq -0x248(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2160
leaq -0xc8(%rbp), %rdi
leaq -0x248(%rbp), %r14
movq %r14, %rsi
callq 0x2190
movq (%r14), %rdi
leaq -0x238(%rbp), %r13
cmpq %r13, %rdi
je 0x46e9
movq -0x238(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x248(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
movl $0x8, %edx
callq 0x2200
leaq -0x248(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x20c0
leaq -0x248(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl -0x228(%rbp,%rax), %r14d
xorl %r15d, %r15d
testb $0x5, %r14b
sete %r15b
movq 0x5887(%rip), %rsi      # 0x9fc0
callq 0x21c0
leaq -0x1d0(%rbp), %rdi
callq 0x2080
sarq $0x20, %rbx
leaq 0x2c79(%rip), %rsi      # 0x73ce
movl $0x1, %ecx
movq %r12, %rdi
movq %rbx, %rdx
callq 0x2210
cmpq $-0x1, %rax
je 0x484a
leaq 0x2c58(%rip), %rsi      # 0x73ce
movl $0x1, %ecx
movq %r12, %rdi
movq %rbx, %rdx
callq 0x2210
movslq %eax, %rbx
leaq 0x2c3f(%rip), %rsi      # 0x73cf
movq %r12, %rdi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x21e0
movslq %eax, %rcx
leaq -0x248(%rbp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2160
leaq -0xa8(%rbp), %rdi
leaq -0x248(%rbp), %rbx
movq %rbx, %rsi
callq 0x2190
movq (%rbx), %rdi
cmpq %r13, %rdi
je 0x47df
movq -0x238(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x248(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movl $0x8, %edx
callq 0x2200
leaq -0x248(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x20c0
andl $0x5, %r14d
leaq -0x1d0(%rbp), %rbx
movq -0x78(%rbx), %rax
movq -0x18(%rax), %rax
xorl %ecx, %ecx
cmpl $0x1, %r14d
adcl $0x1, %ecx
testb $0x5, -0x228(%rbp,%rax)
movq 0x578e(%rip), %rsi      # 0x9fc0
cmovel %ecx, %r15d
leaq -0x248(%rbp), %rdi
callq 0x21c0
movq %rbx, %rdi
callq 0x2080
movq -0x40(%rbp), %rdi
callq 0x66a4
movl -0x30(%rbp), %edi
testl %edi, %edi
jle 0x4873
xorl %ecx, %ecx
cmpl %eax, %edi
jle 0x487e
testl %r15d, %r15d
jne 0x4878
jmp 0x487e
movq %rax, -0x88(%rbp)
xorl %r13d, %r13d
jmp 0x48a4
testl %r15d, %r15d
je 0x487c
movb $0x1, %cl
jmp 0x487e
xorl %ecx, %ecx
movl -0x2c(%rbp), %edx
movq %rax, -0x88(%rbp)
cmpl %eax, %edx
setg %sil
orb %cl, %sil
cmpl %edi, %edx
setl %al
cmpl $0x2, %r15d
sete %r13b
andb %al, %r13b
orb %sil, %r13b
leaq 0x2b5a(%rip), %rsi      # 0x7405
xorl %r14d, %r14d
movl $0x1, %ecx
movq %r12, %rdi
xorl %edx, %edx
callq 0x21e0
cmpq $-0x1, %rax
je 0x494d
leaq 0x2b37(%rip), %rbx      # 0x7405
movl $0x1, %ecx
movq %r12, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x21e0
incl %eax
movslq %eax, %r14
movl $0x1, %ecx
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x21e0
subl %r14d, %eax
movslq %eax, %rcx
leaq -0x248(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2160
leaq -0x80(%rbp), %rdi
leaq -0x248(%rbp), %rbx
movq %rbx, %rsi
callq 0x2190
movq (%rbx), %rdi
leaq -0x238(%rbp), %rax
cmpq %rax, %rdi
je 0x4941
movq -0x238(%rbp), %rsi
incq %rsi
callq 0x2140
testb %r13b, %r13b
je 0x49d8
xorl %r14d, %r14d
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x4966
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x4988
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x49aa
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x49c3
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2140
movl %r14d, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r15d
je 0x4a51
cmpl $0x1, %r15d
jne 0x4b28
movl -0x30(%rbp), %edx
leaq -0x60(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x6a74
movb $0x1, %r14b
testb %al, %al
je 0x494d
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rcx
leaq -0x60(%rbp), %rdi
xorl %edx, %edx
callq 0x2250
cmpq $-0x1, %rax
je 0x4cb1
cmpb $0x0, -0x34(%rbp)
je 0x4ce4
movq 0x5597(%rip), %rdi      # 0x9fc8
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rdi,%rax)
movl -0x30(%rbp), %esi
callq 0x2240
movq %rax, %rdi
jmp 0x4ceb
movl -0x30(%rbp), %r12d
movb $0x1, %r14b
cmpl -0x2c(%rbp), %r12d
jg 0x494d
leaq -0x60(%rbp), %rbx
movq 0x555b(%rip), %r14      # 0x9fc8
leaq 0x295a(%rip), %r13      # 0x73ce
movq -0x40(%rbp), %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x6a74
testb %al, %al
je 0x4c5b
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2250
cmpq $-0x1, %rax
je 0x4b11
movq %r14, %rax
cmpb $0x0, -0x34(%rbp)
je 0x4ac7
movq (%r14), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%r14,%rax)
movq %r14, %rdi
movl %r12d, %esi
callq 0x2240
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2180
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r14, %rdi
callq 0x2180
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leal 0x1(%r12), %eax
cmpl -0x2c(%rbp), %r12d
movl %eax, %r12d
jl 0x4a74
jmp 0x4c13
movq -0x40(%rbp), %rdi
callq 0x66a4
movq -0x88(%rbp), %r13
movl %eax, -0x2c(%rbp)
movb $0x1, %r14b
testl %r13d, %r13d
jle 0x494d
negl %r13d
movl $0x1, %r12d
leaq -0x60(%rbp), %rbx
movq 0x546d(%rip), %r14      # 0x9fc8
movq -0x40(%rbp), %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x6a74
testb %al, %al
je 0x4c1b
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2250
cmpq $-0x1, %rax
je 0x4bfc
movq %r14, %rax
cmpb $0x0, -0x34(%rbp)
je 0x4bae
movq (%r14), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%r14,%rax)
movq %r14, %rdi
movl %r12d, %esi
callq 0x2240
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2811(%rip), %rsi      # 0x73ce
callq 0x2180
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r14, %rdi
callq 0x2180
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leal (%r12,%r13), %eax
incl %eax
movl %r12d, %ecx
incl %ecx
movl %ecx, %r12d
cmpl $0x1, %eax
jne 0x4b5b
movb $0x1, %r14b
jmp 0x494d
movq 0x53a6(%rip), %rdi      # 0x9fc8
leaq 0x27de(%rip), %rsi      # 0x7407
movl $0x8, %edx
callq 0x2180
movq 0x538e(%rip), %rdi      # 0x9fc8
movl %r12d, %esi
callq 0x2240
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
jmp 0x4c99
movq 0x5366(%rip), %rdi      # 0x9fc8
leaq 0x279e(%rip), %rsi      # 0x7407
movl $0x8, %edx
callq 0x2180
movq 0x534e(%rip), %rdi      # 0x9fc8
movl %r12d, %esi
callq 0x2240
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
jmp 0x494a
movq 0x5310(%rip), %rdi      # 0x9fc8
leaq 0x2748(%rip), %rsi      # 0x7407
movl $0x8, %edx
callq 0x2180
movq 0x52f8(%rip), %rdi      # 0x9fc8
xorl %esi, %esi
callq 0x2240
movq %rax, %rdi
callq 0x20a0
jmp 0x494a
movq 0x52dd(%rip), %rdi      # 0x9fc8
leaq 0x26dc(%rip), %rsi      # 0x73ce
movl $0x1, %edx
callq 0x2180
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0x52bd(%rip), %rdi      # 0x9fc8
callq 0x2180
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
jmp 0x494d
jmp 0x4d47
jmp 0x4d73
jmp 0x4d73
jmp 0x4d73
movq %rax, %rbx
movq 0x526f(%rip), %rsi      # 0x9fc0
leaq -0x248(%rbp), %rdi
callq 0x21c0
leaq -0x1d0(%rbp), %rdi
callq 0x2080
jmp 0x4d76
jmp 0x4d73
jmp 0x4d73
jmp 0x4d73
jmp 0x4d73
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x4d8f
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x4db1
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x4dd3
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x4dec
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x2260