// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/cqueues.c
// Function: cqueue_resume
static cqs_status_t cqueue_resume(lua_State *L, struct cqueue *Q, struct callinfo *I, struct thread *T) {
	int otop = lua_gettop(L), nargs, nres, status, tmp_status, index;
	struct event *event;

	status = lua_status(T->L);
	if (status == LUA_YIELD && lua_islightuserdata(T->L, 1) && lua_topointer(T->L, 1) == CQUEUE__POLL) {
		/*
		 * Preserve any previously yielded objects on another stack
		 * until we can call cqueue_update() because when
		 * lua_resume() returns the thread stack will only contain
		 * new objects. Pausing the GC isn't a viable option because
		 * we don't know if or when lua_resume() will return.
		 */
		if (!auxL_xcopy(T->L, L, lua_gettop(T->L)))
			goto nospace;

		nargs = 0;

		if (!lua_checkstack(T->L, T->count + LUA_MINSTACK))
			goto nospace;

		while ((event = TAILQ_FIRST(&T->events))) {
			if (event->pending) {
				lua_pushvalue(T->L, event->index);
				nargs++;
			}

			event_del(Q, event);
		}
	} else {
		nargs = lua_gettop(T->L);
		if (status != LUA_YIELD) {
			if (nargs > 0)
				nargs -= 1; /* exclude function */
		}
	}

	timer_del(Q, &T->timer);

	cstack_push(Q->cstack, &(struct stackinfo){ Q, L, I->self, T->L });

#if LUA_VERSION_NUM < 504
	status = lua_resume(T->L, L, nargs);
	nres = lua_gettop(T->L);
#else
	status = lua_resume(T->L, L, nargs, &nres);
#endif

	cstack_pop(Q->cstack);

	switch (status) {
	case LUA_YIELD:
		if (nres > 0 && lua_islightuserdata(T->L, 1) && lua_topointer(T->L, 1) == CQUEUE__POLL) {
			for (index = 2; index <= nres; index++) {
				switch (lua_type(T->L, index)) {
				case LUA_TNIL:
					continue;
				default:
					if (LUA_OK != (status = event_add(L, Q, I, T, index)))
						goto defunct;
				}
			}

			if (LUA_OK != (status = cqueue_update(L, Q, I, T)))
				goto defunct;

			timer_add(Q, &T->timer, thread_timeout(T));

			if (!TAILQ_EMPTY(&T->events) || isfinite(T->timer.timeout))
				thread_move(T, &Q->thread.polling);
		} else {
			if (LUA_OK != (tmp_status = cqueue_update(L, Q, I, T))) {
				status = tmp_status;
				goto defunct;
			}

			break;
		}
		break;
	case LUA_OK:
		if (LUA_OK != (status = cqueue_update(L, Q, I, T)))
			goto defunct;

		thread_del(L, Q, I, T);

		break;
	default:
		if (LUA_OK != cqueue_update(L, Q, I, T))
			goto defunct;

		lua_xmove(T->L, L, 1); /* move error message */
		I->error.value = lua_gettop(L);
		err_setthread(L, I, T);
defunct:
		thread_del(L, Q, I, T);

		break;
	} /* switch() */

	/* discard objects preserved while resuming coroutine */
	if (!err_onstack(L, I))
		lua_settop(L, otop);

	return status;
nospace:
	err_setinfo(L, I, 0, T, 0, "stack overflow");
	status = LUA_ERRMEM;

	goto defunct;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0xf9b0
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xf2e0
movl %eax, -0x30(%rbp)
cmpl $0x1, -0x30(%rbp)
jne 0x13f94
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0xf280
cmpl $0x2, %eax
jne 0x13f94
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x101d0
movq 0x48076(%rip), %rcx     # 0x5bf58
cmpq %rcx, %rax
jne 0x13f94
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xf9b0
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl %eax, %edx
callq 0x142e0
testb $0x1, %al
jne 0x13f22
jmp 0x142af
movl $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movl 0x18(%rax), %esi
addl $0x14, %esi
callq 0x10240
cmpl $0x0, %eax
jne 0x13f49
jmp 0x142af
jmp 0x13f4b
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x13f92
movq -0x40(%rbp), %rax
testb $0x1, 0x10(%rax)
je 0x13f83
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movl 0x14(%rax), %esi
callq 0xfa50
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x14370
jmp 0x13f4b
jmp 0x13fbc
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xf9b0
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x30(%rbp)
je 0x13fba
cmpl $0x0, -0x28(%rbp)
jle 0x13fb8
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x13fba
jmp 0x13fbc
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x40, %rsi
callq 0x14550
movq -0x10(%rbp), %rax
movq 0x230(%rax), %rdi
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
leaq -0x68(%rbp), %rsi
callq 0x145c0
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rsi
movl -0x28(%rbp), %edx
callq 0xf1b0
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xf9b0
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x230(%rax), %rdi
callq 0x145f0
movl -0x30(%rbp), %eax
movl %eax, -0x7c(%rbp)
testl %eax, %eax
je 0x141e1
jmp 0x1404e
movl -0x7c(%rbp), %eax
subl $0x1, %eax
jne 0x1421a
jmp 0x1405c
cmpl $0x0, -0x2c(%rbp)
jle 0x141ac
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0xf280
cmpl $0x2, %eax
jne 0x141ac
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x101d0
movq 0x47ec0(%rip), %rcx     # 0x5bf58
cmpq %rcx, %rax
jne 0x141ac
movl $0x2, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jg 0x140ff
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl -0x38(%rbp), %esi
callq 0xf280
testl %eax, %eax
jne 0x140c7
jmp 0x140c5
jmp 0x140f4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl -0x38(%rbp), %r8d
callq 0x14610
movl %eax, %ecx
movl %ecx, -0x30(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
je 0x140f0
jmp 0x14271
jmp 0x140f2
jmp 0x140f4
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x140a8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x14880
movl %eax, %ecx
movl %ecx, -0x30(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
je 0x14124
jmp 0x14271
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
callq 0x14ac0
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x14a40
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x14196
movq -0x20(%rbp), %rax
movsd 0x40(%rax), %xmm0
movq %xmm0, %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq %rcx, %rax
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
subq %rcx, %rax
setl %al
testb $0x1, %al
jne 0x14196
jmp 0x141aa
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x208, %rsi            # imm = 0x208
callq 0x120f0
jmp 0x141dc
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x14880
movl %eax, %ecx
movl %ecx, -0x34(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
je 0x141d7
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x14271
jmp 0x14286
jmp 0x14286
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x14880
movl %eax, %ecx
movl %ecx, -0x30(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
je 0x14203
jmp 0x14271
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x14b20
jmp 0x14286
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x14880
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x14239
jmp 0x14271
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rsi
movl $0x1, %edx
callq 0x10380
movq -0x8(%rbp), %rdi
callq 0xf9b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x14c30
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x14b20
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x14c80
testb $0x1, %al
jne 0x142a3
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x107f0
movl -0x30(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rcx
xorl %r8d, %r8d
leaq 0x34032(%rip), %r9      # 0x482f7
movl %r8d, %edx
movb $0x0, %al
callq 0x14cc0
movl $0x4, -0x30(%rbp)
jmp 0x14271
nopl (%rax,%rax)