// File: craigbarstow[P]cmd-line-text-editor/text_editor.cc
// Function: delete_line(text_ed&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool delete_line (text_ed & T, string cl) { //delete lines between two given line positions. If only one position is given, delete just that line
  bool error_state=false;
  string aline,M_string,N_string;
  int i = 0,m=0,n=0,p=1,m_start, m_end, n_start, n_end,number, count=0;
  if (cl.find_first_not_of(" ",1)!=string::npos){ //if first integer is part of substring isolate it
    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 representing first integer can't be converted to integer form, toggle error state to true
      error_state=true;
    } else {count++;} //else, increment count to show that first integer is present
    if (cl.find_first_not_of(" ", m_end+2)!=string::npos){ //if second integer is part of substring isolate it
      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 representing second integer can't be converted to int form, toggle error state to true
	error_state=true;
      } else {count++;} //increment count to show that second integer is present
    }
    //section to make sure the integer values are reasonable
    if (m<=0){ //if integer value of starting position is less 1, toggle error
      error_state=true;
    }
    if (count==2) { //if two integers are present, if second is less than first, or if first is greater than document length, toggle error state
      if (n<m || n>T.get_last_line()) {
	error_state=true;
      }
    }
    if (!error_state) {
      if (count==2){ //if two integers are present, delete the lines between them
	T.delete_lines(m,n);
      }
      else if (count==1) { //if one integer is present, delete just that line
	T.delete_lines(m,m);
      }
    } else {
      return false; //return false if something other than 1 or two integers are present
    } return true; //if !error_state
  }
  return false; //return false if nothing is found after the 'd' statement in the command line, or if error state is true
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x460, %rsp            # imm = 0x460
movq %rsi, -0x408(%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
movq -0x408(%rbp), %rdi
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movl $0x1, -0x90(%rbp)
movl $0x0, -0xa8(%rbp)
leaq 0x4ab5(%rip), %rsi      # 0x93ce
movl $0x1, %edx
callq 0x3140
cmpq $-0x1, %rax
je 0x4c9f
movq -0x408(%rbp), %rdi
leaq 0x4a93(%rip), %rsi      # 0x93ce
movq %rsi, -0x410(%rbp)
movl $0x1, %edx
callq 0x3140
movq -0x410(%rbp), %rsi
movq -0x408(%rbp), %rdi
movl %eax, -0x94(%rbp)
movslq -0x94(%rbp), %rdx
callq 0x3130
movq -0x408(%rbp), %rsi
addl $-0x2, %eax
movl %eax, -0x98(%rbp)
movslq -0x94(%rbp), %rdx
movslq -0x98(%rbp), %rcx
leaq -0xc8(%rbp), %rdi
callq 0x3200
jmp 0x4998
leaq -0x60(%rbp), %rdi
movq %rdi, -0x418(%rbp)
leaq -0xc8(%rbp), %rsi
movq %rsi, -0x420(%rbp)
callq 0x3280
movq -0x420(%rbp), %rdi
callq 0x3160
movq -0x418(%rbp), %rsi
leaq -0x258(%rbp), %rdi
movl $0x8, %edx
callq 0x3340
jmp 0x49dc
leaq -0x258(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x7690
movq %rax, -0x428(%rbp)
jmp 0x49f8
movq -0x428(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3110
movb %al, -0x429(%rbp)
jmp 0x4a16
leaq -0x258(%rbp), %rdi
callq 0x3120
movb -0x429(%rbp), %al
testb $0x1, %al
jne 0x4a2e
jmp 0x4a6e
movb $0x1, -0x19(%rbp)
jmp 0x4a7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x4cd6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x3120
jmp 0x4cd6
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
movq -0x408(%rbp), %rdi
movl -0x98(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdx
leaq 0x4937(%rip), %rsi      # 0x93ce
callq 0x3140
cmpq $-0x1, %rax
je 0x4bde
movq -0x408(%rbp), %rdi
movl -0x98(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdx
leaq 0x490e(%rip), %rsi      # 0x93ce
callq 0x3140
movq -0x408(%rbp), %rdi
movl %eax, -0x9c(%rbp)
movslq -0x9c(%rbp), %rdx
leaq 0x48ef(%rip), %rsi      # 0x93cf
callq 0x3130
movq -0x408(%rbp), %rsi
movl %eax, -0xa0(%rbp)
movslq -0x9c(%rbp), %rdx
movslq -0xa0(%rbp), %rcx
leaq -0x278(%rbp), %rdi
callq 0x3200
jmp 0x4b0e
leaq -0x80(%rbp), %rdi
movq %rdi, -0x438(%rbp)
leaq -0x278(%rbp), %rsi
movq %rsi, -0x440(%rbp)
callq 0x3280
movq -0x440(%rbp), %rdi
callq 0x3160
movq -0x438(%rbp), %rsi
leaq -0x3f8(%rbp), %rdi
movl $0x8, %edx
callq 0x3340
jmp 0x4b52
leaq -0x3f8(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
callq 0x7690
movq %rax, -0x448(%rbp)
jmp 0x4b6e
movq -0x448(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3110
movb %al, -0x449(%rbp)
jmp 0x4b8c
leaq -0x3f8(%rbp), %rdi
callq 0x3120
movb -0x449(%rbp), %al
testb $0x1, %al
jne 0x4ba4
jmp 0x4bcd
movb $0x1, -0x19(%rbp)
jmp 0x4bdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x3f8(%rbp), %rdi
callq 0x3120
jmp 0x4cd6
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x4bde
cmpl $0x0, -0x88(%rbp)
jg 0x4beb
movb $0x1, -0x19(%rbp)
cmpl $0x2, -0xa8(%rbp)
jne 0x4c35
movl -0x8c(%rbp), %eax
cmpl -0x88(%rbp), %eax
jl 0x4c2f
movl -0x8c(%rbp), %eax
movl %eax, -0x454(%rbp)
movq -0x10(%rbp), %rdi
callq 0x82c0
movl %eax, -0x450(%rbp)
jmp 0x4c1f
movl -0x454(%rbp), %eax
movl -0x450(%rbp), %ecx
cmpl %ecx, %eax
jle 0x4c33
movb $0x1, -0x19(%rbp)
jmp 0x4c35
testb $0x1, -0x19(%rbp)
jne 0x4c7f
cmpl $0x2, -0xa8(%rbp)
jne 0x4c5d
movq -0x10(%rbp), %rdi
movl -0x88(%rbp), %esi
movl -0x8c(%rbp), %edx
callq 0x8680
jmp 0x4c5b
jmp 0x4c7d
cmpl $0x1, -0xa8(%rbp)
jne 0x4c7b
movq -0x10(%rbp), %rdi
movl -0x88(%rbp), %edx
movl %edx, %esi
callq 0x8680
jmp 0x4c79
jmp 0x4c7b
jmp 0x4c7d
jmp 0x4c8f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x3fc(%rbp)
jmp 0x4cad
movb $0x1, -0x1(%rbp)
movl $0x1, -0x3fc(%rbp)
jmp 0x4cad
movb $0x0, -0x1(%rbp)
movl $0x1, -0x3fc(%rbp)
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 $0x460, %rsp            # imm = 0x460
popq %rbp
retq
leaq -0x80(%rbp), %rdi
callq 0x3160
leaq -0x60(%rbp), %rdi
callq 0x3160
leaq -0x40(%rbp), %rdi
callq 0x3160
movq -0xd0(%rbp), %rdi
callq 0x3380
nopl (%rax)