// File: /workspace/github_cpp_makefile_star2_O3/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 $0x208, %rsp            # imm = 0x208
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x40(%rbp), %r13
movq %r13, -0x10(%r13)
xorl %eax, %eax
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq -0x60(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x410c(%rip), %rsi      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r14, %rdi
callq 0x2210
cmpq $-0x1, %rax
je 0x34c3
leaq 0x40e9(%rip), %r15      # 0x73ce
movl $0x1, %edx
movl $0x1, %ecx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2210
movslq %eax, %r12
movl $0x1, %ecx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x21e0
addl $-0x2, %eax
movslq %eax, %rcx
leaq -0x230(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2160
leaq -0x70(%rbp), %rdi
leaq -0x230(%rbp), %r14
movq %r14, %rsi
callq 0x2190
movq (%r14), %rdi
leaq -0x220(%rbp), %rax
cmpq %rax, %rdi
je 0x3359
movq -0x220(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x230(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x8, %edx
callq 0x2200
leaq -0x230(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x20c0
leaq -0x230(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl -0x210(%rbp,%rax), %r14d
movq 0x6c25(%rip), %rsi      # 0x9fc0
callq 0x21c0
leaq -0x1b8(%rbp), %rdi
callq 0x2080
movl -0x2c(%rbp), %r15d
testl %r15d, %r15d
js 0x34b9
movq %rbx, %rdi
callq 0x66a4
testb $0x5, %r14b
jne 0x33d0
cmpl %eax, %r15d
jg 0x35ec
testb $0x5, %r14b
jne 0x34c3
cmpl $0x0, -0x2c(%rbp)
je 0x34c3
movq 0x6bdd(%rip), %r14      # 0x9fc8
leaq 0x3ffa(%rip), %rsi      # 0x73ec
movl $0x18, %edx
movq %r14, %rdi
callq 0x2180
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x6bab(%rip), %rdi      # 0x9fc8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leaq -0x80(%rbp), %r13
movq 0x6ba3(%rip), %r14      # 0x9fd8
leaq -0x50(%rbp), %r15
leaq -0x90(%rbp), %r12
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x35a0
movq %r13, -0x90(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x5f5e
movl -0x2c(%rbp), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x683e
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x34b4
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2140
incl -0x2c(%rbp)
jmp 0x3440
testb $0x5, %r14b
je 0x35ec
movq 0x6afe(%rip), %r14      # 0x9fc8
leaq 0x3eff(%rip), %rsi      # 0x73d0
movl $0x1b, %edx
movq %r14, %rdi
callq 0x2180
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x6acc(%rip), %rdi      # 0x9fc8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leaq -0xa0(%rbp), %r13
movq 0x6ac1(%rip), %r14      # 0x9fd8
leaq -0x50(%rbp), %r15
leaq -0xb0(%rbp), %r12
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x35a0
movq %r13, -0xb0(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x5f5e
movl $0x0, -0x2c(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x683e
movq -0xb0(%rbp), %rdi
cmpq %r13, %rdi
je 0x359b
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2140
incl -0x2c(%rbp)
jmp 0x3522
movq 0x6a31(%rip), %rdi      # 0x9fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
leaq -0x40(%rbp), %r13
callq 0x2220
movq 0x6a08(%rip), %rdi      # 0x9fc8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x69ed(%rip), %rdi      # 0x9fc8
callq 0x2040
movb $0x1, %bl
movq %rax, %rdi
callq 0x20d0
jmp 0x35ee
xorl %ebx, %ebx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x3607
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x361c
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2140
movl %ebx, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x6986(%rip), %rsi      # 0x9fc0
leaq -0x230(%rbp), %rdi
callq 0x21c0
leaq -0x1b8(%rbp), %rdi
callq 0x2080
jmp 0x3694
jmp 0x3691
jmp 0x3691
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x3694
movq -0x80(%rbp), %rsi
jmp 0x3687
jmp 0x3691
jmp 0x3691
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r13, %rdi
je 0x3694
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x3694
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x36ad
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x36c6
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x2260