// File: /workspace/github_cpp_makefile_star2_O3/llefranc[P]42_webserv/srcs/server/Request.cpp
// Function: Request::parsingCheck()
void Request::parsingCheck()
{
    // Indicates end of request line / header line
	size_t posCLRF = !_body.isReceiving() ? _buffer.find(CLRF, _index) : 0;

    while (!_body.isReceiving() && newLineReceived(posCLRF))
    {
		// (1) First step
        if (_reqLine.empty())
            parseRequestLine(posCLRF);    
        
        // (3) Third step, double CRLF indicates end of headers
        else if (!_body.isReceiving() && _index == posCLRF)
		{
			_index += CLRF_OCTET_SIZE;
			
			std::map<std::string, std::string>::iterator it = _headers.find("host");
			if (it == _headers.end() || it->second.empty())
				throw StatusLine(400, REASON_400, "host field missing or empty");

			// Body will receive content-length octets
			if ((it = _headers.find("content-length")) != _headers.end())
			{
				_body.startReceiving();
				_body.setSize(atol(it->second.c_str()));
				_body.setMaxSize(findMaxSize(_headers.find("host")->second));
			}
			
			// Case no content-length header, so no body
			else
				throw StatusLine(200, REASON_200);
		}
            
		// (2) Second step
        else if (!_body.isReceiving())
            parseHeaderLine(posCLRF);
            
        _index = posCLRF + CLRF_OCTET_SIZE;
        posCLRF = _buffer.find(CLRF, _index);
    }

	// (4) Fourth step
	if (_body.isReceiving())
		parseBody();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movb 0xa8(%rdi), %al
testb %al, %al
je 0xcb39
xorl %r14d, %r14d
jmp 0xcb5a
movq 0x20(%rbx), %rdx
leaq 0x913e(%rip), %rsi      # 0x15c82
movl $0x2, %ecx
movq %rbx, %rdi
callq 0x46c0
movq %rax, %r14
movb 0xa8(%rbx), %al
testb $0x1, %al
jne 0xcd2f
leaq 0x78(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0x80(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq 0x9106(%rip), %r12      # 0x15c82
leaq -0x48(%rbp), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xce6c
testb %al, %al
je 0xcd29
cmpq $0x0, 0x40(%rbx)
je 0xcce3
cmpb $0x0, 0xa8(%rbx)
jne 0xccfb
cmpq %r14, 0x20(%rbx)
jne 0xccf0
leaq 0x2(%r14), %rax
movq %rax, 0x20(%rbx)
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %r13, %rdi
leaq 0x8a18(%rip), %rsi      # 0x155e7
leaq 0x8a15(%rip), %rdx      # 0x155eb
callq 0x5796
movq -0x50(%rbp), %rdi
movq %r13, %r15
movq %r13, %rsi
callq 0xe25c
movq %rax, %r13
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xcc06
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
cmpq -0x58(%rbp), %r13
je 0xcd4a
cmpq $0x0, 0x48(%r13)
je 0xcd4a
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %r15, %r13
movq %r15, %rdi
leaq 0x89e4(%rip), %rsi      # 0x15614
leaq 0x89eb(%rip), %rdx      # 0x15622
callq 0x5796
movq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0xe25c
movq %rax, %r13
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xcc64
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
cmpq -0x58(%rbp), %r13
je 0xcdab
movb $0x1, 0xa8(%rbx)
movq 0x40(%r13), %rdi
callq 0x44b0
movq %rax, 0xb0(%rbx)
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %r15, %r13
movq %r15, %rdi
leaq 0x894d(%rip), %rsi      # 0x155e7
leaq 0x894a(%rip), %rdx      # 0x155eb
callq 0x5796
movq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0xe25c
addq $0x40, %rax
movq %rbx, %rdi
movq %rax, %rsi
callq 0xd3be
movq %rax, 0xb8(%rbx)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xccfb
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xccfb
movq %rbx, %rdi
movq %r14, %rsi
callq 0xcfb4
jmp 0xccfb
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd3ee
addq $0x2, %r14
movq %r14, 0x20(%rbx)
movl $0x2, %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x46c0
movq %rax, %r14
movb 0xa8(%rbx), %al
cmpb $0x1, %al
jne 0xcb80
jmp 0xcd2f
movb 0xa8(%rbx), %al
testb $0x1, %al
je 0xcd3b
movq %rbx, %rdi
callq 0xd816
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x48, %edi
callq 0x41f0
movq %rax, %r14
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x888f(%rip), %rsi      # 0x155f8
leaq 0x88a3(%rip), %rdx      # 0x15613
callq 0x5796
movb $0x1, %r15b
leaq 0x886d(%rip), %rdx      # 0x155ec
leaq -0x48(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xe0d4
xorl %r15d, %r15d
leaq 0xffd6(%rip), %rsi      # 0x1cd70
leaq 0x13a1(%rip), %rdx      # 0xe142
movq %r14, %rdi
callq 0x46a0
jmp 0xce06
movl $0x48, %edi
callq 0x41f0
movq %rax, %r14
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x8937(%rip), %rdx      # 0x15701
movq %rdx, %rsi
callq 0x5796
movb $0x1, %r15b
leaq 0x8847(%rip), %rdx      # 0x15623
leaq -0x48(%rbp), %rcx
movq %r14, %rdi
movl $0xc8, %esi
callq 0xe0d4
xorl %r15d, %r15d
leaq 0xff79(%rip), %rsi      # 0x1cd70
leaq 0x1344(%rip), %rdx      # 0xe142
movq %r14, %rdi
callq 0x46a0
jmp 0xce0a
jmp 0xce2d
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xce26
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
testb %r15b, %r15b
jne 0xce30
jmp 0xce63
movq %rax, %rbx
movq %r14, %rdi
callq 0x42e0
jmp 0xce63
jmp 0xce42
jmp 0xce47
jmp 0xce42
jmp 0xce47
movq %rax, %rbx
jmp 0xce63
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xce63
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %rbx, %rdi
callq 0x46d0
nop