// File: solaldunckel[P]webserv/srcs/HTTP/Request.cpp
// Function: Request::method_line()
int Request::method_line() {
  if (buffer_.find("\r\n") != std::string::npos) {
    std::string tmp = buffer_.substr(0, buffer_.find(' '));

    if (isValidMethod(tmp)) {
      method_ = tmp;
      buffer_.erase(0, method_.length() + 1);
    } else
      return 501;

    if (buffer_.find(' ') == 0)
      return 400;

    tmp = buffer_.substr(0, buffer_.find(' '));

    if (tmp[0] != '/')
      return 400;

    if (!check_validity(tmp))
      return 403;

    if (tmp.length() < 100000) {
      target_ = tmp;
      buffer_.erase(0, target_.length() + 1);
    } else
      return 414;

    if (target_.find('?') != std::string::npos) {
      query_string_ = target_.substr(target_.find('?') + 1);
      target_.erase(target_.find('?'));
    }

    if (buffer_.find(' ') == 0)
      return 400;

    size_t end = buffer_.find("\r\n");
    tmp = buffer_.substr(0, end);

    if (tmp == "HTTP/1.1") {
      protocol_ = tmp;
      buffer_.erase(0, end + 2);
    } else
      return 505;

    status_ = HEADERS;
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
leaq 0x2168a(%rip), %rsi     # 0x437bb
xorl %eax, %eax
movl %eax, %edx
callq 0x5a70
cmpq $-0x1, %rax
je 0x22567
movq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0xc8(%rbp)
movl $0x20, %esi
callq 0x5730
movq -0xb0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movq %rax, %rcx
leaq -0x30(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x55a0
movq -0xc0(%rbp), %rdi
callq 0x41e50
movb %al, -0xb1(%rbp)
jmp 0x22195
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x221a1
jmp 0x221fb
movq -0xb0(%rbp), %rdi
addq $0x20, %rdi
leaq -0x30(%rbp), %rsi
callq 0x5050
jmp 0x221b7
movq -0xb0(%rbp), %rdi
addq $0x20, %rdi
callq 0x5830
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
incq %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x50d0
jmp 0x221df
jmp 0x2220e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5aa8
jmp 0x2257a
movl $0x1f5, -0x4(%rbp)      # imm = 0x1F5
movl $0x1, -0x40(%rbp)
jmp 0x22551
movq -0xb0(%rbp), %rdi
movl $0x20, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x5730
cmpq $0x0, %rax
jne 0x2223c
movl $0x190, -0x4(%rbp)      # imm = 0x190
movl $0x1, -0x40(%rbp)
jmp 0x22551
movq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0xd0(%rbp)
movl $0x20, %esi
callq 0x5730
movq -0xb0(%rbp), %rsi
movq -0xd0(%rbp), %rdx
movq %rax, %rcx
leaq -0x60(%rbp), %rdi
callq 0x55a0
jmp 0x22274
leaq -0x30(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
leaq -0x60(%rbp), %rsi
movq %rsi, -0xe8(%rbp)
callq 0x56d0
movq -0xe8(%rbp), %rdi
callq 0x5aa8
movq -0xe0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5a80
movq %rax, -0xd8(%rbp)
jmp 0x222b4
movq -0xd8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x222d6
movl $0x190, -0x4(%rbp)      # imm = 0x190
movl $0x1, -0x40(%rbp)
jmp 0x22551
leaq -0x30(%rbp), %rdi
callq 0x23520
movb %al, -0xe9(%rbp)
jmp 0x222e7
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0x22306
jmp 0x222f3
movl $0x193, -0x4(%rbp)      # imm = 0x193
movl $0x1, -0x40(%rbp)
jmp 0x22551
leaq -0x30(%rbp), %rdi
callq 0x5830
cmpq $0x186a0, %rax          # imm = 0x186A0
jae 0x22357
movq -0xb0(%rbp), %rdi
addq $0x40, %rdi
leaq -0x30(%rbp), %rsi
callq 0x5050
jmp 0x2232d
movq -0xb0(%rbp), %rdi
addq $0x40, %rdi
callq 0x5830
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
incq %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x50d0
jmp 0x22355
jmp 0x2236a
movl $0x19e, -0x4(%rbp)      # imm = 0x19E
movl $0x1, -0x40(%rbp)
jmp 0x22551
movq -0xb0(%rbp), %rdi
addq $0x40, %rdi
movl $0x3f, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x5730
cmpq $-0x1, %rax
je 0x2242d
movq -0xb0(%rbp), %rdi
addq $0x40, %rdi
movq %rdi, -0xf8(%rbp)
xorl %eax, %eax
movl %eax, %edx
movl $0x3f, %esi
callq 0x5730
movq -0xf8(%rbp), %rsi
movq %rax, %rdx
incq %rdx
leaq -0x80(%rbp), %rdi
movq $-0x1, %rcx
callq 0x55a0
jmp 0x223cc
movq -0xb0(%rbp), %rdi
addq $0x60, %rdi
leaq -0x80(%rbp), %rsi
movq %rsi, -0x108(%rbp)
callq 0x56d0
movq -0x108(%rbp), %rdi
callq 0x5aa8
movq -0xb0(%rbp), %rdi
addq $0x40, %rdi
movq %rdi, -0x100(%rbp)
xorl %eax, %eax
movl %eax, %edx
movl $0x3f, %esi
callq 0x5730
movq -0x100(%rbp), %rdi
movq %rax, %rsi
movq $-0x1, %rdx
callq 0x50d0
jmp 0x2242b
jmp 0x2242d
movq -0xb0(%rbp), %rdi
movl $0x20, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x5730
cmpq $0x0, %rax
jne 0x2245b
movl $0x190, -0x4(%rbp)      # imm = 0x190
movl $0x1, -0x40(%rbp)
jmp 0x22551
movq -0xb0(%rbp), %rdi
leaq 0x21352(%rip), %rsi     # 0x437bb
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x110(%rbp)
callq 0x5a70
movq -0xb0(%rbp), %rsi
movq -0x110(%rbp), %rdx
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
callq 0x55a0
jmp 0x224a3
leaq -0x30(%rbp), %rdi
movq %rdi, -0x120(%rbp)
leaq -0xa8(%rbp), %rsi
movq %rsi, -0x128(%rbp)
callq 0x56d0
movq -0x128(%rbp), %rdi
callq 0x5aa8
movq -0x120(%rbp), %rdi
leaq 0x2125b(%rip), %rsi     # 0x43736
callq 0x8ff0
movb %al, -0x111(%rbp)
jmp 0x224e8
movb -0x111(%rbp), %al
testb $0x1, %al
jne 0x224f4
jmp 0x22529
movq -0xb0(%rbp), %rdi
subq $-0x80, %rdi
leaq -0x30(%rbp), %rsi
callq 0x5050
jmp 0x2250a
movq -0xb0(%rbp), %rdi
movq -0x88(%rbp), %rdx
addq $0x2, %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x50d0
jmp 0x22527
jmp 0x22539
movl $0x1f9, -0x4(%rbp)      # imm = 0x1F9
movl $0x1, -0x40(%rbp)
jmp 0x22551
movq -0xb0(%rbp), %rax
movl $0x1, 0x120(%rax)
movl $0x0, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5aa8
movl -0x40(%rbp), %eax
testl %eax, %eax
je 0x22565
jmp 0x22563
jmp 0x2256e
jmp 0x22567
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x5950
nopw %cs:(%rax,%rax)