// File: /workspace/github_cpp_makefile_star2_O3/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), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x90(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x70(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movl %eax, -0x34(%rbp)
movl %eax, -0x30(%rbp)
leaq 0x472c(%rip), %rsi      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r15, %rdi
callq 0x2210
cmpq $-0x1, %rax
movq %rbx, -0x40(%rbp)
je 0x30ce
leaq 0x4705(%rip), %rbx      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2210
movslq %eax, %r14
movl $0x1, %ecx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x21e0
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 %r14, %rdx
callq 0x2160
leaq -0xa0(%rbp), %rdi
leaq -0x220(%rbp), %rbx
movq %rbx, %rsi
callq 0x2190
movq (%rbx), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0x2d52
movq -0x210(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x220(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movl $0x8, %edx
callq 0x2200
leaq -0x220(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x20c0
leaq -0x220(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl -0x200(%rbp,%rax), %r14d
xorl %r13d, %r13d
testb $0x5, %r14b
setne -0x29(%rbp)
sete %r13b
movq 0x721a(%rip), %rsi      # 0x9fc0
callq 0x21c0
leaq -0x1a8(%rbp), %rdi
callq 0x2080
sarq $0x20, %r12
leaq 0x460c(%rip), %rsi      # 0x73ce
movl $0x1, %ecx
movq %r15, %rdi
movq %r12, %rdx
callq 0x2210
cmpq $-0x1, %rax
je 0x2ec5
leaq 0x45eb(%rip), %rsi      # 0x73ce
movl $0x1, %ecx
movq %r15, %rdi
movq %r12, %rdx
callq 0x2210
movslq %eax, %rbx
leaq 0x45d2(%rip), %rsi      # 0x73cf
movq %r15, %rdi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x21e0
movslq %eax, %rcx
leaq -0x220(%rbp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2160
leaq -0x80(%rbp), %rdi
leaq -0x220(%rbp), %rbx
movq %rbx, %rsi
callq 0x2190
movq (%rbx), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
movb -0x29(%rbp), %r15b
je 0x2e54
movq -0x210(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x220(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x8, %edx
callq 0x2200
leaq -0x220(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x20c0
andl $0x5, %r14d
leaq -0x1a8(%rbp), %rbx
movq -0x78(%rbx), %rax
movq -0x18(%rax), %rax
xorl %ecx, %ecx
cmpl $0x1, %r14d
adcl $0x1, %ecx
testb $0x5, -0x200(%rbp,%rax)
setne %r14b
movq 0x7118(%rip), %rsi      # 0x9fc0
cmovel %ecx, %r13d
leaq -0x220(%rbp), %rdi
callq 0x21c0
movq %rbx, %rdi
callq 0x2080
orb %r14b, %r15b
jmp 0x2ec9
movb -0x29(%rbp), %r15b
movl -0x34(%rbp), %ebx
movq -0x40(%rbp), %rdi
callq 0x66a4
movl %eax, %r14d
testl %ebx, %ebx
setle %cl
movl -0x34(%rbp), %r12d
cmpl %eax, %r12d
jle 0x2f34
movq 0x70db(%rip), %rbx      # 0x9fc8
leaq 0x44a8(%rip), %rsi      # 0x739c
movl $0x30, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x70a9(%rip), %rdi      # 0x9fc8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movb $0x1, %cl
movl -0x34(%rbp), %r12d
jmp 0x2f37
orb %r15b, %cl
movl -0x30(%rbp), %eax
cmpl %r14d, %eax
setg %dl
orb %cl, %dl
cmpl %r12d, %eax
setl %cl
orb %dl, %cl
cmpl $0x1, %r13d
movzbl %cl, %ecx
movzbl %dl, %edx
cmovnel %ecx, %edx
testb $0x1, %dl
je 0x2f64
xorl %r15d, %r15d
jmp 0x3187
cmpl $0x2, %r13d
je 0x300f
cmpl $0x1, %r13d
jne 0x30ca
cmpb $0x0, -0x38(%rbp)
je 0x2fb5
movq 0x7043(%rip), %rdi      # 0x9fc8
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rdi,%rax)
movl %r12d, %esi
callq 0x2240
leaq 0x4429(%rip), %rsi      # 0x73cd
movl $0x2, %edx
movq %rax, %rdi
callq 0x2180
movl -0x34(%rbp), %r12d
movq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl %r12d, %edx
callq 0x6a74
testb %al, %al
je 0x2f5c
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0x6ff0(%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 0x3187
movb $0x1, %r15b
cmpl %r12d, %eax
jl 0x3187
movq 0x6fa6(%rip), %r13      # 0x9fc8
leaq 0x43a5(%rip), %r14      # 0x73ce
cmpb $0x0, -0x38(%rbp)
movq -0x40(%rbp), %rbx
je 0x305f
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 %r14, %rsi
callq 0x2180
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
movl %r12d, %edx
callq 0x6a74
movl %eax, %r15d
testb %al, %al
je 0x3187
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r13, %rdi
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
leal 0x1(%r12), %eax
cmpl -0x30(%rbp), %r12d
movl %eax, %r12d
jl 0x3029
jmp 0x3187
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x66a4
movl %eax, -0x30(%rbp)
testl %eax, %eax
jle 0x3184
xorl %r12d, %r12d
movq 0x6edd(%rip), %r13      # 0x9fc8
leaq -0x60(%rbp), %r14
incl %r12d
cmpb $0x0, -0x38(%rbp)
je 0x3128
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
leaq 0x42aa(%rip), %rsi      # 0x73cd
callq 0x2180
movq -0x40(%rbp), %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x6a74
movl %eax, %r15d
testb %al, %al
je 0x3187
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r13, %rdi
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
cmpl -0x30(%rbp), %r12d
jl 0x30ef
jmp 0x3187
movb $0x1, %r15b
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x31a0
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x31c2
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x31db
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2140
movl %r15d, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x31f6
jmp 0x3222
jmp 0x3222
movq %rax, %rbx
movq 0x6dc0(%rip), %rsi      # 0x9fc0
leaq -0x220(%rbp), %rdi
callq 0x21c0
leaq -0x1a8(%rbp), %rdi
callq 0x2080
jmp 0x3225
jmp 0x3222
jmp 0x3222
jmp 0x3222
jmp 0x3222
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x323e
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x3260
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x3279
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x2260