// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x38fd(%rip), %rdi      # 0xa012
leaq 0x3903(%rip), %rsi      # 0xa01f
movq %r14, %rdx
callq 0x66c3
movq 0x80b5(%rip), %rdi      # 0xe7e0
pushq $-0x1
popq %r12
testq %rdi, %rdi
je 0x6896
leaq 0x7d11(%rip), %r13      # 0xe450
cmpl $-0x1, (%r13)
je 0x6896
callq 0x4800
testl %eax, %eax
je 0x67b3
callq 0x45e0
movq 0x8081(%rip), %rdi      # 0xe7e0
movq %r14, %rsi
movl %ebx, %edx
callq 0x4070
movq 0x8070(%rip), %rdi      # 0xe7e0
testl %eax, %eax
jle 0x684c
callq 0x45f0
xorl %ebx, %ebx
pushq $0xb
popq %rsi
movq %rax, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4110
cmpl $0x1, %eax
je 0x6899
leaq 0x38bb(%rip), %rdi      # 0xa059
leaq 0x386d(%rip), %rsi      # 0xa012
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5684
jmp 0x6899
movl (%r13), %ecx
movq $0xa, 0x8(%rsp)
movq $0x14d, 0x10(%rsp)      # imm = 0x14D
xorl %eax, %eax
cmpq $0x10, %rax
je 0x67dc
andq $0x0, 0x18(%rsp,%rax,8)
incq %rax
jmp 0x67cb
leal 0x1(%rcx), %ebp
pushq $0x40
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
movslq %eax, %rdx
shll $0x6, %eax
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, 0x18(%rsp,%rdx,8)
callq 0x4050
movq %rax, %r15
andl $0x0, (%rax)
leaq 0x18(%rsp), %rsi
leaq 0x8(%rsp), %r8
movl %ebp, %edi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x43d0
cmpl $-0x1, %eax
je 0x687e
movl (%r13), %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
cltq
movq 0x18(%rsp,%rax,8), %rax
btq %rdx, %rax
jb 0x6753
leaq 0x37f1(%rip), %rsi      # 0xa032
leaq 0x37ca(%rip), %rdx      # 0xa012
xorl %edi, %edi
jmp 0x688f
movl %eax, %esi
callq 0x4040
movl %eax, %ebx
leal -0x2(%rbx), %eax
cmpl $0x2, %eax
jae 0x6878
leaq 0x3793(%rip), %rsi      # 0x9ff7
leaq 0x37a7(%rip), %rdx      # 0xa012
xorl %ebx, %ebx
xorl %edi, %edi
xorl %eax, %eax
callq 0x57ea
jmp 0x6899
testl %ebx, %ebx
jne 0x6896
jmp 0x6899
movl (%r15), %edi
leaq 0x379f(%rip), %rsi      # 0xa027
leaq 0x3783(%rip), %rdx      # 0xa012
xorl %eax, %eax
callq 0x57ea
movl %r12d, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq