// File: /workspace/github_c_makefile_star2_O1/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 0x65f8
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 0x67b8
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 0x64cc
testl %eax, %eax
js 0x67d9
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x41c0
movq %rax, %r14
addq $0x5, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x894d
movq %rax, 0x8(%rsp)
leaq 0x3c74(%rip), %rsi      # 0xa2e8
movq %rax, %rdi
movq %r14, %rdx
callq 0x8344
cmpq %r14, %rax
jae 0x67f0
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x41c0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
ja 0x6795
movq %rax, %r14
testq %rax, %rax
je 0x6790
leaq 0x7d97(%rip), %r15      # 0xe450
leaq 0x38a2(%rip), %r12      # 0x9f62
xorl %r13d, %r13d
cmpq $0x0, 0x8115(%rip)      # 0xe7e0
je 0x6785
cmpl $-0x1, (%r15)
je 0x6785
callq 0x45f0
movq 0x80f9(%rip), %rdi      # 0xe7e0
movq %rbx, %rsi
movl %r14d, %edx
callq 0x47f0
movl %eax, %ebp
movq 0x80e5(%rip), %rdi      # 0xe7e0
testl %eax, %eax
jle 0x673a
callq 0x4260
movq %rax, %rdi
movl $0xb, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4110
cmpl $0x1, %eax
je 0x672b
leaq 0x386f(%rip), %rdi      # 0x9f90
movq %r12, %rsi
xorl %eax, %eax
callq 0x57b1
addl %ebp, %r13d
movl %ebp, %eax
addq %rax, %rbx
subl %ebp, %r14d
xorl %eax, %eax
jmp 0x6778
movl %ebp, %esi
callq 0x4040
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x6761
leaq 0x3887(%rip), %rdi      # 0x9fd7
movq %r12, %rsi
xorl %eax, %eax
callq 0x57b1
movl $0x2, %eax
jmp 0x6778
testl %eax, %eax
je 0x6805
movq 0x8(%rsp), %rdi
callq 0x4540
movl $0x1, %eax
testb $0x1, %al
jne 0x67b1
testl %r14d, %r14d
jg 0x66c3
xorl %ebp, %ebp
testl %r13d, %r13d
setle %bpl
negl %ebp
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x4540
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x679d
leaq 0x3a1c(%rip), %rsi      # 0xa1db
leaq 0x379c(%rip), %rdx      # 0x9f62
leaq 0x37a2(%rip), %rcx      # 0x9f6f
movl $0x16, %edi
xorl %eax, %eax
callq 0x563c
callq 0x4050
movl (%rax), %edi
leaq 0x378c(%rip), %rsi      # 0x9f73
leaq 0x3774(%rip), %rdx      # 0x9f62
jmp 0x6815
leaq 0x378d(%rip), %rsi      # 0x9f84
leaq 0x3764(%rip), %rdx      # 0x9f62
movl $0x4b, %edi
jmp 0x6815
leaq 0x37a1(%rip), %rsi      # 0x9fad
leaq 0x374f(%rip), %rdx      # 0x9f62
xorl %edi, %edi
xorl %eax, %eax
callq 0x563c