// File: ixchow[P]http-tweak/./http.hpp
// Function: http::incoming_request::parse_bytes(char const*, long, std::function<void ()> const&)
bool parse_bytes(char const *begin, ssize_t count, std::function< void() > const &on_finish) {
		for (char const *c = begin; c < begin + count; ++c) {
			if (mode == RequestLine || mode == HeaderLine) {
				line += *c;
				//once line is complete, parse it:
				if (line.size() >= 2 && line[line.size() - 2] == '\r' && line[line.size()-1] == '\n') {
					line.erase(line.size()-2); //trim CRLF

					if (mode == RequestLine) {
						if (line.size() != 0) { //ignore empty lines before request
							//parse "method SP url SP version"
							std::string::size_type i1 = line.find(' ');
							if (i1 == std::string::npos) return false;
							std::string::size_type i2 = line.find(' ', i1+1);
							if (i1 == std::string::npos) return false;
							method = line.substr(0, i1);
							url = line.substr(i1+1, i2-(i1+1));
							std::string version = line.substr(i2+1);
							if (version.substr(0,7) != "HTTP/1.") return false; //unsupported http version

							mode = HeaderLine; //next lines are headers
						}
					} else { assert(mode == HeaderLine);
						if (line.size() == 0) {
							//empty line separates headers from body

							//clean up headers by trimming whitespace as per the spec:
							for (auto &nf : headers) {
								std::string value = "";
								//replace runs of ' '/'\t' with single ' ' (and ignore first such run):
								for (auto const &c : nf.second) {
									if (c == ' ' || c == '\t') {
										if (!value.empty() && value[value.size()-1] != ' ') {
											value += ' ';
										}
									} else {
										value += c;
									}
								}
								if (!value.empty() && value[value.size()-1] == ' ') value = value.substr(0, value.size()-1);
								nf.second = value;
							}

							//set body_remains based on size of body passed in content header:
							for (auto const &nf : headers) {
								if (case_insensitive_equals(nf.first, "Content-Length")) {
									body_remains = std::stoul(nf.second);
								}
							}

							mode = Body;
							if (body_remains == 0) {
								on_finish();
								reset();
							}
						} else {
							//parse "name: [space] value" or "[space] continuation-value"
							if (line[0] == ' ' || line[0] == '\t') {
								//[space] continuation-value
								if (headers.empty()) {
									return false; //nothing to continue
								}
								headers.back().second += line;
							} else {
								auto i = line.find(':');
								if (i == std::string::npos) {
									return false; //no ':' to split field name and value
								}
								headers.emplace_back(line.substr(0, i), line.substr(i+1));
							}
						}
					}
					line = ""; //clear line, now that it's parsed
				}
			} else if (mode == Body) {
				assert(body_remains != 0);
				body += *c;
				--body_remains;
				if (body_remains == 0) {
					on_finish();
					reset();
				}
			}
		}
		return true;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jae 0xf724
movq -0x1f0(%rbp), %rax
cmpl $0x0, 0x78(%rax)
je 0xece1
movq -0x1f0(%rbp), %rax
cmpl $0x1, 0x78(%rax)
jne 0xf68e
movq -0x1f0(%rbp), %rdi
movq -0x30(%rbp), %rax
movb (%rax), %al
addq $0x80, %rdi
movsbl %al, %esi
callq 0x4300
movq -0x1f0(%rbp), %rdi
addq $0x80, %rdi
callq 0x4370
cmpq $0x2, %rax
jb 0xf689
movq -0x1f0(%rbp), %rdi
movq %rdi, %rax
addq $0x80, %rax
movq %rax, -0x1f8(%rbp)
addq $0x80, %rdi
callq 0x4370
movq -0x1f8(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0x47c0
movsbl (%rax), %eax
cmpl $0xd, %eax
jne 0xf689
movq -0x1f0(%rbp), %rdi
movq %rdi, %rax
addq $0x80, %rax
movq %rax, -0x200(%rbp)
addq $0x80, %rdi
callq 0x4370
movq -0x200(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x47c0
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0xf689
movq -0x1f0(%rbp), %rdi
movq %rdi, %rax
addq $0x80, %rax
movq %rax, -0x208(%rbp)
addq $0x80, %rdi
callq 0x4370
movq -0x208(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
movq $-0x1, %rdx
callq 0x4100
movq -0x1f0(%rbp), %rax
cmpl $0x0, 0x78(%rax)
jne 0xf012
movq -0x1f0(%rbp), %rdi
addq $0x80, %rdi
callq 0x4370
cmpq $0x0, %rax
je 0xf00d
movq -0x1f0(%rbp), %rdi
addq $0x80, %rdi
movl $0x20, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x45b0
movq %rax, -0x38(%rbp)
cmpq $-0x1, -0x38(%rbp)
jne 0xee39
movb $0x0, -0x1(%rbp)
jmp 0xf728
movq -0x1f0(%rbp), %rdi
addq $0x80, %rdi
movq -0x38(%rbp), %rdx
addq $0x1, %rdx
movl $0x20, %esi
callq 0x45b0
movq %rax, -0x40(%rbp)
cmpq $-0x1, -0x38(%rbp)
jne 0xee6d
movb $0x0, -0x1(%rbp)
jmp 0xf728
movq -0x1f0(%rbp), %rsi
subq $-0x80, %rsi
movq %rsi, -0x220(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x210(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x44b0
movq -0x230(%rbp), %rsi
movq -0x1f0(%rbp), %rdi
callq 0x4550
movq -0x230(%rbp), %rdi
callq 0x42f0
movq -0x220(%rbp), %rsi
movq -0x38(%rbp), %rdx
incq %rdx
movq -0x40(%rbp), %rcx
subq %rdx, %rcx
leaq -0x80(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x44b0
movq -0x1f0(%rbp), %rdi
movq -0x228(%rbp), %rsi
addq $0x20, %rdi
callq 0x4550
movq -0x228(%rbp), %rdi
callq 0x42f0
movq -0x220(%rbp), %rsi
movq -0x40(%rbp), %rdx
incq %rdx
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x218(%rbp)
movq $-0x1, %rcx
callq 0x44b0
movq -0x218(%rbp), %rsi
movq -0x210(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
movl $0x7, %ecx
callq 0x44b0
jmp 0xef4e
leaq 0x9621(%rip), %rsi      # 0x18576
leaq -0xc0(%rbp), %rdi
callq 0x10a60
movb %al, -0x231(%rbp)
jmp 0xef69
leaq -0xc0(%rbp), %rdi
callq 0x42f0
movb -0x231(%rbp), %al
testb $0x1, %al
jne 0xef81
jmp 0xefc5
movb $0x0, -0x1(%rbp)
movl $0x1, -0xd0(%rbp)
jmp 0xefdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0xeffc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x42f0
jmp 0xeffc
movq -0x1f0(%rbp), %rax
movl $0x1, 0x78(%rax)
movl $0x0, -0xd0(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x42f0
movl -0xd0(%rbp), %eax
testl %eax, %eax
je 0xeffa
jmp 0xeff5
jmp 0xf728
jmp 0xf00d
leaq -0xa0(%rbp), %rdi
callq 0x42f0
jmp 0xf736
jmp 0xf66f
movq -0x1f0(%rbp), %rax
cmpl $0x1, 0x78(%rax)
jne 0xf021
jmp 0xf040
leaq 0x9556(%rip), %rdi      # 0x1857e
leaq 0x92f2(%rip), %rsi      # 0x18321
movl $0xaf, %edx
leaq 0x9556(%rip), %rcx      # 0x18591
callq 0x4330
movq -0x1f0(%rbp), %rdi
addq $0x80, %rdi
callq 0x4370
cmpq $0x0, %rax
jne 0xf4ca
movq -0x1f0(%rbp), %rax
addq $0x40, %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
callq 0xca80
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
callq 0xcab0
movq %rax, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0xcae0
testb $0x1, %al
jne 0xf0b1
jmp 0xf33b
leaq -0xe0(%rbp), %rdi
callq 0xcb20
movq %rax, -0xf0(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x4720
movq -0x240(%rbp), %rdx
leaq 0x9190(%rip), %rsi      # 0x18275
leaq -0x110(%rbp), %rdi
callq 0x4f80
jmp 0xf0f3
leaq -0x111(%rbp), %rdi
callq 0x44f0
movq -0xf0(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rdi
callq 0x4410
movq %rax, -0x128(%rbp)
movq -0x120(%rbp), %rdi
callq 0x42c0
movq %rax, -0x130(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x10a90
testb $0x1, %al
jne 0xf153
jmp 0xf263
leaq -0x128(%rbp), %rdi
callq 0x10ad0
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0xf188
movq -0x138(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x9, %eax
jne 0xf236
leaq -0x110(%rbp), %rdi
callq 0x46b0
testb $0x1, %al
jne 0xf234
leaq -0x110(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x4370
movq -0x250(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x47c0
movq %rax, -0x248(%rbp)
jmp 0xf1ca
movq -0x248(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0xf234
leaq -0x110(%rbp), %rdi
movl $0x20, %esi
callq 0x4300
jmp 0xf1ec
jmp 0xf234
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x111(%rbp), %rdi
callq 0x44f0
jmp 0xf736
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x42f0
jmp 0xf736
jmp 0xf250
movq -0x138(%rbp), %rax
movsbl (%rax), %esi
leaq -0x110(%rbp), %rdi
callq 0x4300
jmp 0xf24e
jmp 0xf250
jmp 0xf252
leaq -0x128(%rbp), %rdi
callq 0x10af0
jmp 0xf137
leaq -0x110(%rbp), %rdi
callq 0x46b0
testb $0x1, %al
jne 0xf305
leaq -0x110(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x4370
movq -0x260(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x47c0
movq %rax, -0x258(%rbp)
jmp 0xf2a5
movq -0x258(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0xf305
leaq -0x110(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x4370
movq -0x268(%rbp), %rsi
movq %rax, %rcx
decq %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x158(%rbp), %rdi
callq 0x44b0
jmp 0xf2e6
leaq -0x110(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x4550
leaq -0x158(%rbp), %rdi
callq 0x42f0
movq -0xf0(%rbp), %rdi
addq $0x20, %rdi
leaq -0x110(%rbp), %rsi
callq 0x4070
jmp 0xf31e
leaq -0x110(%rbp), %rdi
callq 0x42f0
leaq -0xe0(%rbp), %rdi
callq 0xcbc0
jmp 0xf095
movq -0x1f0(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rdi
callq 0xca80
movq %rax, -0x168(%rbp)
movq -0x160(%rbp), %rdi
callq 0xcab0
movq %rax, -0x170(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0xcae0
testb $0x1, %al
jne 0xf38f
jmp 0xf49c
leaq -0x168(%rbp), %rdi
callq 0xcb20
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x278(%rbp)
leaq -0x199(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x4720
movq -0x270(%rbp), %rdx
leaq 0x9220(%rip), %rsi      # 0x185f1
leaq -0x198(%rbp), %rdi
callq 0x4f80
jmp 0xf3df
movq -0x278(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x10b10
movb %al, -0x279(%rbp)
jmp 0xf3fa
leaq -0x198(%rbp), %rdi
callq 0x42f0
leaq -0x199(%rbp), %rdi
callq 0x44f0
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0xf41e
jmp 0xf489
movq -0x178(%rbp), %rdi
addq $0x20, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x10c10
movq %rax, %rcx
movq -0x1f0(%rbp), %rax
movl %ecx, 0x7c(%rax)
jmp 0xf489
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0xf478
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x42f0
leaq -0x199(%rbp), %rdi
callq 0x44f0
jmp 0xf736
jmp 0xf48b
leaq -0x168(%rbp), %rdi
callq 0xcbc0
jmp 0xf373
movq -0x1f0(%rbp), %rax
movl $0x2, 0x78(%rax)
cmpl $0x0, 0x7c(%rax)
jne 0xf4c5
movq -0x28(%rbp), %rdi
callq 0x10c50
movq -0x1f0(%rbp), %rdi
callq 0x10c90
jmp 0xf66d
movq -0x1f0(%rbp), %rdi
addq $0x80, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x47c0
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0xf508
movq -0x1f0(%rbp), %rdi
addq $0x80, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x47c0
movsbl (%rax), %eax
cmpl $0x9, %eax
jne 0xf55f
movq -0x1f0(%rbp), %rdi
addq $0x40, %rdi
callq 0x10d00
testb $0x1, %al
jne 0xf51e
jmp 0xf527
movb $0x0, -0x1(%rbp)
jmp 0xf728
movq -0x1f0(%rbp), %rdi
movq %rdi, %rax
addq $0x80, %rax
movq %rax, -0x288(%rbp)
addq $0x40, %rdi
callq 0x10d40
movq -0x288(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rdi
callq 0x4580
jmp 0xf66b
movq -0x1f0(%rbp), %rdi
addq $0x80, %rdi
movl $0x3a, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x45b0
movq %rax, -0x1a8(%rbp)
cmpq $-0x1, -0x1a8(%rbp)
jne 0xf595
movb $0x0, -0x1(%rbp)
jmp 0xf728
movq -0x1f0(%rbp), %rsi
movq %rsi, %rax
addq $0x40, %rax
movq %rax, -0x298(%rbp)
subq $-0x80, %rsi
movq %rsi, -0x290(%rbp)
movq -0x1a8(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x1c8(%rbp), %rdi
callq 0x44b0
movq -0x290(%rbp), %rsi
movq -0x1a8(%rbp), %rdx
incq %rdx
leaq -0x1e8(%rbp), %rdi
movq $-0x1, %rcx
callq 0x44b0
jmp 0xf5f2
movq -0x298(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
leaq -0x1e8(%rbp), %rdx
callq 0x10d80
jmp 0xf60e
leaq -0x1e8(%rbp), %rdi
callq 0x42f0
leaq -0x1c8(%rbp), %rdi
callq 0x42f0
jmp 0xf66b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0xf65a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x42f0
leaq -0x1c8(%rbp), %rdi
callq 0x42f0
jmp 0xf736
jmp 0xf66d
jmp 0xf66f
movq -0x1f0(%rbp), %rdi
addq $0x80, %rdi
leaq 0x8bf1(%rip), %rsi      # 0x18275
callq 0x45e0
jmp 0xf711
movq -0x1f0(%rbp), %rax
cmpl $0x2, 0x78(%rax)
jne 0xf70f
movq -0x1f0(%rbp), %rax
cmpl $0x0, 0x7c(%rax)
je 0xf6aa
jmp 0xf6c9
leaq 0x8f4f(%rip), %rdi      # 0x18600
leaq 0x8c69(%rip), %rsi      # 0x18321
movl $0xe4, %edx
leaq 0x8ecd(%rip), %rcx      # 0x18591
callq 0x4330
movq -0x1f0(%rbp), %rdi
movq -0x30(%rbp), %rax
movb (%rax), %al
addq $0x58, %rdi
movsbl %al, %esi
callq 0x4300
movq -0x1f0(%rbp), %rax
movl 0x7c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x7c(%rax)
cmpl $0x0, 0x7c(%rax)
jne 0xf70d
movq -0x28(%rbp), %rdi
callq 0x10c50
movq -0x1f0(%rbp), %rdi
callq 0x10c90
jmp 0xf70f
jmp 0xf711
jmp 0xf713
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xecae
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
movq -0xc8(%rbp), %rdi
callq 0x4710
nopw %cs:(%rax,%rax)
nopl (%rax)