// File: /workspace/github_c_makefile_star2_O3/uhlin[P]enhanced-duc/source/network-openssl.c
// Function: net_ssl_recv
int
net_ssl_recv(char *recvbuf, size_t recvbuf_size)
{
	log_assert_arg_nonnull("net_ssl_recv", "recvbuf", recvbuf);

	if (ssl == NULL || g_socket == -1)
		return -1;
	else if (!SSL_pending(ssl)) {
		const int	 maxfdp1 = g_socket + 1;
		fd_set		 readset;
		struct timeval	 tv;

		tv.tv_sec	= 10;
		tv.tv_usec	= 333;

		FD_ZERO(&readset);
		FD_SET(g_socket, &readset);

		errno = 0;

		if (select(maxfdp1, &readset, NULL, NULL, &tv) == -1) {
			log_warn(errno, "%s: select", __func__);
			return -1;
		} else if (!FD_ISSET(g_socket, &readset)) {
			log_warn(0, "%s: no data to receive  --  timed out!",
			    __func__);
			return -1;
		}
	}

	int bytes_received = 0;
	ERR_clear_error();

	if ((bytes_received = SSL_read(ssl, recvbuf, recvbuf_size)) > 0) {
		if (BIO_flush(SSL_get_rbio(ssl)) != 1)
			log_debug("%s: error flushing read bio", __func__);
		return 0;
	}

	switch (SSL_get_error(ssl, bytes_received)) {
	case SSL_ERROR_NONE:
		return 0;
	case SSL_ERROR_WANT_READ:
	case SSL_ERROR_WANT_WRITE:
		log_warn(0, "%s: want read / want write", __func__);
		return 0;
	}

	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
testq %rdi, %rdi
je 0x6931
movq %rdi, %r14
movq 0x8071(%rip), %rdi      # 0xe7e0
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x691c
leaq 0x7ccb(%rip), %rbp      # 0xe450
cmpl $-0x1, (%rbp)
je 0x691c
movq %rsi, %rbx
callq 0x4810
testl %eax, %eax
je 0x67ff
callq 0x45f0
movq 0x8039(%rip), %rdi      # 0xe7e0
movq %r14, %rsi
movl %ebx, %edx
callq 0x4070
movq 0x8028(%rip), %rdi      # 0xe7e0
testl %eax, %eax
jle 0x68c7
callq 0x4600
xorl %r15d, %r15d
movq %rax, %rdi
movl $0xb, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4110
cmpl $0x1, %eax
je 0x691c
leaq 0x3850(%rip), %rdi      # 0xa039
leaq 0x3802(%rip), %rsi      # 0x9ff2
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x5721
jmp 0x691c
movl (%rbp), %ecx
movq %rsp, %rax
movq $0xa, (%rax)
movq $0x14d, 0x8(%rax)       # imm = 0x14D
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r12
movaps %xmm0, (%r12)
movaps %xmm0, 0x10(%r12)
movaps %xmm0, 0x20(%r12)
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x40(%r12)
movaps %xmm0, 0x50(%r12)
movaps %xmm0, 0x60(%r12)
movaps %xmm0, 0x70(%r12)
leal 0x1(%rcx), %r15d
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movl %eax, %edx
andl $-0x40, %edx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x10(%rsp,%rax,8)
callq 0x4050
movq %rax, %r13
movl $0x0, (%rax)
movl %r15d, %edi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rsp, %r8
callq 0x43d0
cmpl $-0x1, %eax
je 0x68fd
movl (%rbp), %eax
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rcx
movq 0x10(%rsp,%rcx,8), %rcx
btq %rax, %rcx
jb 0x679b
leaq 0x3756(%rip), %rsi      # 0xa012
leaq 0x372f(%rip), %rdx      # 0x9ff2
xorl %edi, %edi
jmp 0x690f
movl %eax, %esi
callq 0x4040
movl %eax, %r15d
leal -0x2(%r15), %eax
cmpl $0x2, %eax
jae 0x68f6
leaq 0x36f6(%rip), %rsi      # 0x9fd7
leaq 0x370a(%rip), %rdx      # 0x9ff2
xorl %r15d, %r15d
xorl %edi, %edi
xorl %eax, %eax
callq 0x588f
jmp 0x691c
testl %r15d, %r15d
jne 0x6916
jmp 0x691c
movl (%r13), %edi
leaq 0x36ff(%rip), %rsi      # 0xa007
leaq 0x36e3(%rip), %rdx      # 0x9ff2
xorl %eax, %eax
callq 0x588f
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38a3(%rip), %rsi      # 0xa1db
leaq 0x36b3(%rip), %rdx      # 0x9ff2
leaq 0x36b9(%rip), %rcx      # 0x9fff
movl $0x16, %edi
xorl %eax, %eax
callq 0x55ac