// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../libcperciva/network/network_write.c
// Function: callback_buf
static int
callback_buf(void * cookie)
{
	struct network_write_cookie * C = cookie;
	size_t oplen;
	ssize_t len;
#ifdef POSIXFAIL_MSG_NOSIGNAL
	void (* oldsig)(int);
	int saved_errno;
#endif

	/* If we don't have MSG_NOSIGNAL, ignore SIGPIPE. */
#ifdef POSIXFAIL_MSG_NOSIGNAL
	if ((oldsig = signal(SIGPIPE, SIG_IGN)) == SIG_ERR) {
		warnp("signal(SIGPIPE)");
		goto failed;
	}
#endif

	/* Attempt to read/write data to/from the buffer. */
	oplen = C->buflen - C->bufpos;
	len = send(C->fd, C->buf + C->bufpos, oplen, MSG_NOSIGNAL);

	/* We should never see a send length of zero. */
	assert(len != 0);

	/* If we ignored SIGPIPE, restore the old handler. */
#ifdef POSIXFAIL_MSG_NOSIGNAL
	/* Save errno in case it gets clobbered by signal(). */
	saved_errno = errno;

	if (signal(SIGPIPE, oldsig) == SIG_ERR) {
		warnp("signal(SIGPIPE)");
		goto failed;
	}

	/* Restore saved errno. */
	errno = saved_errno;
#endif

	/* Failure? */
	if (len == -1) {
		/* Was it really an error, or just a try-again? */
		if ((errno == EAGAIN) ||
#if EAGAIN != EWOULDBLOCK
		    (errno == EWOULDBLOCK) ||
#endif
		    (errno == EINTR))
			goto tryagain;

		/* Something went wrong. */
		goto failed;
	}

	/* We processed some data. */
	C->bufpos += (size_t)len;

	/* Do we need to keep going? */
	if (C->bufpos < C->minlen)
		goto tryagain;

	/* Sanity-check: buffer position must fit into a ssize_t. */
	assert(C->bufpos <= SSIZE_MAX);

	/* Invoke the callback and return. */
	return (docallback(C, (ssize_t)C->bufpos));

tryagain:
	/* Reset the event. */
	if (events_network_register(callback_buf, C, C->fd,
	    EVENTS_NETWORK_OP_WRITE))
		goto failed;

	/* Callback was reset. */
	return (0);

failed:
	/* Invoke the callback with a failure status and return. */
	return (docallback(C, -1));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
subq 0x30(%rcx), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
addq 0x30(%rax), %rsi
movq -0x20(%rbp), %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2140
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xcc9a
jmp 0xccb9
leaq 0x2986(%rip), %rdi      # 0xf627
leaq 0x39f2(%rip), %rsi      # 0x1069a
movl $0x56, %edx
leaq 0x39cd(%rip), %rcx      # 0x10681
callq 0x21a0
cmpq $-0x1, -0x28(%rbp)
jne 0xccdb
callq 0x20a0
cmpl $0xb, (%rax)
je 0xccd4
callq 0x20a0
cmpl $0x4, (%rax)
jne 0xccd6
jmp 0xcd4a
jmp 0xcd76
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jae 0xccff
jmp 0xcd4a
movq -0x18(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
cmpq %rcx, 0x30(%rax)
ja 0xcd15
jmp 0xcd34
leaq 0x394e(%rip), %rdi      # 0x1066a
leaq 0x3977(%rip), %rsi      # 0x1069a
movl $0x7c, %edx
leaq 0x3952(%rip), %rcx      # 0x10681
callq 0x21a0
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0xcf30
movl %eax, -0x4(%rbp)
jmp 0xcd89
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
leaq -0x11c(%rip), %rdi      # 0xcc40
movl $0x1, %ecx
callq 0x3550
cmpl $0x0, %eax
je 0xcd6d
jmp 0xcd76
movl $0x0, -0x4(%rbp)
jmp 0xcd89
movq -0x18(%rbp), %rdi
movq $-0x1, %rsi
callq 0xcf30
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)