// File: 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
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x120(%rbp)
movq %rax, %rdi
addq $0x8, %rdi
movq 0x198(%rax), %rdx
addq $0x1, %rdx
movl $0xd, %esi
callq 0x9860
cmpq $-0x1, %rax
je 0x5f0dc
movq -0x120(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movq 0x198(%rax), %rdx
addq $0x1, %rdx
leaq 0xebe4(%rip), %rsi      # 0x6dcb0
callq 0x9c60
cmpq $-0x1, %rax
jne 0x5f0dc
jmp 0x5f6a0
movq -0x120(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movq %rdi, -0x138(%rbp)
movq 0x198(%rax), %rdx
incq %rdx
movq %rdx, -0x130(%rbp)
leaq 0xeba7(%rip), %rsi      # 0x6dcb0
callq 0x9c60
movq -0x120(%rbp), %rcx
movq -0x138(%rbp), %rsi
movq -0x130(%rbp), %rdx
movq 0x198(%rcx), %rcx
notq %rcx
addq %rax, %rcx
leaq -0x28(%rbp), %rdi
callq 0x96b0
leaq -0x69(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x9b10
movq -0x128(%rbp), %rdx
movb $0x0, -0xc2(%rbp)
movb $0x0, -0xc3(%rbp)
movb $0x0, -0xc4(%rbp)
leaq 0xba2c(%rip), %rsi      # 0x6ab98
leaq -0x68(%rbp), %rdi
callq 0xa780
jmp 0x5f177
leaq -0x28(%rbp), %rdi
callq 0x9480
movq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x96b0
jmp 0x5f196
leaq -0x48(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1ab80
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x139(%rbp)
jne 0x5f1b4
jmp 0x5f233
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x9b10
movq -0x148(%rbp), %rdx
movb $0x1, -0xc2(%rbp)
leaq 0xe37d(%rip), %rsi      # 0x6d559
leaq -0xc0(%rbp), %rdi
callq 0xa780
jmp 0x5f1ea
movb $0x1, -0xc3(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x9480
movq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x96b0
jmp 0x5f216
movb $0x1, -0xc4(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1ab80
movb %al, -0x139(%rbp)
movb -0x139(%rbp), %al
movb %al, -0x149(%rbp)
testb $0x1, -0xc4(%rbp)
jne 0x5f24a
jmp 0x5f256
leaq -0xa0(%rbp), %rdi
callq 0x9c98
testb $0x1, -0xc3(%rbp)
jne 0x5f261
jmp 0x5f26d
leaq -0xc0(%rbp), %rdi
callq 0x9c98
testb $0x1, -0xc2(%rbp)
jne 0x5f278
jmp 0x5f284
leaq -0xc1(%rbp), %rdi
callq 0x9700
leaq -0x48(%rbp), %rdi
callq 0x9c98
leaq -0x68(%rbp), %rdi
callq 0x9c98
leaq -0x69(%rbp), %rdi
callq 0x9700
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x5f2ae
jmp 0x5f3b7
movq -0x120(%rbp), %rax
movl $0x190, 0x188(%rax)     # imm = 0x190
movl $0x10, %edi
callq 0x9340
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x158(%rbp)
leaq 0xe870(%rip), %rsi      # 0x6db4d
callq 0x9be0
jmp 0x5f2e4
movq -0x158(%rbp), %rdi
movq 0x2fcd6(%rip), %rsi     # 0x8efc8
movq 0x2fcbf(%rip), %rdx     # 0x8efb8
callq 0x9aa0
jmp 0x5f6bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x5f37b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x5f372
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x5f352
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
testb $0x1, -0xc3(%rbp)
jne 0x5f344
jmp 0x5f350
leaq -0xc0(%rbp), %rdi
callq 0x9c98
jmp 0x5f352
testb $0x1, -0xc2(%rbp)
jne 0x5f35d
jmp 0x5f369
leaq -0xc1(%rbp), %rdi
callq 0x9700
leaq -0x48(%rbp), %rdi
callq 0x9c98
leaq -0x68(%rbp), %rdi
callq 0x9c98
leaq -0x69(%rbp), %rdi
callq 0x9700
jmp 0x5f6a9
movq -0x158(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
callq 0x94c0
jmp 0x5f6a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x5f6a9
movq -0x120(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movq 0x198(%rax), %rdx
addq $0x1, %rdx
leaq 0xe8d9(%rip), %rsi      # 0x6dcb0
callq 0x9c60
cmpq $-0x1, %rax
je 0x5f4f0
leaq 0xb7ab(%rip), %rsi      # 0x6ab98
leaq -0x28(%rbp), %rdi
callq 0xdf50
movb %al, -0x159(%rbp)
jmp 0x5f3fe
movb -0x159(%rbp), %al
testb $0x1, %al
jne 0x5f40d
jmp 0x5f4f0
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x9b10
movq -0x168(%rbp), %rdx
leaq 0xe751(%rip), %rsi      # 0x6db7f
leaq -0xe8(%rbp), %rdi
callq 0xa780
jmp 0x5f43c
leaq -0xe8(%rbp), %rdi
movl $0x1, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x5bdc0
jmp 0x5f453
leaq -0xe8(%rbp), %rdi
callq 0x9c98
leaq -0xe9(%rbp), %rdi
callq 0x9700
movq -0x120(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
leaq -0x28(%rbp), %rsi
callq 0x9070
jmp 0x5f484
movq -0x120(%rbp), %rdi
addq $0x8, %rdi
leaq 0xe81a(%rip), %rsi      # 0x6dcb0
xorl %eax, %eax
movl %eax, %edx
callq 0x9c60
movq %rax, %rcx
movq -0x120(%rbp), %rax
addq $0x2, %rcx
movq %rcx, 0x198(%rax)
jmp 0x5f697
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x5f4df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x9c98
leaq -0xe9(%rbp), %rdi
callq 0x9700
jmp 0x5f6a9
movq -0x120(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movq 0x198(%rax), %rdx
addq $0x1, %rdx
leaq 0xe7a0(%rip), %rsi      # 0x6dcb0
callq 0x9c60
cmpq $-0x1, %rax
je 0x5f629
leaq 0xe033(%rip), %rsi      # 0x6d559
leaq -0x28(%rbp), %rdi
callq 0xdf50
movb %al, -0x169(%rbp)
jmp 0x5f537
movb -0x169(%rbp), %al
testb $0x1, %al
jne 0x5f546
jmp 0x5f629
leaq -0x111(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x9b10
movq -0x178(%rbp), %rdx
leaq 0xe63e(%rip), %rsi      # 0x6dba5
leaq -0x110(%rbp), %rdi
callq 0xa780
jmp 0x5f575
leaq -0x110(%rbp), %rdi
movl $0x1, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x5bdc0
jmp 0x5f58c
leaq -0x110(%rbp), %rdi
callq 0x9c98
leaq -0x111(%rbp), %rdi
callq 0x9700
movq -0x120(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
leaq -0x28(%rbp), %rsi
callq 0x9070
jmp 0x5f5bd
movq -0x120(%rbp), %rdi
addq $0x8, %rdi
leaq 0xe6e1(%rip), %rsi      # 0x6dcb0
xorl %eax, %eax
movl %eax, %edx
callq 0x9c60
movq %rax, %rcx
movq -0x120(%rbp), %rax
addq $0x2, %rcx
movq %rcx, 0x198(%rax)
jmp 0x5f695
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x5f618
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x9c98
leaq -0x111(%rbp), %rdi
callq 0x9700
jmp 0x5f6a9
movq -0x120(%rbp), %rax
movl $0x190, 0x188(%rax)     # imm = 0x190
movl $0x10, %edi
callq 0x9340
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x180(%rbp)
leaq 0xe4f5(%rip), %rsi      # 0x6db4d
callq 0x9be0
jmp 0x5f65f
movq -0x180(%rbp), %rdi
movq 0x2f95b(%rip), %rsi     # 0x8efc8
movq 0x2f944(%rip), %rdx     # 0x8efb8
callq 0x9aa0
jmp 0x5f6bb
movq -0x180(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
callq 0x94c0
jmp 0x5f6a9
jmp 0x5f697
leaq -0x28(%rbp), %rdi
callq 0x9c98
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x9c98
movq -0x78(%rbp), %rdi
callq 0x9af0
nopl (%rax,%rax)