// File: llefranc[P]42_webserv/srcs/server/Request.cpp
// Function: Request::parseRequestLine(unsigned long)
void Request::parseRequestLine(size_t posCLRF)
{
	// Checking that first line is not empty or contains whitespaces
	if (posCLRF == _index)
		throw StatusLine(400, REASON_400, "first line is empty");

    std::string requestLine = _buffer.substr(_index, posCLRF - _index);
	
    if (requestLine.find_first_of("\r\n\t\v\f") != std::string::npos)
		throw StatusLine(400, REASON_400, "whitespaces not allowed");
	else if (std::count(requestLine.begin(), requestLine.end(), ' ') > 2)
		throw StatusLine(400, REASON_400, "too many spaces");

	// Splitting the request line
	std::vector<std::string> tokens = splitWithSep(requestLine, ' ');
		
	if (tokens.size() != 3)
		throw StatusLine(400, REASON_400, "a field from request line is missing");

	// Parsing the request line
    parseURI(tokens[1]);    
	parseMethodToken(tokens[0]);
	parseHTTPVersion(tokens[2]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x158(%rbp)
movq -0x10(%rbp), %rax
cmpq 0x20(%rcx), %rax
jne 0x17f10
movb $0x1, -0x45(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0x168(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x58f0
movq -0x160(%rbp), %rdx
leaq 0xb8b1(%rip), %rsi      # 0x23730
leaq -0x30(%rbp), %rdi
callq 0x63e0
jmp 0x17e8a
movq -0x168(%rbp), %rdi
leaq 0xb75f(%rip), %rdx      # 0x235f7
movl $0x190, %esi            # imm = 0x190
leaq -0x30(%rbp), %rcx
callq 0x199d0
jmp 0x17ea8
movq -0x168(%rbp), %rdi
movb $0x0, -0x45(%rbp)
leaq 0x18ed6(%rip), %rsi     # 0x30d90
leaq 0x1bbf(%rip), %rdx      # 0x19a80
callq 0x58a0
jmp 0x183a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x17eee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5a08
leaq -0x31(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x45(%rbp)
jne 0x17eff
jmp 0x17f0b
movq -0x168(%rbp), %rdi
callq 0x53f0
jmp 0x183a0
movq -0x158(%rbp), %rsi
movq 0x20(%rsi), %rdx
movq -0x10(%rbp), %rcx
subq 0x20(%rsi), %rcx
leaq -0x68(%rbp), %rdi
callq 0x5590
leaq -0x68(%rbp), %rdi
leaq 0xb80d(%rip), %rsi      # 0x23744
xorl %eax, %eax
movl %eax, %edx
callq 0x52b0
cmpq $-0x1, %rax
je 0x18026
movb $0x1, -0x8a(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0x178(%rbp)
leaq -0x89(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x58f0
movq -0x170(%rbp), %rdx
leaq 0xb7c7(%rip), %rsi      # 0x2374a
leaq -0x88(%rbp), %rdi
callq 0x63e0
jmp 0x17f91
movq -0x178(%rbp), %rdi
leaq 0xb658(%rip), %rdx      # 0x235f7
movl $0x190, %esi            # imm = 0x190
leaq -0x88(%rbp), %rcx
callq 0x199d0
jmp 0x17fb2
movq -0x178(%rbp), %rdi
movb $0x0, -0x8a(%rbp)
leaq 0x18dc9(%rip), %rsi     # 0x30d90
leaq 0x1ab2(%rip), %rdx      # 0x19a80
callq 0x58a0
jmp 0x183a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x17ffe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x5a08
leaq -0x89(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x8a(%rbp)
jne 0x18015
jmp 0x18021
movq -0x178(%rbp), %rdi
callq 0x53f0
jmp 0x18397
leaq -0x68(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x5480
movq -0x188(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x5320
movq %rax, -0xa0(%rbp)
movb $0x20, -0xa1(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
leaq -0xa1(%rbp), %rdx
callq 0x19e60
movq %rax, -0x180(%rbp)
jmp 0x1807a
movq -0x180(%rbp), %rax
cmpq $0x2, %rax
jle 0x18178
movb $0x1, -0xca(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0x198(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x58f0
movq -0x190(%rbp), %rdx
leaq 0xb69e(%rip), %rsi      # 0x23762
leaq -0xc8(%rbp), %rdi
callq 0x63e0
jmp 0x180d2
movq -0x198(%rbp), %rdi
leaq 0xb517(%rip), %rdx      # 0x235f7
movl $0x190, %esi            # imm = 0x190
leaq -0xc8(%rbp), %rcx
callq 0x199d0
jmp 0x180f3
movq -0x198(%rbp), %rdi
movb $0x0, -0xca(%rbp)
leaq 0x18c88(%rip), %rsi     # 0x30d90
leaq 0x1971(%rip), %rdx      # 0x19a80
callq 0x58a0
jmp 0x183a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x18397
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x18150
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x5a08
leaq -0xc9(%rbp), %rdi
callq 0x55c0
testb $0x1, -0xca(%rbp)
jne 0x18167
jmp 0x18173
movq -0x198(%rbp), %rdi
callq 0x53f0
jmp 0x18397
jmp 0x1817a
leaq -0x108(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x5250
jmp 0x1818c
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
movl $0x20, %edx
callq 0x20eb0
jmp 0x181a6
leaq -0x108(%rbp), %rdi
callq 0x5a08
leaq -0xe8(%rbp), %rdi
callq 0xaa60
cmpq $0x3, %rax
je 0x182c1
movb $0x1, -0x12a(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0x1a8(%rbp)
leaq -0x129(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x58f0
movq -0x1a0(%rbp), %rdx
leaq 0xb571(%rip), %rsi      # 0x23772
leaq -0x128(%rbp), %rdi
callq 0x63e0
jmp 0x1820f
movq -0x1a8(%rbp), %rdi
leaq 0xb3da(%rip), %rdx      # 0x235f7
movl $0x190, %esi            # imm = 0x190
leaq -0x128(%rbp), %rcx
callq 0x199d0
jmp 0x18230
movq -0x1a8(%rbp), %rdi
movb $0x0, -0x12a(%rbp)
leaq 0x18b4b(%rip), %rsi     # 0x30d90
leaq 0x1834(%rip), %rdx      # 0x19a80
callq 0x58a0
jmp 0x183a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x5a08
jmp 0x18397
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x18299
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x5a08
leaq -0x129(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x12a(%rbp)
jne 0x182b0
jmp 0x182bc
movq -0x1a8(%rbp), %rdi
callq 0x53f0
jmp 0x1838b
leaq -0xe8(%rbp), %rdi
movl $0x1, %esi
callq 0x10b10
movq %rax, %rsi
leaq -0x150(%rbp), %rdi
callq 0x5250
jmp 0x182e3
movq -0x158(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x18d10
jmp 0x182f8
leaq -0x150(%rbp), %rdi
callq 0x5a08
xorl %eax, %eax
movl %eax, %esi
leaq -0xe8(%rbp), %rdi
callq 0x10b10
movq -0x158(%rbp), %rdi
movq %rax, %rsi
callq 0x18fc0
jmp 0x18325
leaq -0xe8(%rbp), %rdi
movl $0x2, %esi
callq 0x10b10
movq -0x158(%rbp), %rdi
movq %rax, %rsi
callq 0x194b0
jmp 0x18347
leaq -0xe8(%rbp), %rdi
callq 0x9950
leaq -0x68(%rbp), %rdi
callq 0x5a08
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1838b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x5a08
leaq -0xe8(%rbp), %rdi
callq 0x9950
leaq -0x68(%rbp), %rdi
callq 0x5a08
movq -0x40(%rbp), %rdi
callq 0x58e0
nopl (%rax)