// File: /workspace/github_cpp_makefile_star2_O2/mbourand[P]webserv/srcs/Request.cpp
// Function: Request::parse_protocol_version()
void Request::parse_protocol_version()
{
	// _parse_start + 1 is the first character of the protocol version
	if (_raw.find('\r', _parse_start + 1) != std::string::npos && _raw.find("\r\n", _parse_start + 1) == std::string::npos)
		return;
	std::string version = _raw.substr(_parse_start + 1, _raw.find("\r\n", _parse_start + 1) - (_parse_start + 1));
	if (std::string("HTTP/1.1").substr(0, version.size()) != version && std::string("HTTP/1.0").substr(0, version.size()) != version)
	{
		_error_code = 400;
		throw std::invalid_argument("Request protocol version could not be recognized.");
	}
	if (_raw.find("\r\n", _parse_start + 1) != std::string::npos && version == "HTTP/1.1")
	{
		Logger::print("Request protocol version is HTTP/1.1.", true, INFO, VERBOSE);
		_protocolVersion = version;
		_parse_start = _raw.find("\r\n") + 2;
	}
	else if (_raw.find("\r\n", _parse_start + 1) != std::string::npos && version == "HTTP/1.0")
	{
		Logger::print("Request protocol version is HTTP/1.0.", true, INFO, VERBOSE);
		_protocolVersion = version;
		_parse_start = _raw.find("\r\n") + 2;
	}
	else
	{
		_error_code = 400;
		throw std::invalid_argument("Request protocol version could not be recognized.");
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
movq 0x198(%rdi), %rdx
incq %rdx
pushq $0xd
popq %rsi
movq %r14, %rdi
callq 0x7650
cmpq $-0x1, %rax
je 0x28212
movq 0x198(%rbx), %rdx
incq %rdx
leaq 0x7680(%rip), %rsi      # 0x2f880
movq %r14, %rdi
callq 0x7980
cmpq $-0x1, %rax
je 0x28450
movq 0x198(%rbx), %r15
incq %r15
leaq 0x765d(%rip), %rsi      # 0x2f880
movq %r14, %rdi
movq %r15, %rdx
callq 0x7980
movq 0x198(%rbx), %rcx
notq %rcx
addq %rax, %rcx
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x7540
leaq 0x4925(%rip), %rsi      # 0x2cb77
leaq 0x48(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x8032
movq 0x10(%rsp), %rcx
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
xorl %edx, %edx
callq 0x7540
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xe716
testb %al, %al
je 0x28331
leaq 0x6e94(%rip), %rsi      # 0x2f129
leaq 0xa8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x8032
movq 0x10(%rsp), %rcx
leaq 0xc8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
xorl %edx, %edx
callq 0x7540
leaq 0xc8(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0xe716
movl %eax, %ebp
movq %r15, %rdi
callq 0x79b8
leaq 0xa8(%rsp), %rdi
callq 0x79b8
leaq 0x28(%rsp), %rdi
callq 0x79b8
leaq 0x48(%rsp), %rdi
callq 0x79b8
testb %bpl, %bpl
je 0x28345
movl $0x190, 0x188(%rbx)     # imm = 0x190
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %r14
leaq 0x73f9(%rip), %rsi      # 0x2f71d
movq %rax, %rdi
callq 0x7910
jmp 0x28482
leaq 0x28(%rsp), %rdi
callq 0x79b8
leaq 0x48(%rsp), %rdi
callq 0x79b8
movq 0x198(%rbx), %rdx
incq %rdx
leaq 0x752a(%rip), %rsi      # 0x2f880
movq %r14, %rdi
callq 0x7980
cmpq $-0x1, %rax
je 0x283b0
leaq 0x480c(%rip), %rsi      # 0x2cb77
leaq 0x8(%rsp), %rdi
callq 0x91b7
testb %al, %al
je 0x283b0
leaq 0x73cf(%rip), %rsi      # 0x2f74f
leaq 0x88(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x8032
leaq 0x88(%rsp), %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x26da2
leaq 0x88(%rsp), %rdi
jmp 0x28414
movq 0x198(%rbx), %rdx
incq %rdx
leaq 0x74bf(%rip), %rsi      # 0x2f880
movq %r14, %rdi
callq 0x7980
cmpq $-0x1, %rax
je 0x2845e
leaq 0x6d4f(%rip), %rsi      # 0x2f129
leaq 0x8(%rsp), %rdi
callq 0x91b7
testb %al, %al
je 0x2845e
leaq 0x7386(%rip), %rsi      # 0x2f775
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x8032
leaq 0x68(%rsp), %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x26da2
leaq 0x68(%rsp), %rdi
callq 0x79b8
leaq 0x120(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x7300
leaq 0x744f(%rip), %rsi      # 0x2f880
movq %r14, %rdi
xorl %edx, %edx
callq 0x7980
addq $0x2, %rax
movq %rax, 0x198(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x79b8
addq $0xe8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x190, 0x188(%rbx)     # imm = 0x190
pushq $0x10
popq %rdi
callq 0x7290
movq %rax, %r14
leaq 0x72a3(%rip), %rsi      # 0x2f71d
movq %rax, %rdi
callq 0x7910
movq 0x1ab3f(%rip), %rsi     # 0x42fc8
movq 0x1ab20(%rip), %rdx     # 0x42fb0
movq %r14, %rdi
callq 0x7830
jmp 0x284d6
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x284eb
jmp 0x284f4
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x79b8
jmp 0x284be
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x79b8
jmp 0x284e6
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x284eb
jmp 0x284f4
movq %rax, %rbx
movq %r14, %rdi
callq 0x73d0
jmp 0x284f7
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x79b8
jmp 0x284f7
jmp 0x284f4
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x79b8
movq %rbx, %rdi
callq 0x7860
nop