// File: /workspace/github_c_makefile_star2_O1/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, %r14
cmpl $0x1fff, 0x28(%rdi)     # imm = 0x1FFF
jg 0x174c7
leaq 0x18(%r14), %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x1d737
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x175f9
movq 0x18(%r14), %rsi
movl 0x28(%r14), %edx
movq 0x78(%r14), %rdi
callq 0x3060
movl %eax, %ebx
testl %eax, %eax
jle 0x175c8
movl $0x0, 0x80(%r14)
xorl %eax, %eax
callq 0x17d59
cmpl $0x8, (%rax)
jl 0x17522
leaq 0xc828(%rip), %rsi      # 0x23d28
leaq 0xcc80(%rip), %rdx      # 0x24187
leaq 0xcc88(%rip), %r8       # 0x24196
movl $0x8, %edi
movl $0x5c6, %ecx            # imm = 0x5C6
movl %ebx, %r9d
xorl %eax, %eax
callq 0x17d92
movq (%r14), %r15
xorl %edi, %edi
callq 0x3310
movslq 0x1c(%r15), %rcx
addq %rax, %rcx
movq %rcx, 0x60(%r14)
leaq 0xb0(%r14), %rdi
movq 0x18(%r14), %rdx
movl %ebx, %ecx
leaq 0x16075(%rip), %rsi     # 0x2d5c0
callq 0x3efc
testq %rax, %rax
jne 0x175f9
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x175f9
movzbl 0xc7(%r14), %edi
andl $0x7f, %edi
callq 0x7bc5
movq 0x128(%r14), %rcx
testq %rcx, %rcx
leaq 0xc863(%rip), %r10      # 0x23df2
cmovneq %rcx, %r10
subq $0x8, %rsp
leaq 0xc78a(%rip), %rsi      # 0x23d28
leaq 0xcbe2(%rip), %rdx      # 0x24187
leaq 0xc0bc(%rip), %r8       # 0x23668
movl $0x3, %edi
movl $0x5cf, %ecx            # imm = 0x5CF
movq %rax, %r9
xorl %eax, %eax
pushq %r10
callq 0x17d92
addq $0x10, %rsp
jmp 0x175f9
movq 0x78(%r14), %rdi
movl %ebx, %esi
callq 0x3030
cmpl $0x3, %eax
je 0x175ec
movl %eax, %ebp
cmpl $0x2, %eax
jne 0x1760a
movl $0x2, 0x80(%r14)
jmp 0x175f7
movl $0x3, 0x80(%r14)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x2, 0x84(%r14)
je 0x175f9
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x17675
movl %ebp, %edi
callq 0x1776e
movq %rax, %r10
movq 0x128(%r14), %rax
testq %rax, %rax
leaq 0xc7b2(%rip), %r11      # 0x23df2
cmovneq %rax, %r11
leaq 0xc6dd(%rip), %rsi      # 0x23d28
leaq 0xcb35(%rip), %rdx      # 0x24187
leaq 0xc005(%rip), %r8       # 0x2365e
movl $0x3, %edi
movl $0x5b7, %ecx            # imm = 0x5B7
movl %ebp, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x17d92
addq $0x10, %rsp
cmpl $0x5, %ebp
jne 0x175f9
callq 0x34a0
movq %rax, %rbp
testl %ebp, %ebp
je 0x175f9
leaq 0xc693(%rip), %r15      # 0x23d28
leaq 0xcaeb(%rip), %r12      # 0x24187
leaq 0xbfbb(%rip), %r13      # 0x2365e
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x176f6
movslq %ebp, %rdi
xorl %esi, %esi
callq 0x3120
movq %rax, %r10
movq 0x128(%r14), %r11
testq %r11, %r11
leaq 0xc725(%rip), %rax      # 0x23df2
cmoveq %rax, %r11
movl $0x3, %edi
movq %r15, %rsi
movq %r12, %rdx
movl $0x5bc, %ecx            # imm = 0x5BC
movq %r13, %r8
movl %ebp, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x17d92
addq $0x10, %rsp
callq 0x34a0
movq %rax, %rbp
testl %ebp, %ebp
jne 0x176a3
jmp 0x175f9