// File: m1c0l[P]http-client-server/HttpMessage.cpp
// Function: HttpMessage::decode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int HttpMessage::decode(string encoded) {
	stringstream ss;
	ss << encoded;
	string line;

	size_t start = 0, end = 0;
	bool firstLine = true;

	// header
	while ((end = encoded.find(CRLF, start)) != string::npos) {
		line = encoded.substr(start, end - start);
		start = end + sizeof(CRLF) - 1;

		if (line.size() == 0 && !firstLine) // end of header
			break;

		if (firstLine) {
			int decodeStatus = decodeFirstLine(line);
			if (decodeStatus) {
				return decodeStatus;
			}
		}
		else {
			int decodeStatus = decodeHeaderLine(line);
			if (decodeStatus) {
				return decodeStatus;
			}
		}

		firstLine = false;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rsi, -0x260(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x268(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x52d0
movq -0x260(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x5380
jmp 0x5c96
leaq -0x1d0(%rbp), %rdi
callq 0x55c0
movq $0x0, -0x1d8(%rbp)
movq $0x0, -0x1e0(%rbp)
movb $0x1, -0x1e1(%rbp)
movq -0x260(%rbp), %rdi
movq -0x1d8(%rbp), %rdx
leaq 0xd4a2(%rip), %rsi      # 0x13176
callq 0x5720
movq %rax, -0x1e0(%rbp)
cmpq $-0x1, %rax
je 0x5ec8
movq -0x260(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
movq -0x1e0(%rbp), %rcx
subq %rdx, %rcx
leaq -0x208(%rbp), %rdi
callq 0x5440
jmp 0x5d10
leaq -0x1d0(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x5500
leaq -0x208(%rbp), %rdi
callq 0x5280
movq -0x1e0(%rbp), %rax
addq $0x3, %rax
subq $0x1, %rax
movq %rax, -0x1d8(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x52c0
cmpq $0x0, %rax
jne 0x5d93
testb $0x1, -0x1e1(%rbp)
jne 0x5d93
jmp 0x5ec8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5f09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5efd
testb $0x1, -0x1e1(%rbp)
je 0x5e34
leaq -0x230(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x51a0
jmp 0x5db5
movq -0x268(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
leaq -0x230(%rbp), %rsi
callq *%rax
movl %eax, -0x26c(%rbp)
jmp 0x5dd3
leaq -0x230(%rbp), %rdi
callq 0x5280
movl -0x26c(%rbp), %eax
movl %eax, -0x20c(%rbp)
cmpl $0x0, -0x20c(%rbp)
je 0x5e2f
movl -0x20c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x234(%rbp)
jmp 0x5ed9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x5280
jmp 0x5efd
jmp 0x5ebc
leaq -0x258(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x51a0
jmp 0x5e49
movq -0x268(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x59d0
movl %eax, -0x270(%rbp)
jmp 0x5e64
leaq -0x258(%rbp), %rdi
callq 0x5280
movl -0x270(%rbp), %eax
movl %eax, -0x238(%rbp)
cmpl $0x0, -0x238(%rbp)
je 0x5eba
movl -0x238(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x234(%rbp)
jmp 0x5ed9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x5280
jmp 0x5efd
jmp 0x5ebc
movb $0x0, -0x1e1(%rbp)
jmp 0x5cbf
movl $0x0, -0x4(%rbp)
movl $0x1, -0x234(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x5280
leaq -0x1a0(%rbp), %rdi
callq 0x5300
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
leaq -0x1d0(%rbp), %rdi
callq 0x5280
leaq -0x1a0(%rbp), %rdi
callq 0x5300
movq -0x1a8(%rbp), %rdi
callq 0x5680
nopw %cs:(%rax,%rax)