// File: andresziemecki[P]MQTT/mqtt.cpp
// Function: SimPublisher::runSim()
void SimPublisher::runSim(){
    // Registrar el cliente
    brops = broker.registerClient(this);
    // Esperar un rato a que empiecen las conecciones
    std::this_thread::sleep_for (std::chrono::seconds(rand() % 3));
    
    // Mandar el connect
    brops->sendMsg(ConnectMsg(usuario_pass.username, usuario_pass.password));
    // esperar por CONNACK sin errores
    std::unique_lock<std::mutex> lock(mmutex);
    while(!connack_value){ 
        if(cond_var.wait_for(lock, std::chrono::seconds(5), [&](){return ready;})){
            break;
        }
        else{
            cout << "Loggin Error, no response of the broker" << endl;
            break;
        }
    }

    if (connack_value)
        ;
    else{
        mutex_cout.lock();
        cout << "Connack not recive -> Error" << endl; // DISCONNECT
        mutex_cout.unlock();
        return;
    }
    // Si el cliente es subscriptor que se subscriba a algo, sino que publique
    if(!Par_del_client.subscriptor)
        Publish();
    else
        Subscribirse(Par_del_client.topic_name);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x110(%rbp)
movq 0x8(%rsi), %rdi
callq 0x6200
movq %rax, %rcx
movq -0x110(%rbp), %rax
movq %rcx, 0xf8(%rax)
callq 0x3070
movslq %eax, %rcx
imulq $0x55555556, %rcx, %rdx # imm = 0x55555556
movq %rdx, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
movl %eax, -0x14(%rbp)
leaq -0x10(%rbp), %rdi
movq %rdi, -0x120(%rbp)
leaq -0x14(%rbp), %rsi
callq 0x71d0
movq -0x120(%rbp), %rdi
callq 0x7120
movq -0x110(%rbp), %rsi
movq 0xf8(%rsi), %rax
movq %rax, -0x118(%rbp)
addq $0x10, %rsi
leaq -0x88(%rbp), %rdi
callq 0x30e0
movq -0x110(%rbp), %rsi
addq $0x30, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x30e0
jmp 0x65d8
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x84a0
jmp 0x65f1
movq -0x118(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq -0x68(%rbp), %rsi
callq *%rax
jmp 0x6607
leaq -0x68(%rbp), %rdi
callq 0x8550
leaq -0xa8(%rbp), %rdi
callq 0x3160
leaq -0x88(%rbp), %rdi
callq 0x3160
movq -0x110(%rbp), %rsi
addq $0x98, %rsi
leaq -0xc8(%rbp), %rdi
callq 0x85a0
movq -0x110(%rbp), %rax
movb 0x90(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x665a
jmp 0x677f
movq -0x110(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x128(%rbp)
movl $0x5, -0xd4(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd4(%rbp), %rsi
callq 0x71d0
jmp 0x668d
movq -0x128(%rbp), %rdi
movq -0x110(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rcx
leaq -0xc8(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x68a0
movb %al, -0x129(%rbp)
jmp 0x66c4
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x66d0
jmp 0x674c
jmp 0x677f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x6724
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x6718
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x8550
leaq -0xa8(%rbp), %rdi
callq 0x3160
leaq -0x88(%rbp), %rdi
callq 0x3160
jmp 0x6891
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x6885
movq 0x15885(%rip), %rdi     # 0x1bfd8
leaq 0xba47(%rip), %rsi      # 0x121a1
callq 0x3200
movq %rax, -0x138(%rbp)
jmp 0x6768
movq -0x138(%rbp), %rdi
movq 0x1584a(%rip), %rsi     # 0x1bfc0
callq 0x3220
jmp 0x677d
jmp 0x677f
movq -0x110(%rbp), %rax
testb $0x1, 0x90(%rax)
je 0x6791
jmp 0x67ed
leaq 0x15a50(%rip), %rdi     # 0x1c1e8
callq 0x76c0
jmp 0x679f
movq 0x15832(%rip), %rdi     # 0x1bfd8
leaq 0xba1c(%rip), %rsi      # 0x121c9
callq 0x3200
movq %rax, -0x140(%rbp)
jmp 0x67bb
movq -0x140(%rbp), %rdi
movq 0x157f7(%rip), %rsi     # 0x1bfc0
callq 0x3220
jmp 0x67d0
leaq 0x15a11(%rip), %rdi     # 0x1c1e8
callq 0x7720
jmp 0x67de
movl $0x1, -0xe4(%rbp)
jmp 0x6870
movq -0x110(%rbp), %rax
testb $0x1, 0x78(%rax)
jne 0x680a
movq -0x110(%rbp), %rdi
callq 0x6920
jmp 0x6808
jmp 0x6866
movq -0x110(%rbp), %rsi
addq $0x58, %rsi
leaq -0x108(%rbp), %rdi
callq 0x30e0
jmp 0x6823
movq -0x110(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x6b30
jmp 0x6838
leaq -0x108(%rbp), %rdi
callq 0x3160
jmp 0x6866
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x3160
jmp 0x6885
movl $0x0, -0xe4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x85e0
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
leaq -0xc8(%rbp), %rdi
callq 0x85e0
movq -0xb0(%rbp), %rdi
callq 0x3340
nopl (%rax)