// File: 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
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rsi, -0x270(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movl $0x0, -0x2c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x32d0
leaq -0x70(%rbp), %rdi
callq 0x32d0
movq -0x270(%rbp), %rdi
leaq 0x4f99(%rip), %rsi      # 0x93ce
movl $0x1, %edx
callq 0x3140
cmpq $-0x1, %rax
je 0x45cc
movq -0x270(%rbp), %rdi
leaq 0x4f77(%rip), %rsi      # 0x93ce
movq %rsi, -0x278(%rbp)
movl $0x1, %edx
callq 0x3140
movq -0x278(%rbp), %rsi
movq -0x270(%rbp), %rdi
movl %eax, -0x20(%rbp)
movslq -0x20(%rbp), %rdx
callq 0x3130
movq -0x270(%rbp), %rsi
addl $-0x2, %eax
movl %eax, -0x24(%rbp)
movslq -0x20(%rbp), %rdx
movslq -0x24(%rbp), %rcx
leaq -0x90(%rbp), %rdi
callq 0x3200
jmp 0x44a5
leaq -0x70(%rbp), %rdi
movq %rdi, -0x280(%rbp)
leaq -0x90(%rbp), %rsi
movq %rsi, -0x288(%rbp)
callq 0x3280
movq -0x288(%rbp), %rdi
callq 0x3160
movq -0x280(%rbp), %rsi
leaq -0x220(%rbp), %rdi
movl $0x8, %edx
callq 0x3340
jmp 0x44e9
leaq -0x220(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x7690
movq %rax, -0x290(%rbp)
jmp 0x4502
movq -0x290(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32a0
movb %al, -0x291(%rbp)
jmp 0x4520
leaq -0x220(%rbp), %rdi
callq 0x3120
movb -0x291(%rbp), %al
testb $0x1, %al
jne 0x4538
jmp 0x457d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x457d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x487f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3120
jmp 0x487f
cmpl $0x0, -0x28(%rbp)
jl 0x45ad
movl -0x28(%rbp), %eax
movl %eax, -0x29c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x82c0
movl %eax, -0x298(%rbp)
jmp 0x459d
movl -0x29c(%rbp), %eax
movl -0x298(%rbp), %ecx
cmpl %ecx, %eax
jle 0x45b7
cmpl $0x1, -0x2c(%rbp)
jne 0x45b7
movb $0x1, -0x19(%rbp)
cmpl $0x1, -0x2c(%rbp)
jne 0x45ca
cmpl $0x0, -0x28(%rbp)
jne 0x45ca
movl $0x0, -0x2c(%rbp)
jmp 0x45cc
testb $0x1, -0x19(%rbp)
jne 0x4851
movl -0x2c(%rbp), %eax
movl %eax, -0x2a0(%rbp)
testl %eax, %eax
je 0x45f9
jmp 0x45e5
movl -0x2a0(%rbp), %eax
subl $0x1, %eax
je 0x471b
jmp 0x4831
movq 0x79c8(%rip), %rdi      # 0xbfc8
leaq 0x4dc9(%rip), %rsi      # 0x93d0
callq 0x31f0
movq %rax, -0x2a8(%rbp)
jmp 0x4615
movq -0x2a8(%rbp), %rdi
movq 0x7995(%rip), %rsi      # 0xbfb8
callq 0x3210
jmp 0x462a
jmp 0x462c
movq 0x79a5(%rip), %rdi      # 0xbfd8
leaq -0x50(%rbp), %rsi
callq 0x3070
movq %rax, -0x2b0(%rbp)
jmp 0x4645
movq -0x2b0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32a0
movb %al, -0x2b1(%rbp)
jmp 0x4663
movb -0x2b1(%rbp), %al
testb $0x1, %al
jne 0x466f
jmp 0x46e7
movq -0x10(%rbp), %rax
movq %rax, -0x2c0(%rbp)
leaq -0x240(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x30e0
jmp 0x468c
movq -0x2c0(%rbp), %rdi
movl $0x0, -0x28(%rbp)
leaq -0x240(%rbp), %rsi
xorl %edx, %edx
callq 0x8460
jmp 0x46aa
leaq -0x240(%rbp), %rdi
callq 0x3160
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x462c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x3160
jmp 0x487f
movq 0x78ea(%rip), %rdi      # 0xbfd8
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
xorl %esi, %esi
callq 0x3350
jmp 0x4701
movq 0x78c0(%rip), %rdi      # 0xbfc8
movq 0x78a9(%rip), %rsi      # 0xbfb8
callq 0x3210
jmp 0x4716
jmp 0x4841
movq 0x78a6(%rip), %rdi      # 0xbfc8
leaq 0x4cc3(%rip), %rsi      # 0x93ec
callq 0x31f0
movq %rax, -0x2c8(%rbp)
jmp 0x4737
movq -0x2c8(%rbp), %rdi
movq 0x7873(%rip), %rsi      # 0xbfb8
callq 0x3210
jmp 0x474c
jmp 0x474e
movq 0x7883(%rip), %rdi      # 0xbfd8
leaq -0x50(%rbp), %rsi
callq 0x3070
movq %rax, -0x2d0(%rbp)
jmp 0x4767
movq -0x2d0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32a0
movb %al, -0x2d1(%rbp)
jmp 0x4785
movb -0x2d1(%rbp), %al
testb $0x1, %al
jne 0x4791
jmp 0x4800
movq -0x10(%rbp), %rax
movq %rax, -0x2e0(%rbp)
leaq -0x260(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x30e0
jmp 0x47ae
movq -0x2e0(%rbp), %rdi
movl -0x28(%rbp), %edx
leaq -0x260(%rbp), %rsi
callq 0x8460
jmp 0x47c6
leaq -0x260(%rbp), %rdi
callq 0x3160
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x474e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x3160
jmp 0x487f
movq 0x77d1(%rip), %rdi      # 0xbfd8
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
xorl %esi, %esi
callq 0x3350
jmp 0x481a
movq 0x77a7(%rip), %rdi      # 0xbfc8
movq 0x7790(%rip), %rsi      # 0xbfb8
callq 0x3210
jmp 0x482f
jmp 0x4841
movb $0x0, -0x1(%rbp)
movl $0x1, -0x264(%rbp)
jmp 0x485f
movb $0x1, -0x1(%rbp)
movl $0x1, -0x264(%rbp)
jmp 0x485f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x264(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3160
leaq -0x50(%rbp), %rdi
callq 0x3160
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
leaq -0x70(%rbp), %rdi
callq 0x3160
leaq -0x50(%rbp), %rdi
callq 0x3160
movq -0x98(%rbp), %rdi
callq 0x3380
nopl (%rax)