// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/ns_msg.c
// Function: ns_set_ecs6
static int ns_set_ecs6(ns_opt_t* opt, struct sockaddr_in6* addr, int srcprefix, int scopeprefix)
{
	stream_t s = STREAM_INIT();
	uint8_t* optdata;
	int addrlen;
	uint8_t saddr[16];
	uint8_t mask = 0xff;

	addrlen = srcprefix / 8;
	if (srcprefix % 8)
		addrlen++;

	if (addrlen > 16)
		addrlen = 16;

	optdata = realloc(opt->data, 4 + addrlen);
	if (optdata == NULL) {
		return -1;
	}

	memcpy(saddr, addr->sin6_addr.s6_addr, 16);

	if (srcprefix % 8) {
		mask <<= (8 - (srcprefix % 8));
		saddr[addrlen - 1] &= mask;
	}

	opt->length = 4 + addrlen;
	opt->data = optdata;
	s.array = opt->data;
	s.cap = opt->length;
	if (stream_writei16(&s, ADDR_FAMILY_NUM_IP6) != 2)
		return -1;
	if (stream_writei8(&s, srcprefix) != 1)
		return -1;
	if (stream_writei8(&s, scopeprefix) != 1)
		return -1;
	if (stream_write(&s, (const char*)saddr, addrlen) != addrlen)
		return -1;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3200
movb $-0x1, -0x61(%rbp)
movl -0x1c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, -0x44(%rbp)
movl -0x1c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x29cb1
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x10, -0x44(%rbp)
jle 0x29cbe
movl $0x10, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x44(%rbp), %eax
addl $0x4, %eax
movslq %eax, %rsi
callq 0x35c0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x29ceb
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x29df6
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq %rcx, -0x60(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x1c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x29d41
movl -0x1c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl $0x8, %ecx
subl %edx, %ecx
movzbl -0x61(%rbp), %eax
shll %cl, %eax
movb %al, -0x61(%rbp)
movzbl -0x61(%rbp), %edx
movl -0x44(%rbp), %eax
subl $0x1, %eax
cltq
movzbl -0x60(%rbp,%rax), %ecx
andl %edx, %ecx
movb %cl, -0x60(%rbp,%rax)
movl -0x44(%rbp), %eax
addl $0x4, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x2(%rax), %eax
movl %eax, -0x28(%rbp)
leaq -0x38(%rbp), %rdi
movl $0x2, %edx
movl %edx, %esi
callq 0x2dc90
cmpl $0x2, %eax
je 0x29d93
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x29df6
movl -0x1c(%rbp), %esi
leaq -0x38(%rbp), %rdi
movl $0x1, %edx
callq 0x2dc90
cmpl $0x1, %eax
je 0x29db2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x29df6
movl -0x20(%rbp), %esi
leaq -0x38(%rbp), %rdi
movl $0x1, %edx
callq 0x2dc90
cmpl $0x1, %eax
je 0x29dd1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x29df6
leaq -0x60(%rbp), %rsi
movl -0x44(%rbp), %edx
leaq -0x38(%rbp), %rdi
callq 0x2d9e0
cmpl -0x44(%rbp), %eax
je 0x29def
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x29df6
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop