// File: /workspace/github_cpp_makefile_star2_O3/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 $0xf8, %rsp
movq %rsi, %rbx
movl %edi, %r14d
leaq -0xb2e(%rip), %rsi      # 0x2ee0
movl $0x2, %edi
callq 0x2210
cmpl $0x1, %r14d
jg 0x3a40
movq 0x45ab(%rip), %rdi      # 0x7fd0
leaq 0x1995(%rip), %rsi      # 0x53c1
movl $0x18, %edx
callq 0x21f0
movl $0x1, %ebx
jmp 0x415b
movq 0x8(%rbx), %rsi
leaq -0xf0(%rbp), %rbx
leaq -0x70(%rbp), %rdx
movq %rbx, %rdi
callq 0x2e94
leaq -0x100(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0x110(%rbp), %rdi
callq 0x2580
movq -0x110(%rbp), %rsi
leaq -0x6c(%rbp), %rdx
movl $0x2, %edi
callq 0x22d0
movl %eax, %ebx
movq -0x110(%rbp), %rdi
cmpq %r14, %rdi
je 0x3aaa
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x21c0
testl %ebx, %ebx
je 0x4097
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x17c3(%rip), %rdx      # 0x5284
leaq -0x70(%rbp), %rdi
movq %rdx, %rsi
callq 0x261e
leaq -0x48(%rbp), %rdi
callq 0x3071
leaq 0x46c3(%rip), %rdi      # 0x81a0
leaq -0x48(%rbp), %rbx
movq %rbx, %rsi
callq 0x2230
movq (%rbx), %rdi
leaq -0x38(%rbp), %r14
cmpq %r14, %rdi
je 0x3b01
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0x48(%rbp), %rdi
movq %r14, (%rdi)
leaq -0x50(%rbp), %rsi
movq $0x152, (%rsi)          # imm = 0x152
xorl %edx, %edx
callq 0x22a0
movq %rax, %rbx
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %r15
movq %r15, -0x38(%rbp)
leaq 0x1602(%rip), %rsi      # 0x5132
movl $0x152, %edx            # imm = 0x152
movq %rax, %rdi
callq 0x2140
movq %r15, -0x40(%rbp)
movb $0x0, (%rbx,%r15)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x447b(%rip), %rdi      # 0x7fd0
callq 0x21f0
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x3b6f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq 0x1870(%rip), %rsi      # 0x53e6
leaq -0x70(%rbp), %rdi
callq 0x2070
testl %eax, %eax
je 0x3f9a
movq 0x4452(%rip), %r13      # 0x7fe0
leaq -0x70(%rbp), %r15
leaq 0x17b7(%rip), %rbx      # 0x5350
movq %r13, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x22c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x41bc
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2070
testl %eax, %eax
je 0x3dde
movq %r15, %rdi
leaq 0x1772(%rip), %rsi      # 0x534a
callq 0x2070
testl %eax, %eax
je 0x41e0
movq %r15, %rdi
leaq 0x1809(%rip), %rsi      # 0x53f8
callq 0x2070
testl %eax, %eax
je 0x3d8f
movq -0x68(%rbp), %rax
cmpq $0x9, %rax
jb 0x3c50
movl $0x9, %ecx
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x1730(%rip), %rsi      # 0x5356
callq 0x2070
movl %eax, %r12d
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x3c43
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testl %r12d, %r12d
je 0x3e80
movq -0x68(%rbp), %rax
cmpq $0x5, %rax
jb 0x3e64
movl $0x5, %ecx
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x1730(%rip), %rsi      # 0x53aa
callq 0x2070
movl %eax, %r12d
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x3c97
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testl %r12d, %r12d
je 0x3d8f
cmpq $0x5, -0x68(%rbp)
jb 0x3e64
movl $0x5, %ecx
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x174f(%rip), %rsi      # 0x541a
callq 0x2070
movl %eax, %r12d
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x3ce8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testl %r12d, %r12d
je 0x3d8f
cmpq $0x5, -0x68(%rbp)
jb 0x3e64
movl $0x5, %ecx
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x1704(%rip), %rsi      # 0x5420
callq 0x2070
movl %eax, %r12d
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x3d39
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testl %r12d, %r12d
je 0x3d8f
cmpq $0x7, -0x68(%rbp)
jb 0x3e64
movl $0x7, %ecx
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x21d0
movq %r12, %rdi
leaq 0x16bd(%rip), %rsi      # 0x5426
callq 0x2070
movl %eax, %r12d
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x3d86
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
testl %r12d, %r12d
jne 0x3e64
movl $0x1b, %edx
movq 0x4235(%rip), %rdi      # 0x7fd0
leaq 0x165c(%rip), %rsi      # 0x53fe
callq 0x21f0
movq 0x4222(%rip), %rcx      # 0x7fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x4204(%rip), %rdi      # 0x7fd0
callq 0x2030
movq %rax, %rdi
callq 0x2100
jmp 0x3e64
movq %rbx, %r15
movq %r13, %rbx
movq %r14, %r13
movq %r14, -0x48(%rbp)
movq $0x152, -0x50(%rbp)     # imm = 0x152
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
xorl %edx, %edx
callq 0x22a0
movq %rax, %r12
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %r14
movq %r14, -0x38(%rbp)
movl $0x152, %edx            # imm = 0x152
movq %rax, %rdi
leaq 0x1312(%rip), %rsi      # 0x5132
callq 0x2140
movq %r14, -0x40(%rbp)
movb $0x0, (%r12,%r14)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x4193(%rip), %rdi      # 0x7fd0
callq 0x21f0
movq -0x48(%rbp), %rdi
movq %r13, %r14
cmpq %r13, %rdi
je 0x3e5a
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %r13
movq %r15, %rbx
leaq -0x70(%rbp), %r15
movq %r15, %rdi
leaq 0x1578(%rip), %rsi      # 0x53e6
callq 0x2070
testl %eax, %eax
jne 0x3b99
jmp 0x3f9a
movq -0x68(%rbp), %rcx
movl $0xa, %edx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x21d0
leaq -0xc0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq 0x42f6(%rip), %rsi      # 0x81a0
movq 0x42f7(%rip), %rdx      # 0x81a8
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x2580
leaq -0xd0(%rbp), %rdi
callq 0x2fff
movl %eax, %r12d
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x3ef1
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r12b, %r12b
je 0x3f64
leaq 0x42a3(%rip), %rdi      # 0x81a0
leaq -0x48(%rbp), %rsi
callq 0x20e0
movl $0x15, %edx
movq 0x40be(%rip), %rdi      # 0x7fd0
leaq 0x147b(%rip), %rsi      # 0x5394
callq 0x21f0
movq 0x427b(%rip), %rsi      # 0x81a0
movq 0x427c(%rip), %rdx      # 0x81a8
movq 0x409d(%rip), %rdi      # 0x7fd0
callq 0x21f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
jmp 0x3f7c
movl $0x33, %edx
movq 0x4060(%rip), %rdi      # 0x7fd0
leaq 0x13e9(%rip), %rsi      # 0x5360
callq 0x21f0
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x3e64
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x3e64
movl $0xa0, %edi
callq 0x21a0
movq %rax, %r14
leaq -0xa0(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x2580
leaq -0x80(%rbp), %r12
movq %r12, -0x10(%r12)
movq 0x41c1(%rip), %rsi      # 0x81a0
movq 0x41c2(%rip), %rdx      # 0x81a8
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x2580
leaq -0xb0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movq %r14, %rdi
movl $0x2000, %ecx           # imm = 0x2000
callq 0x26bc
movq %r14, 0x41d1(%rip)      # 0x81e8
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x402f
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x404a
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq 0x4197(%rip), %rdi      # 0x81e8
callq 0x2dce
movq 0x418b(%rip), %rdi      # 0x81e8
callq 0x2a10
movq 0x417f(%rip), %rdi      # 0x81e8
callq 0x2dce
leaq -0xc92(%rip), %rdx      # 0x33e3
leaq -0x118(%rbp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x22b0
testl %eax, %eax
je 0x40b9
movl $0x27, %edx
leaq 0x1399(%rip), %rsi      # 0x542e
jmp 0x40e4
movl $0x1, %ebx
movq 0x3f2d(%rip), %rdi      # 0x7fd0
leaq 0x1330(%rip), %rsi      # 0x53da
movl $0xb, %edx
callq 0x21f0
jmp 0x413c
leaq -0xe90(%rip), %rdx      # 0x3230
leaq -0x120(%rbp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x22b0
testl %eax, %eax
je 0x416f
movl $0x2a, %edx
leaq 0x1372(%rip), %rsi      # 0x5456
movq 0x3ee5(%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 0x3ebf(%rip), %rdi      # 0x7fd0
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2100
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x413c
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0xe0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x415b
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x21c0
movl %ebx, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3e5a(%rip), %rbx      # 0x7fd0
leaq 0x1304(%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 0x3e28(%rip), %rdi      # 0x7fd0
callq 0x2030
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x2100
jmp 0x4123
movq 0x3e0d(%rip), %rdi      # 0x7fd0
leaq 0x1225(%rip), %rsi      # 0x53ef
movl $0x8, %edx
callq 0x21f0
movq 0x3df5(%rip), %rdi      # 0x7fd0
callq 0x20d0
xorl %edi, %edi
callq 0x2220
jmp 0x427f
jmp 0x427f
jmp 0x427f
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x4216
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x4216
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x4236
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x4236
movq %rax, %rbx
movl $0xa0, %esi
movq %r14, %rdi
jmp 0x4274
jmp 0x4253
jmp 0x427f
jmp 0x427f
jmp 0x424a
jmp 0x427f
movq %rax, %rbx
jmp 0x429b
jmp 0x427f
jmp 0x427f
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
jne 0x426d
jmp 0x4282
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x4282
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x4282
jmp 0x427f
jmp 0x427f
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x429b
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0xe0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x42ba
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2280