// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../libcperciva/network_ssl/network_ssl.c
// Function: dowrite
static int
dowrite(struct network_ssl_ctx * ssl)
{
	size_t len;
	int sslerr;
	int ret;
#ifndef SO_NOSIGPIPE
	void (* oldsig)(int);
#endif

	/*
	 * Flush any errors internal to the SSL stack; otherwise if we
	 * encounter an error we won't be able to identify which error
	 * needs to be reported.
	 */
	ERR_clear_error();

	/* If we don't have SO_NOSIGPIPE, ignore SIGPIPE. */
#ifndef SO_NOSIGPIPE
	if ((oldsig = signal(SIGPIPE, SIG_IGN)) == SIG_ERR) {
		warnp("signal(SIGPIPE)");
		return (-1);
	}
#endif

	/* Ask the SSL stack to write some data. */
	while ((ret = SSL_write_ex(ssl->ssl, &ssl->write_buf[ssl->write_bufpos],
	    ssl->write_buflen - ssl->write_bufpos, &len)) > 0) {
		/* We wrote some data. */
		ssl->write_bufpos += len;

		/* Sanity-check. */
		assert(ssl->write_bufpos <= ssl->write_buflen);

		/* Have we written enough? */
		if (ssl->write_bufpos >= ssl->write_minlen) {
			/* If we ignored SIGPIPE, restore the old handler. */
#ifndef SO_NOSIGPIPE
			if (signal(SIGPIPE, oldsig) == SIG_ERR) {
				warnp("signal(SIGPIPE)");
				return (-1);
			}
#endif

			return (docallback(ssl->write_callback,
			    ssl->write_cookie, (ssize_t)ssl->write_bufpos,
			    &ssl->write_callback));
		}
	}

	/* If we ignored SIGPIPE, restore the old handler. */
#ifndef SO_NOSIGPIPE
	if (signal(SIGPIPE, oldsig) == SIG_ERR) {
		warnp("signal(SIGPIPE)");
		return (-1);
	}
#endif

	/* SSL_write_ex couldn't send any data... why? */
	switch ((sslerr = SSL_get_error(ssl->ssl, ret))) {
	case SSL_ERROR_WANT_READ:
		/* Nothing to do until the socket is readable. */
		ssl->write_needs_r = 1;
		return (0);
	case SSL_ERROR_WANT_WRITE:
		/* Nothing to do until the socket is writable. */
		ssl->write_needs_w = 1;
		return (0);
	case SSL_ERROR_SYSCALL:
		/* Something bad happened to our connection. */
		break;
	case SSL_ERROR_SSL:
		/* SSL failure, probably a protocol error. */
		warn0("SSL failure: %s",
		    ERR_error_string(ERR_get_error(), NULL));
		break;
	default:
		/* Don't know what happened here.  Fail the write. */
		warn0("Unknown SSL error: %d", sslerr);
		break;
	}

	/* Connection failure. */
	return (docallback(ssl->write_callback, ssl->write_cookie, -1,
	    &ssl->write_callback));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
callq 0x34e0
movl $0xd, %edi
movl $0x1, %esi
callq 0x35d0
movq %rax, -0x28(%rbp)
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0x14cb3
jmp 0x14c72
callq 0x3040
cmpl $0x0, (%rax)
je 0x14c97
leaq 0xba3c(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x14ca5
leaq 0xba21(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x6930
jmp 0x14ca7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14f2b
jmp 0x14cb5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rsi
movq -0x10(%rbp), %rax
addq 0x80(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rdx
movq -0x10(%rbp), %rax
subq 0x80(%rax), %rdx
leaq -0x18(%rbp), %rcx
callq 0x3660
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jle 0x14def
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x70(%rcx), %rax
ja 0x14d25
jmp 0x14d44
leaq 0xba13(%rip), %rdi      # 0x2073f
leaq 0xb72b(%rip), %rsi      # 0x2045e
movl $0x186, %edx            # imm = 0x186
leaq 0xba27(%rip), %rcx      # 0x20766
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x78(%rcx), %rax
jb 0x14dea
movq -0x28(%rbp), %rsi
movl $0xd, %edi
callq 0x35d0
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0x14dba
jmp 0x14d79
callq 0x3040
cmpl $0x0, (%rax)
je 0x14d9e
leaq 0xb935(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x14dac
leaq 0xb91a(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x6930
jmp 0x14dae
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14f2b
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdx
movq -0x10(%rbp), %rcx
addq $0x58, %rcx
callq 0x14f40
movl %eax, -0x4(%rbp)
jmp 0x14f2b
jmp 0x14cb5
movq -0x28(%rbp), %rsi
movl $0xd, %edi
callq 0x35d0
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0x14e4c
jmp 0x14e0b
callq 0x3040
cmpl $0x0, (%rax)
je 0x14e30
leaq 0xb8a3(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x14e3e
leaq 0xb888(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x6930
jmp 0x14e40
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14f2b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x20(%rbp), %esi
callq 0x3030
movl %eax, -0x1c(%rbp)
decl %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x4, %eax
ja 0x14ee4
movq -0x30(%rbp), %rax
leaq 0xb58d(%rip), %rcx      # 0x20404
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movl $0x1, 0x88(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x14f2b
movq -0x10(%rbp), %rax
movl $0x1, 0x8c(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x14f2b
jmp 0x14f04
jmp 0x14eb5
callq 0x34b0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3110
movq %rax, %rsi
leaq 0xb849(%rip), %rdi      # 0x20719
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
jmp 0x14f04
jmp 0x14ee6
movl -0x1c(%rbp), %esi
leaq 0xb839(%rip), %rdi      # 0x20729
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
jmp 0x14f04
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rsi
movq -0x10(%rbp), %rcx
addq $0x58, %rcx
movq $-0x1, %rdx
callq 0x14f40
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)