// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/ns_msg.c
// Function: ns_rdata_read_opts
static int ns_rdata_read_opts(ns_rr_t *rr, stream_t *s)
{
    opt_rdata_into info;
	ns_optlist_t *opts;
    ns_opt_t *opt;
    info = ns_rdata_read_edns_optinfo(rr, s);
    if (info.count < 0)
        return -1;
	opts = malloc(sizeof(ns_optlist_t));
    if (opts) {
        int i = 0;
        stream_t ns = *s;
        ns.size = s->pos + rr->rdlength;
		opts->optcount = info.count;
		opts->opts = malloc(opts->optcount * sizeof(ns_opt_t));
        if (opts->opts == NULL) {
            free(opts);
            return -1;
        }
        memset(opts->opts, 0, opts->optcount * sizeof(ns_opt_t));
#define do_return(n) \
        for (i = 0; i < opts->optcount; i++) { \
            opt = opts->opts + i; \
            free(opt->data); \
        } \
        free(opts); \
        return (n);

#define check_size(n) \
        if (stream_rsize(&ns) < (n)) { \
            do_return(-1); \
        }

        while(stream_rsize(&ns) > 0) {
            opt = opts->opts + i;
            check_size(4);
            opt->code = (uint16_t)stream_readi16(&ns);
            opt->length = (uint16_t)stream_readi16(&ns);
            opt->data = malloc(opt->length);
            if (opt->data == NULL) {
                do_return(-1);
            }
            check_size(opt->length);
            memcpy(opt->data, ns.array + ns.pos, opt->length);
            stream_seek(&ns, opt->length, SEEK_CUR);
            i++;
        }
        rr->rdata = opts;
        return 0;
#undef check_size
#undef do_return
    }
    else
        return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2be40
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x2b8db
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2bb81
movl $0x10, %edi
callq 0x34d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2bb7a
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x50(%rbp)
movl -0x20(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movslq 0x8(%rax), %rdi
shlq $0x4, %rdi
callq 0x34d0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x2b96e
movq -0x28(%rbp), %rdi
callq 0x3460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2bb81
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movslq 0x8(%rax), %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x3200
movl -0x50(%rbp), %eax
subl -0x4c(%rbp), %eax
cmpl $0x0, %eax
jle 0x2bb65
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x50(%rbp), %eax
subl -0x4c(%rbp), %eax
cmpl $0x4, %eax
jge 0x2ba0e
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2b9f9
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3460
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2b9bf
movq -0x28(%rbp), %rdi
callq 0x3460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2bb81
leaq -0x58(%rbp), %rdi
movl $0x2, %esi
callq 0x2e340
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, (%rax)
leaq -0x58(%rbp), %rdi
movl $0x2, %esi
callq 0x2e340
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x30(%rbp), %rax
movzwl 0x2(%rax), %eax
movl %eax, %edi
callq 0x34d0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x2baba
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2baa5
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3460
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2ba6b
movq -0x28(%rbp), %rdi
callq 0x3460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2bb81
movl -0x50(%rbp), %eax
subl -0x4c(%rbp), %eax
movq -0x30(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x2bb1f
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2bb0d
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3460
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2bad3
movq -0x28(%rbp), %rdi
callq 0x3460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2bb81
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x58(%rbp), %rsi
movslq -0x4c(%rbp), %rax
addq %rax, %rsi
movq -0x30(%rbp), %rax
movzwl 0x2(%rax), %eax
movl %eax, %edx
callq 0x32d0
movq -0x30(%rbp), %rax
movzwl 0x2(%rax), %esi
leaq -0x58(%rbp), %rdi
movl $0x1, %edx
callq 0x2d6a0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2b988
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x2bb81
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)