// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rsi, %r15
movq %rdi, %rbx
leaq -0x40(%rbp), %r13
movq %r13, -0x10(%r13)
xorl %r12d, %r12d
movq %r12, -0x8(%r13)
movb %r12b, (%r13)
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r12, -0x8(%rax)
movb %r12b, (%rax)
leaq 0x40e2(%rip), %rsi      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r15, %rdi
callq 0x2210
cmpq $-0x1, %rax
je 0x33f7
leaq 0x40bf(%rip), %r14      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2210
movslq %eax, %r12
movl $0x1, %ecx
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x21e0
addl $-0x2, %eax
movslq %eax, %rcx
leaq -0x238(%rbp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2160
leaq -0x70(%rbp), %rdi
leaq -0x238(%rbp), %r14
movq %r14, %rsi
callq 0x2190
movq (%r14), %rdi
leaq -0x228(%rbp), %rax
cmpq %rax, %rdi
je 0x3383
movq -0x228(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x238(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x8, %edx
callq 0x2200
leaq -0x238(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x20c0
leaq -0x238(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl -0x218(%rbp,%rax), %r14d
movq 0x6bfb(%rip), %rsi      # 0x9fc0
callq 0x21c0
leaq -0x1c0(%rbp), %rdi
callq 0x2080
movl -0x2c(%rbp), %r15d
testl %r15d, %r15d
js 0x33fb
movq %rbx, %rdi
callq 0x66b4
xorl %r12d, %r12d
testb $0x5, %r14b
jne 0x3409
cmpl %eax, %r15d
jg 0x3406
jmp 0x3409
movb $0x1, %al
jmp 0x3419
testb $0x5, %r14b
je 0x3406
xorl %r12d, %r12d
jmp 0x3409
movb $0x1, %r12b
testb $0x5, %r14b
setne %cl
cmpl $0x0, -0x2c(%rbp)
sete %al
orb %cl, %al
testb %r12b, %r12b
jne 0x3635
testb %al, %al
movq %r12, -0x78(%rbp)
je 0x3512
movq 0x6b93(%rip), %r15      # 0x9fc8
leaq 0x3f94(%rip), %rsi      # 0x73d0
movl $0x1b, %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 0x6b61(%rip), %rdi      # 0x9fc8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leaq -0xa8(%rbp), %r14
movq 0x6b56(%rip), %r15      # 0x9fd8
leaq -0x50(%rbp), %r12
leaq -0xb8(%rbp), %r13
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x35e9
movq %r14, -0xb8(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x5f86
movl $0x0, -0x2c(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x684e
movq -0xb8(%rbp), %rdi
cmpq %r14, %rdi
je 0x350a
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2140
incl -0x2c(%rbp)
jmp 0x348d
movq 0x6aaf(%rip), %r15      # 0x9fc8
leaq 0x3ecc(%rip), %rsi      # 0x73ec
movl $0x18, %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 0x6a7d(%rip), %rdi      # 0x9fc8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leaq -0x88(%rbp), %r14
movq 0x6a72(%rip), %r15      # 0x9fd8
leaq -0x50(%rbp), %r12
leaq -0x98(%rbp), %r13
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x35e9
movq %r14, -0x98(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x5f86
movl -0x2c(%rbp), %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x684e
movq -0x98(%rbp), %rdi
cmpq %r14, %rdi
je 0x35e4
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2140
incl -0x2c(%rbp)
jmp 0x3571
movq 0x69e8(%rip), %rdi      # 0x9fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
leaq -0x40(%rbp), %r13
callq 0x2220
movq -0x78(%rbp), %r12
movq 0x69bb(%rip), %rdi      # 0x9fc8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x69a0(%rip), %rdi      # 0x9fc8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x364e
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x3663
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2140
xorb $0x1, %r12b
movl %r12d, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x693a(%rip), %rsi      # 0x9fc0
leaq -0x238(%rbp), %rdi
callq 0x21c0
leaq -0x1c0(%rbp), %rdi
callq 0x2080
jmp 0x36e3
jmp 0x36e0
jmp 0x36e0
jmp 0x36e0
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r14, %rdi
je 0x36e3
movq -0x88(%rbp), %rsi
jmp 0x36d4
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
cmpq %r14, %rdi
je 0x36e3
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x36e3
jmp 0x36e0
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x36fc
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3715
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x2260