// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
callq 0x3550
cmpl $0x0, %eax
je 0x3375
jmp 0x3537
cmpl $0x0, -0x1c(%rbp)
jge 0x339e
jmp 0x337d
movl -0x1c(%rbp), %esi
leaq 0x6e13(%rip), %rdi      # 0xa19a
movb $0x0, %al
callq 0x6810
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3537
cmpl $0x0, -0x20(%rbp)
je 0x33cd
cmpl $0x1, -0x20(%rbp)
je 0x33cd
jmp 0x33ac
movl -0x20(%rbp), %esi
leaq 0x6e12(%rip), %rdi      # 0xa1c8
movb $0x0, %al
callq 0x6810
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3537
movslq -0x1c(%rbp), %rax
movq %rax, -0x30(%rbp)
movq 0x1b0f4(%rip), %rdi     # 0x1e4d0
callq 0x35e0
movq %rax, %rcx
movq -0x30(%rbp), %rax
cmpq %rcx, %rax
jb 0x3404
movslq -0x1c(%rbp), %rdi
addq $0x1, %rdi
callq 0x3600
cmpl $0x0, %eax
je 0x3404
jmp 0x3537
cmpl $0x0, -0x20(%rbp)
jne 0x3420
movq 0x1b0bf(%rip), %rdi     # 0x1e4d0
movslq -0x1c(%rbp), %rsi
callq 0x36b0
movq %rax, -0x28(%rbp)
jmp 0x3438
movq 0x1b0a9(%rip), %rdi     # 0x1e4d0
movslq -0x1c(%rbp), %rsi
callq 0x36b0
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3452
callq 0x20a0
movl $0x11, (%rax)
jmp 0x3537
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x27a0
movq -0x28(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x3471
jmp 0x3537
cmpq $0x0, 0x1b05f(%rip)     # 0x1e4d8
jne 0x3480
callq 0x3f50
movq 0x1b049(%rip), %rdi     # 0x1e4d0
movslq -0x1c(%rbp), %rsi
callq 0x36b0
cmpq $-0x1, 0x10(%rax)
jne 0x34a9
movslq -0x1c(%rbp), %rdi
callq 0x36e0
cmpl $0x0, %eax
je 0x34a7
jmp 0x3520
jmp 0x34a9
cmpl $0x0, -0x20(%rbp)
jne 0x34e4
movq 0x1b02a(%rip), %rax     # 0x1e4e0
movq %rax, -0x38(%rbp)
movq 0x1b00f(%rip), %rdi     # 0x1e4d0
movslq -0x1c(%rbp), %rsi
callq 0x36b0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq 0x10(%rcx), %rcx
movswl 0x4(%rax,%rcx,8), %edx
orl $0x1, %edx
movw %dx, 0x4(%rax,%rcx,8)
jmp 0x3517
movq 0x1aff5(%rip), %rax     # 0x1e4e0
movq %rax, -0x40(%rbp)
movq 0x1afda(%rip), %rdi     # 0x1e4d0
movslq -0x1c(%rbp), %rsi
callq 0x36b0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq 0x10(%rcx), %rcx
movswl 0x4(%rax,%rcx,8), %edx
orl $0x4, %edx
movw %dx, 0x4(%rax,%rcx,8)
movl $0x0, -0x4(%rbp)
jmp 0x353e
movq -0x28(%rbp), %rax
movq (%rax), %rdi
callq 0x2820
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)