// File: /workspace/github_cpp_makefile_star2_O1/davidcairuz[P]network-internet-relay-chat/client.cpp
// Function: client_send_thread(void*)
void* client_send_thread(void* arg) {
    cout << "Connected to server" << endl;
    client_socket->Write(nickname);
    string message = "";

    while (!quit) {
        if (!getline(cin, message, '\n')) {
            cout << "Tiau" << endl;
            message = "/quit";
        }

        // checa mensagens especiais
        if (message == "/menu") {
            cout << get_menu();
            continue;
            
        } else if(message.size() >= 10 && message.substr(0, 9) == "/nickname") {
            if (message.size () < 12) 
                cout << "Type a valid username (a-z, A-Z, ., _, -, size > 2)";
            
            string new_nickname = message.substr(10, message.size());
            
            if (check_username(nickname)) {
                nickname = new_nickname;
                cout << "Nickname updated to: " << nickname << endl;        
            }

        } else if(message.size() >= 6 && message.substr(0, 5) == "/join") {
            string new_channel = message.substr(6, message.size());
            
            if (check_channel_name(new_channel)) {
                channel = new_channel;
            } else {
                cout << "Invalid channel " << channel << endl;
                continue;
            }
        }

        // envia cada catch da mesagem
        for (int i = 0; (unsigned int)i < message.size(); i += Socket::buffer_size) {
            client_socket->Write(message.substr(i, Socket::buffer_size));
            client_socket->Check();
        }

        if (message == "/quit") {
            quit = true;
        }

        message = "/quit";
    }

    pthread_exit(NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq 0x4bd4(%rip), %rbx      # 0x7fd0
leaq 0x1f2e(%rip), %rsi      # 0x5331
movl $0x13, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x4daa(%rip), %r14      # 0x81e8
leaq -0xe0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x4d50(%rip), %rsi      # 0x81a0
movq 0x4d51(%rip), %rdx      # 0x81a8
addq %rsi, %rdx
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
callq 0x2580
movq %r14, %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2cce
movq -0xf0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3494
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x1de1(%rip), %rdx      # 0x5284
leaq -0x68(%rbp), %rdi
movq %rdx, %rsi
callq 0x261a
cmpb $0x0, 0x4d2a(%rip)      # 0x81e0
je 0x34bf
xorl %edi, %edi
callq 0x2290
leaq -0xc0(%rbp), %rbx
leaq -0x68(%rbp), %r15
leaq -0xd0(%rbp), %r12
movq 0x4b08(%rip), %rdi      # 0x7fe0
movq %r15, %rsi
movl $0xa, %edx
callq 0x22c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x3558
movl $0x4, %edx
movq 0x4ad1(%rip), %rdi      # 0x7fd0
leaq 0x1e3f(%rip), %rsi      # 0x5345
callq 0x21f0
movq 0x4abe(%rip), %rcx      # 0x7fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x4aa0(%rip), %rdi      # 0x7fd0
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq -0x60(%rbp), %rdx
movl $0x5, %r8d
movq %r15, %rdi
xorl %esi, %esi
leaq 0x1df7(%rip), %rcx      # 0x534a
callq 0x2270
movq %r15, %rdi
leaq 0x1dee(%rip), %rsi      # 0x5350
callq 0x2070
testl %eax, %eax
je 0x35ac
movq -0x60(%rbp), %r14
cmpq $0xa, %r14
jb 0x362d
movl $0x9, %ecx
leaq -0x130(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r13, %rdi
leaq 0x1dba(%rip), %rsi      # 0x5356
callq 0x2070
testl %eax, %eax
sete %r13b
jmp 0x3630
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x152, -0x70(%rbp)     # imm = 0x152
leaq -0x48(%rbp), %rdi
leaq -0x70(%rbp), %rsi
xorl %edx, %edx
callq 0x22a0
movq %rax, %r14
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %r13
movq %r13, -0x38(%rbp)
movl $0x152, %edx            # imm = 0x152
movq %rax, %rdi
leaq 0x1b49(%rip), %rsi      # 0x5132
callq 0x2140
movq %r13, -0x40(%rbp)
movb $0x0, (%r14,%r13)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x49ca(%rip), %rdi      # 0x7fd0
callq 0x21f0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3984
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x3984
xorl %r13d, %r13d
cmpq $0xa, %r14
jb 0x3658
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rax
cmpq %rax, %rdi
je 0x3658
movq -0x120(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x60(%rbp), %r14
testb %r13b, %r13b
je 0x3787
cmpq $0xb, %r14
ja 0x3683
movl $0x33, %edx
movq 0x4959(%rip), %rdi      # 0x7fd0
leaq 0x1ce2(%rip), %rsi      # 0x5360
callq 0x21f0
movq -0x60(%rbp), %rcx
movl $0xa, %edx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x21d0
leaq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x4af3(%rip), %rsi      # 0x81a0
movq 0x4af4(%rip), %rdx      # 0x81a8
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x2580
leaq -0xb0(%rbp), %rdi
callq 0x2ff7
movl %eax, %r14d
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x36f4
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r14b, %r14b
je 0x3765
leaq 0x4aa0(%rip), %rdi      # 0x81a0
leaq -0x48(%rbp), %rsi
callq 0x20e0
movl $0x15, %edx
movq 0x48bb(%rip), %rdi      # 0x7fd0
leaq 0x1c78(%rip), %rsi      # 0x5394
callq 0x21f0
movq 0x4a78(%rip), %rsi      # 0x81a0
movq 0x4a79(%rip), %rdx      # 0x81a8
movq 0x489a(%rip), %rdi      # 0x7fd0
callq 0x21f0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x38e8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x38e8
cmpq $0x6, %r14
jb 0x37bd
movl $0x5, %ecx
leaq -0x110(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r13, %rdi
leaq 0x1bfa(%rip), %rsi      # 0x53aa
callq 0x2070
testl %eax, %eax
sete %r13b
jmp 0x37c0
xorl %r13d, %r13d
cmpq $0x6, %r14
jb 0x37e8
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x37e8
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r13b, %r13b
je 0x38e8
movq -0x60(%rbp), %rcx
movl $0x6, %edx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x21d0
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x2580
leaq -0x90(%rbp), %rdi
callq 0x2f15
movl %eax, %r13d
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3853
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r13b, %r13b
je 0x386a
leaq 0x4961(%rip), %rdi      # 0x81c0
leaq -0x48(%rbp), %rsi
callq 0x20e0
jmp 0x38c6
movl $0x10, %edx
movq 0x475a(%rip), %rdi      # 0x7fd0
leaq 0x1b33(%rip), %rsi      # 0x53b0
callq 0x21f0
movq 0x4937(%rip), %rsi      # 0x81c0
movq 0x4938(%rip), %rdx      # 0x81c8
movq 0x4739(%rip), %rdi      # 0x7fd0
callq 0x21f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x38df
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r13b, %r13b
je 0x3984
cmpq $0x0, -0x60(%rbp)
je 0x3950
xorl %r13d, %r13d
movq 0x48ef(%rip), %r14      # 0x81e8
movl $0x1000, %ecx           # imm = 0x1000
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x21d0
movq %r14, %rdi
movq %r12, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2cce
movq -0xd0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3937
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq 0x48aa(%rip), %rdi      # 0x81e8
callq 0x2dc6
addq $0x1000, %r13           # imm = 0x1000
cmpq %r13, -0x60(%rbp)
ja 0x38f2
movq %r15, %rdi
leaq 0x19f0(%rip), %r14      # 0x534a
movq %r14, %rsi
callq 0x2070
testl %eax, %eax
jne 0x396d
movb $0x1, 0x4873(%rip)      # 0x81e0
movq -0x60(%rbp), %rdx
movl $0x5, %r8d
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rcx
callq 0x2270
cmpb $0x0, 0x4855(%rip)      # 0x81e0
je 0x34d1
jmp 0x34b8
jmp 0x39de
jmp 0x39de
jmp 0x39de
jmp 0x39de
jmp 0x39a4
jmp 0x39de
jmp 0x39a4
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x39e1
movq -0x38(%rbp), %rsi
jmp 0x39d2
jmp 0x39de
movq %rax, %r14
movq -0xd0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x39e1
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x39e1
jmp 0x39de
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x3a17
movq -0x58(%rbp), %rsi
jmp 0x3a0f
movq %rax, %r14
jmp 0x3a17
movq %rax, %r14
movq -0xf0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3a17
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq %r14, %rdi
callq 0x2280