// File: /workspace/github_cpp_makefile_star2_O1/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 $0x208, %rsp            # imm = 0x208
movl %edx, -0x34(%rbp)
movq %rsi, %r15
movq %rdi, -0x40(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
xorl %r13d, %r13d
movq %r13, -0x8(%rax)
movb %r13b, (%rax)
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r13, -0x8(%rax)
movb %r13b, (%rax)
leaq -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r13, -0x8(%rax)
movb %r13b, (%rax)
movl %r13d, -0x2c(%rbp)
movl %r13d, -0x30(%rbp)
leaq 0x4729(%rip), %rsi      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r15, %rdi
callq 0x2210
movl $0x0, %ecx
cmpq $-0x1, %rax
je 0x2f74
leaq 0x4701(%rip), %r14      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2210
movslq %eax, %r13
movl $0x1, %ecx
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x21e0
movq %rax, %r12
shlq $0x20, %r12
movabsq $-0x200000000, %rcx     # imm = 0xFFFFFFFE00000000
addq %r12, %rcx
sarq $0x20, %rcx
leaq -0x228(%rbp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2160
leaq -0xa8(%rbp), %rdi
leaq -0x228(%rbp), %r14
movq %r14, %rsi
callq 0x2190
movq (%r14), %rdi
leaq -0x218(%rbp), %rax
cmpq %rax, %rdi
je 0x2d56
movq -0x218(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x228(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movl $0x8, %edx
callq 0x2200
leaq -0x228(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x20c0
leaq -0x228(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl -0x208(%rbp,%rax), %ebx
xorl %r13d, %r13d
testb $0x5, %bl
setne %al
movl %eax, -0x44(%rbp)
sete %r13b
movq 0x7216(%rip), %rsi      # 0x9fc0
callq 0x21c0
leaq -0x1b0(%rbp), %rdi
callq 0x2080
sarq $0x20, %r12
leaq 0x4608(%rip), %rsi      # 0x73ce
movl $0x1, %ecx
movq %r15, %rdi
movq %r12, %rdx
callq 0x2210
cmpq $-0x1, %rax
je 0x2edb
leaq 0x45e7(%rip), %rsi      # 0x73ce
movl $0x1, %ecx
movq %r15, %rdi
movq %r12, %rdx
callq 0x2210
movslq %eax, %r14
leaq 0x45ce(%rip), %rsi      # 0x73cf
movq %r15, %rdi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x21e0
movslq %eax, %rcx
leaq -0x228(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2160
leaq -0x88(%rbp), %rdi
leaq -0x228(%rbp), %r14
movq %r14, %rsi
callq 0x2190
movq (%r14), %rdi
leaq -0x218(%rbp), %rax
cmpq %rax, %rdi
movl -0x44(%rbp), %r15d
je 0x2e5b
movq -0x218(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x228(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movl $0x8, %edx
callq 0x2200
leaq -0x228(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x20c0
andl $0x5, %ebx
leaq -0x1b0(%rbp), %r14
movq -0x78(%r14), %rax
movq -0x18(%rax), %rax
movb -0x208(%rbp,%rax), %al
testb $0x5, %al
movl $0x0, %ecx
movb %r15b, %cl
movl $0x1, %r15d
cmovel %ecx, %r15d
xorl %ecx, %ecx
cmpl $0x1, %ebx
adcl $0x1, %ecx
testb $0x5, %al
movq 0x70ff(%rip), %rsi      # 0x9fc0
cmovel %ecx, %r13d
leaq -0x228(%rbp), %rdi
callq 0x21c0
movq %r14, %rdi
callq 0x2080
jmp 0x2edf
movl -0x44(%rbp), %r15d
movl -0x2c(%rbp), %ebx
movq -0x40(%rbp), %rdi
callq 0x66b4
movl %eax, %r14d
testl %ebx, %ebx
movzbl %r15b, %r15d
movl $0x1, %ebx
cmovlel %ebx, %r15d
cmpl %eax, -0x2c(%rbp)
jle 0x2f4b
movq 0x70bf(%rip), %r15      # 0x9fc8
leaq 0x448c(%rip), %rsi      # 0x739c
movl $0x30, %edx
movq %r15, %rdi
callq 0x2180
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x708d(%rip), %rdi      # 0x9fc8
callq 0x2040
movb $0x1, %r15b
movq %rax, %rdi
callq 0x20d0
movl -0x30(%rbp), %eax
cmpl %r14d, %eax
movzbl %r15b, %ecx
cmovgl %ebx, %ecx
cmpl $0x1, %r13d
jne 0x2f66
movl $0x1, %r13d
jmp 0x2f74
cmpl -0x2c(%rbp), %eax
movzbl %cl, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
testb %cl, %cl
je 0x2fe7
xorl %r15d, %r15d
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x2f97
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x2fb9
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x2fd2
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2140
movl %r15d, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r13d
je 0x3092
cmpl $0x1, %r13d
jne 0x314f
cmpb $0x0, -0x34(%rbp)
je 0x3034
movq 0x6fc0(%rip), %rdi      # 0x9fc8
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rdi,%rax)
movl -0x2c(%rbp), %esi
callq 0x2240
leaq 0x43a6(%rip), %rsi      # 0x73cd
movl $0x2, %edx
movq %rax, %rdi
callq 0x2180
movl -0x2c(%rbp), %edx
leaq -0x68(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x6a84
testb %al, %al
je 0x2f78
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x6f6d(%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
movb $0x1, %r15b
movq %rax, %rdi
callq 0x20d0
jmp 0x2f7b
movl -0x2c(%rbp), %r12d
movb $0x1, %r15b
cmpl -0x30(%rbp), %r12d
jg 0x2f7b
movq 0x6f1e(%rip), %r13      # 0x9fc8
leaq 0x431d(%rip), %rbx      # 0x73ce
cmpb $0x0, -0x34(%rbp)
je 0x30e3
movq (%r13), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%r13,%rax)
movq %r13, %rdi
movl %r12d, %esi
callq 0x2240
movl $0x1, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2180
movq -0x40(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl %r12d, %edx
callq 0x6a84
movl %eax, %r15d
testb %al, %al
je 0x2f7b
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %r13, %rdi
callq 0x2180
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leal 0x1(%r12), %eax
cmpl -0x30(%rbp), %r12d
movl %eax, %r12d
jl 0x30b1
jmp 0x2f7b
movq -0x40(%rbp), %rdi
callq 0x66b4
movl %eax, -0x30(%rbp)
testl %eax, %eax
jle 0x320d
xorl %r12d, %r12d
movq 0x6e5b(%rip), %r13      # 0x9fc8
leaq 0x4259(%rip), %rbx      # 0x73cd
incl %r12d
cmpb $0x0, -0x34(%rbp)
je 0x31a9
movq (%r13), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%r13,%rax)
movq %r13, %rdi
movl %r12d, %esi
callq 0x2240
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2180
movq -0x40(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl %r12d, %edx
callq 0x6a84
movl %eax, %r15d
testb %al, %al
je 0x2f7b
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %r13, %rdi
callq 0x2180
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
cmpl -0x30(%rbp), %r12d
jl 0x3174
jmp 0x2f7b
movb $0x1, %r15b
jmp 0x2f7b
jmp 0x321b
jmp 0x3247
jmp 0x3247
movq %rax, %rbx
movq 0x6d9b(%rip), %rsi      # 0x9fc0
leaq -0x228(%rbp), %rdi
callq 0x21c0
leaq -0x1b0(%rbp), %rdi
callq 0x2080
jmp 0x324a
jmp 0x3247
jmp 0x3247
jmp 0x3247
jmp 0x3247
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x3266
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x3288
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x32a1
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x2260