// File: craigbarstow[P]cmd-line-text-editor/text_editor.cc
// Function: move_line(text_ed&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool move_line (text_ed & T, string cl) {
  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 substring representing the first integer from the given string
    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 substring cant be converted to an integer, toggle error state to true
      error_state=true;
    } else {count++;} //if it can, increment count to show first integer is present
    if (cl.find_first_not_of(" ", m_end+2)!=string::npos){ //section to isolate the substring representing the second integer from the given string
      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 substring cant be converted to an integer, toggle error state to true
	error_state=true;
      } else {count++;} //if it can be, increment count to show second integer is present
      if (cl.find_first_not_of(" ", n_end+1)!=string::npos) { //section to isolate the substring representing the third integer from the given string
	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 third integer is present
	  count++;
	} 
      }
    }
    //SECTION TO MAKE SURE THE INTEGERS MAKE SENSE
    if (m<=0){ //if first integer is less than 1, toggle error state to true
      error_state=true;
    }
    if (count<=2){
      if (n>T.get_last_line()) { //if second int is greater than document length, reset it
	n=T.get_last_line();
      }
      if (n<=0) { //if second it is less than zero, 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 || o>T.get_last_line()) { //if the third integer is less than three, toggle error state to true
	error_state = true;
      }
    }
    if (!error_state) {
      if (count==3){ //if three integers are present, move the lines from the first to the second integer to after the position given by the third integer
	T.move_lines(m,n,o);
       } else if (count==2) { //if two integers are present, move the first line to after the position given by the second
	T.move_lines(m,m,n); //n+1
      }	else if (count==1) {
	return false;  //return false if only one integer is found
      }
      return true; //if error state is false, return true
    }
  }
  return false; //if error state is true or the first integer isnt found, return false
}

// 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 0x3fcf(%rip), %rsi      # 0x93ce
movl $0x1, %edx
callq 0x3140
cmpq $-0x1, %rax
je 0x5971
movq -0x5d8(%rbp), %rdi
leaq 0x3fad(%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 0x547e
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 0x54c2
leaq -0x288(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x7690
movq %rax, -0x5f8(%rbp)
jmp 0x54de
movq -0x5f8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3110
movb %al, -0x5f9(%rbp)
jmp 0x54fc
leaq -0x288(%rbp), %rdi
callq 0x3120
movb -0x5f9(%rbp), %al
testb $0x1, %al
jne 0x5514
jmp 0x5554
movb $0x1, -0x19(%rbp)
jmp 0x5563
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x59b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x3120
jmp 0x59b4
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 0x3e51(%rip), %rsi      # 0x93ce
callq 0x3140
cmpq $-0x1, %rax
je 0x582a
movq -0x5d8(%rbp), %rdi
movl -0xbc(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdx
leaq 0x3e28(%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 0x55fb
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 0x563f
leaq -0x428(%rbp), %rdi
leaq -0xac(%rbp), %rsi
callq 0x7690
movq %rax, -0x620(%rbp)
jmp 0x565b
movq -0x620(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3110
movb %al, -0x621(%rbp)
jmp 0x5679
leaq -0x428(%rbp), %rdi
callq 0x3120
movb -0x621(%rbp), %al
testb $0x1, %al
jne 0x5691
jmp 0x56ba
movb $0x1, -0x19(%rbp)
jmp 0x56c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x428(%rbp), %rdi
callq 0x3120
jmp 0x59b4
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 0x3ceb(%rip), %rsi      # 0x93ce
callq 0x3140
cmpq $-0x1, %rax
je 0x5828
movq -0x5d8(%rbp), %rdi
movl -0xc4(%rbp), %eax
incl %eax
movslq %eax, %rdx
leaq 0x3cc3(%rip), %rsi      # 0x93ce
callq 0x3140
movq -0x5d8(%rbp), %rdi
movl %eax, -0xc8(%rbp)
movslq -0xc8(%rbp), %rdx
leaq 0x3ca4(%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 0x5759
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 0x57a0
leaq -0x5c8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x7690
movq %rax, -0x640(%rbp)
jmp 0x57bc
movq -0x640(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32a0
movb %al, -0x641(%rbp)
jmp 0x57da
leaq -0x5c8(%rbp), %rdi
callq 0x3120
movb -0x641(%rbp), %al
testb $0x1, %al
jne 0x57f2
jmp 0x5826
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x5826
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x5c8(%rbp), %rdi
callq 0x3120
jmp 0x59b4
jmp 0x5828
jmp 0x582a
cmpl $0x0, -0xa8(%rbp)
jg 0x5837
movb $0x1, -0x19(%rbp)
cmpl $0x2, -0xd4(%rbp)
jg 0x5899
movl -0xac(%rbp), %eax
movl %eax, -0x64c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x82c0
movl %eax, -0x648(%rbp)
jmp 0x585d
movl -0x64c(%rbp), %eax
movl -0x648(%rbp), %ecx
cmpl %ecx, %eax
jle 0x588a
movq -0x10(%rbp), %rdi
callq 0x82c0
movl %eax, -0x650(%rbp)
jmp 0x587e
movl -0x650(%rbp), %eax
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
jg 0x5897
movb $0x1, -0x19(%rbp)
jmp 0x5899
cmpl $0x3, -0xd4(%rbp)
jne 0x58f0
movl -0xac(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jge 0x58b4
movb $0x1, -0x19(%rbp)
cmpl $0x0, -0xb0(%rbp)
jle 0x58ea
movl -0xb0(%rbp), %eax
movl %eax, -0x658(%rbp)
movq -0x10(%rbp), %rdi
callq 0x82c0
movl %eax, -0x654(%rbp)
jmp 0x58da
movl -0x658(%rbp), %eax
movl -0x654(%rbp), %ecx
cmpl %ecx, %eax
jle 0x58ee
movb $0x1, -0x19(%rbp)
jmp 0x58f0
testb $0x1, -0x19(%rbp)
jne 0x596f
cmpl $0x3, -0xd4(%rbp)
jne 0x591e
movq -0x10(%rbp), %rdi
movl -0xa8(%rbp), %esi
movl -0xac(%rbp), %edx
movl -0xb0(%rbp), %ecx
callq 0x87d0
jmp 0x591c
jmp 0x595f
cmpl $0x2, -0xd4(%rbp)
jne 0x5942
movq -0x10(%rbp), %rdi
movl -0xa8(%rbp), %edx
movl -0xac(%rbp), %ecx
movl %edx, %esi
callq 0x87d0
jmp 0x5940
jmp 0x595d
cmpl $0x1, -0xd4(%rbp)
jne 0x595b
movb $0x0, -0x1(%rbp)
movl $0x1, -0x5cc(%rbp)
jmp 0x597f
jmp 0x595d
jmp 0x595f
movb $0x1, -0x1(%rbp)
movl $0x1, -0x5cc(%rbp)
jmp 0x597f
jmp 0x5971
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
nopw (%rax,%rax)