// File: /workspace/github_c_makefile_star2_O3/uhlin[P]enhanced-duc/source/network-openssl.c
// Function: net_ssl_send
int
net_ssl_send(const char *fmt, ...)
{
	char		*buf = NULL;
	char		*bufptr = NULL;
	int		 buflen = 0;
	int		 n_sent = 0;
	size_t		 newSize = 0;
	static const char
			 message_terminate[] = "\r\n\r\n";
	va_list		 ap;

	log_assert_arg_nonnull("net_ssl_send", "fmt", fmt);

	va_start(ap, fmt);
	if (my_vasprintf(&buf, fmt, ap) < 0)
		fatal(errno, "%s: my_vasprintf", __func__);
	va_end(ap);

	newSize = strlen(buf) + nitems(message_terminate);
	buf = xrealloc(buf, newSize);

	if (strlcat(buf, message_terminate, newSize) >= newSize)
		fatal(EOVERFLOW, "%s: strlcat", __func__);
	if (strlen(buf) > INT_MAX) {
		free(buf);
		return -1;
	}

	bufptr = buf;
	buflen = (int) strlen(buf);

	while (buflen > 0) {
		if (ssl == NULL || g_socket == -1)
			break;

		ERR_clear_error();
		const int ret = SSL_write(ssl, bufptr, buflen);

		if (ret > 0) {
			if (BIO_flush(SSL_get_wbio(ssl)) != 1)
				log_debug("%s: error flushing write bio",
				    __func__);
			n_sent += ret;
			bufptr += ret;
			buflen -= ret;
		} else {
			switch (SSL_get_error(ssl, ret)) {
			case SSL_ERROR_NONE:
				fatal(0, "%s: 'SSL_ERROR_NONE' reached "
				    "unexpectedly", __func__);
				break;
			case SSL_ERROR_WANT_READ:
			case SSL_ERROR_WANT_WRITE:
				log_debug("%s: want read / want write", __func__);
				continue;
			}

			free(buf);
			return -1;
		}
	}

	free(buf);
	return (n_sent > 0 ? 0 : -1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x50(%rsp)
movq %r9, 0x58(%rsp)
testb %al, %al
je 0x6548
movaps %xmm0, 0x60(%rsp)
movaps %xmm1, 0x70(%rsp)
movaps %xmm2, 0x80(%rsp)
movaps %xmm3, 0x90(%rsp)
movaps %xmm4, 0xa0(%rsp)
movaps %xmm5, 0xb0(%rsp)
movaps %xmm6, 0xc0(%rsp)
movaps %xmm7, 0xd0(%rsp)
movq $0x0, 0x8(%rsp)
testq %rdi, %rdi
je 0x66f9
movq %rdi, %r10
leaq 0x30(%rsp), %rax
leaq 0x10(%rsp), %rdx
movq %rax, 0x10(%rdx)
leaq 0x120(%rsp), %rax
movq %rax, 0x8(%rdx)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%rdx)
leaq 0x8(%rsp), %rdi
movq %r10, %rsi
callq 0x641c
testl %eax, %eax
js 0x671a
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x41c0
movq %rax, %r14
addq $0x5, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x87f1
movq %rax, 0x8(%rsp)
leaq 0x3d24(%rip), %rsi      # 0xa2e8
movq %rax, %rdi
movq %r14, %rdx
callq 0x81fc
cmpq %r14, %rax
jae 0x6731
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x41c0
movq %rax, %r15
addq $-0x80000000, %rax      # imm = 0x80000000
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq $-0x7fffffff, %rax      # imm = 0x80000001
jb 0x66c0
leaq 0x7e4a(%rip), %r13      # 0xe450
xorl %ebp, %ebp
cmpq $0x0, 0x81d0(%rip)      # 0xe7e0
je 0x66b2
cmpl $-0x1, (%r13)
je 0x66b2
callq 0x45f0
movq 0x81b3(%rip), %rdi      # 0xe7e0
movq %r14, %rsi
movl %r15d, %edx
callq 0x47f0
movl %eax, %r12d
movq 0x819e(%rip), %rdi      # 0xe7e0
testl %eax, %eax
jle 0x6684
callq 0x4260
movq %rax, %rdi
movl $0xb, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4110
cmpl $0x1, %eax
je 0x6676
leaq 0x3928(%rip), %rdi      # 0x9f90
leaq 0x38f3(%rip), %rsi      # 0x9f62
xorl %eax, %eax
callq 0x5721
addl %r12d, %ebp
movl %r12d, %eax
addq %rax, %r14
subl %r12d, %r15d
jmp 0x66a9
movl %r12d, %esi
callq 0x4040
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x66dc
leaq 0x393c(%rip), %rdi      # 0x9fd7
leaq 0x38c0(%rip), %rsi      # 0x9f62
xorl %eax, %eax
callq 0x5721
testl %r15d, %r15d
jg 0x6608
movq 0x8(%rsp), %r14
xorl %ebx, %ebx
testl %ebp, %ebp
setle %bl
negl %ebx
movq %r14, %rdi
callq 0x4540
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %eax, %eax
je 0x66e7
movq 0x8(%rsp), %r14
jmp 0x66c0
leaq 0x38bf(%rip), %rsi      # 0x9fad
leaq 0x386d(%rip), %rdx      # 0x9f62
xorl %edi, %edi
jmp 0x6744
leaq 0x3adb(%rip), %rsi      # 0xa1db
leaq 0x385b(%rip), %rdx      # 0x9f62
leaq 0x3861(%rip), %rcx      # 0x9f6f
movl $0x16, %edi
xorl %eax, %eax
callq 0x55ac
callq 0x4050
movl (%rax), %edi
leaq 0x384b(%rip), %rsi      # 0x9f73
leaq 0x3833(%rip), %rdx      # 0x9f62
jmp 0x6744
leaq 0x384c(%rip), %rsi      # 0x9f84
leaq 0x3823(%rip), %rdx      # 0x9f62
movl $0x4b, %edi
xorl %eax, %eax
callq 0x55ac