// File: /workspace/github_c_makefile_star2_O1/bhk[P]tooltree/monoglot/./xpio_c.c
// Function: XPQueue_wakeChildWaiters
static int
XPQueue_wakeChildWaiters(XPQueue *me, lua_State *L, int ndxReady, int ndxWaiters)
{
   int nTop = lua_gettop(L);
   int numReady = lengthOf(L, ndxReady);
   int numWaiting = 0;

   ndxReady = lua_absindex(L, ndxReady);
   ndxWaiters = lua_absindex(L, ndxWaiters);

   // enumerate waiters (process -> task)
   lua_pushvalue(L, ndxWaiters);
   for (lua_pushnil(L); lua_next(L, -2) != 0; lua_pop(L, 1)) {
      // xpproc is at -2;  task is at -1

      if (xpproc_isExited(L, -2)) {
         // put task in ready[]
         lua_pushvalue(L, -1);
         lua_rawseti(L, ndxReady, ++numReady);

         // mark task as not pending
         lua_pushnil(L);
         lua_setfield(L, -2, "_dequeue");

         // remove task from childWaiters
         lua_pushvalue(L, -2);
         lua_pushnil(L);
         lua_rawset(L, ndxWaiters);
      } else {
         ++numWaiting;
      }
      //printf("... wcw loop: %d, %d\n", numReady, numWaiting);
   }

   //printf("wakeChildWaiters: numWaiting=%d numReady=%d\n", numWaiting, numReady);

   {
      //int cnt = 0;
      lua_pushvalue(L, ndxWaiters);
      for (lua_pushnil(L); lua_next(L, -2) != 0; lua_pop(L, 1)) {
         //++cnt;
      }
      //printf("wakeChildWaiters: %d waiters left\n", cnt);
   }

   lua_settop(L, nTop);
   return numWaiting;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x5c2f
movl %eax, (%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x461a
movl %eax, %r15d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5c0e
movl %eax, 0x4(%rsp)
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5c0e
movl %eax, %r12d
movq %rbx, %rdi
movl %eax, %esi
callq 0x5e15
movq %rbx, %rdi
callq 0x630a
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6f12
xorl %r14d, %r14d
testl %eax, %eax
je 0x51b5
leaq 0x1a7ad(%rip), %rbp     # 0x1f8c0
leaq 0x11f0f(%rip), %r13     # 0x17029
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %rbp, %rdx
movq %r13, %rcx
callq 0x47de
cmpl $0x0, 0x8(%rax)
je 0x5138
incl %r14d
jmp 0x5193
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5e15
incl %r15d
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movl %r15d, %edx
callq 0x69b9
movq %rbx, %rdi
callq 0x630a
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0x12097(%rip), %rdx     # 0x17205
callq 0x68eb
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5e15
movq %rbx, %rdi
callq 0x630a
movq %rbx, %rdi
movl %r12d, %esi
callq 0x6951
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5c43
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6f12
testl %eax, %eax
jne 0x511a
movq %rbx, %rdi
movl %r12d, %esi
callq 0x5e15
movq %rbx, %rdi
callq 0x630a
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6f12
testl %eax, %eax
je 0x51e8
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5c43
jmp 0x51c8
movq %rbx, %rdi
movl (%rsp), %esi
callq 0x5c43
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq