// File: /workspace/github_cpp_makefile_star2_O3/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 0x1fc25
movq %rdi, %r14
movl %esi, %r13d
leaq 0x10(%rsp), %r12
leaq 0x10aeb4(%rip), %r15    # 0x12aa40
leaq 0x20(%rsp), %rbp
movq %r12, %rdi
leaq -0x30c0(%rip), %rsi     # 0x1cadb
movq %r14, %rdx
callq 0x25bd0
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x8, %esi
movl $0xc70f6907, %edx       # imm = 0xC70F6907
leaq 0x18(%rsp), %rdi
callq 0x357b0
movq %rax, 0x20(%rsp)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x33bbe
cmpq $0x0, 0x10(%rsp)
jne 0x1fdaa
movq %r15, %rdi
callq 0x157f0
testl %eax, %eax
jne 0x1fda3
leaq 0x10aea2(%rip), %rdi    # 0x12aa98
movq %rbp, %rsi
callq 0x25b6a
movl $0x2, (%rax)
movq %r15, %rdi
callq 0x15860
cmpq $0x0, 0x10(%rsp)
jne 0x1fe11
addq $0x60, %r14
decq %r13
jne 0x1fb91
movl 0x2c(%rsp), %eax
testl %eax, %eax
jle 0x1fcdc
movl %eax, %r13d
leaq 0x10(%rsp), %r15
leaq 0x10ae00(%rip), %rbp    # 0x12aa40
leaq 0x10ae51(%rip), %r14    # 0x12aa98
leaq 0x20(%rsp), %r12
movq %r15, %rdi
leaq -0x56b5(%rip), %rsi     # 0x1a5a1
movq %rbx, %rdx
callq 0x25c5a
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x8, %esi
movl $0xc70f6907, %edx       # imm = 0xC70F6907
leaq 0x18(%rsp), %rdi
callq 0x357b0
movq %rax, 0x20(%rsp)
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x33bbe
cmpq $0x0, 0x10(%rsp)
jne 0x1fdd0
movq %rbp, %rdi
callq 0x157f0
testl %eax, %eax
jne 0x1fdc9
movq %r14, %rdi
movq %r12, %rsi
callq 0x25b6a
movl $0x2, (%rax)
movq %rbp, %rdi
callq 0x15860
cmpq $0x0, 0x10(%rsp)
jne 0x1fe11
addq $0x20, %rbx
decq %r13
jne 0x1fc4c
leaq 0x10(%rsp), %rbx
leaq 0x10ad58(%rip), %r14    # 0x12aa40
leaq 0x10ada9(%rip), %r15    # 0x12aa98
movb $0x1, 0xf(%rsp)
movq 0x30(%rsp), %r12
movq 0x38(%rsp), %r13
cmpq %r13, %r12
je 0x1fd65
movq (%r12), %rax
movq %rax, 0x10(%rsp)
movl $0x8, %esi
movl $0xc70f6907, %edx       # imm = 0xC70F6907
movq %rbx, %rdi
callq 0x357b0
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0x157f0
testl %eax, %eax
jne 0x1fd9c
movq %r15, %rdi
movq %rbx, %rsi
callq 0x25b6a
movl (%rax), %ebp
movq %r14, %rdi
callq 0x15860
cmpl $0x1, %ebp
jne 0x1fd5a
cmpq $0x0, (%r12)
je 0x1fd5f
movq %r12, %rdi
callq 0xb4010
jmp 0x1fd5f
movb $0x0, 0xf(%rsp)
addq $0x8, %r12
jmp 0x1fcfe
movl $0x1, %edi
callq 0x15440
cmpb $0x0, 0xf(%rsp)
je 0x1fcef
cmpb $0x0, 0x10ad0f(%rip)    # 0x12aa90
jne 0x1fdef
leaq 0x30(%rsp), %rdi
callq 0x25ce2
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x177cf
movl %eax, %edi
callq 0x177cf
leaq 0xc41a8(%rip), %rdi     # 0xe3f59
leaq 0xc41b1(%rip), %rsi     # 0xe3f69
leaq 0xc41b3(%rip), %rcx     # 0xe3f72
movl $0x20e, %edx            # imm = 0x20E
callq 0x151b0
movl %eax, %edi
callq 0x177cf
leaq 0xc4182(%rip), %rdi     # 0xe3f59
leaq 0xc418b(%rip), %rsi     # 0xe3f69
leaq 0xc418d(%rip), %rcx     # 0xe3f72
movl $0x21b, %edx            # imm = 0x21B
callq 0x151b0
xorl %edi, %edi
callq 0x151a0
jmp 0x1fe20
jmp 0x1fe18
jmp 0x1fe06
jmp 0x1fe20
jmp 0x1fe18
jmp 0x1fe06
jmp 0x1fe20
jmp 0x1fe06
movq %rax, %rbx
cmpq $0x0, 0x10(%rsp)
je 0x1fe23
callq 0x35400
jmp 0x1fe20
movq %rax, %rdi
callq 0x25e51
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x25ce2
movq %rbx, %rdi
callq 0xdfce0