// File: /workspace/github_cpp_makefile_star2_O3/Computer-Kids-Club[P]screenshare-pro-backend/http.cpp
// Function: parse_header[abi:cxx11](char const*, char const*)
std::unordered_map<std::string, std::string> parse_header(const char *msg, const char *msg_end) {
    const char *head = msg;
    const char *tail = msg;

    std::unordered_map<std::string, std::string> http_request;

    // Find request type
    while (tail != msg_end && *tail != ' ')
        ++tail;
    http_request["Type"] = std::string(head, tail);

    // Find path
    while (tail != msg_end && *tail == ' ')
        ++tail;
    head = tail;
    while (tail != msg_end && *tail != ' ')
        ++tail;
    http_request["Path"] = std::string(head, tail);

    // Find HTTP version
    while (tail != msg_end && *tail == ' ')
        ++tail;
    head = tail;
    while (tail != msg_end && *tail != '\r')
        ++tail;
    http_request["Version"] = std::string(head, tail);
    if (tail != msg_end)
        ++tail;  // skip '\r'
    // TODO: what about the trailing '\n'?

    // Map all headers from a key to a value
    head = tail;
    while (head < msg_end && *head != '\r') {
        tail = head;
        while (tail < msg_end && *tail != '\r')
            ++tail;
        const char *colon = (const char *)memchr(head, ':', tail - head);
        if (colon == NULL) {
            // TODO: malformed headers, what should happen?
            break;
        }
        const char *value = colon + 1;
        while (value < tail && *value == ' ')
            ++value;
        if (head < colon && value < tail && tail <= msg_end) {
            http_request[std::string(head, colon)] = std::string(value, tail);
        }
        head = tail + 1;
        while (head < msg_end && (*head == '\n' || *head == '\r' || *head == ' '))
            head++;
        //printf("%d\n", head - msg);
        // TODO: what about the trailing '\n'?
    }

    return http_request;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r14
leaq 0x30(%rdi), %rax
movq %rax, (%rdi)
movq $0x1, 0x8(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
movl $0x3f800000, 0x20(%rdi) # imm = 0x3F800000
movq %rdi, -0x70(%rbp)
movups %xmm0, 0x28(%rdi)
movq %rsi, %r12
cmpq %rdx, %rsi
je 0x5e0c
cmpb $0x20, (%r12)
je 0x5e07
incq %r12
cmpq %r14, %r12
jne 0x5df5
movq %r14, %r12
movq %r12, %r15
jmp 0x5e0f
movq %rsi, %r15
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0x68(%rbp), %rdi
movq %r15, %rdx
callq 0x495c
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x1759(%rip), %rsi      # 0x758b
leaq 0x1756(%rip), %rdx      # 0x758f
leaq -0x48(%rbp), %rdi
callq 0x495c
leaq -0x48(%rbp), %rsi
movq -0x70(%rbp), %rdi
callq 0x588e
leaq -0x68(%rbp), %rsi
movq %rax, %rdi
callq 0x2280
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x5e74
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5e8d
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
cmpq %r14, %r15
je 0x5eaf
movq %r14, %rax
subq %r12, %rax
addq %r15, %rax
cmpb $0x20, (%r15)
jne 0x5eac
incq %r15
cmpq %r14, %r15
jne 0x5e9b
movq %rax, %r15
movq %r15, %r12
cmpq %r14, %r15
je 0x5ed7
movq %r14, %rax
subq %r12, %rax
addq %r15, %rax
movq %r15, %r12
cmpb $0x20, (%r12)
je 0x5ed2
incq %r12
cmpq %r14, %r12
jne 0x5ec0
movq %rax, %r12
movq %r12, %r13
jmp 0x5eda
movq %r15, %r13
leaq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
movq %rax, (%rdi)
movq %r15, %rsi
movq %r13, %rdx
callq 0x495c
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x168e(%rip), %rsi      # 0x7590
leaq 0x168b(%rip), %rdx      # 0x7594
callq 0x495c
leaq -0x48(%rbp), %rsi
movq -0x70(%rbp), %rdi
callq 0x588e
leaq -0x68(%rbp), %rsi
movq %rax, %rdi
callq 0x2280
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x5f40
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5f59
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
cmpq %r14, %r13
je 0x5f7c
movq %r14, %rax
subq %r12, %rax
addq %r13, %rax
cmpb $0x20, (%r13)
jne 0x5f79
incq %r13
cmpq %r14, %r13
jne 0x5f67
movq %rax, %r13
movq %r13, %r12
cmpq %r14, %r13
je 0x5fab
movq %r14, %rax
subq %r12, %rax
addq %r13, %rax
movq %r13, %r12
movb (%r12), %cl
cmpb $0xd, %cl
je 0x5fa1
incq %r12
cmpq %r14, %r12
jne 0x5f8d
movq %rax, %r12
xorl %ebx, %ebx
cmpb $0xd, %cl
sete %bl
jmp 0x5fb0
xorl %ebx, %ebx
movq %r13, %r12
leaq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
movq %rax, (%rdi)
movq %r13, %rsi
movq %r12, %rdx
callq 0x495c
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x15bd(%rip), %rsi      # 0x7595
leaq 0x15bd(%rip), %rdx      # 0x759c
callq 0x495c
leaq -0x48(%rbp), %rsi
movq -0x70(%rbp), %rdi
callq 0x588e
leaq -0x68(%rbp), %rsi
movq %rax, %rdi
callq 0x2280
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x6016
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x602f
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
addq %rbx, %r12
cmpq %r14, %r12
jae 0x6178
leaq -0x1(%r14), %rax
movq %rax, -0x78(%rbp)
movabsq $0x100002400, %rbx      # imm = 0x100002400
cmpb $0xd, (%r12)
je 0x6178
movq %r12, %r15
cmpq %r14, %r12
jae 0x607a
movq %r14, %rax
subq %r12, %rax
movq %r12, %r15
cmpb $0xd, (%r15)
je 0x607a
incq %r15
decq %rax
jne 0x6069
movq %r14, %r15
movq %r15, %rdx
subq %r12, %rdx
movq %r12, %rdi
movl $0x3a, %esi
callq 0x2220
testq %rax, %rax
je 0x6178
movq %rax, %r13
incq %rax
cmpq %r15, %rax
jae 0x613a
leaq 0x1(%rax), %rsi
cmpb $0x20, (%rax)
movq %rsi, %rax
je 0x609c
cmpq %r13, %r12
setae %al
cmpq %r14, %r15
seta %cl
orb %al, %cl
jne 0x613a
decq %rsi
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rdi
movq %r15, %rdx
callq 0x495c
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x495c
movq -0x70(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x588e
movq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x2280
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x6121
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x613a
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
leaq 0x1(%r15), %r12
cmpq %r14, %r12
jae 0x616f
movq %r15, %rax
addq %r14, %rax
subq %r15, %rax
movq -0x78(%rbp), %rcx
subq %r15, %rcx
movzbl (%r12), %edx
cmpq $0x20, %rdx
ja 0x616f
btq %rdx, %rbx
jae 0x616f
incq %r12
decq %rcx
jne 0x6153
movq %rax, %r12
cmpq %r14, %r12
jb 0x604d
movq -0x70(%rbp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x619d
jmp 0x61bb
jmp 0x61d9
jmp 0x619d
jmp 0x61bb
jmp 0x61d9
jmp 0x619d
jmp 0x61bb
jmp 0x61d9
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x61be
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x61be
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x61dc
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x61dc
movq %rax, %r14
movq -0x70(%rbp), %rdi
callq 0x42ae
movq %r14, %rdi
callq 0x2320
nopl (%rax)