// File: /workspace/github_cpp_makefile_star2_O2/craigbarstow[P]cmd-line-text-editor/text_editor.cc
// Function: type_lines(text_ed&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
bool type_lines(text_ed & T, string cl, bool toggle) { //type lines between two given integers. If only one integer is given, type just that line. If no integers are given, type the whole document.
  bool error_state=false;
  string aline,m_string,n_string;
  int i=0,m=0,n=0,p=1,m_begin, m_end, n_begin, n_end,document_length,count=0;
  if (cl.find_first_not_of(" ",1)!=string::npos){ //this section selects the first integer from the substring
    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 the substring cant be converted to an integer, set error state to false
      error_state=true;
    } else {count++;} //if it can be converted, increment the count
    if (cl.find_first_not_of(" ", m_end+2)!=string::npos){ //this section selects the second integer from the substring
      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)){
	error_state=true;
      } else {count++;} //if it can be converted, increment the count
    }
    //SECTION TO MAKE SURE INTEGERS MAKE SENSE
    if (m<=0){ //if the line number is below 1, this automatically sets it to one
      error_state=true;
    }
    document_length = T.get_last_line();
    if (m>document_length) { //this makes sure that the starting position is less than the last line of the document
      error_state = true;
      cout << "The first line number given exceeds file length." << endl;
    }
    if (n>document_length) { //if the ending position is greater than the document length, toggle error state to true
      error_state=true;
    }
    if (count!=1 && n<m){ //if both a  start position and an end position are put in, and the end value is greater than the starting value, the error state will be toggled to true
      error_state=true;
    }
  }
  if (!error_state) { 
    switch (count) {
    case 0: //if no integers are input, print the entire document
      n = T.get_last_line();
      for (i = 1; i<=n ;i++) {
	if (toggle) { //if toggling line numbers is on, print line numbers
	  cout << setw(2) << i << "  ";
	}
	if (T.get_line(aline,i)) { //if the given line can be retrieved, display it
	  cout << aline << endl;
	} else { //if it can't, return false
	  return false;
	}
      }      
      break;
    case 1: //if one integer is input, print just that line
      if (toggle) { //if toggling line numbers is on, print line numbers
	cout << setw(2) << m << "  ";
      }
      if (T.get_line(aline,m)) { //if the line can be retrieved, display it
	cout << aline << endl;
      } else {return false;} 
      break; 
    case 2:
      for (i = m; i<=n; i++){ // for each line between the start and end line positions
	if (toggle) { //if toggling line numbers is on, print the line numbers
	  cout << setw(2) << i << " ";
	} 
	if (T.get_line(aline,i)) { //if the line can be retrieved, display it
	  cout << aline << endl;
	} else {
	  return false;
	}
      }
      break;
    }
    return true;
  }
  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movl %edx, -0x38(%rbp)
