// File: /workspace/github_c_makefile_star2_O2/GangZhuo[P]dohclient/src/http.c
// Function: http_conn_recv
static int http_conn_recv(http_conn_t* conn)
{
	stream_t* s = &conn->conn.rs;
	char* buffer;
	int buflen, nread;
	size_t nparsed;

	if (s->cap < 8*1024) {
		if (stream_set_cap(s, 8 * 1024)) {
			return -1;
		}
	}

	buffer = s->array;
	buflen = s->cap;

	nread = SSL_read(conn->ssl, buffer, buflen);

	if (nread <= 0) {
		int err = SSL_get_error(conn->ssl, nread);
		if (err == SSL_ERROR_WANT_READ) {
			conn->ssl_status = SSL_ERROR_WANT_READ;
			return 0;
		}
		else if (err == SSL_ERROR_WANT_WRITE) {
			conn->ssl_status = SSL_ERROR_WANT_WRITE;
			return 0;
		}
		else {
			if (conn->status != HTTP_CONN_ST_IDLE) {
				loge("errno=%d, %s - %s\n",
					err, http_ssl_errstr(err),
					conn->tag ? conn->tag : "");
				if (err == SSL_ERROR_SYSCALL) {
					while ((err = ERR_get_error()) != 0) {
						loge("errno=%d, %s - %s\n",
							err, ERR_error_string(err, NULL),
							conn->tag ? conn->tag : "");
					}
				}
			}
			return -1;
		}
	}
	else {
		conn->ssl_status = 0;

		logv("recv %d bytes\n", nread);

		http_update_expire(conn);

		nparsed = http_parser_execute(&conn->parser, &parser_settings, s->array, nread);

		if (nparsed <= 0) {
			loge("%s - %s\n",
					http_errno_name(conn->parser.http_errno),
					conn->tag ? conn->tag : "");
			return -1;
		}

		return nread;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x28(%rdi), %edx
pushq $-0x1
popq %r14
cmpl $0x1fff, %edx           # imm = 0x1FFF
jg 0x15e8c
leaq 0x18(%rbx), %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x1b9d4
testl %eax, %eax
jne 0x1607f
movl 0x28(%rbx), %edx
movq 0x18(%rbx), %rsi
movq 0x78(%rbx), %rdi
callq 0x3060
movl %eax, %ebp
testl %eax, %eax
jle 0x15f6f
andl $0x0, 0x80(%rbx)
xorl %eax, %eax
callq 0x165f5
cmpl $0x8, (%rax)
jl 0x15edd
leaq 0xbe77(%rip), %rsi      # 0x21d34
leaq 0xc2cf(%rip), %rdx      # 0x22193
leaq 0xc2d7(%rip), %r8       # 0x221a2
pushq $0x8
popq %rdi
movl $0x5c6, %ecx            # imm = 0x5C6
movl %ebp, %r9d
xorl %eax, %eax
callq 0x1662e
movq %rbx, %rdi
callq 0x1610e
leaq 0xb0(%rbx), %rdi
movq 0x18(%rbx), %rdx
movl %ebp, %ecx
leaq 0x186d7(%rip), %rsi     # 0x2e5d0
callq 0x3e90
testq %rax, %rax
jne 0x16082
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x1607f
movzbl 0xc7(%rbx), %edi
andl $0x7f, %edi
callq 0x761a
movq 0x128(%rbx), %rcx
testq %rcx, %rcx
leaq 0xbec7(%rip), %r10      # 0x21dfe
cmovneq %rcx, %r10
subq $0x8, %rsp
leaq 0xbdee(%rip), %rsi      # 0x21d34
leaq 0xc246(%rip), %rdx      # 0x22193
leaq 0xb724(%rip), %r8       # 0x21678
pushq $0x3
popq %rdi
movl $0x5cf, %ecx            # imm = 0x5CF
movq %rax, %r9
xorl %eax, %eax
pushq %r10
callq 0x1662e
popq %rax
popq %rcx
jmp 0x1607f
movq 0x78(%rbx), %rdi
movl %ebp, %esi
callq 0x3030
cmpl $0x3, %eax
je 0x15f92
movl %eax, %ebp
cmpl $0x2, %eax
jne 0x15fa3
movl $0x2, 0x80(%rbx)
jmp 0x15f9c
movl $0x3, 0x80(%rbx)
xorl %ebp, %ebp
jmp 0x16082
cmpl $0x2, 0x84(%rbx)
je 0x1607f
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x16008
movl %ebp, %edi
callq 0x160f0
movq %rax, %r10
movq 0x128(%rbx), %rax
testq %rax, %rax
leaq 0xbe27(%rip), %r11      # 0x21dfe
cmovneq %rax, %r11
leaq 0xbd52(%rip), %rsi      # 0x21d34
leaq 0xc1aa(%rip), %rdx      # 0x22193
leaq 0xb67e(%rip), %r8       # 0x2166e
pushq $0x3
popq %rdi
movl $0x5b7, %ecx            # imm = 0x5B7
movl %ebp, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x1662e
popq %rax
popq %rcx
cmpl $0x5, %ebp
jne 0x1607f
leaq 0xc17f(%rip), %r15      # 0x22193
leaq 0xb653(%rip), %r12      # 0x2166e
pushq $0x3
popq %rbp
callq 0x34b0
movq %rax, %r13
testl %r13d, %r13d
je 0x1607f
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x1601e
movslq %r13d, %rdi
xorl %esi, %esi
callq 0x3120
movq %rax, %r10
movq 0x128(%rbx), %r11
testq %r11, %r11
leaq 0xbda9(%rip), %rax      # 0x21dfe
cmoveq %rax, %r11
movl %ebp, %edi
leaq 0xbcd2(%rip), %rsi      # 0x21d34
movq %r15, %rdx
movl $0x5bc, %ecx            # imm = 0x5BC
movq %r12, %r8
movl %r13d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x1662e
popq %rax
popq %rcx
jmp 0x1601e
movl %r14d, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq