// File: /workspace/github_c_makefile_star2_O2/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 %rdi, %rbx
leaq 0x30(%rsp), %r15
movq %rsi, 0x8(%r15)
movq %rdx, 0x10(%r15)
movq %rcx, 0x18(%r15)
movq %r8, 0x20(%r15)
movq %r9, 0x28(%r15)
testb %al, %al
je 0x64d9
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 %rsp, %r14
andq $0x0, (%r14)
leaq 0x3a9b(%rip), %rdi      # 0x9f82
leaq 0x3aa1(%rip), %rsi      # 0x9f8f
movq %rbx, %rdx
callq 0x66c3
leaq 0x10(%rsp), %rdx
movq %r15, 0x10(%rdx)
leaq 0x120(%rsp), %rax
movq %rax, 0x8(%rdx)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%rdx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x63b0
testl %eax, %eax
js 0x6694
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x41c0
movq %rax, %r14
addq $0x5, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8652
movq %rax, (%rsp)
leaq 0x3dcf(%rip), %rsi      # 0xa323
movq %rax, %rdi
movq %r14, %rdx
callq 0x80a0
cmpq %r14, %rax
jae 0x66ab
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x41c0
testq $-0x80000000, %rax      # imm = 0x80000000
je 0x658c
movq %rbx, %rdi
callq 0x4530
pushq $-0x1
popq %rax
jmp 0x6663
movq %rax, %r14
leaq 0x7eba(%rip), %rbp      # 0xe450
leaq 0x39e5(%rip), %r12      # 0x9f82
leaq 0x3a53(%rip), %r13      # 0x9ff7
movl $0x0, 0xc(%rsp)
testl %r14d, %r14d
jle 0x664e
cmpq $0x0, 0x8223(%rip)      # 0xe7e0
je 0x664e
cmpl $-0x1, (%rbp)
je 0x664e
callq 0x45e0
movq 0x8207(%rip), %rdi      # 0xe7e0
movq %rbx, %rsi
movl %r14d, %edx
callq 0x47e0
movl %eax, %r15d
movq 0x81f2(%rip), %rdi      # 0xe7e0
testl %eax, %eax
jg 0x6611
movl %r15d, %esi
callq 0x4040
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x6675
movq %r13, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x5684
jmp 0x65ac
callq 0x4260
movq %rax, %rdi
pushq $0xb
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4110
cmpl $0x1, %eax
je 0x663b
leaq 0x397f(%rip), %rdi      # 0x9fb0
movq %r12, %rsi
xorl %eax, %eax
callq 0x5684
addl %r15d, 0xc(%rsp)
movl %r15d, %eax
addq %rax, %rbx
subl %r15d, %r14d
jmp 0x65ac
movq (%rsp), %rdi
callq 0x4530
xorl %eax, %eax
cmpl $0x0, 0xc(%rsp)
setle %al
negl %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %eax, %eax
je 0x6682
movq (%rsp), %rdi
jmp 0x657f
leaq 0x3944(%rip), %rsi      # 0x9fcd
leaq 0x38f2(%rip), %rdx      # 0x9f82
xorl %edi, %edi
jmp 0x66bc
callq 0x4050
movl (%rax), %edi
leaq 0x38f1(%rip), %rsi      # 0x9f93
leaq 0x38d9(%rip), %rdx      # 0x9f82
jmp 0x66bc
leaq 0x38f2(%rip), %rsi      # 0x9fa4
leaq 0x38c9(%rip), %rdx      # 0x9f82
pushq $0x4b
popq %rdi
xorl %eax, %eax
callq 0x5513