// File: /workspace/github_c_makefile_star2_O1/wahern[P]cqueues/src/lib/dns.c
// Function: dns_resconf_search
size_t dns_resconf_search(void *dst, size_t lim, const void *qname, size_t qlen, struct dns_resolv_conf *resconf, dns_resconf_i_t *state) {
	unsigned pc, srchi, ndots, len;

	DNS_SM_ENTER;

	/* if FQDN then return as-is and finish */
	if (dns_d_isanchored(qname, qlen)) {
		len = dns_d_anchor(dst, lim, qname, qlen);
		DNS_SM_YIELD(len);
		DNS_SM_EXIT;
	}

	ndots = dns_d_ndots(qname, qlen);

	if (ndots >= resconf->options.ndots) {
		len = dns_d_anchor(dst, lim, qname, qlen);
		DNS_SM_YIELD(len);
	}

	while (srchi < lengthof(resconf->search) && resconf->search[srchi][0]) {
		struct dns_buf buf = DNS_B_INTO(dst, lim);
		const char *dn = resconf->search[srchi++];

		dns_b_put(&buf, qname, qlen);
		dns_b_putc(&buf, '.');
		dns_b_puts(&buf, dn);
		if (!dns_d_isanchored(dn, strlen(dn)))
			dns_b_putc(&buf, '.');
		len = dns_b_strllen(&buf);
		DNS_SM_YIELD(len);
	}

	if (ndots < resconf->options.ndots) {
		len = dns_d_anchor(dst, lim, qname, qlen);
		DNS_SM_YIELD(len);
	}

	DNS_SM_LEAVE;

	return dns_strlcpy(dst, "", lim);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r14
movq %r8, %rbp
movq %rdx, %r8
movq %rsi, %r12
movl (%r9), %r13d
movl %r13d, %r15d
shrl $0x8, %r15d
movl $0xff, %eax
andl %eax, %r15d
movl %r13d, %ebx
shrl $0x10, %ebx
andl %eax, %ebx
andl %r13d, %eax
cmpl $0xc, %eax
jle 0x2cc74
cmpl $0xd, %eax
je 0x2cd43
cmpl $0x1a, %eax
je 0x2cd43
cmpl $0x1f, %eax
je 0x2cdfc
jmp 0x2ce0f
testl %eax, %eax
je 0x2cc86
cmpl $0x5, %eax
je 0x2cdfc
jmp 0x2ce0f
testq %rcx, %rcx
je 0x2ccd0
cmpb $0x2e, -0x1(%r8,%rcx)
jne 0x2ccd0
testq %rcx, %rcx
je 0x2cf88
cmpq %rcx, %r12
movq %rcx, %rdx
cmovbq %r12, %rdx
movq %rdi, (%rsp)
movq %r8, %rsi
movq %rcx, %rbp
movq %r8, %r13
callq 0x105f0
movq %rbp, %rcx
cmpb $0x2e, -0x1(%r13,%rbp)
jne 0x2cfc2
movq (%rsp), %rax
jmp 0x2cfd2
movq %rdi, (%rsp)
movq %r14, 0x18(%rsp)
movq %r8, %rdi
movl $0x2e, %esi
movq %rcx, %rdx
movq %rcx, %rbx
movq %r8, %r14
callq 0xfe90
testq %rax, %rax
movq %rbx, 0x8(%rsp)
movq %r14, 0x10(%rsp)
je 0x2cd22
addq %rbx, %r14
xorl %ebx, %ebx
incq %rax
movq %r14, %rdx
subq %rax, %rdx
movq %rax, %rdi
movl $0x2e, %esi
callq 0xfe90
incl %ebx
testq %rax, %rax
jne 0x2cd03
jmp 0x2cd24
xorl %ebx, %ebx
cmpl %ebx, 0x5b4(%rbp)
jbe 0x2cea5
movq 0x18(%rsp), %r14
movq (%rsp), %rdi
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
cmpl $0x3, %r15d
ja 0x2cdb7
movl %r15d, %eax
shll $0x8, %eax
cmpb $0x0, 0x180(%rbp,%rax)
je 0x2cdb7
movq %r14, 0x18(%rsp)
cmpq %rcx, %r12
movq %rcx, %r15
cmovbq %r12, %r15
addq %rbp, %rax
addq $0x180, %rax            # imm = 0x180
movq %rax, 0x20(%rsp)
movq %rcx, %rax
subq %r15, %rax
xorl %ebp, %ebp
cmpq %rcx, %r12
cmovbq %rax, %rbp
leaq (%rdi,%r12), %rax
movq %rax, 0x8(%rsp)
movq %rdi, (%rsp)
movq (%rsp), %rdi
movq %r8, %rsi
movq %r15, %rdx
callq 0xfa60
movq (%rsp), %rax
leaq (%rax,%r15), %r14
cmpq %r12, %r15
jge 0x2ce1e
movb $0x2e, (%r14)
incq %r14
jmp 0x2ce21
cmpl 0x5b4(%rbp), %ebx
jae 0x2cdfc
testq %rcx, %rcx
je 0x2ceee
cmpq %rcx, %r12
movq %rcx, %rdx
cmovbq %r12, %rdx
movq %rdi, (%rsp)
movq %r8, %rsi
movq %rcx, %rbp
movq %r8, %r13
callq 0x105f0
movq %rbp, %rcx
cmpb $0x2e, -0x1(%r13,%rbp)
jne 0x2cef2
movq (%rsp), %rax
jmp 0x2cf02
shll $0x8, %r15d
movzbl %bl, %eax
shll $0x10, %eax
addl %r15d, %eax
addl $0x22, %eax
movq %rax, (%r14)
testq %r12, %r12
jle 0x2ce17
movb $0x0, (%rdi)
xorl %eax, %eax
jmp 0x2cff9
incq %rbp
movq %rbp, 0x10(%rsp)
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
callq 0xf560
movq 0x8(%rsp), %rcx
subq %r14, %rcx
cmpq %rax, %rcx
movq %rax, %r15
cmovbq %rcx, %r15
movq %rax, %rdx
subq %r15, %rdx
xorl %r12d, %r12d
cmpq %rax, %rcx
cmovbq %rdx, %r12
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0xfa60
addq %r14, %r15
addq 0x10(%rsp), %r12
movq %rbp, %rdi
callq 0xf560
testq %rax, %rax
je 0x2ce89
cmpb $0x2e, -0x1(%rbp,%rax)
jne 0x2ce89
movq 0x18(%rsp), %rdx
jmp 0x2cf2e
cmpq 0x8(%rsp), %r15
movq 0x18(%rsp), %rdx
jae 0x2cf2b
movb $0x2e, (%r15)
incq %r15
jmp 0x2cf2e
movq 0x8(%rsp), %rax
testq %rax, %rax
movq 0x18(%rsp), %r14
movq (%rsp), %rdi
je 0x2cf84
cmpq %rax, %r12
movq %rax, %rdx
cmovbq %r12, %rdx
movq 0x10(%rsp), %rbp
movq %rbp, %rsi
movq %rax, %r13
callq 0x105f0
movq %r13, %rcx
cmpb $0x2e, -0x1(%rbp,%r13)
jne 0x2cf8c
movq (%rsp), %rax
jmp 0x2cf9c
xorl %ecx, %ecx
jmp 0x2cf16
cmpq %r12, %rcx
movq (%rsp), %rax
jae 0x2ceff
movb $0x2e, (%rax,%rcx)
incq %rcx
testq %r12, %r12
je 0x2cf16
decq %r12
cmpq %rcx, %r12
cmovaeq %rcx, %r12
movb $0x0, (%rax,%r12)
shll $0x8, %r15d
movzbl %bl, %eax
shll $0x10, %eax
addl %r15d, %eax
addl $0x1f, %eax
jmp 0x2cff4
incq %r12
movq (%rsp), %rcx
cmpq 0x8(%rsp), %r15
jae 0x2cf45
movb $0x0, (%r15)
subq %rcx, %r15
movq %r15, %rax
jmp 0x2cf62
cmpq %rcx, %r15
jbe 0x2cf60
leaq -0x1(%r15), %rax
cmpb $0x0, -0x1(%r15)
je 0x2cf5b
incq %r12
movb $0x0, (%rax)
subq %rcx, %rax
jmp 0x2cf62
xorl %eax, %eax
addl %r12d, %eax
addl $0x100, %r13d           # imm = 0x100
andl $0xff00, %r13d          # imm = 0xFF00
movzbl %bl, %ecx
shll $0x10, %ecx
addl %r13d, %ecx
addl $0x1a, %ecx
movq %rcx, (%rdx)
jmp 0x2cff9
xorl %ecx, %ecx
jmp 0x2cfb0
xorl %ecx, %ecx
jmp 0x2cfe6
cmpq %r12, %rcx
movq (%rsp), %rax
jae 0x2cf99
movb $0x2e, (%rax,%rcx)
incq %rcx
testq %r12, %r12
je 0x2cfb0
decq %r12
cmpq %rcx, %r12
cmovaeq %rcx, %r12
movb $0x0, (%rax,%r12)
shll $0x8, %r15d
movzbl %bl, %eax
shll $0x10, %eax
addl %r15d, %eax
addl $0xd, %eax
jmp 0x2cff4
cmpq %r12, %rcx
movq (%rsp), %rax
jae 0x2cfcf
movb $0x2e, (%rax,%rcx)
incq %rcx
testq %r12, %r12
je 0x2cfe6
decq %r12
cmpq %rcx, %r12
cmovaeq %rcx, %r12
movb $0x0, (%rax,%r12)
shll $0x8, %r15d
shll $0x10, %ebx
leal (%r15,%rbx), %eax
addl $0x5, %eax
movq %rax, (%r14)
movl %ecx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq