// File: /workspace/github_c_makefile_star2_O3/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 0x5c80
movl %eax, (%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4670
movl %eax, %r15d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5c5f
movl %eax, 0x4(%rsp)
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5c5f
movl %eax, %r12d
movq %rbx, %rdi
movl %eax, %esi
callq 0x5f7e
movq %rbx, %rdi
callq 0x6478
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x7095
xorl %r14d, %r14d
testl %eax, %eax
je 0x5213
leaq 0x1a74f(%rip), %rbp     # 0x1f8c0
leaq 0x11eb1(%rip), %r13     # 0x17029
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %rbp, %rdx
movq %r13, %rcx
callq 0x4834
cmpl $0x0, 0x8(%rax)
je 0x5196
incl %r14d
jmp 0x51f1
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5f7e
incl %r15d
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movl %r15d, %edx
callq 0x6b2f
movq %rbx, %rdi
callq 0x6478
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0x12039(%rip), %rdx     # 0x17205
callq 0x6a5a
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5f7e
movq %rbx, %rdi
callq 0x6478
movq %rbx, %rdi
movl %r12d, %esi
callq 0x6ac0
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5c94
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x7095
testl %eax, %eax
jne 0x5178
movq %rbx, %rdi
movl %r12d, %esi
callq 0x5f7e
movq %rbx, %rdi
callq 0x6478
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x7095
testl %eax, %eax
je 0x5246
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5c94
jmp 0x5226
movq %rbx, %rdi
movl (%rsp), %esi
callq 0x5c94
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq