// File: 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
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x118(%rbp)
addq $0xa8, %rdi
callq 0x19900
testb $0x1, %al
jne 0x175aa
movq -0x118(%rbp), %rdi
movq 0x20(%rdi), %rdx
leaq 0xc6d9(%rip), %rsi      # 0x23c75
callq 0x59e0
movq %rax, -0x120(%rbp)
jmp 0x175b5
xorl %eax, %eax
movq %rax, -0x120(%rbp)
jmp 0x175b5
movq -0x120(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x118(%rbp), %rdi
addq $0xa8, %rdi
callq 0x19900
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x121(%rbp)
jne 0x175f8
movq -0x118(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x17be0
movb %al, -0x121(%rbp)
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x17607
jmp 0x17ba6
movq -0x118(%rbp), %rdi
addq $0x30, %rdi
callq 0x19920
testb $0x1, %al
jne 0x1761d
jmp 0x17632
movq -0x118(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x17e20
jmp 0x17b7a
movq -0x118(%rbp), %rdi
addq $0xa8, %rdi
callq 0x19900
testb $0x1, %al
jne 0x17b4f
movq -0x118(%rbp), %rax
movq 0x20(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x17b4f
movq -0x118(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x2, %rcx
movq %rcx, 0x20(%rax)
addq $0x78, %rax
movq %rax, -0x138(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x58f0
movq -0x130(%rbp), %rdx
leaq 0xbf54(%rip), %rsi      # 0x235f2
leaq -0x38(%rbp), %rdi
callq 0x63e0
jmp 0x176a9
movq -0x138(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x19950
movq %rax, -0x140(%rbp)
jmp 0x176c2
movq -0x140(%rbp), %rax
movq %rax, -0x18(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5a08
leaq -0x39(%rbp), %rdi
callq 0x55c0
movq -0x118(%rbp), %rdi
addq $0x78, %rdi
callq 0x19980
movq %rax, -0x58(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x11f40
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x141(%rbp)
jne 0x1772a
leaq -0x18(%rbp), %rdi
callq 0x199b0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5870
movb %al, -0x141(%rbp)
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0x17739
jmp 0x1782e
movb $0x1, -0x7a(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0x158(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x58f0
movq -0x150(%rbp), %rdx
leaq 0xbe97(%rip), %rsi      # 0x23603
leaq -0x78(%rbp), %rdi
callq 0x63e0
jmp 0x17777
movq -0x158(%rbp), %rdi
leaq 0xbe72(%rip), %rdx      # 0x235f7
movl $0x190, %esi            # imm = 0x190
leaq -0x78(%rbp), %rcx
callq 0x199d0
jmp 0x17795
movq -0x158(%rbp), %rdi
movb $0x0, -0x7a(%rbp)
leaq 0x195e9(%rip), %rsi     # 0x30d90
leaq 0x22d2(%rip), %rdx      # 0x19a80
callq 0x58a0
jmp 0x17bdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x177db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5a08
leaq -0x39(%rbp), %rdi
callq 0x55c0
jmp 0x17bd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1780c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5a08
leaq -0x79(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x7a(%rbp)
jne 0x1781d
jmp 0x17829
movq -0x158(%rbp), %rdi
callq 0x53f0
jmp 0x17bd4
movq -0x118(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x168(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x58f0
movq -0x160(%rbp), %rdx
leaq 0xbdbe(%rip), %rsi      # 0x2361f
leaq -0xa8(%rbp), %rdi
callq 0x63e0
jmp 0x1786f
movq -0x168(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x19950
movq %rax, -0x170(%rbp)
jmp 0x1788b
movq -0x118(%rbp), %rdi
movq -0x170(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x18(%rbp)
addq $0x78, %rdi
callq 0x19980
movq %rax, -0xb8(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x19ab0
movb %al, -0x171(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5a08
leaq -0xa9(%rbp), %rdi
callq 0x55c0
movb -0x171(%rbp), %al
testb $0x1, %al
jne 0x178f8
jmp 0x17a71
movq -0x118(%rbp), %rdi
addq $0xa8, %rdi
movq %rdi, -0x190(%rbp)
callq 0x19ae0
leaq -0x18(%rbp), %rdi
callq 0x199b0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5240
movq %rax, %rdi
callq 0x5650
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0x19b00
movq -0x118(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x188(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x58f0
movq -0x180(%rbp), %rdx
leaq 0xbc81(%rip), %rsi      # 0x235f2
leaq -0xe0(%rbp), %rdi
callq 0x63e0
jmp 0x1797f
movq -0x188(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x19950
movq %rax, -0x198(%rbp)
jmp 0x1799b
movq -0x198(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x199b0
movq -0x118(%rbp), %rdi
movq %rax, %rsi
addq $0x20, %rsi
callq 0x183b0
movq %rax, -0x1a0(%rbp)
jmp 0x179d1
movq -0x1a0(%rbp), %rsi
movq -0x190(%rbp), %rdi
callq 0x19b20
jmp 0x179e6
leaq -0xe0(%rbp), %rdi
callq 0x5a08
leaq -0xe1(%rbp), %rdi
callq 0x55c0
jmp 0x17b4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x17a29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5a08
leaq -0xa9(%rbp), %rdi
callq 0x55c0
jmp 0x17bd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x17a60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x5a08
leaq -0xe1(%rbp), %rdi
callq 0x55c0
jmp 0x17bd4
movb $0x1, -0x10a(%rbp)
movl $0x48, %edi
callq 0x5290
movq %rax, -0x1b0(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x58f0
movq -0x1a8(%rbp), %rdx
leaq 0xbc62(%rip), %rsi      # 0x2370c
leaq -0x108(%rbp), %rdi
callq 0x63e0
jmp 0x17ab8
movq -0x1b0(%rbp), %rdi
leaq 0xbb68(%rip), %rdx      # 0x2362e
movl $0xc8, %esi
leaq -0x108(%rbp), %rcx
callq 0x199d0
jmp 0x17ad9
movq -0x1b0(%rbp), %rdi
movb $0x0, -0x10a(%rbp)
leaq 0x192a2(%rip), %rsi     # 0x30d90
leaq 0x1f8b(%rip), %rdx      # 0x19a80
callq 0x58a0
jmp 0x17bdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x17b25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x5a08
leaq -0x109(%rbp), %rdi
callq 0x55c0
testb $0x1, -0x10a(%rbp)
jne 0x17b3c
jmp 0x17b48
movq -0x1b0(%rbp), %rdi
callq 0x53f0
jmp 0x17bd4
jmp 0x17b78
movq -0x118(%rbp), %rdi
addq $0xa8, %rdi
callq 0x19900
testb $0x1, %al
jne 0x17b76
movq -0x118(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x18410
jmp 0x17b78
jmp 0x17b7a
movq -0x118(%rbp), %rdi
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, 0x20(%rdi)
movq 0x20(%rdi), %rdx
leaq 0xc0dd(%rip), %rsi      # 0x23c75
callq 0x59e0
movq %rax, -0x10(%rbp)
jmp 0x175c0
movq -0x118(%rbp), %rdi
addq $0xa8, %rdi
callq 0x19900
testb $0x1, %al
jne 0x17bbf
jmp 0x17bcb
movq -0x118(%rbp), %rdi
callq 0x18970
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x58e0
nopl (%rax)