// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movq 0x3f1e(%rip), %rdi      # 0x6fd0
leaq 0x1278(%rip), %rsi      # 0x4331
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movq 0x4113(%rip), %rbx      # 0x71e0
leaq 0x40c4(%rip), %rsi      # 0x7198
leaq -0x88(%rbp), %r14
movq %r14, %rdi
callq 0x2230
pushq $-0x1
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2abe
leaq -0x88(%rbp), %rdi
callq 0x22e8
leaq 0x1180(%rip), %rsi      # 0x4284
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x254a
leaq -0x68(%rbp), %r14
leaq -0x48(%rbp), %rbx
leaq -0xa8(%rbp), %r15
pushq $-0x1
popq %r12
cmpb $0x0, 0x40ad(%rip)      # 0x71d8
jne 0x33f2
movq 0x3ea8(%rip), %rdi      # 0x6fe0
movq %r14, %rsi
pushq $0xa
popq %rdx
callq 0x22a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x317b
movq 0x3e78(%rip), %rdi      # 0x6fd0
leaq 0x11e6(%rip), %rsi      # 0x4345
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movq %r14, %rdi
leaq 0x11d4(%rip), %rsi      # 0x434a
callq 0x22c0
movq %r14, %rdi
leaq 0x11cb(%rip), %rsi      # 0x4350
callq 0x39fd
testb %al, %al
je 0x31b2
movq %rbx, %rdi
callq 0x2d45
movq 0x3e33(%rip), %rdi      # 0x6fd0
movq %rbx, %rsi
callq 0x2160
movq %rbx, %rdi
callq 0x22e8
jmp 0x3124
movq -0x60(%rbp), %rcx
cmpq $0xa, %rcx
jb 0x32a2
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
pushq $0x9
popq %rcx
callq 0x21c0
movq %rbx, %rdi
leaq 0x117c(%rip), %rsi      # 0x4356
callq 0x39fd
movq %rbx, %rdi
movl %eax, %ebx
callq 0x22e8
movq -0x60(%rbp), %rcx
testb %bl, %bl
je 0x329e
cmpq $0xb, %rcx
leaq -0x48(%rbp), %rbx
ja 0x3216
movq 0x3dca(%rip), %rdi      # 0x6fd0
leaq 0x1153(%rip), %rsi      # 0x4360
callq 0x2180
movq -0x60(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
pushq $0xa
popq %rdx
callq 0x21c0
leaq -0xe8(%rbp), %rdi
leaq 0x3f66(%rip), %rsi      # 0x7198
callq 0x2230
leaq -0xe8(%rbp), %r13
movq %r13, %rdi
callq 0x2d9c
movl %eax, %ebx
movq %r13, %rdi
callq 0x22e8
testb %bl, %bl
leaq -0x48(%rbp), %rbx
je 0x3291
leaq 0x3f39(%rip), %rdi      # 0x7198
movq %rbx, %rsi
callq 0x20e0
movq 0x3d62(%rip), %rdi      # 0x6fd0
leaq 0x111f(%rip), %rsi      # 0x4394
callq 0x2180
movq %rax, %rdi
leaq 0x3f14(%rip), %rsi      # 0x7198
callq 0x2160
movq %rax, %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x22e8
jmp 0x3373
leaq -0x48(%rbp), %rbx
cmpq $0x6, %rcx
jb 0x3373
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
pushq $0x5
popq %rcx
callq 0x21c0
movq %rbx, %rdi
leaq 0x10e4(%rip), %rsi      # 0x43aa
callq 0x39fd
movl %eax, %ebx
leaq -0x48(%rbp), %rdi
callq 0x22e8
testb %bl, %bl
leaq -0x48(%rbp), %rbx
je 0x3373
movq -0x60(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x6
popq %rdx
callq 0x21c0
leaq -0xc8(%rbp), %rdi
movq %rbx, %rsi
callq 0x2230
leaq -0xc8(%rbp), %r13
movq %r13, %rdi
callq 0x2cca
movl %eax, %ebx
movq %r13, %rdi
callq 0x22e8
testb %bl, %bl
je 0x3332
leaq 0x3e91(%rip), %rdi      # 0x71b8
leaq -0x48(%rbp), %rsi
callq 0x20e0
jmp 0x335c
movq 0x3c97(%rip), %rdi      # 0x6fd0
leaq 0x1070(%rip), %rsi      # 0x43b0
callq 0x2180
movq %rax, %rdi
leaq 0x3e69(%rip), %rsi      # 0x71b8
callq 0x2160
movq %rax, %rdi
callq 0x20d0
leaq -0x48(%rbp), %r13
movq %r13, %rdi
callq 0x22e8
testb %bl, %bl
movq %r13, %rbx
je 0x3124
xorl %ebx, %ebx
cmpq %rbx, -0x60(%rbp)
jbe 0x33c0
movq 0x3e5e(%rip), %r13      # 0x71e0
movl $0x1000, %ecx           # imm = 0x1000
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x21c0
movq %r13, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x2abe
movq %r15, %rdi
callq 0x22e8
movq 0x3e2e(%rip), %rdi      # 0x71e0
callq 0x2b92
addq $0x1000, %rbx           # imm = 0x1000
jmp 0x3375
movq %r14, %rdi
leaq 0xf80(%rip), %rsi       # 0x434a
callq 0x39fd
testb %al, %al
je 0x33da
movb $0x1, 0x3dfe(%rip)      # 0x71d8
movq %r14, %rdi
leaq 0xf66(%rip), %rsi       # 0x434a
callq 0x22c0
leaq -0x48(%rbp), %rbx
jmp 0x3124
xorl %edi, %edi
callq 0x2270
jmp 0x3425
jmp 0x3425
jmp 0x3425
jmp 0x3425
jmp 0x3405
jmp 0x3405
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
jmp 0x341e
jmp 0x3425
jmp 0x3425
jmp 0x3425
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x22e8
jmp 0x3428
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x343d
movq %rax, %rbx
jmp 0x3442
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x22e8
movq %rbx, %rdi
callq 0x2260