// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rdi, %r13
callq 0x2fd8
pushq $-0x1
popq %rbx
testl %eax, %eax
jne 0x2d3b
testl %r14d, %r14d
js 0x2d22
cmpl $0x2, %ebp
jb 0x2d4c
leaq 0x44ad(%rip), %rdi      # 0x71cb
movl %ebp, %esi
jmp 0x2d2c
leaq 0x4474(%rip), %rdi      # 0x719d
movl %r14d, %esi
xorl %eax, %eax
callq 0x4aa8
callq 0x2090
andl $0x0, (%rax)
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %r15d
movq 0x1876a(%rip), %rdi     # 0x1b4c0
callq 0x3034
cmpq %r15, %rax
movq %r15, %rsi
movq %r15, 0x10(%rsp)
ja 0x2de2
leaq 0x1(%rsi), %rax
movq %rax, 0x8(%rsp)
movq 0x18748(%rip), %rdi     # 0x1b4c0
callq 0x3034
movq %rax, %r15
movq 0x18739(%rip), %rdi     # 0x1b4c0
pushq $0x18
popq %rdx
movq 0x8(%rsp), %rsi
callq 0x54ed
testl %eax, %eax
jne 0x2d3b
jmp 0x2dd8
movq 0x1871f(%rip), %rdi     # 0x1b4c0
movq %r15, %rsi
callq 0x303c
andq $0x0, (%rax)
movq 0x1870c(%rip), %rdi     # 0x1b4c0
movq %r15, %rsi
callq 0x303c
andq $0x0, 0x8(%rax)
movq 0x186f8(%rip), %rdi     # 0x1b4c0
movq %r15, %rsi
callq 0x303c
orq $-0x1, 0x10(%rax)
incq %r15
movq 0x10(%rsp), %rsi
cmpq %rsi, %r15
jbe 0x2d9a
xorl %r15d, %r15d
testl %ebp, %ebp
setne %r15b
movq 0x186ce(%rip), %rdi     # 0x1b4c0
callq 0x303c
shll $0x3, %r15d
cmpq $0x0, (%rax,%r15)
je 0x2e12
callq 0x2090
movl $0x11, (%rax)
jmp 0x2d3b
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %r12
callq 0x26a8
movq %rax, (%r12,%r15)
testq %rax, %rax
je 0x2d3b
cmpq $0x0, 0x18693(%rip)     # 0x1b4c8
jne 0x2e3c
callq 0x33dc
movq 0x1867d(%rip), %rdi     # 0x1b4c0
movq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0x303c
cmpq $-0x1, 0x10(%rax)
jne 0x2f31
movq 0x1865e(%rip), %rdi     # 0x1b4c0
movq %r13, %rsi
callq 0x303c
cmpq $-0x1, 0x10(%rax)
jne 0x2f7b
movq 0x18664(%rip), %r13     # 0x1b4e0
movq 0x18645(%rip), %rcx     # 0x1b4c8
cmpq %rcx, %r13
jne 0x2ee9
leaq (,%r13,2), %rax
testq %r13, %r13
pushq $0x10
popq %r13
cmovneq %rax, %r13
movq %r13, %rax
shrq $0x3d, %rax
je 0x2eb4
callq 0x2090
movl $0xc, (%rax)
jmp 0x2f68
movq %rcx, 0x8(%rsp)
movq 0x18610(%rip), %rdi     # 0x1b4d0
leaq (,%r13,8), %rsi
callq 0x2270
testq %rax, %rax
je 0x2f68
movq %rax, 0x185f3(%rip)     # 0x1b4d0
movq %r13, 0x185fc(%rip)     # 0x1b4e0
movq 0x8(%rsp), %rcx
cmpq %r13, %rcx
jae 0x2f9a
cmpl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
je 0x2fb9
movq 0x185ca(%rip), %rax     # 0x1b4d0
movl %r14d, (%rax,%rcx,8)
andl $0x0, 0x4(%rax,%rcx,8)
movq 0x185aa(%rip), %rdi     # 0x1b4c0
movq 0x10(%rsp), %r13
movq %r13, %rsi
movq %rcx, %rbx
callq 0x303c
movq %rbx, 0x10(%rax)
incq 0x18597(%rip)           # 0x1b4c8
movq 0x18598(%rip), %rbx     # 0x1b4d0
movq 0x18581(%rip), %rdi     # 0x1b4c0
movq %r13, %rsi
callq 0x303c
movq 0x10(%rax), %rax
movzwl 0x4(%rbx,%rax,8), %ecx
testl %ebp, %ebp
je 0x2f59
orl $0x4, %ecx
jmp 0x2f5c
orl $0x1, %ecx
movw %cx, 0x4(%rbx,%rax,8)
xorl %ebx, %ebx
jmp 0x2d3b
movq (%r12,%r15), %rdi
callq 0x2720
andq $0x0, (%r12,%r15)
jmp 0x2d3b
leaq 0x42f2(%rip), %rdi      # 0x7274
leaq 0x429a(%rip), %rsi      # 0x7223
leaq 0x4313(%rip), %rcx      # 0x72a3
movl $0x8d, %edx
callq 0x2160
leaq 0x4319(%rip), %rdi      # 0x72ba
leaq 0x427b(%rip), %rsi      # 0x7223
leaq 0x42f4(%rip), %rcx      # 0x72a3
movl $0x9e, %edx
callq 0x2160
leaq 0x430b(%rip), %rdi      # 0x72cb
leaq 0x425c(%rip), %rsi      # 0x7223
leaq 0x42d5(%rip), %rcx      # 0x72a3
movl $0x9f, %edx
callq 0x2160