// File: AraKhachatryan[P]messenger/encode_decode.cpp
// Function: decode_message(char const*, unsigned long, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void decode_message( const char * encoded_message, size_t io_buffer_length,
                    std::vector<std::string>& dest_names, std::string& message_info, std::string&  message )
{
    size_t name_char_count = 0;
    size_t name_char_firs_pos = 0;
    bool new_name_flag = 0;


    for( size_t i = 0; i < 100; ++i )
    {
        if ( encoded_message[0] == 0x00 )
        {
            break;
        }

        if ( (encoded_message[i] == ',') || (encoded_message[i] == 0x00) )
        {
            if ( new_name_flag )
            {
                name_char_firs_pos += name_char_count + new_name_flag;
            }
            name_char_count = i - name_char_firs_pos;

            dest_names.push_back(std::string(encoded_message + name_char_firs_pos, name_char_count));

            if ( encoded_message[i] == 0x00 )
            {
                break;
            }

            if ( encoded_message[i] == ',' )
            {
                new_name_flag = 1;
                continue;
            }
        }
    }

    // copy message info part to message_info until reaching 0x00
    name_char_count = 0;
    for( size_t i = 100; i < 128; ++i )
    {
        if ( encoded_message[100] == 0x00 )
        {
            break;
        }

        if ( encoded_message[i] == 0x00 )
        {
            name_char_count = i - 100;

            message_info = std::string(encoded_message + 100, name_char_count);

            if ( encoded_message[i] == 0x00 )
            {
                break;
            }
        }

    }

    // copy message part to message until reaching 0x00
    name_char_count = 0;
    for( size_t i = 128; i < io_buffer_length; ++i )
    {
        if ( encoded_message[128] == 0x00 )
        {
            break;
        }

        if ( encoded_message[i] == 0x00 )
        {
            name_char_count = i - 128;

            message = std::string(encoded_message + 128, name_char_count);

            if ( encoded_message[i] == 0x00 )
            {
                break;
            }
        }

    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
movq $0x0, -0x48(%rbp)
cmpq $0x64, -0x48(%rbp)
jae 0x4936
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x47f7
jmp 0x4936
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
je 0x481d
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4923
testb $0x1, -0x39(%rbp)
je 0x483b
movq -0x30(%rbp), %rax
movb -0x39(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
addq %rcx, %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xf8(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x23b0
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
movq -0xe8(%rbp), %rcx
leaq -0x68(%rbp), %rdi
callq 0x22c0
jmp 0x48a2
movq -0x100(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x4cb0
jmp 0x48b4
leaq -0x68(%rbp), %rdi
callq 0x2150
leaq -0x69(%rbp), %rdi
callq 0x2290
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x490a
jmp 0x4936
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x48fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2150
leaq -0x69(%rbp), %rdi
callq 0x2290
jmp 0x4b85
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
jne 0x4921
movb $0x1, -0x39(%rbp)
jmp 0x4925
jmp 0x4923
jmp 0x4925
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x47db
movq $0x0, -0x30(%rbp)
movq $0x64, -0x88(%rbp)
cmpq $0x80, -0x88(%rbp)
jae 0x4a59
movq -0x8(%rbp), %rax
movsbl 0x64(%rax), %eax
cmpl $0x0, %eax
jne 0x496c
jmp 0x4a59
movq -0x8(%rbp), %rax
movq -0x88(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4a40
movq -0x88(%rbp), %rax
addq $-0x64, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
addq $0x64, %rax
movq %rax, -0x118(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x23b0
movq -0x118(%rbp), %rsi
movq -0x110(%rbp), %rdx
movq -0x108(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
callq 0x22c0
jmp 0x49e3
movq -0x20(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x22e0
leaq -0xa8(%rbp), %rdi
callq 0x2150
leaq -0xa9(%rbp), %rdi
callq 0x2290
movq -0x8(%rbp), %rax
movq -0x88(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4a3e
jmp 0x4a59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa9(%rbp), %rdi
callq 0x2290
jmp 0x4b85
jmp 0x4a40
jmp 0x4a42
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x4949
movq $0x0, -0x30(%rbp)
movq $0x80, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x4b7c
movq -0x8(%rbp), %rax
movsbl 0x80(%rax), %eax
cmpl $0x0, %eax
jne 0x4a92
jmp 0x4b7c
movq -0x8(%rbp), %rax
movq -0xb8(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4b63
movq -0xb8(%rbp), %rax
addq $-0x80, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
subq $-0x80, %rax
movq %rax, -0x130(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x23b0
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rdx
movq -0x120(%rbp), %rcx
leaq -0xd8(%rbp), %rdi
callq 0x22c0
jmp 0x4b09
movq -0x28(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22e0
leaq -0xd8(%rbp), %rdi
callq 0x2150
leaq -0xd9(%rbp), %rdi
callq 0x2290
movq -0x8(%rbp), %rax
movq -0xb8(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4b61
jmp 0x4b7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xd9(%rbp), %rdi
callq 0x2290
jmp 0x4b85
jmp 0x4b63
jmp 0x4b65
movq -0xb8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb8(%rbp)
jmp 0x4a6c
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x2390
nop