// File: craigbarstow[P]cmd-line-text-editor/text_editor.cc
// Function: copy_line(text_ed&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool copy_line (text_ed & T, string cl) { //Copy area between two given line numbers (inclusive) to after a third given line number if three numbers are given. If only two integers are given, move the line at the first position to after the position given by the second integer
  bool error_state=false;
  string aline,M_string,N_string,O_string;
  int i = 0,m=0,n=0,o=0,p=1,m_start, m_end, n_start, n_end, o_start, o_end, number, count=0;
  if (cl.find_first_not_of(" ",1)!=string::npos){ //section to isolate the first integer from the string entered into the command line
    m_start= cl.find_first_not_of(" ",1);
    m_end = cl.find_first_of(" ", m_start)-2;
    M_string=cl.substr(m_start,m_end);
    if (!(istringstream(M_string) >> m)) { //if the substring representing the first integer cannot be converted to an integer, toggle the error state to true
      error_state=true;
      m=1;
    } else {count++;} //increment count to show one integer is present
    if (cl.find_first_not_of(" ", m_end+2)!=string::npos){ //section to isolate the second integer from the string entered into the command line
      n_start = cl.find_first_not_of(" ", m_end+2);
      n_end = cl.find_first_of(" ",n_start);
      N_string=cl.substr(n_start,n_end);
      if (!(istringstream(N_string) >> n)){ //if the substring representing the second integer cannot be converted to an integer, toggle the error state to true
	error_state=true;
      } else {count++;} //increment count to show that two integers are present
      if (cl.find_first_not_of(" ", n_end+1)!=string::npos) { //section to isolate the third integer from the string entered into the command line
	  o_start = cl.find_first_not_of(" ", n_end+1);
	  o_end = cl.find_first_of("",o_start);
	  O_string=cl.substr(o_start,o_end);
	  if (istringstream(O_string) >> o){ //if substring can be converted to an integer, increment count to show a third integer is present
	    count++; 
	  } 
	}
    }
    //SECTION TO MAKE SURE INTEGERS MAKE SENSE
    if (m<1){ //if first integer is less than 1, toggle error state to true
      error_state=true;
    }
    if (n>T.get_last_line()) { //if second int is greater than document length, toggle error state
      error_state=true;
    }
    if (n<1) { //if second it is less than one, toggle error state to true
      error_state=true;
    }
    if (count==3) {
      if (n<m) { //if three integers are present and the first 
	error_state = true;
      }
      if (o<=0) { //if the third integer is less than three, toggle error state to true
	error_state = true;
      }
      if (o>T.get_last_line()) { //if third integer is greater than document length, reset it
	o=T.get_last_line();
      }
    }
    if (!error_state) { 
      if (count==3){ //if three integers are present, copy lines from the start position to the end position to after the given location
	T.copy_lines(m,n,o);
       }
      else if (count==2) { //if two integers are present, copy the line given by the first position to after the position denoted by the second integer
	T.copy_lines(m,m,n);
      }	
      return true; //return true if error state is false
    } else {
      return false; //return false if error state is true
    }
  }
  return false; //return false if nothing is found after the initial 'c' substring in the input string
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x660, %rsp            # imm = 0x660
movq %rsi, -0x5d8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x32d0
leaq -0x60(%rbp), %rdi
callq 0x32d0
leaq -0x80(%rbp), %rdi
callq 0x32d0
leaq -0xa0(%rbp), %rdi
callq 0x32d0
movq -0x5d8(%rbp), %rdi
movl $0x0, -0xa4(%rbp)
movl $0x0, -0xa8(%rbp)
movl $0x0, -0xac(%rbp)
movl $0x0, -0xb0(%rbp)
movl $0x1, -0xb4(%rbp)
movl $0x0, -0xd4(%rbp)
leaq 0x463f(%rip), %rsi      # 0x93ce
movl $0x1, %edx
callq 0x3140
cmpq $-0x1, %rax
je 0x52f7
movq -0x5d8(%rbp), %rdi
leaq 0x461d(%rip), %rsi      # 0x93ce
movq %rsi, -0x5e0(%rbp)
movl $0x1, %edx
callq 0x3140
movq -0x5e0(%rbp), %rsi
movq -0x5d8(%rbp), %rdi
movl %eax, -0xb8(%rbp)
movslq -0xb8(%rbp), %rdx
callq 0x3130
movq -0x5d8(%rbp), %rsi
addl $-0x2, %eax
movl %eax, -0xbc(%rbp)
movslq -0xb8(%rbp), %rdx
movslq -0xbc(%rbp), %rcx
leaq -0xf8(%rbp), %rdi
callq 0x3200
jmp 0x4e0e
leaq -0x60(%rbp), %rdi
movq %rdi, -0x5e8(%rbp)
leaq -0xf8(%rbp), %rsi
movq %rsi, -0x5f0(%rbp)
callq 0x3280
movq -0x5f0(%rbp), %rdi
callq 0x3160
movq -0x5e8(%rbp), %rsi
leaq -0x288(%rbp), %rdi
movl $0x8, %edx
callq 0x3340
jmp 0x4e52
leaq -0x288(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x7690
movq %rax, -0x5f8(%rbp)
jmp 0x4e6e
movq -0x5f8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3110
movb %al, -0x5f9(%rbp)
jmp 0x4e8c
leaq -0x288(%rbp), %rdi
callq 0x3120
movb -0x5f9(%rbp), %al
testb $0x1, %al
jne 0x4ea4
jmp 0x4eee
movb $0x1, -0x19(%rbp)
movl $0x1, -0xa8(%rbp)
jmp 0x4efd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x533a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x3120
jmp 0x533a
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
movq -0x5d8(%rbp), %rdi
movl -0xbc(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdx
leaq 0x44b7(%rip), %rsi      # 0x93ce
callq 0x3140
cmpq $-0x1, %rax
je 0x51c4
movq -0x5d8(%rbp), %rdi
movl -0xbc(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdx
leaq 0x448e(%rip), %rsi      # 0x93ce
movq %rsi, -0x608(%rbp)
callq 0x3140
movq -0x608(%rbp), %rsi
movq -0x5d8(%rbp), %rdi
movl %eax, -0xc0(%rbp)
movslq -0xc0(%rbp), %rdx
callq 0x3130
movq -0x5d8(%rbp), %rsi
movl %eax, -0xc4(%rbp)
movslq -0xc0(%rbp), %rdx
movslq -0xc4(%rbp), %rcx
leaq -0x2a8(%rbp), %rdi
callq 0x3200
jmp 0x4f95
leaq -0x80(%rbp), %rdi
movq %rdi, -0x610(%rbp)
leaq -0x2a8(%rbp), %rsi
movq %rsi, -0x618(%rbp)
callq 0x3280
movq -0x618(%rbp), %rdi
callq 0x3160
movq -0x610(%rbp), %rsi
leaq -0x428(%rbp), %rdi
movl $0x8, %edx
callq 0x3340
jmp 0x4fd9
leaq -0x428(%rbp), %rdi
leaq -0xac(%rbp), %rsi
callq 0x7690
movq %rax, -0x620(%rbp)
jmp 0x4ff5
movq -0x620(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3110
movb %al, -0x621(%rbp)
jmp 0x5013
leaq -0x428(%rbp), %rdi
callq 0x3120
movb -0x621(%rbp), %al
testb $0x1, %al
jne 0x502b
jmp 0x5054
movb $0x1, -0x19(%rbp)
jmp 0x5063
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x428(%rbp), %rdi
callq 0x3120
jmp 0x533a
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
movq -0x5d8(%rbp), %rdi
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
leaq 0x4351(%rip), %rsi      # 0x93ce
callq 0x3140
cmpq $-0x1, %rax
je 0x51c2
movq -0x5d8(%rbp), %rdi
movl -0xc4(%rbp), %eax
incl %eax
movslq %eax, %rdx
leaq 0x4329(%rip), %rsi      # 0x93ce
callq 0x3140
movq -0x5d8(%rbp), %rdi
movl %eax, -0xc8(%rbp)
movslq -0xc8(%rbp), %rdx
leaq 0x430a(%rip), %rsi      # 0x93cf
callq 0x3130
movq -0x5d8(%rbp), %rsi
movl %eax, -0xcc(%rbp)
movslq -0xc8(%rbp), %rdx
movslq -0xcc(%rbp), %rcx
leaq -0x448(%rbp), %rdi
callq 0x3200
jmp 0x50f3
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x630(%rbp)
leaq -0x448(%rbp), %rsi
movq %rsi, -0x638(%rbp)
callq 0x3280
movq -0x638(%rbp), %rdi
callq 0x3160
movq -0x630(%rbp), %rsi
leaq -0x5c8(%rbp), %rdi
movl $0x8, %edx
callq 0x3340
jmp 0x513a
leaq -0x5c8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x7690
movq %rax, -0x640(%rbp)
jmp 0x5156
movq -0x640(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32a0
movb %al, -0x641(%rbp)
jmp 0x5174
leaq -0x5c8(%rbp), %rdi
callq 0x3120
movb -0x641(%rbp), %al
testb $0x1, %al
jne 0x518c
jmp 0x51c0
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x51c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x5c8(%rbp), %rdi
callq 0x3120
jmp 0x533a
jmp 0x51c2
jmp 0x51c4
cmpl $0x1, -0xa8(%rbp)
jge 0x51d1
movb $0x1, -0x19(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0x64c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x82c0
movl %eax, -0x648(%rbp)
jmp 0x51ee
movl -0x64c(%rbp), %eax
movl -0x648(%rbp), %ecx
cmpl %ecx, %eax
jle 0x5202
movb $0x1, -0x19(%rbp)
cmpl $0x1, -0xac(%rbp)
jge 0x520f
movb $0x1, -0x19(%rbp)
cmpl $0x3, -0xd4(%rbp)
jne 0x5283
movl -0xac(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jge 0x522a
movb $0x1, -0x19(%rbp)
cmpl $0x0, -0xb0(%rbp)
jg 0x5237
movb $0x1, -0x19(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, -0x654(%rbp)
movq -0x10(%rbp), %rdi
callq 0x82c0
movl %eax, -0x650(%rbp)
jmp 0x5254
movl -0x654(%rbp), %eax
movl -0x650(%rbp), %ecx
cmpl %ecx, %eax
jle 0x5281
movq -0x10(%rbp), %rdi
callq 0x82c0
movl %eax, -0x658(%rbp)
jmp 0x5275
movl -0x658(%rbp), %eax
movl %eax, -0xb0(%rbp)
jmp 0x5283
testb $0x1, -0x19(%rbp)
jne 0x52e7
cmpl $0x3, -0xd4(%rbp)
jne 0x52b1
movq -0x10(%rbp), %rdi
movl -0xa8(%rbp), %esi
movl -0xac(%rbp), %edx
movl -0xb0(%rbp), %ecx
callq 0x8770
jmp 0x52af
jmp 0x52d7
cmpl $0x2, -0xd4(%rbp)
jne 0x52d5
movq -0x10(%rbp), %rdi
movl -0xa8(%rbp), %edx
movl -0xac(%rbp), %ecx
movl %edx, %esi
callq 0x8770
jmp 0x52d3
jmp 0x52d5
jmp 0x52d7
movb $0x1, -0x1(%rbp)
movl $0x1, -0x5cc(%rbp)
jmp 0x5305
movb $0x0, -0x1(%rbp)
movl $0x1, -0x5cc(%rbp)
jmp 0x5305
movb $0x0, -0x1(%rbp)
movl $0x1, -0x5cc(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3160
leaq -0x80(%rbp), %rdi
callq 0x3160
leaq -0x60(%rbp), %rdi
callq 0x3160
leaq -0x40(%rbp), %rdi
callq 0x3160
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x660, %rsp            # imm = 0x660
popq %rbp
retq
leaq -0xa0(%rbp), %rdi
callq 0x3160
leaq -0x80(%rbp), %rdi
callq 0x3160
leaq -0x60(%rbp), %rdi
callq 0x3160
leaq -0x40(%rbp), %rdi
callq 0x3160
movq -0x100(%rbp), %rdi
callq 0x3380
nopl (%rax)