// File: /workspace/github_c_makefile_star2_O3/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 0x3244
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x3090
testl %r14d, %r14d
js 0x3074
cmpl $0x2, %ebp
jb 0x30a1
leaq 0x415b(%rip), %rdi      # 0x71cb
movl %ebp, %esi
jmp 0x307e
leaq 0x4122(%rip), %rdi      # 0x719d
movl %r14d, %esi
xorl %eax, %eax
callq 0x5017
callq 0x2090
movl $0x0, (%rax)
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %r14d
movq 0x18415(%rip), %rdi     # 0x1b4c0
movl $0x18, %esi
callq 0x5bca
movq %r14, 0x8(%rsp)
cmpq %r14, %rax
jbe 0x30fa
xorl %r13d, %r13d
testl %ebp, %ebp
setne %r13b
movq 0x183f1(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq 0x8(%rsp), %rsi
callq 0x5d0c
shll $0x3, %r13d
cmpq $0x0, (%rax,%r13)
je 0x319c
callq 0x2090
movl $0x11, (%rax)
jmp 0x3090
movq 0x8(%rsp), %rax
leaq 0x1(%rax), %r13
movq 0x183b6(%rip), %rdi     # 0x1b4c0
movl $0x18, %esi
callq 0x5bca
movq %rax, %r14
movq 0x183a2(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r13, 0x10(%rsp)
movq %r13, %rsi
callq 0x5ad8
testl %eax, %eax
jne 0x3090
cmpq 0x8(%rsp), %r14
ja 0x30bf
xorl %r13d, %r13d
movq 0x18377(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r14, %rsi
callq 0x5d0c
movq %r13, (%rax)
movq 0x18360(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r14, %rsi
callq 0x5d0c
movq %r13, 0x8(%rax)
movq 0x18348(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r14, %rsi
callq 0x5d0c
movq $-0x1, 0x10(%rax)
incq %r14
cmpq %r14, 0x10(%rsp)
jne 0x3142
jmp 0x30bf
movq %rax, %r14
movq %r12, %rdi
movq %r15, %rsi
callq 0x27dc
movq %rax, (%r14,%r13)
testq %rax, %rax
je 0x3090
cmpq $0x0, 0x18309(%rip)     # 0x1b4c8
jne 0x31c6
callq 0x37dc
movq 0x182f3(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x5d0c
cmpq $-0x1, 0x10(%rax)
je 0x3213
movq 0x182e3(%rip), %rbx     # 0x1b4d0
movq 0x182cc(%rip), %rdi     # 0x1b4c0
movl $0x18, %edx
movq %r15, %rsi
callq 0x5d0c
movq 0x10(%rax), %rax
movzwl 0x4(%rbx,%rax,8), %ecx
testl %ebp, %ebp
je 0x3235
orl $0x4, %ecx
jmp 0x3238
movq %r15, %rdi
callq 0x32a0
testl %eax, %eax
je 0x31e6
movq (%r14,%r13), %rdi
callq 0x2856
movq $0x0, (%r14,%r13)
jmp 0x3090
orl $0x1, %ecx
movw %cx, 0x4(%rbx,%rax,8)
xorl %ebx, %ebx
jmp 0x3090