// File: /workspace/github_c_makefile_star2_O3/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
cmpl $0x1fff, %edx           # imm = 0x1FFF
jg 0x16e6a
leaq 0x18(%rbx), %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x1cf07
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x16f95
movl 0x28(%rbx), %edx
movq 0x18(%rbx), %rsi
movq 0x78(%rbx), %rdi
callq 0x3060
movl %eax, %ebp
testl %eax, %eax
jle 0x16f65
movl $0x0, 0x80(%rbx)
xorl %eax, %eax
callq 0x176e5
cmpl $0x8, (%rax)
jl 0x16ec0
leaq 0xce96(%rip), %rsi      # 0x23d34
leaq 0xd2ee(%rip), %rdx      # 0x24193
leaq 0xd2f6(%rip), %r8       # 0x241a2
movl $0x8, %edi
movl $0x5c6, %ecx            # imm = 0x5C6
movl %ebp, %r9d
xorl %eax, %eax
callq 0x1771e
movq (%rbx), %r14
xorl %edi, %edi
callq 0x3310
movslq 0x1c(%r14), %rcx
addq %rax, %rcx
movq %rcx, 0x60(%rbx)
leaq 0xb0(%rbx), %rdi
movq 0x18(%rbx), %rdx
movl %ebp, %ecx
leaq 0x166d7(%rip), %rsi     # 0x2d5c0
callq 0x407c
testq %rax, %rax
jne 0x16f95
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x16f95
movzbl 0xc7(%rbx), %edi
andl $0x7f, %edi
callq 0x7911
movq 0x128(%rbx), %rcx
testq %rcx, %rcx
leaq 0xced2(%rip), %r10      # 0x23dfe
cmovneq %rcx, %r10
subq $0x8, %rsp
leaq 0xcdf9(%rip), %rsi      # 0x23d34
leaq 0xd251(%rip), %rdx      # 0x24193
leaq 0xc72f(%rip), %r8       # 0x23678
movl $0x3, %edi
movl $0x5cf, %ecx            # imm = 0x5CF
movq %rax, %r9
xorl %eax, %eax
pushq %r10
callq 0x1771e
addq $0x10, %rsp
jmp 0x16f95
movq 0x78(%rbx), %rdi
movl %ebp, %esi
callq 0x3030
cmpl $0x3, %eax
je 0x16f89
movl %eax, %r14d
cmpl $0x2, %eax
jne 0x16fa6
movl $0x2, 0x80(%rbx)
jmp 0x16f93
movl $0x3, 0x80(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, 0x84(%rbx)
je 0x16f95
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x17011
movl %r14d, %edi
callq 0x17106
movq %rax, %r10
movq 0x128(%rbx), %rax
testq %rax, %rax
leaq 0xce22(%rip), %r11      # 0x23dfe
cmovneq %rax, %r11
leaq 0xcd4d(%rip), %rsi      # 0x23d34
leaq 0xd1a5(%rip), %rdx      # 0x24193
leaq 0xc679(%rip), %r8       # 0x2366e
movl $0x3, %edi
movl $0x5b7, %ecx            # imm = 0x5B7
movl %r14d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x1771e
addq $0x10, %rsp
cmpl $0x5, %r14d
jne 0x16f95
callq 0x34a0
movq %rax, %r13
testl %r13d, %r13d
je 0x16f95
leaq 0xcd01(%rip), %r14      # 0x23d34
leaq 0xd159(%rip), %r15      # 0x24193
leaq 0xc62d(%rip), %r12      # 0x2366e
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x17094
movslq %r13d, %rdi
xorl %esi, %esi
callq 0x3120
movq %rax, %r10
movq 0x128(%rbx), %r11
testq %r11, %r11
leaq 0xcd93(%rip), %rax      # 0x23dfe
cmoveq %rax, %r11
movl $0x3, %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x5bc, %ecx            # imm = 0x5BC
movq %r12, %r8
movl %r13d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x1771e
addq $0x10, %rsp
callq 0x34a0
movq %rax, %r13
testl %r13d, %r13d
jne 0x17041
jmp 0x16f95