// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/ns_msg.c
// Function: ns_parse_ect
ns_ecs_t* ns_parse_ect(ns_ecs_t *ecs, char *data, int len)
{
	int addrlen, i;
	stream_t ns = STREAM_INIT();
	ns.array = data;
	ns.cap = len;
	ns.size = len;
	ns.pos = 0;

#define check_size(n) \
        if (stream_rsize(&ns) < (n)) { \
            return NULL; \
        }

	memset(ecs, 0, sizeof(ns_ecs_t));

	check_size(2);
	ecs->family = stream_readi16(&ns);
	check_size(2);
	ecs->src_prefix_len = stream_readi8(&ns);
	ecs->scope_prefix_len = stream_readi8(&ns);

	addrlen = ecs->src_prefix_len / 8;
	if (ecs->src_prefix_len % 8)
		addrlen++;

	if (ecs->family == ADDR_FAMILY_NUM_IP) {
		if (addrlen > 4) {
			/* invalid src_prefix_len */
			return NULL;
		}
	}
	else if (ecs->family == ADDR_FAMILY_NUM_IP6) {
		if (addrlen > 16) {
			/* invalid src_prefix_len */
			return NULL;
		}
	}
	else {
		/* invalid family */
		return NULL;
	}

	check_size(addrlen);

	for (i = 0; i < addrlen; i++) {
		((uint8_t *)(&ecs->subnet))[i] = stream_readi8(&ns);
	}

#undef check_size

	return ecs;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3200
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x3200
movl -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
cmpl $0x2, %eax
jge 0x2a556
movq $0x0, -0x8(%rbp)
jmp 0x2a680
leaq -0x40(%rbp), %rdi
movl $0x2, %esi
callq 0x2e340
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, (%rax)
movl -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
cmpl $0x2, %eax
jge 0x2a586
movq $0x0, -0x8(%rbp)
jmp 0x2a680
leaq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x2e340
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2(%rax)
leaq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x2e340
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x2a5e5
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0x2a603
cmpl $0x4, -0x20(%rbp)
jle 0x2a601
movq $0x0, -0x8(%rbp)
jmp 0x2a680
jmp 0x2a62d
movq -0x10(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0x2a621
cmpl $0x10, -0x20(%rbp)
jle 0x2a61f
movq $0x0, -0x8(%rbp)
jmp 0x2a680
jmp 0x2a62b
movq $0x0, -0x8(%rbp)
jmp 0x2a680
jmp 0x2a62d
movl -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x2a642
movq $0x0, -0x8(%rbp)
jmp 0x2a680
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x2a678
leaq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x2e340
movb %al, %dl
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb %dl, 0x4(%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2a649
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)