// File: /workspace/github_cpp_makefile_star2_O1/davidcairuz[P]network-internet-relay-chat/client.cpp
// Function: main
int main(int argc, char* argv[]) {
    signal(SIGINT, Sigint_handler);

    if (argc < 2) {
        cout << "Provide your ip, please\n";
        return 1; 
    }

    string ip = argv[1];
    if (!check_ip(ip)) {
        cout << "Invalid IP\n";
        return 1;
    }

    pthread_t tid_receive;
    pthread_t tid_send;
    string command = "";
    
    nickname = get_nickname();
    cout << get_menu();

    // menu enquanto desconectado
    while (command != "/connect") {
        if(!getline(cin, command, '\n')) {
            cout << "quitting" << endl;
            exit(0);
        }

        if (command == "/menu") 
            cout << get_menu();
        else if(command == "/quit") 
            exit(0);
        else if(command == "/ping") 
            cout << "You've got to be connected!" << endl;
        else if(command.size() >= 9 && command.substr(0, 9) == "/nickname") {
            string new_nickname = command.substr(10, command.size());
            
            if (check_username(nickname)) {
                nickname = new_nickname;
                cout << "Nickname updated to: " << nickname << endl;        
            } else {
                cout << "Type a valid username (a-z, A-Z, ., _, -, size > 2)";
            }    
        } else if(command.size() >= 5 && command.substr(0, 5) == "/join") {
            cout << "You've got to be connected!" << endl;
        } else if (command.size() >= 5 && command.substr(0, 5) == "/kick") {
            cout << "You've got to be connected!" << endl;
        } else if (command.size() >= 5 && command.substr(0, 5) == "/mute") {
            cout << "You've got to be connected!" << endl;
        } else if (command.size() >= 7 && command.substr(0, 7) == "/unmute") {
            cout << "You've got to be connected!" << endl;
        }
    }

    client_socket = new Socket(ip, nickname);
    client_socket->Check();

    client_socket->Connect();
    client_socket->Check();

    if (pthread_create(&tid_send, NULL, client_send_thread, NULL) != 0) {
        cout << "Failed to create thread to send message" << endl;
        return 1;
    }
    if (pthread_create(&tid_receive, NULL, client_receive_thread, NULL) != 0) {
        cout << "Failed to create thread to receive message" << endl;
        return 1;
    }

    while (!quit);

    cout << "É nois flw vlw" << endl;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rsi, %rbx
movl %edi, %r14d
leaq -0xb68(%rip), %rsi      # 0x2ed8
movl $0x2, %edi
callq 0x2210
cmpl $0x1, %r14d
jg 0x3a72
movq 0x4579(%rip), %rdi      # 0x7fd0
leaq 0x1963(%rip), %rsi      # 0x53c1
movl $0x18, %edx
callq 0x21f0
movl $0x1, %ebx
jmp 0x422d
movq 0x8(%rbx), %rsi
leaq -0x110(%rbp), %rbx
leaq -0x68(%rbp), %rdx
movq %rbx, %rdi
callq 0x2e8c
leaq -0x120(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0x130(%rbp), %rdi
callq 0x2580
movq -0x130(%rbp), %rsi
leaq -0x64(%rbp), %rdx
movl $0x2, %edi
callq 0x22d0
movl %eax, %ebx
movq -0x130(%rbp), %rdi
cmpq %r14, %rdi
je 0x3adc
movq -0x120(%rbp), %rsi
incq %rsi
callq 0x21c0
testl %ebx, %ebx
je 0x4169
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x1791(%rip), %rdx      # 0x5284
leaq -0x68(%rbp), %rdi
movq %rdx, %rsi
callq 0x261a
leaq -0x48(%rbp), %rdi
callq 0x3074
leaq 0x4691(%rip), %rdi      # 0x81a0
leaq -0x48(%rbp), %rbx
movq %rbx, %rsi
callq 0x2230
movq (%rbx), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3b33
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq -0x88(%rbp), %rsi
movq $0x152, (%rsi)          # imm = 0x152
xorl %edx, %edx
callq 0x22a0
movq %rax, %rbx
movq %rax, -0x48(%rbp)
movq -0x88(%rbp), %r14
movq %r14, -0x38(%rbp)
leaq 0x15c6(%rip), %rsi      # 0x5132
movl $0x152, %edx            # imm = 0x152
movq %rax, %rdi
callq 0x2140
movq %r14, -0x40(%rbp)
movb $0x0, (%rbx,%r14)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x443f(%rip), %rbx      # 0x7fd0
movq %rbx, %rdi
callq 0x21f0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3bb2
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq 0x182d(%rip), %rsi      # 0x53e6
leaq -0x68(%rbp), %rdi
callq 0x2070
testl %eax, %eax
je 0x4066
leaq -0x68(%rbp), %r15
leaq 0x1811(%rip), %r13      # 0x53e6
leaq -0x88(%rbp), %r12
movq 0x43fd(%rip), %rdi      # 0x7fe0
movq %r15, %rsi
movl $0xa, %edx
callq 0x22c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x428e
movq %r15, %rdi
leaq 0x1744(%rip), %rsi      # 0x5350
callq 0x2070
testl %eax, %eax
je 0x3c7d
movq %r15, %rdi
leaq 0x172b(%rip), %rsi      # 0x534a
callq 0x2070
testl %eax, %eax
je 0x42b2
movq %r15, %rdi
leaq 0x17c2(%rip), %rsi      # 0x53f8
callq 0x2070
testl %eax, %eax
je 0x4018
movq -0x60(%rbp), %r14
cmpq $0x9, %r14
jb 0x3cfe
movl $0x9, %ecx
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x16e9(%rip), %rsi      # 0x5356
callq 0x2070
testl %eax, %eax
sete %r12b
jmp 0x3d01
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x152, -0x90(%rbp) # imm = 0x152
leaq -0x48(%rbp), %rdi
leaq -0x90(%rbp), %rsi
xorl %edx, %edx
callq 0x22a0
movq %rax, %r14
movq %rax, -0x48(%rbp)
movq -0x90(%rbp), %r12
movq %r12, -0x38(%rbp)
movl $0x152, %edx            # imm = 0x152
movq %rax, %rdi
leaq 0x146f(%rip), %rsi      # 0x5132
callq 0x2140
movq %r12, -0x40(%rbp)
movb $0x0, (%r14,%r12)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x21f0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
leaq -0x88(%rbp), %r12
jne 0x3eea
jmp 0x4053
xorl %r12d, %r12d
cmpq $0x9, %r14
jb 0x3d23
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x3d23
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r12b, %r12b
je 0x3e16
movq -0x60(%rbp), %rcx
movl $0xa, %edx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x21d0
leaq -0x88(%rbp), %r12
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq 0x4443(%rip), %rsi      # 0x81a0
movq 0x4444(%rip), %rdx      # 0x81a8
addq %rsi, %rdx
leaq -0xf0(%rbp), %rdi
callq 0x2580
leaq -0xf0(%rbp), %rdi
callq 0x2ff7
movl %eax, %r14d
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x3da4
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r14b, %r14b
je 0x3ec5
leaq 0x43ec(%rip), %rdi      # 0x81a0
leaq -0x48(%rbp), %rsi
callq 0x20e0
movl $0x15, %edx
movq %rbx, %rdi
leaq 0x15c8(%rip), %rsi      # 0x5394
callq 0x21f0
movq 0x43c8(%rip), %rsi      # 0x81a0
movq 0x43c9(%rip), %rdx      # 0x81a8
movq %rbx, %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
jmp 0x3ed9
movq -0x60(%rbp), %r14
cmpq $0x5, %r14
jb 0x3e50
movl $0x5, %ecx
leaq -0x1b0(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x1567(%rip), %rsi      # 0x53aa
callq 0x2070
testl %eax, %eax
sete %r12b
jmp 0x3e53
xorl %r12d, %r12d
cmpq $0x5, %r14
jb 0x3e7b
movq -0x1b0(%rbp), %rdi
leaq -0x1a0(%rbp), %rax
cmpq %rax, %rdi
je 0x3e7b
movq -0x1a0(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r12b, %r12b
leaq -0x88(%rbp), %r12
jne 0x4018
movq -0x60(%rbp), %r14
cmpq $0x5, %r14
jb 0x3efb
movl $0x5, %ecx
leaq -0x190(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x1562(%rip), %rsi      # 0x541a
callq 0x2070
testl %eax, %eax
sete %r12b
jmp 0x3efe
movl $0x33, %edx
movq %rbx, %rdi
leaq 0x148c(%rip), %rsi      # 0x5360
callq 0x21f0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4053
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x4053
xorl %r12d, %r12d
cmpq $0x5, %r14
jb 0x3f26
movq -0x190(%rbp), %rdi
leaq -0x180(%rbp), %rax
cmpq %rax, %rdi
je 0x3f26
movq -0x180(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r12b, %r12b
leaq -0x88(%rbp), %r12
jne 0x4018
movq -0x60(%rbp), %r14
cmpq $0x5, %r14
jb 0x3f70
movl $0x5, %ecx
leaq -0x170(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x14bd(%rip), %rsi      # 0x5420
callq 0x2070
testl %eax, %eax
sete %r12b
jmp 0x3f73
xorl %r12d, %r12d
cmpq $0x5, %r14
jb 0x3f9b
movq -0x170(%rbp), %rdi
leaq -0x160(%rbp), %rax
cmpq %rax, %rdi
je 0x3f9b
movq -0x160(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r12b, %r12b
leaq -0x88(%rbp), %r12
jne 0x4018
movq -0x60(%rbp), %r14
cmpq $0x7, %r14
jb 0x3fe1
movl $0x7, %ecx
leaq -0x150(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x1452(%rip), %rsi      # 0x5426
callq 0x2070
testl %eax, %eax
sete %r12b
jmp 0x3fe4
xorl %r12d, %r12d
cmpq $0x7, %r14
jb 0x400c
movq -0x150(%rbp), %rdi
leaq -0x140(%rbp), %rax
cmpq %rax, %rdi
je 0x400c
movq -0x140(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r12b, %r12b
leaq -0x88(%rbp), %r12
je 0x4053
movl $0x1b, %edx
movq %rbx, %rdi
leaq 0x13d7(%rip), %rsi      # 0x53fe
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 %r15, %rdi
movq %r13, %rsi
callq 0x2070
testl %eax, %eax
jne 0x3bdc
movl $0xa0, %edi
callq 0x21a0
movq %rax, %r14
leaq -0xc0(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x110(%rbp), %rsi
movq -0x108(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x2580
leaq -0xa0(%rbp), %r12
movq %r12, -0x10(%r12)
movq 0x40f2(%rip), %rsi      # 0x81a0
movq 0x40f3(%rip), %rdx      # 0x81a8
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x2580
leaq -0xd0(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
movq %r14, %rdi
movl $0x2000, %ecx           # imm = 0x2000
callq 0x26b4
movq %r14, 0x4102(%rip)      # 0x81e8
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0x4101
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
je 0x411c
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq 0x40c5(%rip), %rdi      # 0x81e8
callq 0x2dc6
movq 0x40b9(%rip), %rdi      # 0x81e8
callq 0x2a08
movq 0x40ad(%rip), %rdi      # 0x81e8
callq 0x2dc6
leaq -0xd66(%rip), %rdx      # 0x33e1
leaq -0x1b8(%rbp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x22b0
testl %eax, %eax
je 0x418b
movl $0x27, %edx
leaq 0x12c7(%rip), %rsi      # 0x542e
jmp 0x41b6
movl $0x1, %ebx
movq 0x3e5b(%rip), %rdi      # 0x7fd0
leaq 0x125e(%rip), %rsi      # 0x53da
movl $0xb, %edx
callq 0x21f0
jmp 0x420e
leaq -0xf5f(%rip), %rdx      # 0x3233
leaq -0x1c0(%rbp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x22b0
testl %eax, %eax
je 0x4241
movl $0x2a, %edx
leaq 0x12a0(%rip), %rsi      # 0x5456
movq 0x3e13(%rip), %rbx      # 0x7fd0
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x3ded(%rip), %rdi      # 0x7fd0
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2100
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x420e
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x422d
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x21c0
movl %ebx, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3d88(%rip), %rbx      # 0x7fd0
leaq 0x1232(%rip), %rsi      # 0x5481
movl $0xf, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x3d56(%rip), %rdi      # 0x7fd0
callq 0x2030
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x2100
jmp 0x41f5
movq 0x3d3b(%rip), %rdi      # 0x7fd0
leaq 0x1153(%rip), %rsi      # 0x53ef
movl $0x8, %edx
callq 0x21f0
movq 0x3d23(%rip), %rdi      # 0x7fd0
callq 0x20d0
xorl %edi, %edi
callq 0x2220
jmp 0x434c
jmp 0x434c
jmp 0x434c
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0x42eb
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x42eb
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
je 0x430b
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x430b
movq %rax, %rbx
movl $0xa0, %esi
movq %r14, %rdi
jmp 0x4343
jmp 0x432c
jmp 0x434c
jmp 0x434c
jmp 0x431f
jmp 0x434c
movq %rax, %rbx
jmp 0x4368
jmp 0x434c
jmp 0x434c
jmp 0x432c
jmp 0x434c
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x434f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x434f
jmp 0x434c
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4368
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4387
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2280