// File: /workspace/github_cpp_makefile_star2_O1/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 0xcaf8
xorl %r14d, %r14d
jmp 0xcb13
movq 0x20(%rbx), %rdx
leaq 0x917f(%rip), %rsi      # 0x15c82
movl $0x2, %ecx
movq %rbx, %rdi
callq 0x46c0
movq %rax, %r14
cmpb $0x0, 0xa8(%rbx)
je 0xcb3c
cmpb $0x1, 0xa8(%rbx)
jne 0xcb2d
movq %rbx, %rdi
callq 0xd81a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x78(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0x80(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq 0x912c(%rip), %r12      # 0x15c82
leaq -0x48(%rbp), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xce2e
testb %al, %al
je 0xcb1c
cmpq $0x0, 0x40(%rbx)
je 0xccbd
movb 0xa8(%rbx), %al
testb %al, %al
jne 0xccc8
movq 0x20(%rbx), %rcx
cmpq %r14, %rcx
jne 0xccf8
addq $0x2, %rcx
movq %rcx, 0x20(%rbx)
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %r13, %rdi
leaq 0x8a3e(%rip), %rsi      # 0x155e7
leaq 0x8a3b(%rip), %rdx      # 0x155eb
callq 0x5790
movq -0x50(%rbp), %rdi
movq %r13, %r15
movq %r13, %rsi
callq 0xe28e
movq %rax, %r13
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xcbe0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
cmpq -0x58(%rbp), %r13
je 0xcd09
cmpq $0x0, 0x48(%r13)
je 0xcd09
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %r15, %r13
movq %r15, %rdi
leaq 0x8a0a(%rip), %rsi      # 0x15614
leaq 0x8a11(%rip), %rdx      # 0x15622
callq 0x5790
movq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0xe28e
movq %rax, %r13
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xcc3e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
cmpq -0x58(%rbp), %r13
je 0xcd6a
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 0x8973(%rip), %rsi      # 0x155e7
leaq 0x8970(%rip), %rdx      # 0x155eb
callq 0x5790
movq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0xe28e
addq $0x40, %rax
movq %rbx, %rdi
movq %rax, %rsi
callq 0xd396
movq %rax, 0xb8(%rbx)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xccc8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xccc8
movq %rbx, %rdi
movq %r14, %rsi
callq 0xcf7a
addq $0x2, %r14
movq %r14, 0x20(%rbx)
movl $0x2, %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x46c0
movq %rax, %r14
cmpb $0x1, 0xa8(%rbx)
jne 0xcb5a
jmp 0xcb1c
testb %al, %al
jne 0xccc8
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd3c6
jmp 0xccc8
movl $0x48, %edi
callq 0x41f0
movq %rax, %r14
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x88d0(%rip), %rsi      # 0x155f8
leaq 0x88e4(%rip), %rdx      # 0x15613
callq 0x5790
movb $0x1, %r15b
leaq 0x88ae(%rip), %rdx      # 0x155ec
leaq -0x48(%rbp), %rcx
movq %r14, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0xe106
xorl %r15d, %r15d
leaq 0x10017(%rip), %rsi     # 0x1cd70
leaq 0x1414(%rip), %rdx      # 0xe174
movq %r14, %rdi
callq 0x46a0
jmp 0xcdc5
movl $0x48, %edi
callq 0x41f0
movq %rax, %r14
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x8978(%rip), %rdx      # 0x15701
movq %rdx, %rsi
callq 0x5790
movb $0x1, %r15b
leaq 0x8888(%rip), %rdx      # 0x15623
leaq -0x48(%rbp), %rcx
movq %r14, %rdi
movl $0xc8, %esi
callq 0xe106
xorl %r15d, %r15d
leaq 0xffba(%rip), %rsi      # 0x1cd70
leaq 0x13b7(%rip), %rdx      # 0xe174
movq %r14, %rdi
callq 0x46a0
jmp 0xcdc9
jmp 0xcde7
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xcded
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xcded
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xce25
movq %r14, %rdi
callq 0x42e0
jmp 0xce25
jmp 0xce04
jmp 0xce09
jmp 0xce04
jmp 0xce09
movq %rax, %rbx
jmp 0xce25
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xce25
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %rbx, %rdi
callq 0x46d0
nop