// File: /workspace/github_cpp_makefile_star2_O2/craigbarstow[P]cmd-line-text-editor/text_editor.cc
// Function: add_lines(text_ed&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool add_lines (text_ed & T, string cl) { //add lines to the array representing the document, but don't save it
  bool error_state = false;
  int m_begin, m_end, m, count=0;  
  string new_line, m_string;
  if (cl.find_first_not_of(" ",1)!=string::npos){ //this section selects the 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 can be converted to an integer, increment the count
      count++;
    }
    //SECTION TO MAKE SURE INTEGER MAKES SENSE
    if ((m < 0 || m > T.get_last_line()) && count==1) {
      error_state=true;
    }
    if (count==1 && m==0) { //if m is equal to zero, set count to zero so lines will be added at the beginning of the document
      count=0;
    }
  }
  if (!error_state) {
    switch (count) {
    case 0: //if no integer is present, add lines starting at document start
      cout << " Press Control +  D to stop"<<endl;
      while (getline(cin,new_line)){ //continue accepting new lines until ctrl d is entered
	T.insert_line(new_line,m=0);
	m++;
      }
      cin.clear();
      cout << endl;
      break;
    case 1:
      cout << " Press control-D to stop"<<endl;
      while (getline(cin,new_line)){ //continue accepting new lines until ctrl d is entered
	T.insert_line(new_line,m);
	m++;
      }
      cin.clear();
      cout << endl;
      break;
    default:
      return false;
    }
    return true; //return true after running switch statement contents
  }
    return false; //return false if error state is true
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x210, %rsp            # imm = 0x210
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x36a8(%rip), %rsi      # 0x63ce
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x2120
cmpq $-0x1, %rax
je 0x2e82
leaq 0x368c(%rip), %r15      # 0x63ce
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2120
movslq %eax, %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2100
addl $-0x2, %eax
movslq %eax, %rcx
leaq -0x228(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x21a0
leaq -0x68(%rbp), %r14
leaq -0x228(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x21c0
movq %r15, %rdi
callq 0x20d0
leaq -0x228(%rbp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x2220
leaq -0x228(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x2130
leaq -0x228(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl -0x208(%rbp,%rax), %r14d
callq 0x20e0
movl -0x24(%rbp), %r15d
testl %r15d, %r15d
js 0x2e78
movq %rbx, %rdi
callq 0x5182
testb $0x5, %r14b
jne 0x2df8
cmpl %eax, %r15d
jg 0x2f16
testb $0x5, %r14b
jne 0x2e82
cmpl $0x0, -0x24(%rbp)
je 0x2e82
movq 0x61b9(%rip), %rdi      # 0x8fc8
leaq 0x35d6(%rip), %rsi      # 0x63ec
callq 0x2190
movq %rax, %rdi
callq 0x20f0
movq 0x61ae(%rip), %r14      # 0x8fd8
leaq -0x48(%rbp), %r15
leaq -0x88(%rbp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2ef1
movq %r12, %rdi
movq %r15, %rsi
callq 0x21e0
movl -0x24(%rbp), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5288
movq %r12, %rdi
callq 0x20d0
incl -0x24(%rbp)
jmp 0x2e35
testb $0x5, %r14b
je 0x2f16
movq 0x613f(%rip), %rdi      # 0x8fc8
leaq 0x3540(%rip), %rsi      # 0x63d0
callq 0x2190
movq %rax, %rdi
callq 0x20f0
movq 0x6134(%rip), %r14      # 0x8fd8
leaq -0x48(%rbp), %r15
leaq -0xa8(%rbp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2ef1
movq %r12, %rdi
movq %r15, %rsi
callq 0x21e0
andl $0x0, -0x24(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x5288
movq %r12, %rdi
callq 0x20d0
incl -0x24(%rbp)
jmp 0x2eaf
movq 0x60e0(%rip), %rdi      # 0x8fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x2230
movb $0x1, %bl
movq 0x60b9(%rip), %rdi      # 0x8fc8
callq 0x20f0
jmp 0x2f18
xorl %ebx, %ebx
leaq -0x68(%rbp), %rdi
callq 0x20d0
leaq -0x48(%rbp), %rdi
callq 0x20d0
movl %ebx, %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x228(%rbp), %rdi
callq 0x20e0
jmp 0x2f75
jmp 0x2f72
jmp 0x2f72
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
jmp 0x2f6b
jmp 0x2f72
jmp 0x2f72
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x20d0
jmp 0x2f75
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x20d0
leaq -0x48(%rbp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x2260