// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../lib/wire/wire_readpacket.c
// Function: wire_readpacket_peek
int
wire_readpacket_peek(struct netbuf_read * R, struct wire_packet * P)
{
	CRC32C_CTX ctx;
	uint8_t * data;
	size_t datalen;
	uint8_t cbuf[4];
	size_t i;

	/* No packet data yet. */
	P->buf = NULL;

	/* Ask the buffered reader what it has. */
	netbuf_read_peek(R, &data, &datalen);

	/* If we have less than 20 bytes, we don't have a complete packet. */
	if (datalen < 20)
		goto nopacket;

	/* Verify the header checksum. */
	CRC32C_Init(&ctx);
	CRC32C_Update(&ctx, data, 12);
	CRC32C_Final(cbuf, &ctx);
	if (memcmp(&data[12], cbuf, 4)) {
		warn0("Incorrect CRC on packet header");
		goto failed;
	}

	/* Parse ID and length. */
	P->ID = be64dec(&data[0]);
	P->len = be32dec(&data[8]);

	/* Make sure the length is reasonable. */
	if (P->len > SIZE_MAX - 20)
		goto failed;

	/* Do we have the complete packet? */
	if (datalen < P->len + 20)
		goto nopacket;

	/* Verify the data checksum. */
	CRC32C_Init(&ctx);
	CRC32C_Update(&ctx, &data[16], P->len);
	CRC32C_Final(cbuf, &ctx);
	for (i = 0; i < 4; i++)
		cbuf[i] ^= data[16 + P->len + i];
	if (memcmp(&data[12], cbuf, 4)) {
		warn0("Incorrect CRC on packet data");
		goto failed;
	}

	/* Point at the data. */
	P->buf = &data[16];

nopacket:
	/* Success! */
	return (0);

failed:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0xb6a0
cmpq $0x14, -0x30(%rbp)
jae 0xd259
jmp 0xd3d1
leaq -0x1c(%rbp), %rdi
callq 0x9ff0
movq -0x28(%rbp), %rsi
leaq -0x1c(%rbp), %rdi
movl $0xc, %edx
callq 0xa190
leaq -0x34(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xa300
movq -0x28(%rbp), %rax
addq $0xc, %rax
leaq -0x34(%rbp), %rcx
movl (%rcx), %ecx
movl (%rax), %eax
subl %ecx, %eax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xd2be
jmp 0xd2a0
leaq 0x3476(%rip), %rdi      # 0x1071d
movb $0x0, %al
callq 0x6a10
callq 0x20a0
movl $0x0, (%rax)
jmp 0xd3da
movq -0x28(%rbp), %rdi
callq 0xd3f0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0xd480
movl %eax, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $-0x15, 0x8(%rax)
jbe 0xd2fa
jmp 0xd3da
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $0x14, %rcx
cmpq %rcx, %rax
jae 0xd314
jmp 0xd3d1
leaq -0x1c(%rbp), %rdi
callq 0x9ff0
movq -0x28(%rbp), %rsi
addq $0x10, %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x1c(%rbp), %rdi
callq 0xa190
leaq -0x34(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xa300
movq $0x0, -0x40(%rbp)
cmpq $0x4, -0x40(%rbp)
jae 0xd387
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $0x10, %rcx
addq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %edx
movq -0x40(%rbp), %rax
movzbl -0x34(%rbp,%rax), %ecx
xorl %edx, %ecx
movb %cl, -0x34(%rbp,%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xd34b
movq -0x28(%rbp), %rax
addq $0xc, %rax
leaq -0x34(%rbp), %rcx
movl (%rcx), %ecx
movl (%rax), %eax
subl %ecx, %eax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xd3c1
jmp 0xd3a6
leaq 0x338f(%rip), %rdi      # 0x1073c
movb $0x0, %al
callq 0x6a10
callq 0x20a0
movl $0x0, (%rax)
jmp 0xd3da
movq -0x28(%rbp), %rcx
addq $0x10, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
jmp 0xd3e1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)