// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movq %r9, %r14
movq %rsi, %r9
movq (%r14), %r15
movl %r15d, %r12d
shrl $0x8, %r12d
movl $0xff, %eax
andl %eax, %r12d
movl %r15d, %ebp
shrl $0x10, %ebp
andl %eax, %ebp
cmpb $0x1f, %r15b
je 0x288ca
andl %r15d, %eax
cmpl $0x5, %eax
je 0x288ca
cmpl $0xd, %eax
je 0x28824
cmpl $0x1a, %eax
je 0x28824
testl %eax, %eax
jne 0x288de
testq %rcx, %rcx
je 0x287ab
cmpb $0x2e, -0x1(%rdx,%rcx)
jne 0x287ab
movq %r9, %rsi
callq 0xfbe0
shll $0x8, %r12d
shll $0x10, %ebp
leal (%r12,%rbp), %ecx
addl $0x5, %ecx
jmp 0x289b7
movq %r8, (%rsp)
movq %r9, 0x10(%rsp)
movq %rdi, 0x48(%rsp)
movq %r14, 0x50(%rsp)
movq %rcx, 0x8(%rsp)
leaq (%rdx,%rcx), %r14
xorl %r13d, %r13d
pushq $0x2e
popq %rbx
movq %rdx, 0x40(%rsp)
movq %rdx, %rax
xorl %ebp, %ebp
movq %r14, %rdx
subq %rax, %rdx
movq %rax, %rdi
movl %ebx, %esi
callq 0xff20
testq %rax, %rax
je 0x287fa
incl %ebp
incq %rax
addl $0x10000, %r13d         # imm = 0x10000
jmp 0x287d7
movq (%rsp), %r8
cmpl %ebp, 0x5b4(%r8)
movq 0x50(%rsp), %r14
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %rcx
movq 0x40(%rsp), %rdx
jbe 0x28969
cmpl $0x3, %r12d
ja 0x288a3
movl %r12d, %ebx
shll $0x8, %ebx
cmpb $0x0, 0x180(%r8,%rbx)
je 0x288a3
movq %r8, (%rsp)
movq %rdi, 0x18(%rsp)
leaq (%rdi,%r9), %rax
movq %rax, 0x28(%rsp)
andl $0x0, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
cmpq %rcx, %r9
movq %rcx, %r12
cmovbq %r9, %r12
movq %rdi, %r13
movq %rdx, %rsi
movq %r9, 0x10(%rsp)
movq %r12, %rdx
movq %rcx, 0x8(%rsp)
callq 0xfad0
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
addq %r12, %r13
movq %r13, 0x20(%rsp)
subq %rax, %rcx
jbe 0x288fb
movq %rcx, 0x38(%rsp)
movl $0x9b918cc0, 0x30(%rsp) # imm = 0x9B918CC0
incq %rcx
jmp 0x288fe
cmpl 0x5b4(%r8), %ebp
jae 0x288ca
movq %r9, %rsi
callq 0xfbe0
shll $0x8, %r12d
movzbl %bpl, %ecx
shll $0x10, %ecx
addl %r12d, %ecx
addl $0x1f, %ecx
jmp 0x289b7
shll $0x8, %r12d
movzbl %bpl, %eax
shll $0x10, %eax
addl %r12d, %eax
addl $0x22, %eax
movq %rax, (%r14)
leaq 0xb716(%rip), %rsi      # 0x33ffb
movq %r9, %rdx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf4f0
pushq $0x1
popq %rcx
movq (%rsp), %rdx
addq %rdx, %rbx
addq $0x180, %rbx            # imm = 0x180
cmpq %rax, %r12
jge 0x28921
leaq 0x1(%r13), %rax
movq %rax, 0x20(%rsp)
movb $0x2e, (%r13)
jmp 0x2892e
movq %rcx, 0x38(%rsp)
movl $0x9b918cc0, 0x30(%rsp) # imm = 0x9B918CC0
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x25689
movq %rbx, %rdi
callq 0xf580
testq %rax, %rax
je 0x2894f
cmpb $0x2e, -0x1(%rbx,%rax)
je 0x28992
movq 0x20(%rsp), %rax
cmpq 0x28(%rsp), %rax
jae 0x28985
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rsp)
movb $0x2e, (%rax)
jmp 0x28992
movq %r9, %rsi
callq 0xfbe0
shll $0x8, %r12d
andl $0xff0000, %r13d        # imm = 0xFF0000
leal (%r12,%r13), %ecx
addl $0xd, %ecx
jmp 0x289b7
incq 0x38(%rsp)
movl $0x9b918cc0, 0x30(%rsp) # imm = 0x9B918CC0
leaq 0x18(%rsp), %rdi
callq 0x25899
addl $0x100, %r15d           # imm = 0x100
andl $0xff00, %r15d          # imm = 0xFF00
movzbl %bpl, %ecx
shll $0x10, %ecx
addl %r15d, %ecx
addl $0x1a, %ecx
movq %rcx, (%r14)
movl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq