// File: /workspace/github_c_makefile_star2_O2/rouming[P]io/zmtp.c
// Function: zmtp_expect_msg
static int zmtp_expect_msg(struct zmtp *zmtp, struct io_req *req,
			   bool need_payload, bool *more)
{
	int len;
	uint8_t flags;
	uint64_t size;

	assert(req->buf.iov_num >= 1);
	assert(req->buf.iov_num <= 3);

	assert(req->buf.iov[0].iov_len == 1);
	flags = *(uint8_t *)req->buf.iov[0].iov_base;
	if (flags & ~ZMTP_F_MASK) {
		/* TODO: probably respond with ERROR? */
		len = -EMSGSIZE;
		goto out;
	}
	if (req->buf.iov_num == 1) {
		/* Flag is received, size is required */

		len = zmtp_flags_to_size_len(flags);
		if (len < 0)
			goto out;
		/* Advance position by ourselves */
		req->buf.pos.iov_ind = req->buf.iov_num;
		req->buf.pos.iov_off = 0;
		/* Set length of a next buffer to receive */
		req->buf.iov[req->buf.iov_num].iov_len = len;
		req->buf.iov_num += 1;
		len = 0;
	} else {
		/* Flag+size are received */

		/* Short or long size? */
		if (req->buf.iov[1].iov_len == 1)
			size = *(uint8_t *)req->buf.iov[1].iov_base;
		else if (req->buf.iov[1].iov_len == 8) {
			size = *(uint64_t *)req->buf.iov[1].iov_base;
			size = be64toh(size);
		} else
			assert(0);
		if (size > INT_MAX) {
			/* That is insane */
			len = -EMSGSIZE;
			goto out;
		} else
			len = (int)size;
		if (len == 0) {
			/* Delimiter is received. Rewind a buffer and repeat. */
			zmtp_init_rd_hdr_req(zmtp, req);
		} else {
			if (need_payload && req->buf.iov_num == 2) {
				/* Advance position by ourselves */
				req->buf.pos.iov_ind = req->buf.iov_num;
				req->buf.pos.iov_off = 0;
				/* Set size for a payload */
				req->buf.iov[req->buf.iov_num].iov_len = size;
				req->buf.iov_num += 1;
				len = 0;
			}
			if (more)
				*more = !!(flags & ZMTP_F_MORE);
		}
	}

out:
	return len;
}

// Assembly:
pushq %rax
movq 0x148(%rsi), %r9
testq %r9, %r9
je 0x2193
cmpq $0x4, %r9
jae 0x21b2
cmpq $0x1, 0x30(%rsi)
jne 0x21d1
movq 0x28(%rsi), %rax
movb (%rax), %r8b
pushq $-0x5a
popq %rax
cmpb $0x7, %r8b
ja 0x2191
cmpq $0x1, %r9
jne 0x2111
andq $0x0, 0x130(%rsi)
testb $0x2, %r8b
pushq $0x1
popq %rax
pushq $0x8
popq %rcx
cmoveq %rax, %rcx
movq %rax, 0x128(%rsi)
movq %rcx, 0x40(%rsi)
movq $0x2, 0x148(%rsi)
jmp 0x218f
movq 0x40(%rsi), %r10
cmpq $0x8, %r10
je 0x212f
cmpq $0x1, %r10
jne 0x21f0
movq 0x38(%rsi), %rax
movzbl (%rax), %r10d
jmp 0x2142
movq 0x38(%rsi), %r10
movq (%r10), %r10
bswapq %r10
cmpq $0x7fffffff, %r10       # imm = 0x7FFFFFFF
ja 0x2191
testq %r10, %r10
je 0x218a
cmpq $0x2, %r9
setne %al
xorb $0x1, %dl
orb %al, %dl
movl %r10d, %eax
jne 0x217c
movq $0x2, 0x128(%rsi)
andq $0x0, 0x130(%rsi)
movq %r10, 0x50(%rsi)
movq $0x3, 0x148(%rsi)
xorl %eax, %eax
testq %rcx, %rcx
je 0x2191
andb $0x1, %r8b
movb %r8b, (%rcx)
jmp 0x2191
callq 0x2050
xorl %eax, %eax
popq %rcx
retq
leaq 0x3132(%rip), %rdi      # 0x52cc
leaq 0x30d3(%rip), %rsi      # 0x5274
leaq 0x313a(%rip), %rcx      # 0x52e2
movl $0x113, %edx            # imm = 0x113
callq 0x10d0
leaq 0x316b(%rip), %rdi      # 0x5324
leaq 0x30b4(%rip), %rsi      # 0x5274
leaq 0x311b(%rip), %rcx      # 0x52e2
movl $0x114, %edx            # imm = 0x114
callq 0x10d0
leaq 0x3162(%rip), %rdi      # 0x533a
leaq 0x3095(%rip), %rsi      # 0x5274
leaq 0x30fc(%rip), %rcx      # 0x52e2
movl $0x116, %edx            # imm = 0x116
callq 0x10d0
leaq 0x3434(%rip), %rdi      # 0x562b
leaq 0x3076(%rip), %rsi      # 0x5274
leaq 0x30dd(%rip), %rcx      # 0x52e2
movl $0x134, %edx            # imm = 0x134
callq 0x10d0