// File: /workspace/github_cpp_makefile_star2_O3/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 0x4bd2(%rip), %r13      # 0x7fd0
leaq 0x1f2c(%rip), %rsi      # 0x5331
movl $0x13, %edx
movq %r13, %rdi
callq 0x21f0
movq (%r13), %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 0x4da7(%rip), %r14      # 0x81e8
leaq -0xe0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x4d4d(%rip), %rsi      # 0x81a0
movq 0x4d4e(%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 0x2cd6
movq -0xf0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3497
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x1dde(%rip), %rdx      # 0x5284
leaq -0x68(%rbp), %rdi
movq %rdx, %rsi
callq 0x261e
cmpb $0x0, 0x4d27(%rip)      # 0x81e0
je 0x34c2
xorl %edi, %edi
callq 0x2290
leaq -0xc0(%rbp), %rbx
leaq -0x68(%rbp), %r15
leaq -0xd0(%rbp), %r12
movq 0x4b05(%rip), %rdi      # 0x7fe0
movq %r15, %rsi
movl $0xa, %edx
callq 0x22c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x354d
movl $0x4, %edx
movq %r13, %rdi
leaq 0x1e40(%rip), %rsi      # 0x5345
callq 0x21f0
movq (%r13), %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 -0x60(%rbp), %rdx
movl $0x5, %r8d
movq %r15, %rdi
xorl %esi, %esi
leaq 0x1e02(%rip), %rcx      # 0x534a
callq 0x2270
movq %r15, %rdi
leaq 0x1df9(%rip), %rsi      # 0x5350
callq 0x2070
testl %eax, %eax
je 0x3690
movq -0x60(%rbp), %rcx
cmpq $0xa, %rcx
jb 0x35bc
movl $0x9, %ecx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r14, %rdi
leaq 0x1dc8(%rip), %rsi      # 0x5356
callq 0x2070
movl %eax, %r14d
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x35af
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x60(%rbp), %rcx
testl %r14d, %r14d
je 0x3714
cmpq $0x6, %rcx
jb 0x38af
movl $0x5, %ecx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r14, %rdi
leaq 0x1dc4(%rip), %rsi      # 0x53aa
callq 0x2070
movl %eax, %r14d
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3607
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testl %r14d, %r14d
jne 0x38af
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 0x2f1d
movl %eax, %r14d
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3672
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r14b, %r14b
je 0x382a
leaq 0x4b3e(%rip), %rdi      # 0x81c0
leaq -0x48(%rbp), %rsi
callq 0x20e0
jmp 0x3886
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 0x1a65(%rip), %rsi      # 0x5132
callq 0x2140
movq %r13, -0x40(%rbp)
movb $0x0, (%r14,%r13)
movq 0x48ee(%rip), %r13      # 0x7fd0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r13, %rdi
callq 0x21f0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3952
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x3952
cmpq $0xb, %rcx
ja 0x3732
movl $0x33, %edx
movq %r13, %rdi
leaq 0x1c37(%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 0x4a48(%rip), %rsi      # 0x81a0
movq 0x4a49(%rip), %rdx      # 0x81a8
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x2580
leaq -0xb0(%rbp), %rdi
callq 0x2fff
movl %eax, %r14d
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x379f
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r14b, %r14b
je 0x3808
leaq 0x49f5(%rip), %rdi      # 0x81a0
leaq -0x48(%rbp), %rsi
callq 0x20e0
movl $0x15, %edx
movq %r13, %rdi
leaq 0x1bd1(%rip), %rsi      # 0x5394
callq 0x21f0
movq 0x49d1(%rip), %rsi      # 0x81a0
movq 0x49d2(%rip), %rdx      # 0x81a8
movq %r13, %rdi
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 0x38af
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x38af
movl $0x10, %edx
movq 0x479a(%rip), %rdi      # 0x7fd0
leaq 0x1b73(%rip), %rsi      # 0x53b0
callq 0x21f0
movq 0x4977(%rip), %rsi      # 0x81c0
movq 0x4978(%rip), %rdx      # 0x81c8
movq 0x4779(%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 0x389f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r14b, %r14b
movq 0x4727(%rip), %r13      # 0x7fd0
je 0x3952
cmpq $0x0, -0x60(%rbp)
je 0x3917
xorl %r14d, %r14d
movq 0x4928(%rip), %r13      # 0x81e8
movl $0x1000, %ecx           # imm = 0x1000
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x21d0
movq %r13, %rdi
movq %r12, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2cd6
movq -0xd0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x38fe
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq 0x48e3(%rip), %rdi      # 0x81e8
callq 0x2dce
addq $0x1000, %r14           # imm = 0x1000
cmpq %r14, -0x60(%rbp)
ja 0x38b9
movq %r15, %rdi
leaq 0x1a29(%rip), %r14      # 0x534a
movq %r14, %rsi
callq 0x2070
testl %eax, %eax
jne 0x3934
movb $0x1, 0x48ac(%rip)      # 0x81e0
movq -0x60(%rbp), %rdx
movl $0x5, %r8d
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rcx
callq 0x2270
movq 0x467e(%rip), %r13      # 0x7fd0
cmpb $0x0, 0x4887(%rip)      # 0x81e0
je 0x34d4
jmp 0x34bb
jmp 0x39ac
jmp 0x39ac
jmp 0x39ac
jmp 0x39ac
jmp 0x3972
jmp 0x39ac
jmp 0x3972
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x39af
movq -0x38(%rbp), %rsi
jmp 0x39a0
jmp 0x39ac
movq %rax, %r14
movq -0xd0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x39af
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x39af
jmp 0x39ac
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x39e5
movq -0x58(%rbp), %rsi
jmp 0x39dd
movq %rax, %r14
jmp 0x39e5
movq %rax, %r14
movq -0xf0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x39e5
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq %r14, %rdi
callq 0x2280