// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/liball/../libcperciva/events/events_network.c
// Function: events_network_register
int
events_network_register(int (* func)(void *), void * cookie, int s, int op)
{
	struct eventrec ** r;

	/* Initialize if necessary. */
	if (init())
		goto err0;

	/* Sanity-check socket number. */
	if (s < 0) {
		warn0("Invalid file descriptor for network event: %d", s);
		goto err0;
	}

	/* Sanity-check operation. */
	if ((op != EVENTS_NETWORK_OP_READ) &&
	    (op != EVENTS_NETWORK_OP_WRITE)) {
		warn0("Invalid operation for network event: %d", op);
		goto err0;
	}

	/* Grow the array if necessary. */
	if (((size_t)(s) >= socketlist_getsize(S)) &&
	    (growsocketlist((size_t)s + 1) != 0))
		goto err0;

	/* Look up the relevant event pointer. */
	if (op == EVENTS_NETWORK_OP_READ)
		r = &socketlist_get(S, (size_t)s)->reader;
	else
		r = &socketlist_get(S, (size_t)s)->writer;

	/* Error out if we already have an event registered. */
	if (*r != NULL) {
		errno = EEXIST;
		goto err0;
	}

	/* Register the new event. */
	if ((*r = events_mkrec(func, cookie)) == NULL)
		goto err0;

	/* If we had no events registered, start a clock. */
	if (nfds == 0)
		events_network_selectstats_startclock();

	/* If this descriptor isn't in the pollfd array, add it. */
	if (socketlist_get(S, (size_t)s)->pollpos == (size_t)(-1)) {
		if (growpollfd((size_t)s))
			goto err1;
	}

	/* Set the appropriate event flag. */
	if (op == EVENTS_NETWORK_OP_READ)
		fds[socketlist_get(S, (size_t)s)->pollpos].events |= POLLIN;
	else
		fds[socketlist_get(S, (size_t)s)->pollpos].events |= POLLOUT;

	/* Success! */
	return (0);

err1:
	events_freerec(*r);
	*r = NULL;
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %r12
callq 0x322e
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x3074
testl %r14d, %r14d
js 0x3058
cmpl $0x2, %ebp
jb 0x3085
leaq 0x4177(%rip), %rdi      # 0x71cb
movl %ebp, %esi
jmp 0x3062
leaq 0x413e(%rip), %rdi      # 0x719d
movl %r14d, %esi
xorl %eax, %eax
callq 0x500f
callq 0x2090
movl $0x0, (%rax)
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, 0x10(%rsp)
movl %r14d, %r15d
movq 0x1842c(%rip), %rdi     # 0x1b4c0
movl $0x18, %esi
callq 0x5bcb
cmpq %r15, %rax
ja 0x3151
leaq 0x1(%r15), %r13
movq 0x1840e(%rip), %rdi     # 0x1b4c0
movl $0x18, %esi
callq 0x5bcb
movq %rax, %r14
movq 0x183fa(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r13, %rsi
callq 0x5ad9
movl %eax, 0x4(%rsp)
testl %eax, %eax
setne %al
movq %r15, 0x8(%rsp)
cmpq %r15, %r14
seta %cl
orb %al, %cl
jne 0x3141
xorl %r15d, %r15d
movq 0x183cb(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r14, %rsi
callq 0x5d0d
movq %r15, (%rax)
movq 0x183b4(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r14, %rsi
callq 0x5d0d
movq %r15, 0x8(%rax)
movq 0x1839c(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r14, %rsi
callq 0x5d0d
movq $-0x1, 0x10(%rax)
incq %r14
cmpq %r14, %r13
jne 0x30ee
cmpl $0x0, 0x4(%rsp)
movq 0x8(%rsp), %r15
jne 0x3074
xorl %r13d, %r13d
testl %ebp, %ebp
setne %r13b
movq 0x1835f(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r15, %rsi
callq 0x5d0d
shll $0x3, %r13d
cmpq $0x0, (%rax,%r13)
je 0x3189
callq 0x2090
movl $0x11, (%rax)
jmp 0x3074
movq %rax, %r14
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0x27dc
movq %rax, (%r14,%r13)
testq %rax, %rax
je 0x3074
cmpq $0x0, 0x1831a(%rip)     # 0x1b4c8
jne 0x31b5
callq 0x37b8
movq 0x18304(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r15, %rsi
callq 0x5d0d
cmpq $-0x1, 0x10(%rax)
je 0x31fd
movq 0x182f9(%rip), %rbx     # 0x1b4d0
movq 0x182e2(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r15, %rsi
callq 0x5d0d
movq 0x10(%rax), %rax
movzwl 0x4(%rbx,%rax,8), %ecx
testl %ebp, %ebp
je 0x321f
orl $0x4, %ecx
jmp 0x3222
movq %r15, %rdi
callq 0x328a
testl %eax, %eax
je 0x31d0
movq (%r14,%r13), %rdi
callq 0x285a
movq $0x0, (%r14,%r13)
jmp 0x3074
orl $0x1, %ecx
movw %cx, 0x4(%rbx,%rax,8)
xorl %ebx, %ebx
jmp 0x3074