// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/main.c
// Function: peer_recv
static int peer_recv(peer_t* peer)
{
	sock_t sock = peer->conn.sock;
	stream_t* s = &peer->conn.rs;
	char* buffer;
	int buflen, nread;

	buflen = s->cap - s->size;

	/* 2 bytes for length of dns-message, 1 byte for '\0' */
	if (buflen < NS_PAYLOAD_SIZE + 3) {
		if (stream_set_cap(s, s->size + NS_PAYLOAD_SIZE + 3)) {
			return -1;
		}
		buflen = s->cap - s->size - 1; /* reserve 1 bytes for '\0' */
	}

	buffer = s->array + s->size;

	nread = tcp_recv(sock, buffer, buflen);

	if (nread == -1)
		return -1;

	if (nread == 0)
		return 0;

	s->size += nread;

	s->array[s->size] = '\0'; /* so we can print as string */

	peer->conn.rx += nread;

	logv("server  recv %d bytes - %s \tproto:tcp\n",
		nread, get_sockname(peer->conn.sock));

	if (loglevel > LOG_DEBUG) {
		bprint(buffer, nread);
	}

	if (peer_handle_recv(peer)) {
		return -1;
	}

	update_expire(&peer->conn);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x20(%rbp), %rcx
subl 0x8(%rcx), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x403, -0x2c(%rbp)     # imm = 0x403
jge 0x31bd9
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %esi
addl $0x400, %esi            # imm = 0x400
addl $0x3, %esi
callq 0x2d900
cmpl $0x0, %eax
je 0x31bc5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x31cf3
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x20(%rbp), %rcx
subl 0x8(%rcx), %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movslq 0x8(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %edi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x26730
movl %eax, -0x30(%rbp)
cmpl $-0x1, -0x30(%rbp)
jne 0x31c13
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x31cf3
cmpl $0x0, -0x30(%rbp)
jne 0x31c25
movl $0x0, -0x4(%rbp)
jmp 0x31cf3
movl -0x30(%rbp), %ecx
movq -0x20(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movslq 0x8(%rcx), %rcx
movb $0x0, (%rax,%rcx)
movslq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x58(%rax), %rcx
movq %rcx, 0x58(%rax)
movb $0x0, %al
callq 0x242d0
cmpl $0x8, (%rax)
jl 0x31ca0
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
callq 0x25120
movl -0x34(%rbp), %r9d
movl $0x8, %edi
leaq 0x6f40(%rip), %rsi      # 0x38bc2
leaq 0x7ea9(%rip), %rdx      # 0x39b32
movl $0x31e, %ecx            # imm = 0x31E
leaq 0x7ea7(%rip), %r8       # 0x39b3c
movq %rax, (%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x31ca2
movb $0x0, %al
callq 0x242d0
cmpl $0x7, (%rax)
jle 0x31ccc
jmp 0x31cb0
movb $0x0, %al
callq 0x242d0
cmpl $0x7, (%rax)
jl 0x31cc8
movq -0x28(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x2e3d0
jmp 0x31cca
jmp 0x31ccc
movq -0x10(%rbp), %rdi
callq 0x332b0
cmpl $0x0, %eax
je 0x31ce3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x31cf3
movq -0x10(%rbp), %rdi
callq 0x32040
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)