// File: /workspace/github_cpp_makefile_star2_O1/greenpau[P]mnpa/main.cpp
// Function: mgr_thread(MulticastSender*, int, MulticastReceiver*, int)
void mgr_thread(struct MulticastSender senders[], int cnts, struct MulticastReceiver receivers[], int cntr) {
    volatile bool finished = false;
    std::vector <std::thread> thrs;

    if (cnts > 0) {
        for( int i = 0; i < cnts; i++ ) {
            std::thread thr = std::thread(sender_thread, senders[i]);
            auto thrid = std::hash<std::thread::id>()(thr.get_id());
            thrs.push_back(std::move(thr));
            assert(!thr.joinable());
            mu_thrids.lock();
            thrids[thrid] = 2;
            //logit(INFO,"started sender thread #" + std::to_string(thrid) + " in stage #" + std::to_string(thrids[thrid]));
            mu_thrids.unlock();
        }
    }

    if (cntr > 0) {
        for( int i = 0; i < cntr; i++ ) {
            std::thread thr = std::thread(receiver_thread, receivers[i]);
            auto thrid = std::hash<std::thread::id>()(thr.get_id());
            thrs.push_back(std::move(thr));
            assert(!thr.joinable());
            mu_thrids.lock();
            thrids[thrid] = 2;
            //logit(INFO,"started sender thread #" + std::to_string(thrid) + " in stage #" + std::to_string(thrids[thrid]));
            mu_thrids.unlock();
        }
    }

    do {
        finished = true;
        std::for_each(thrs.begin(), thrs.end(), [&finished](std::thread& thr) {
            auto thrid = std::hash<std::thread::id>()(thr.get_id());
            mu_thrids.lock();
            unsigned int thr_status = thrids[thrid];
            mu_thrids.unlock();
            //logit(INFO, "thread #" + std::to_string(thrid) + " is in stage #" + std::to_string(thr_status));
            if (thr_status != 1) {
                finished = false;
            } else {
                if (thr.joinable() && thr_status == 1) {
                    thr.join();
                }
            }
        });
        sleep(1);
    } while (finished == false);

    if (DAEMONIZE == false) {
        return;
    } else {
        exit(0);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, 0x2c(%rsp)
movq %rdx, %rbx
movb $0x0, 0xf(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testl %esi, %esi
jle 0x20ca3
movq %rdi, %r14
movl %esi, %r13d
leaq 0x10(%rsp), %r12
leaq 0x10ae36(%rip), %r15    # 0x12ba40
leaq 0x20(%rsp), %rbp
movq %r12, %rdi
leaq -0x30f6(%rip), %rsi     # 0x1db23
movq %r14, %rdx
callq 0x26b92
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x8, %esi
movl $0xc70f6907, %edx       # imm = 0xC70F6907
leaq 0x18(%rsp), %rdi
callq 0x36750
movq %rax, 0x20(%rsp)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x34b66
cmpq $0x0, 0x10(%rsp)
jne 0x20e28
movq %r15, %rdi
callq 0x167f0
testl %eax, %eax
jne 0x20e21
leaq 0x10ae24(%rip), %rdi    # 0x12ba98
movq %rbp, %rsi
callq 0x26b2c
movl $0x2, (%rax)
movq %r15, %rdi
callq 0x16860
cmpq $0x0, 0x10(%rsp)
jne 0x20e8f
addq $0x60, %r14
decq %r13
jne 0x20c0f
movl 0x2c(%rsp), %eax
testl %eax, %eax
jle 0x20d5a
movl %eax, %r13d
leaq 0x10(%rsp), %r15
leaq 0x10ad82(%rip), %rbp    # 0x12ba40
leaq 0x10add3(%rip), %r14    # 0x12ba98
leaq 0x20(%rsp), %r12
movq %r15, %rdi
leaq -0x5734(%rip), %rsi     # 0x1b5a0
movq %rbx, %rdx
callq 0x26c2c
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x8, %esi
movl $0xc70f6907, %edx       # imm = 0xC70F6907
leaq 0x18(%rsp), %rdi
callq 0x36750
movq %rax, 0x20(%rsp)
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x34b66
cmpq $0x0, 0x10(%rsp)
jne 0x20e4e
movq %rbp, %rdi
callq 0x167f0
testl %eax, %eax
jne 0x20e47
movq %r14, %rdi
movq %r12, %rsi
callq 0x26b2c
movl $0x2, (%rax)
movq %rbp, %rdi
callq 0x16860
cmpq $0x0, 0x10(%rsp)
jne 0x20e8f
addq $0x20, %rbx
decq %r13
jne 0x20cca
leaq 0x10(%rsp), %rbx
leaq 0x10acda(%rip), %r14    # 0x12ba40
leaq 0x10ad2b(%rip), %r15    # 0x12ba98
movb $0x1, 0xf(%rsp)
movq 0x30(%rsp), %r12
movq 0x38(%rsp), %r13
cmpq %r13, %r12
je 0x20de3
movq (%r12), %rax
movq %rax, 0x10(%rsp)
movl $0x8, %esi
movl $0xc70f6907, %edx       # imm = 0xC70F6907
movq %rbx, %rdi
callq 0x36750
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0x167f0
testl %eax, %eax
jne 0x20e1a
movq %r15, %rdi
movq %rbx, %rsi
callq 0x26b2c
movl (%rax), %ebp
movq %r14, %rdi
callq 0x16860
cmpl $0x1, %ebp
jne 0x20dd8
cmpq $0x0, (%r12)
je 0x20ddd
movq %r12, %rdi
callq 0xb5000
jmp 0x20ddd
movb $0x0, 0xf(%rsp)
addq $0x8, %r12
jmp 0x20d7c
movl $0x1, %edi
callq 0x16440
cmpb $0x0, 0xf(%rsp)
je 0x20d6d
cmpb $0x0, 0x10ac91(%rip)    # 0x12ba90
jne 0x20e6d
leaq 0x30(%rsp), %rdi
callq 0x26cc6
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x187d1
movl %eax, %edi
callq 0x187d1
leaq 0xc40fa(%rip), %rdi     # 0xe4f29
leaq 0xc4103(%rip), %rsi     # 0xe4f39
leaq 0xc4105(%rip), %rcx     # 0xe4f42
movl $0x20e, %edx            # imm = 0x20E
callq 0x161b0
movl %eax, %edi
callq 0x187d1
leaq 0xc40d4(%rip), %rdi     # 0xe4f29
leaq 0xc40dd(%rip), %rsi     # 0xe4f39
leaq 0xc40df(%rip), %rcx     # 0xe4f42
movl $0x21b, %edx            # imm = 0x21B
callq 0x161b0
xorl %edi, %edi
callq 0x161a0
jmp 0x20e9e
jmp 0x20e96
jmp 0x20e84
jmp 0x20e9e
jmp 0x20e96
jmp 0x20e84
jmp 0x20e9e
jmp 0x20e84
movq %rax, %rbx
cmpq $0x0, 0x10(%rsp)
je 0x20ea1
callq 0x363a0
jmp 0x20e9e
movq %rax, %rdi
callq 0x26e39
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x26cc6
movq %rbx, %rdi
callq 0xe0cd0