// File: /workspace/github_cpp_makefile_star2_O3/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), %r14
leaq 0x138(%rdi), %rax
movq %rax, -0x78(%rbp)
leaq 0x158(%rdi), %rax
movq %rax, -0x70(%rbp)
movq %r14, %rdi
leaq -0x80(%rbp), %rsi
callq 0x6926
movq -0x80(%rbp), %r12
movl 0x8(%r12), %eax
cmpq $0x5, %rax
ja 0x45eb
leaq 0x49f7(%rip), %rcx      # 0x9004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x78(%rbp), %rdi
leaq 0x4a93(%rip), %rsi      # 0x90b4
callq 0x3090
testl %eax, %eax
jne 0x4642
movq -0x70(%rbp), %rdi
leaq 0x4a7f(%rip), %rsi      # 0x90b4
callq 0x3090
testl %eax, %eax
je 0x4bdf
movq %rbx, %rdi
movq %r12, %rsi
callq 0x501a
testb %al, %al
je 0x4bbd
leaq 0x8b54(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dba
movl $0x26, %edx
movq 0x8963(%rip), %r15      # 0xcfd8
movq %r15, %rdi
leaq 0x4a37(%rip), %rsi      # 0x90b6
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x742a
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
movl $0x7, %edx
movq %rax, %rdi
leaq 0x4a25(%rip), %rsi      # 0x90e9
callq 0x3200
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
jmp 0x4c85
leaq 0x8ab4(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dba
movl $0x28, %edx
movq 0x88c3(%rip), %r15      # 0xcfd8
movq %r15, %rdi
leaq 0x4a02(%rip), %rsi      # 0x9121
callq 0x3200
movq 0x138(%rbx), %rsi
movq 0x140(%rbx), %rdx
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x49cc(%rip), %rsi      # 0x9118
callq 0x3200
movl $0x6, %edx
movq %r15, %rdi
leaq 0x49ba(%rip), %rsi      # 0x911a
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x742a
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x47cf
callq 0x31c0
leaq 0x89da(%rip), %rdi      # 0xd1b0
callq 0x3170
leaq -0x130(%rbp), %r15
movq %r15, -0x140(%rbp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq -0x140(%rbp), %r13
movq %r13, %rdi
callq 0x742a
movq %rbx, %rdi
movq %r13, %rsi
callq 0x53c0
movq -0x140(%rbp), %rdi
jmp 0x493e
leaq 0x898d(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dba
movl $0x28, %edx
movq 0x879c(%rip), %r15      # 0xcfd8
movq %r15, %rdi
leaq 0x4904(%rip), %rsi      # 0x914a
callq 0x3200
movq 0x138(%rbx), %rsi
movq 0x140(%rbx), %rdx
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x48a5(%rip), %rsi      # 0x9118
callq 0x3200
movl $0x6, %edx
movq %r15, %rdi
leaq 0x4893(%rip), %rsi      # 0x911a
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x742a
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x48f6
callq 0x31c0
leaq 0x88b3(%rip), %rdi      # 0xd1b0
callq 0x3170
leaq -0x110(%rbp), %r15
movq %r15, -0x120(%rbp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq -0x120(%rbp), %r13
movq %r13, %rdi
callq 0x742a
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5456
movq -0x120(%rbp), %rdi
cmpq %r15, %rdi
jne 0x4bb3
jmp 0x4cc3
leaq 0x885d(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dba
movl $0x26, %edx
movq 0x866c(%rip), %r15      # 0xcfd8
movq %r15, %rdi
leaq 0x477b(%rip), %rsi      # 0x90f1
callq 0x3200
movq 0x138(%rbx), %rsi
movq 0x140(%rbx), %rdx
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4775(%rip), %rsi      # 0x9118
callq 0x3200
movl $0x6, %edx
movq %r15, %rdi
leaq 0x4763(%rip), %rsi      # 0x911a
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x742a
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
leaq 0x474b(%rip), %rsi      # 0x9147
callq 0x3200
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq 0x30(%r12), %rsi
movq 0x38(%r12), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x742a
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4a6b
callq 0x31c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4a7d
callq 0x31c0
leaq 0x872c(%rip), %rdi      # 0xd1b0
callq 0x3170
cmpb $0x1, 0x50(%r12)
jne 0x4b22
leaq -0xf0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %r15
movq %r15, %rdi
callq 0x742a
leaq -0xd0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq 0x30(%r12), %rsi
movq 0x38(%r12), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %r13
movq %r13, %rdi
callq 0x742a
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x510e
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x4b0f
callq 0x31c0
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
jmp 0x4baa
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %r15
movq %r15, %rdi
callq 0x742a
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq 0x30(%r12), %rsi
movq 0x38(%r12), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %r13
movq %r13, %rdi
callq 0x742a
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x530a
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x4b9c
callq 0x31c0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x4cc3
callq 0x31c0
jmp 0x4cc3
movq 0x30(%rbx), %rdi
leaq 0x7fb0(%rip), %rax      # 0xcb78
movq %rax, -0x48(%rbp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, -0x40(%rbp)
jmp 0x4cba
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4f86
leaq 0x85bf(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dba
movl $0x26, %edx
movq 0x83ce(%rip), %r15      # 0xcfd8
movq %r15, %rdi
leaq 0x44a2(%rip), %rsi      # 0x90b6
callq 0x3200
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x742a
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
movl $0xb, %edx
movq %rax, %rdi
leaq 0x4484(%rip), %rsi      # 0x90dd
callq 0x3200
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4c97
callq 0x31c0
leaq 0x8512(%rip), %rdi      # 0xd1b0
callq 0x3170
movq 0x30(%rbx), %rdi
leaq 0x7eca(%rip), %rax      # 0xcb78
movq %rax, -0x48(%rbp)
movq $0x1, -0x40(%rbp)
movq (%rdi), %rax
leaq -0x48(%rbp), %rsi
callq *(%rax)
movq (%r12), %rax
movq %r12, %rdi
callq *0x10(%rax)
jmp 0x45eb
leaq 0x84d7(%rip), %rdi      # 0xd1b0
callq 0x3270
testl %eax, %eax
jne 0x4dba
movq 0x82eb(%rip), %r14      # 0xcfd8
leaq 0x447f(%rip), %rsi      # 0x9173
movl $0x29, %edx
movq %r14, %rdi
callq 0x3200
movq 0x138(%rbx), %rsi
movq 0x140(%rbx), %rdx
movq %r14, %rdi
callq 0x3200
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3150
leaq 0x8468(%rip), %rdi      # 0xd1b0
callq 0x3170
movq (%r12), %rax
movq %r12, %rdi
callq *0x10(%rax)
movq %rbx, %rdi
callq 0x553c
leaq 0x85c(%rip), %rax       # 0x55c2
leaq -0x48(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq 0x20(%rbx), %rdx
leaq -0x148(%rbp), %rcx
movq %rbx, (%rcx)
addq $0x118, %rbx            # imm = 0x118
leaq -0x68(%rbp), %r14
movq %r14, %rdi
movq %rbx, %r8
callq 0x69f6
movq %r14, %rdi
callq 0x32d0
cmpq $0x0, -0x68(%rbp)
jne 0x4dd0
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 0x4dd0
movq %rax, %rbx
jmp 0x4e88
callq 0x3080
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x4e25
callq 0x31c0
jmp 0x4e25
movq %rax, %rbx
jmp 0x4e12
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x4e12
callq 0x31c0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
jmp 0x4e7e
movq %rax, %rbx
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
jmp 0x4e7e
jmp 0x4e73
movq %rax, %rbx
movq -0x140(%rbp), %rdi
jmp 0x4e4d
movq %rax, %rbx
movq -0x120(%rbp), %rdi
cmpq %r15, %rdi
jne 0x4e83
jmp 0x4e88
jmp 0x4e73
jmp 0x4e73
jmp 0x4e73
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4e76
callq 0x31c0
jmp 0x4e76
jmp 0x4e73
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4e88
callq 0x31c0
movq %rbx, %rdi
callq 0x32e0