// File: /workspace/github_cpp_makefile_star2_O3/AraKhachatryan[P]messenger/client.cpp
// Function: recv_thread(void*)
void * recv_thread( void * arg )
{
    char input[512];

	std::vector<std::string> names_from;
	std::string message_info;
	std::string message_from;

	int socket_desc = *(int*)arg;

	while(1)
    {
        names_from.clear();
        message_info.clear();
        message_from.clear();

        int rv = recv(socket_desc, input, sizeof(input), 0);
		if ( rv == -1 ){
            std::cerr << "Error reading from server: " << std::strerror(errno) << std::endl;
            break;
        } else if ( rv  == 0 ) {
            break;
        }

        decode_message(input, sizeof(input), names_from, message_info, message_from);

        // Private incoming messages
        if( !message_info.compare("Private") )
        {
            std::cout << terminal::TEXT_BOLD << terminal::TEXTCOLOR_RED << names_from.front()
                        << terminal::RESET_ALL <<  "-> " << terminal::TEXT_BOLD << terminal::TEXTCOLOR_GREEN
                        << message_from << terminal::RESET_ALL << std::endl;
        // Public incoming messages
        } else if ( !message_info.compare("Public") ) {
            std::cout << terminal::TEXT_BOLD << terminal::TEXTCOLOR_WHITE << names_from.front()
                        << terminal::RESET_ALL <<  "-> " << terminal::TEXT_BOLD << terminal::TEXTCOLOR_GREEN
                        << message_from << terminal::RESET_ALL << std::endl;
        // New active clients notifications from server
        } else if ( !message_info.compare("Server:online") ) {
            std::cout << terminal::TEXT_BOLD << terminal::TEXTCOLOR_CYAN;
            for( auto it = names_from.begin(); it != names_from.end(); ++it )
            {
                std::cout << *it;
                if( *it != names_from.back() )
                {
                    std:: cout << ", ";
                }
            }
            std::cout << terminal::RESET_ALL << terminal::TEXT_BOLD << terminal::TEXTCOLOR_WHITE
                        << message_from << terminal::RESET_ALL << std::endl;
        }


	} // End while()

	std::cout << "Server is down!!! Closing recv_thread and socket..." << std::endl;
	close(socket_desc);
	pthread_exit(NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
xorl %ecx, %ecx
leaq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rcx, -0x8(%rax)
movb %cl, (%rax)
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rcx, -0x8(%rax)
movb %cl, (%rax)
movl (%rdi), %eax
movl %eax, 0xc(%rsp)
leaq 0x70(%rsp), %rbp
leaq 0x50(%rsp), %r12
movq 0x419f(%rip), %r14      # 0x6fc8
leaq 0x234a(%rip), %rbx      # 0x517a
xorl %r13d, %r13d
xorl %r15d, %r15d
cmpq %r15, %r13
je 0x2e82
movq %rbx, %r14
movq %r12, %rbx
movq %rbp, %r12
leaq 0x10(%r15), %rbp
movq -0x10(%rbp), %rdi
cmpq %rdi, %rbp
je 0x2e5d
movq (%rbp), %rsi
incq %rsi
callq 0x21c0
leaq 0x20(%rbp), %rax
addq $0x10, %rbp
cmpq %r13, %rbp
movq %rax, %rbp
jne 0x2e48
movq %r15, 0x18(%rsp)
movq %r12, %rbp
movq %rbx, %r12
movq %r14, %rbx
movq 0x4146(%rip), %r14      # 0x6fc8
xorl %ecx, %ecx
movq %rcx, 0x58(%rsp)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq %rcx, 0x38(%rsp)
movq 0x30(%rsp), %rax
movb %cl, (%rax)
movl $0x200, %edx            # imm = 0x200
movl 0xc(%rsp), %edi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0x2070
testl %eax, %eax
je 0x3558
cmpl $-0x1, %eax
je 0x34cb
movl $0x200, %esi            # imm = 0x200
movq %rbp, %rdi
leaq 0x10(%rsp), %rdx
movq %r12, %rcx
leaq 0x30(%rsp), %r8
callq 0x3b22
movq %r12, %rdi
leaq 0x2241(%rip), %rsi      # 0x5125
callq 0x2060
testl %eax, %eax
je 0x311e
movq %r12, %rdi
leaq 0x2236(%rip), %rsi      # 0x5131
callq 0x2060
testl %eax, %eax
je 0x32e6
movq %r12, %rdi
leaq 0x2226(%rip), %rsi      # 0x5138
callq 0x2060
testl %eax, %eax
jne 0x34bc
movb 0x424b(%rip), %al       # 0x7170
movq %r14, %r15
cmpb $0x1, %al
jne 0x2f66
movl $0x2, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r14, %rdi
movl $0x1, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2222(%rip), %rsi      # 0x517d
callq 0x21e0
movb 0x420a(%rip), %al       # 0x7170
testb $0x1, %al
je 0x2f9b
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
movl $0x24, %esi
callq 0x2250
movl $0x1, %edx
movq %rax, %rdi
leaq 0x21e7(%rip), %rsi      # 0x517d
callq 0x21e0
movq 0x10(%rsp), %r15
cmpq 0x18(%rsp), %r15
je 0x2ffc
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x21e0
movq 0x18(%rsp), %r13
movq 0x8(%r15), %rdx
cmpq -0x18(%r13), %rdx
jne 0x2fda
testq %rdx, %rdx
je 0x2ff3
movq -0x20(%r13), %rsi
movq (%r15), %rdi
callq 0x21d0
testl %eax, %eax
je 0x2ff3
movl $0x2, %edx
movq %r14, %rdi
leaq 0x2119(%rip), %rsi      # 0x5102
callq 0x21e0
movq 0x18(%rsp), %r13
addq $0x20, %r15
cmpq %r13, %r15
jne 0x2fa7
movb 0x416e(%rip), %al       # 0x7170
movq %r14, %r15
cmpb $0x1, %al
jne 0x3040
movl $0x2, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r14, %rdi
xorl %esi, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2148(%rip), %rsi      # 0x517d
callq 0x21e0
movb 0x4130(%rip), %al       # 0x7170
testb $0x1, %al
je 0x307e
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
movl $0x1, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x210a(%rip), %rsi      # 0x517d
callq 0x21e0
movb 0x40f2(%rip), %al       # 0x7170
testb $0x1, %al
je 0x30b6
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
movl $0x25, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20cc(%rip), %rsi      # 0x517d
callq 0x21e0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r15, %rdi
callq 0x21e0
movq %rax, %r15
cmpb $0x1, 0x409e(%rip)      # 0x7170
jne 0x3105
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
xorl %esi, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x207d(%rip), %rsi      # 0x517d
callq 0x21e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
jmp 0x34a9
movb 0x404c(%rip), %al       # 0x7170
movq %r14, %r15
cmpb $0x1, %al
jne 0x3165
movl $0x2, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r14, %rdi
movl $0x1, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2023(%rip), %rsi      # 0x517d
callq 0x21e0
movb 0x400b(%rip), %al       # 0x7170
testb $0x1, %al
je 0x319d
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
movl $0x1f, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1fe5(%rip), %rsi      # 0x517d
callq 0x21e0
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, %rdi
callq 0x21e0
movq %rax, %r15
cmpb $0x1, 0x3fb5(%rip)      # 0x7170
jne 0x31ee
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
xorl %esi, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1f94(%rip), %rsi      # 0x517d
callq 0x21e0
movl $0x3, %edx
movq %r15, %rdi
leaq 0x1f30(%rip), %rsi      # 0x512d
callq 0x21e0
movb 0x3f68(%rip), %al       # 0x7170
cmpb $0x1, %al
jne 0x3246
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
movl $0x1, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1f42(%rip), %rsi      # 0x517d
callq 0x21e0
movb 0x3f2a(%rip), %al       # 0x7170
testb $0x1, %al
je 0x327e
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
movl $0x20, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1f04(%rip), %rsi      # 0x517d
callq 0x21e0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r15, %rdi
callq 0x21e0
movq %rax, %r15
cmpb $0x1, 0x3ed6(%rip)      # 0x7170
jne 0x32cd
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
xorl %esi, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1eb5(%rip), %rsi      # 0x517d
callq 0x21e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
jmp 0x34a9
movb 0x3e84(%rip), %al       # 0x7170
movq %r14, %r15
cmpb $0x1, %al
jne 0x332d
movl $0x2, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r14, %rdi
movl $0x1, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1e5b(%rip), %rsi      # 0x517d
callq 0x21e0
movb 0x3e43(%rip), %al       # 0x7170
testb $0x1, %al
je 0x3365
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
movl $0x25, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1e1d(%rip), %rsi      # 0x517d
callq 0x21e0
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, %rdi
callq 0x21e0
movq %rax, %r15
cmpb $0x1, 0x3ded(%rip)      # 0x7170
jne 0x33b6
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
xorl %esi, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1dcc(%rip), %rsi      # 0x517d
callq 0x21e0
movl $0x3, %edx
movq %r15, %rdi
leaq 0x1d68(%rip), %rsi      # 0x512d
callq 0x21e0
movb 0x3da0(%rip), %al       # 0x7170
cmpb $0x1, %al
jne 0x340e
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
movl $0x1, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1d7a(%rip), %rsi      # 0x517d
callq 0x21e0
movb 0x3d62(%rip), %al       # 0x7170
testb $0x1, %al
je 0x3446
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
movl $0x20, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1d3c(%rip), %rsi      # 0x517d
callq 0x21e0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r15, %rdi
callq 0x21e0
movq %rax, %r15
cmpb $0x1, 0x3d0e(%rip)      # 0x7170
jne 0x3495
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
xorl %esi, %esi
callq 0x2250
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1ced(%rip), %rsi      # 0x517d
callq 0x21e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r13
jmp 0x2e36
movq 0x3b1e(%rip), %rbx      # 0x6ff0
leaq 0x1c30(%rip), %rsi      # 0x5109
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x21e0
callq 0x2040
movl (%rax), %edi
callq 0x2090
testq %rax, %rax
jne 0x3510
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2240
jmp 0x352d
movq %rax, %r14
movq %rax, %rdi
callq 0x20b0
movq 0x3ace(%rip), %rdi      # 0x6ff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x21e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x3aa5(%rip), %rdi      # 0x6ff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq 0x3a69(%rip), %rbx      # 0x6fc8
leaq 0x1be0(%rip), %rsi      # 0x5146
movl $0x33, %edx
movq %rbx, %rdi
callq 0x21e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x3a37(%rip), %rdi      # 0x6fc8
callq 0x2030
movq %rax, %rdi
callq 0x2110
movl 0xc(%rsp), %edi
callq 0x22b0
xorl %edi, %edi
callq 0x2270
jmp 0x35b4
jmp 0x35b4
jmp 0x35b4
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x35d3
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x35ef
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0x10(%rsp), %rdi
callq 0x37a6
movq %rbx, %rdi
callq 0x2260