// File: /workspace/github_cpp_makefile_star2_O2/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, 0xe(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
testl %esi, %esi
jle 0x1b1a6
movq %rdi, %r14
movl %esi, %ebp
leaq 0x10(%rsp), %r12
leaq 0x108924(%rip), %r13    # 0x123a40
leaq 0x18(%rsp), %r15
subq $0x1, %rbp
jb 0x1b1a6
movq %r12, %rdi
leaq -0xe4f(%rip), %rsi      # 0x1a2e2
movq %r14, %rdx
callq 0x1e116
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xf(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1df70
movq %rax, 0x18(%rsp)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x2a8f0
cmpq $0x0, 0x10(%rsp)
jne 0x1b2fd
movq %r13, %rdi
callq 0x1e02c
leaq 0x108919(%rip), %rdi    # 0x123a98
movq %r15, %rsi
callq 0x1e040
movl $0x2, (%rax)
movq %r13, %rdi
callq 0x15850
movq %r12, %rdi
callq 0x1e19a
addq $0x60, %r14
jmp 0x1b121
movl 0x2c(%rsp), %eax
testl %eax, %eax
jle 0x1b24a
movl %eax, %ebp
leaq 0x10(%rsp), %r15
leaq 0x108880(%rip), %r14    # 0x123a40
leaq 0x1088d1(%rip), %r12    # 0x123a98
leaq 0x18(%rsp), %r13
subq $0x1, %rbp
jb 0x1b24a
movq %r15, %rdi
leaq -0x1a86(%rip), %rsi     # 0x19756
movq %rbx, %rdx
callq 0x1e1a8
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xf(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1df70
movq %rax, 0x18(%rsp)
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x2a8f0
cmpq $0x0, 0x10(%rsp)
jne 0x1b31c
movq %r14, %rdi
callq 0x1e02c
movq %r12, %rdi
movq %r13, %rsi
callq 0x1e040
movl $0x2, (%rax)
movq %r14, %rdi
callq 0x15850
movq %r15, %rdi
callq 0x1e19a
addq $0x20, %rbx
jmp 0x1b1cc
leaq 0x10(%rsp), %r15
leaq 0x1087ea(%rip), %r12    # 0x123a40
leaq 0x10883b(%rip), %r13    # 0x123a98
movb $0x1, 0xe(%rsp)
movq 0x30(%rsp), %rbp
movq 0x38(%rsp), %rbx
cmpq %rbx, %rbp
je 0x1b2cc
movq (%rbp), %rax
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x1df70
movq %rax, 0x10(%rsp)
movq %r12, %rdi
callq 0x1e02c
movq %r13, %rdi
movq %r15, %rsi
callq 0x1e040
movl (%rax), %r14d
movq %r12, %rdi
callq 0x15850
cmpl $0x1, %r14d
jne 0x1b2c1
cmpq $0x0, (%rbp)
je 0x1b2c6
movq %rbp, %rdi
callq 0xaa3e0
jmp 0x1b2c6
movb $0x0, 0xe(%rsp)
addq $0x8, %rbp
jmp 0x1b26c
pushq $0x1
popq %rdi
callq 0x15440
cmpb $0x0, 0xe(%rsp)
je 0x1b25d
cmpb $0x0, 0x1087ae(%rip)    # 0x123a90
jne 0x1b33b
leaq 0x30(%rsp), %rdi
callq 0x1e22a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbfc25(%rip), %rdi     # 0xdaf29
leaq 0xbfc2e(%rip), %rsi     # 0xdaf39
leaq 0xbfc30(%rip), %rcx     # 0xdaf42
movl $0x20e, %edx            # imm = 0x20E
callq 0x151b0
leaq 0xbfc06(%rip), %rdi     # 0xdaf29
leaq 0xbfc0f(%rip), %rsi     # 0xdaf39
leaq 0xbfc11(%rip), %rcx     # 0xdaf42
movl $0x21b, %edx            # imm = 0x21B
callq 0x151b0
xorl %edi, %edi
callq 0x151a0
jmp 0x1b359
jmp 0x1b359
jmp 0x1b359
jmp 0x1b34a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1e19a
jmp 0x1b35c
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x1e22a
movq %rbx, %rdi
callq 0xd6ab0