// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/ns_msg.c
// Function: ns_read_cstring
static int ns_read_cstring(stream_t *dst, stream_t *s)
{
	int spos = s->pos, dpos = dst->pos, len;

#define do_return(r) \
	s->pos = spos; \
	dst->pos = dpos; \
	return (r);

#define check_len(n) \
	if (stream_rsize(s) < (n)) { \
		loge("truncated stream\n"); \
		do_return(-1); \
	}

	check_len(1);
	len = stream_readi8(s);

	check_len(len);
	if (stream_writess(dst, s, len) != len) {
		loge("write stream\n");
		do_return(-1);
	}

	if (stream_writei8(dst, 0) != 1) {
		loge("write stream\n");
		do_return(-1);
	}

	stream_seek(dst, -1, SEEK_CUR);


#undef check_len
#undef do_return

	return dst->pos - dpos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0xc(%rcx), %eax
cmpl $0x1, %eax
jge 0x2bcbd
jmp 0x2bc69
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x2bc9b
movl $0x3, %edi
leaq 0xc793(%rip), %rsi      # 0x38414
leaq 0xcb38(%rip), %rdx      # 0x387c0
movl $0x24e, %ecx            # imm = 0x24E
leaq 0xc7e9(%rip), %r8       # 0x3847d
movb $0x0, %al
callq 0x243b0
jmp 0x2bc9d
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2be2a
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x2e340
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0xc(%rcx), %eax
cmpl -0x24(%rbp), %eax
jge 0x2bd37
jmp 0x2bce3
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x2bd15
movl $0x3, %edi
leaq 0xc719(%rip), %rsi      # 0x38414
leaq 0xcabe(%rip), %rdx      # 0x387c0
movl $0x251, %ecx            # imm = 0x251
leaq 0xc76f(%rip), %r8       # 0x3847d
movb $0x0, %al
callq 0x243b0
jmp 0x2bd17
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2be2a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x2db40
cmpl -0x24(%rbp), %eax
je 0x2bda2
jmp 0x2bd4e
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x2bd80
movl $0x3, %edi
leaq 0xc6ae(%rip), %rsi      # 0x38414
leaq 0xca53(%rip), %rdx      # 0x387c0
movl $0x253, %ecx            # imm = 0x253
leaq 0xca39(%rip), %r8       # 0x387b2
movb $0x0, %al
callq 0x243b0
jmp 0x2bd82
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2be2a
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x2dc90
cmpl $0x1, %eax
je 0x2be0a
jmp 0x2bdb9
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x2bdeb
movl $0x3, %edi
leaq 0xc643(%rip), %rsi      # 0x38414
leaq 0xc9e8(%rip), %rdx      # 0x387c0
movl $0x258, %ecx            # imm = 0x258
leaq 0xc9ce(%rip), %r8       # 0x387b2
movb $0x0, %al
callq 0x243b0
jmp 0x2bded
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2be2a
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x2d6a0
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)