// File: /workspace/github_cpp_makefile_star2_O2/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
cmpb $0x0, 0xa8(%rdi)
je 0xb408
xorl %r14d, %r14d
jmp 0xb41e
movq 0x20(%rbx), %rdx
leaq 0x681d(%rip), %rsi      # 0x11c30
movq %rbx, %rdi
callq 0x47c0
movq %rax, %r14
leaq 0x78(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x80(%rbx), %rax
movq %rax, -0x40(%rbp)
leaq 0x67f8(%rip), %r12      # 0x11c30
leaq -0x60(%rbp), %r13
movb 0xa8(%rbx), %al
testb %al, %al
jne 0xb58c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb694
testb %al, %al
je 0xb586
cmpq $0x0, 0x40(%rbx)
je 0xb550
cmpb $0x0, 0xa8(%rbx)
jne 0xb568
cmpq %r14, 0x20(%rbx)
jne 0xb55d
leaq 0x2(%r14), %rax
movq %rax, 0x20(%rbx)
movq %r13, %rdi
leaq 0x614f(%rip), %rsi      # 0x115e0
leaq -0x29(%rbp), %rdx
callq 0x4ec8
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0xc702
movq %rax, %r15
movq %r13, %rdi
callq 0x47d8
cmpq -0x40(%rbp), %r15
je 0xb5a7
cmpq $0x0, 0x48(%r15)
je 0xb5a7
movq %r13, %rdi
leaq 0x613d(%rip), %rsi      # 0x1160d
leaq -0x29(%rbp), %rdx
callq 0x4ec8
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0xc702
movq %rax, %r15
movq %r13, %rdi
callq 0x47d8
cmpq -0x40(%rbp), %r15
je 0xb5fc
movb $0x1, 0xa8(%rbx)
movq 0x40(%r15), %rdi
callq 0x44d0
movq %rax, 0xb0(%rbx)
movq %r13, %rdi
leaq 0x60c5(%rip), %rsi      # 0x115e0
leaq -0x29(%rbp), %rdx
callq 0x4ec8
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0xc702
addq $0x40, %rax
movq %rbx, %rdi
movq %rax, %rsi
callq 0xbad2
movq %rax, 0xb8(%rbx)
movq %r13, %rdi
callq 0x47d8
jmp 0xb568
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb7ba
jmp 0xb568
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbb02
addq $0x2, %r14
movq %r14, 0x20(%rbx)
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x47c0
movq %rax, %r14
jmp 0xb43c
movb 0xa8(%rbx), %al
testb $0x1, %al
je 0xb598
movq %rbx, %rdi
callq 0xbdf4
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x48
popq %rdi
callq 0x4220
movq %rax, %r14
leaq 0x6038(%rip), %rsi      # 0x115f1
leaq -0x60(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4ec8
movb $0x1, %r15b
leaq 0x6015(%rip), %rdx      # 0x115e5
leaq -0x60(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xc540
xorl %r15d, %r15d
leaq 0xd7a5(%rip), %rsi      # 0x18d90
leaq 0xfa4(%rip), %rdx       # 0xc596
movq %r14, %rdi
callq 0x46b0
jmp 0xb64f
pushq $0x48
popq %rdi
callq 0x4220
movq %rax, %r14
leaq 0x60ec(%rip), %rsi      # 0x116fa
leaq -0x60(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4ec8
movb $0x1, %r15b
leaq 0x5ff7(%rip), %rdx      # 0x1161c
leaq -0x60(%rbp), %rcx
movq %r14, %rdi
movl $0xc8, %esi
callq 0xc540
xorl %r15d, %r15d
leaq 0xd750(%rip), %rsi      # 0x18d90
leaq 0xf4f(%rip), %rdx       # 0xc596
movq %r14, %rdi
callq 0x46b0
jmp 0xb653
jmp 0xb666
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x47d8
testb %r15b, %r15b
jne 0xb669
jmp 0xb68c
movq %rax, %rbx
movq %r14, %rdi
callq 0x4330
jmp 0xb68c
jmp 0xb67b
jmp 0xb680
jmp 0xb67b
jmp 0xb680
movq %rax, %rbx
jmp 0xb68c
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x47d8
movq %rbx, %rdi
callq 0x46d0