// File: /workspace/github_cpp_makefile_star2_O1/andresziemecki[P]MQTT/mqtt.cpp
// Function: Client::startClient()
void Client::startClient(void){
    Message *m;
    bool disconnect = false;
    do{ 
        recvQueue.pop(&m); 
        switch (m->getType()){
            case Message::Type::CONNECT: {
                ConnectMsg *M = (ConnectMsg *)m;
                if (u_p.username == "$" && u_p.password=="$"){
                    Register_User(M);
                    mutex_cout.lock();
                    cout << "From SimClient\tMessage: CONNECT\tfrom: "<< M->getUsername() << " Registered"<< endl;
                    mutex_cout.unlock();
                    cif->recvMsg(ConnAckMsg(ConnAckMsg::Status::CONNECTION_OK));
                    }
                else if (check_username(M)){
                    mutex_cout.lock();
                    cout << "From SimClient\tMessage: CONNECT\tfrom: "<< M->getUsername() << "Logined" << endl;
                    mutex_cout.unlock();
                    cif->recvMsg(ConnAckMsg(ConnAckMsg::Status::CONNECTION_OK));}
                else
                    cif->recvMsg(ConnAckMsg(ConnAckMsg::Status::LOGIN_ERROR));
                delete(M);
                break;}
            case Message::Type::CONNACK: 
                break; // No hay connack hacia el Client, por eso no hay nada
            case Message::Type::PUBLISH:{
                PublishMsg *M = (PublishMsg *)m;
                mutex_cout.lock();
                cout << "From SimClient\tMessage: PUBLISH\tfrom: "<< u_p.username<<"\t" << "Topic " << M->getTopic() << ": " << M->getValue() << endl;
                mutex_cout.unlock();
                if (M->getRetain())
                    insert_retainedTopic (M->getTopic(), M->getValue());
                else
                    warn_everybody_thisTopic(M->getTopic(), M->getValue());
                delete(M);
                break;} 
            case Message::Type::SUBSCRIBE: {
                SubscribeMsg *M = (SubscribeMsg *)m;
                mutex_cout.lock();
                cout << "From SimClient\tMessage: SUBSCRIBE\tfrom: "<< u_p.username<<"\t" << "Topic "<< M->getTopic()<< endl;
                mutex_cout.unlock();
                insert_subscriber(M->getTopic());
                delete(M);
                break; }
            case Message::Type::UNSUBSCRIBE:{
                    UnsubscribeMsg *M = (UnsubscribeMsg *)m;
                    mutex_cout.lock();
                    cout << "From SimClient\tMessage: UNSUCRIBE\tfrom: "<< u_p.username<<"\t" << "Topic "<< M->getTopic() << endl;
                    mutex_cout.unlock();
                    unsuscribe_topic(M->getTopic());
                    delete(M);
                break; }
            case Message::Type::DISCONNECT:{
                DisconnectMsg *M = (DisconnectMsg *)m;
                mutex_cout.lock();
                cout << "From SimClient\tMessage: DISCONNECT\tfrom: "<< u_p.username<<endl;
                mutex_cout.unlock();
                disconnect = true;
                delete(M);
                break;}
        }
    }while(!disconnect);
    unsuscribe_all_topics(); 
    std::thread thr (&Broker::ClientDestruction,B,this, Client_TopicName);
    thr.detach();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
leaq 0x38(%rdi), %rax
movq %rax, -0x80(%rbp)
leaq 0x138(%rdi), %rax
movq %rax, -0x78(%rbp)
leaq 0x158(%rdi), %rax
movq %rax, -0x70(%rbp)
xorl %r15d, %r15d
movq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x699c
movq -0x88(%rbp), %r13
movl 0x8(%r13), %eax
cmpq $0x5, %rax
ja 0x4d54
leaq 0x49e0(%rip), %rcx      # 0x9004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x78(%rbp), %rdi
leaq 0x4a7c(%rip), %rsi      # 0x90b4
callq 0x3090
testl %eax, %eax
jne 0x4659
movq -0x70(%rbp), %rdi
leaq 0x4a68(%rip), %rsi      # 0x90b4
callq 0x3090
testl %eax, %eax
je 0x4c62
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5022
testb %al, %al
je 0x4c40
leaq 0x8b3d(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dc1
movl $0x26, %edx
movq 0x894c(%rip), %r12      # 0xcfd8
movq %r12, %rdi
leaq 0x4a20(%rip), %rsi      # 0x90b6
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x74c0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x4a10(%rip), %rsi      # 0x90e9
callq 0x3200
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
jmp 0x4d07
leaq 0x8a9e(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dc1
movl $0x28, %edx
movq 0x88ad(%rip), %r12      # 0xcfd8
movq %r12, %rdi
leaq 0x49ec(%rip), %rsi      # 0x9121
callq 0x3200
movq 0x138(%rbx), %rsi
movq 0x140(%rbx), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x49b6(%rip), %rsi      # 0x9118
callq 0x3200
movl $0x6, %edx
movq %r12, %rdi
leaq 0x49a4(%rip), %rsi      # 0x911a
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x74c0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x47e3
callq 0x31c0
leaq 0x89c6(%rip), %rdi      # 0xd1b0
callq 0x3170
leaq -0x138(%rbp), %r12
movq %r12, -0x148(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x148(%rbp), %r14
movq %r14, %rdi
callq 0x74c0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x53ca
movq -0x148(%rbp), %rdi
jmp 0x4b19
leaq 0x897b(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dc1
movl $0x26, %edx
movq 0x878a(%rip), %r12      # 0xcfd8
movq %r12, %rdi
leaq 0x4899(%rip), %rsi      # 0x90f1
callq 0x3200
movq 0x138(%rbx), %rsi
movq 0x140(%rbx), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4893(%rip), %rsi      # 0x9118
callq 0x3200
movl $0x6, %edx
movq %r12, %rdi
leaq 0x4881(%rip), %rsi      # 0x911a
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x74c0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movl $0x2, %edx
movq %rax, %rdi
leaq 0x486b(%rip), %rsi      # 0x9147
callq 0x3200
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq 0x30(%r13), %rsi
movq 0x38(%r13), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x74c0
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4949
callq 0x31c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x495b
callq 0x31c0
leaq 0x884e(%rip), %rdi      # 0xd1b0
callq 0x3170
cmpb $0x1, 0x50(%r13)
jne 0x4ba9
leaq -0xf8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x108(%rbp), %r12
movq %r12, %rdi
callq 0x74c0
leaq -0xd8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq 0x30(%r13), %rsi
movq 0x38(%r13), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %r14
movq %r14, %rdi
callq 0x74c0
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5126
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x49e8
callq 0x31c0
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
jmp 0x4c2d
leaq 0x87ae(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dc1
movl $0x28, %edx
movq 0x85bd(%rip), %r12      # 0xcfd8
movq %r12, %rdi
leaq 0x4725(%rip), %rsi      # 0x914a
callq 0x3200
movq 0x138(%rbx), %rsi
movq 0x140(%rbx), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x46c6(%rip), %rsi      # 0x9118
callq 0x3200
movl $0x6, %edx
movq %r12, %rdi
leaq 0x46b4(%rip), %rsi      # 0x911a
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x74c0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4ad3
callq 0x31c0
leaq 0x86d6(%rip), %rdi      # 0xd1b0
callq 0x3170
leaq -0x118(%rbp), %r12
movq %r12, -0x128(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x128(%rbp), %r14
movq %r14, %rdi
callq 0x74c0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5460
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
jne 0x4c36
jmp 0x4d4a
leaq 0x8682(%rip), %r15      # 0xd1b0
movq %r15, %rdi
callq 0x3270
testl %eax, %eax
jne 0x4dc1
movl $0x29, %edx
movq 0x848e(%rip), %r12      # 0xcfd8
movq %r12, %rdi
leaq 0x461f(%rip), %rsi      # 0x9173
callq 0x3200
movq 0x138(%rbx), %rsi
movq 0x140(%rbx), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
movq %r15, %rdi
callq 0x3170
movb $0x1, %r15b
jmp 0x4d45
leaq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %r14
movq %r14, %rdi
callq 0x74c0
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0x30(%r13), %rsi
movq 0x38(%r13), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
callq 0x74c0
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x5314
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x4c1f
callq 0x31c0
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x4d4a
callq 0x31c0
jmp 0x4d4a
movq 0x30(%rbx), %rdi
leaq 0x7f2d(%rip), %rax      # 0xcb78
movq %rax, -0x48(%rbp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, -0x40(%rbp)
jmp 0x4d3c
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4f8e
leaq 0x853c(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dc1
movl $0x26, %edx
movq 0x834b(%rip), %r12      # 0xcfd8
movq %r12, %rdi
leaq 0x441f(%rip), %rsi      # 0x90b6
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x74c0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r12, %rdi
callq 0x3200
movq %rax, %r12
movl $0xb, %edx
movq %rax, %rdi
leaq 0x4403(%rip), %rsi      # 0x90dd
callq 0x3200
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4d19
callq 0x31c0
leaq 0x8490(%rip), %rdi      # 0xd1b0
callq 0x3170
movq 0x30(%rbx), %rdi
leaq 0x7e48(%rip), %rax      # 0xcb78
movq %rax, -0x48(%rbp)
movq $0x1, -0x40(%rbp)
movq (%rdi), %rax
leaq -0x48(%rbp), %rsi
callq *(%rax)
testq %r13, %r13
je 0x4d54
movq (%r13), %rax
movq %r13, %rdi
callq *0x10(%rax)
testb $0x1, %r15b
je 0x45f8
movq %rbx, %rdi
callq 0x5546
leaq 0x85f(%rip), %rax       # 0x55cc
leaq -0x48(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq 0x20(%rbx), %rdx
leaq -0x150(%rbp), %rcx
movq %rbx, (%rcx)
addq $0x118, %rbx            # imm = 0x118
leaq -0x68(%rbp), %r14
movq %r14, %rdi
movq %rbx, %r8
callq 0x6a6c
movq %r14, %rdi
callq 0x32d0
cmpq $0x0, -0x68(%rbp)
jne 0x4dd7
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x3140
cmpq $0x0, -0x68(%rbp)
jne 0x4dd7
movq %rax, %rbx
jmp 0x4e78
callq 0x3080
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x4dfc
callq 0x31c0
jmp 0x4dfc
movq %rax, %rbx
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
jmp 0x4e6e
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x4e2c
callq 0x31c0
jmp 0x4e2c
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
jmp 0x4e6e
jmp 0x4e63
jmp 0x4e63
movq %rax, %rbx
movq -0x148(%rbp), %rdi
jmp 0x4e56
movq %rax, %rbx
movq -0x128(%rbp), %rdi
cmpq %r12, %rdi
jne 0x4e73
jmp 0x4e78
jmp 0x4e63
jmp 0x4e63
jmp 0x4e63
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4e78
callq 0x31c0
movq %rbx, %rdi
callq 0x32e0
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4e66
callq 0x31c0
jmp 0x4e66
nop