movq %rsi, %r15
movq %rdi, %rbx
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x90(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x70(%rbp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
andl $0x0, -0x34(%rbp)
movb %cl, (%rdx)
andl $0x0, -0x30(%rbp)
leaq 0x3b04(%rip), %rsi      # 0x63ce
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x2120
cmpq $-0x1, %rax
je 0x2b9b
leaq 0x3ae8(%rip), %r14      # 0x63ce
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2120
movslq %eax, %r13
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2100
movq %rax, %r12
shlq $0x20, %r12
movabsq $-0x200000000, %rcx     # imm = 0xFFFFFFFE00000000
addq %r12, %rcx
sarq $0x20, %rcx
leaq -0x220(%rbp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x21a0
leaq -0xa0(%rbp), %r14
leaq -0x220(%rbp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x21c0
movq %r13, %rdi
callq 0x20d0
leaq -0x220(%rbp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x2220
leaq -0x220(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x2130
leaq -0x220(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl -0x200(%rbp,%rax), %r13d
xorl %eax, %eax
testb $0x5, %r13b
setne -0x29(%rbp)
sete %al
movl %eax, -0x3c(%rbp)
callq 0x20e0
sarq $0x20, %r12
leaq 0x3a26(%rip), %rsi      # 0x63ce
movq %r15, %rdi
movq %r12, %rdx
callq 0x2120
cmpq $-0x1, %rax
je 0x2a76
leaq 0x3a0a(%rip), %rsi      # 0x63ce
movq %r15, %rdi
movq %r12, %rdx
callq 0x2120
movslq %eax, %r14
leaq 0x39f6(%rip), %rsi      # 0x63cf
movq %r15, %rdi
movq %r14, %rdx
callq 0x2100
movslq %eax, %rcx
leaq -0x220(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x21a0
leaq -0x80(%rbp), %r14
leaq -0x220(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x21c0
movq %r15, %rdi
callq 0x20d0
leaq -0x220(%rbp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x2220
leaq -0x220(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2130
andl $0x5, %r13d
leaq -0x220(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
xorl %ecx, %ecx
cmpl $0x1, %r13d
adcl $0x1, %ecx
testb $0x5, -0x200(%rbp,%rax)
setne %r14b
movl -0x3c(%rbp), %r12d
cmovel %ecx, %r12d
callq 0x20e0
movb -0x29(%rbp), %r13b
orb %r14b, %r13b
jmp 0x2a7e
movl -0x3c(%rbp), %r12d
movb -0x29(%rbp), %r13b
movl -0x34(%rbp), %r15d
movq %rbx, %rdi
callq 0x5182
movl %eax, %r14d
testl %r15d, %r15d
setle %cl
movl -0x34(%rbp), %r15d
cmpl %eax, %r15d
jle 0x2abf
movq 0x6525(%rip), %rdi      # 0x8fc8
leaq 0x38f2(%rip), %rsi      # 0x639c
callq 0x2190
movq %rax, %rdi
callq 0x20f0
movb $0x1, %cl
movl -0x34(%rbp), %r15d
jmp 0x2ac2
orb %r13b, %cl
movl -0x30(%rbp), %eax
cmpl %r14d, %eax
setg %dl
orb %cl, %dl
cmpl %r15d, %eax
setl %cl
orb %dl, %cl
cmpl $0x1, %r12d
movzbl %cl, %ecx
movzbl %dl, %edx
cmovnel %ecx, %edx
testb $0x1, %dl
je 0x2b1d
xorl %r12d, %r12d
leaq -0x80(%rbp), %rdi
callq 0x20d0
leaq -0xa0(%rbp), %rdi
callq 0x20d0
leaq -0x60(%rbp), %rdi
callq 0x20d0
movl %r12d, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r12d, %r12d
je 0x2b9b
cmpl $0x1, %r12d
jne 0x2c24
cmpb $0x0, -0x38(%rbp)
je 0x2b64
movq 0x648f(%rip), %rdi      # 0x8fc8
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rdi,%rax)
movl %r15d, %esi
callq 0x2250
leaq 0x3875(%rip), %rsi      # 0x63cd
movq %rax, %rdi
callq 0x2190
movl -0x34(%rbp), %r15d
leaq -0x60(%rbp), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x5436
testb %al, %al
je 0x2ae7
movq 0x6446(%rip), %rdi      # 0x8fc8
leaq -0x60(%rbp), %rsi
callq 0x2170
movb $0x1, %r12b
movq %rax, %rdi
callq 0x20f0
jmp 0x2aea
movq %rbx, %rdi
callq 0x5182
movl %eax, -0x30(%rbp)
pushq $0x1
popq %r15
movq 0x6417(%rip), %r13      # 0x8fc8
leaq -0x60(%rbp), %r14
cmpl %eax, %r15d
setg %r12b
jg 0x2aea
cmpb $0x0, -0x38(%rbp)
je 0x2bf3
movq (%r13), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%r13,%rax)
movq %r13, %rdi
movl %r15d, %esi
callq 0x2250
movq %rax, %rdi
leaq 0x37df(%rip), %rsi      # 0x63cd
callq 0x2190
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x5436
testb %al, %al
je 0x2aea
movq %r13, %rdi
movq %r14, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20f0
incl %r15d
movl -0x30(%rbp), %eax
jmp 0x2bb5
movq 0x639d(%rip), %r13      # 0x8fc8
leaq 0x379c(%rip), %r14      # 0x63ce
cmpl %eax, %r15d
setg %r12b
jg 0x2aea
cmpb $0x0, -0x38(%rbp)
je 0x2c6c
movq (%r13), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%r13,%rax)
movq %r13, %rdi
movl %r15d, %esi
callq 0x2250
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
movl %r15d, %edx
callq 0x5436
testb %al, %al
je 0x2aea
movq %r13, %rdi
leaq -0x60(%rbp), %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20f0
incl %r15d
movl -0x30(%rbp), %eax
jmp 0x2c32
jmp 0x2ca5
jmp 0x2cbe
jmp 0x2cbe
movq %rax, %rbx
leaq -0x220(%rbp), %rdi
callq 0x20e0
jmp 0x2cc1
jmp 0x2cbe
jmp 0x2cbe
jmp 0x2cbe
jmp 0x2cbe
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x20d0
leaq -0xa0(%rbp), %rdi
callq 0x20d0
leaq -0x60(%rbp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x2260