// File: /workspace/github_c_makefile_star2_O2/wahern[P]cqueues/src/lib/dns.c
// Function: dns_resconf_loadfile
int dns_resconf_loadfile(struct dns_resolv_conf *resconf, FILE *fp) {
	unsigned sa_count	= 0;
	char words[6][DNS_D_MAXNAME + 1];
	unsigned wp, wc, i, j, n;
	int ch, error;

	rewind(fp);

	do {
		memset(words, '\0', sizeof words);
		wp	= 0;
		wc	= 0;

		while (EOF != (ch = getc(fp)) && ch != '\n') {
			if (dns_resconf_issep(ch)) {
				if (wp > 0) {
					wp	= 0;

					if (++wc >= lengthof(words))
						goto skip;
				}
			} else if (dns_resconf_iscom(ch)) {
skip:
				do {
					ch	= getc(fp);
				} while (ch != EOF && ch != '\n');

				break;
			} else if (wp < sizeof words[wc] - 1) {
				words[wc][wp++] = ch;
			} else {
				wp = 0; /* drop word */
				goto skip;
			}
		}

		if (wp > 0)
			wc++;

		if (wc < 2)
			continue;

		switch (dns_resconf_keyword(words[0])) {
		case DNS_RESCONF_NAMESERVER:
			if (sa_count >= lengthof(resconf->nameserver))
				continue;

			if ((error = dns_resconf_pton(&resconf->nameserver[sa_count], words[1])))
				continue;

			sa_count++;

			break;
		case DNS_RESCONF_DOMAIN:
		case DNS_RESCONF_SEARCH:
			memset(resconf->search, '\0', sizeof resconf->search);

			for (i = 1, j = 0; i < wc && j < lengthof(resconf->search); i++, j++)
				dns_d_anchor(resconf->search[j], sizeof resconf->search[j], words[i], strlen(words[i]));

			break;
		case DNS_RESCONF_LOOKUP:
			for (i = 1, j = 0; i < wc && j < lengthof(resconf->lookup); i++) {
				switch (dns_resconf_keyword(words[i])) {
				case DNS_RESCONF_FILE:
					resconf->lookup[j++]	= 'f';

					break;
				case DNS_RESCONF_BIND:
					resconf->lookup[j++]	= 'b';

					break;
				case DNS_RESCONF_CACHE:
					resconf->lookup[j++]	= 'c';

					break;
				default:
					break;
				} /* switch() */
			} /* for() */

			break;
		case DNS_RESCONF_FAMILY:
			for (i = 1, j = 0; i < wc && j < lengthof(resconf->family); i++) {
				switch (dns_resconf_keyword(words[i])) {
				case DNS_RESCONF_INET4:
					resconf->family[j++]	= AF_INET;

					break;
				case DNS_RESCONF_INET6:
					resconf->family[j++]	= AF_INET6;

					break;
				default:
					break;
				}
			}

			break;
		case DNS_RESCONF_OPTIONS:
			for (i = 1; i < wc; i++) {
				switch (dns_resconf_keyword(words[i])) {
				case DNS_RESCONF_EDNS0:
					resconf->options.edns0	= 1;

					break;
				case DNS_RESCONF_NDOTS:
					for (j = sizeof "ndots:" - 1, n = 0; dns_isdigit(words[i][j]); j++) {
						n	*= 10;
						n	+= words[i][j] - '0';
					} /* for() */

					resconf->options.ndots	= n;

					break;
				case DNS_RESCONF_TIMEOUT:
					for (j = sizeof "timeout:" - 1, n = 0; dns_isdigit(words[i][j]); j++) {
						n	*= 10;
						n	+= words[i][j] - '0';
					} /* for() */

					resconf->options.timeout	= n;

					break;
				case DNS_RESCONF_ATTEMPTS:
					for (j = sizeof "attempts:" - 1, n = 0; dns_isdigit(words[i][j]); j++) {
						n	*= 10;
						n	+= words[i][j] - '0';
					} /* for() */

					resconf->options.attempts	= n;

					break;
				case DNS_RESCONF_ROTATE:
					resconf->options.rotate		= 1;

					break;
				case DNS_RESCONF_RECURSE:
					resconf->options.recurse	= 1;

					break;
				case DNS_RESCONF_SMART:
					resconf->options.smart		= 1;

					break;
				case DNS_RESCONF_TCP:
					resconf->options.tcp		= DNS_RESCONF_TCP_ONLY;

					break;
				case DNS_RESCONF_TCPx:
					switch (dns_resconf_keyword(&words[i][sizeof "tcp:" - 1])) {
					case DNS_RESCONF_ENABLE:
						resconf->options.tcp	= DNS_RESCONF_TCP_ENABLE;

						break;
					case DNS_RESCONF_ONE:
					case DNS_RESCONF_ONLY:
						resconf->options.tcp	= DNS_RESCONF_TCP_ONLY;

						break;
					case DNS_RESCONF_ZERO:
					case DNS_RESCONF_DISABLE:
						resconf->options.tcp	= DNS_RESCONF_TCP_DISABLE;

						break;
					default:
						break;
					} /* switch() */

					break;
				default:
					break;
				} /* switch() */
			} /* for() */

			break;
		case DNS_RESCONF_INTERFACE:
			for (i = 0, n = 0; dns_isdigit(words[2][i]); i++) {
				n	*= 10;
				n	+= words[2][i] - '0';
			}

			dns_resconf_setiface(resconf, words[1], n);

			break;
		default:
			break;
		} /* switch() */
	} while (ch != EOF);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x638, %rsp            # imm = 0x638
movq %rsi, %r13
movq %rdi, %rbx
movq %rsi, %rdi
callq 0xf160
leaq 0x180(%rbx), %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movq %r13, 0x20(%rsp)
movq %rbx, 0x10(%rsp)
movq %r14, 0x8(%rsp)
movl $0x600, %edx            # imm = 0x600
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0xf790
xorl %r15d, %r15d
movl %r15d, %eax
xorl %r14d, %r14d
shlq $0x8, %rax
leaq (%rsp,%rax), %r12
addq $0x30, %r12
movq %r13, %rdi
callq 0xf370
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x27bc1
cmpl $0xa, %ebp
je 0x27bc1
movzbl %bpl, %edi
callq 0x272bc
xorb $0x1, %al
cmpl $0x2c, %ebp
setne %cl
testb %al, %cl
jne 0x27b90
testl %r14d, %r14d
movl $0x0, %r14d
je 0x27b5a
jmp 0x27baf
cmpl $0x3b, %ebp
je 0x27bc9
cmpl $0x23, %ebp
je 0x27bc9
cmpl $0xfe, %r14d
ja 0x27bc6
movl %r14d, %eax
incl %r14d
movb %bpl, (%rax,%r12)
jmp 0x27b5a
leal 0x1(%r15), %r12d
cmpl $0x4, %r15d
movl %r12d, %r15d
jbe 0x27b48
xorl %r14d, %r14d
jmp 0x27bcc
movl %r15d, %r12d
jmp 0x27be0
xorl %r14d, %r14d
movl %r15d, %r12d
movq %r13, %rdi
callq 0xf370
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x27be0
cmpl $0xa, %ebp
jne 0x27bcc
cmpl $0x1, %r14d
sbbl $-0x1, %r12d
cmpl $0x2, %r12d
jb 0x27f17
leaq 0x30(%rsp), %rdi
callq 0x27f39
cmpl $0xa, %eax
ja 0x27c80
movl %eax, %eax
leaq 0x9ef6(%rip), %rcx      # 0x31b00
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %r12d, %ecx
movq %rcx, 0x18(%rsp)
jmpq *%rax
movl $0x400, %edx            # imm = 0x400
movq 0x28(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0xf790
leaq 0x130(%rsp), %r15
xorl %eax, %eax
movl $0x100, %r14d           # imm = 0x100
leaq 0x1(%rax), %rbx
cmpq 0x18(%rsp), %rbx
jae 0x27c76
cmpq $0x3, %rax
ja 0x27c76
movq %r15, %rdi
callq 0xf580
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
movq %r15, %rdx
movq %rax, %rcx
callq 0xfbe0
addq %r14, %r12
addq %r14, %r15
movq %rbx, %rax
jmp 0x27c3f
movq 0x10(%rsp), %rbx
jmp 0x27f17
cmpl $0x14, %eax
jne 0x27f17
xorl %r14d, %r14d
xorl %r12d, %r12d
movl %r14d, %eax
movzbl 0x230(%rsp,%rax), %r15d
movl %r15d, %edi
callq 0x27abb
testb %al, %al
je 0x27f03
movsbl %r15b, %eax
imull $0xa, %r12d, %ecx
cwtl
leal (%rcx,%rax), %r12d
addl $-0x30, %r12d
incl %r14d
jmp 0x27c8f
pushq $0x1
popq %r14
cmpq 0x18(%rsp), %r14
je 0x27f17
movq %r14, %rax
shlq $0x8, %rax
leaq (%rsp,%rax), %r15
addq $0x30, %r15
movq %r15, %rdi
callq 0x27f39
addl $-0xb, %eax
cmpl $0x8, %eax
ja 0x27e1d
leaq 0x9e32(%rip), %rcx      # 0x31b2c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x1, 0x5b0(%rbx)
jmp 0x27e1d
movb $0x1, 0x5c0(%rbx)
jmp 0x27e1d
xorl %r13d, %r13d
pushq $0x8
popq %rbx
movl %ebx, %eax
movzbl (%rax,%r15), %r12d
movl %r12d, %edi
callq 0x27abb
testb %al, %al
je 0x27d48
movsbl %r12b, %eax
imull $0xa, %r13d, %ecx
leal (%rcx,%rax), %r13d
addl $-0x30, %r13d
incl %ebx
jmp 0x27d21
movq 0x10(%rsp), %rbx
movl %r13d, 0x5b8(%rbx)
jmp 0x27dca
xorl %r13d, %r13d
pushq $0x9
popq %rbx
movl %ebx, %eax
movzbl (%rax,%r15), %r12d
movl %r12d, %edi
callq 0x27abb
testb %al, %al
je 0x27d83
movsbl %r12b, %eax
imull $0xa, %r13d, %ecx
leal (%rcx,%rax), %r13d
addl $-0x30, %r13d
incl %ebx
jmp 0x27d5c
movq 0x10(%rsp), %rbx
movl %r13d, 0x5bc(%rbx)
jmp 0x27dca
xorl %r13d, %r13d
pushq $0x6
popq %rbx
movl %ebx, %eax
movzbl (%rax,%r15), %r12d
movl %r12d, %edi
callq 0x27abb
testb %al, %al
je 0x27dbe
movsbl %r12b, %eax
imull $0xa, %r13d, %ecx
leal (%rcx,%rax), %r13d
addl $-0x30, %r13d
incl %ebx
jmp 0x27d97
movq 0x10(%rsp), %rbx
movl %r13d, 0x5b4(%rbx)
movq 0x20(%rsp), %r13
jmp 0x27e1d
movb $0x1, 0x5c1(%rbx)
jmp 0x27e1d
movb $0x1, 0x5c2(%rbx)
jmp 0x27e1d
addq $0x4, %r15
movq %r15, %rdi
callq 0x27f39
addl $-0x15, %eax
cmpl $0x4, %eax
ja 0x27e1d
leaq 0x9d52(%rip), %rcx      # 0x31b50
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x2, 0x5c4(%rbx)
jmp 0x27e1d
movl $0x1, 0x5c4(%rbx)
incq %r14
jmp 0x27cc5
andl $0x0, 0x5c4(%rbx)
jmp 0x27e1d
xorl %r14d, %r14d
leaq 0x130(%rsp), %r15
pushq $0x1
popq %r12
cmpq 0x18(%rsp), %r12
jae 0x27f17
cmpl $0x23, %r14d
ja 0x27f17
movq %r15, %rdi
callq 0x27f39
addl $-0x4, %eax
cmpl $0x2, %eax
ja 0x27e7b
shll $0x3, %eax
movl $0x636266, %edx         # imm = 0x636266
movl %eax, %ecx
shrl %cl, %edx
movl %r14d, %eax
incl %r14d
movb %dl, 0x580(%rbx,%rax)
incq %r12
addq $0x100, %r15            # imm = 0x100
jmp 0x27e3d
movq 0x8(%rsp), %r14
cmpl $0x2, %r14d
ja 0x27f1c
movl %r14d, %edi
shlq $0x7, %rdi
addq %rbx, %rdi
leaq 0x130(%rsp), %rsi
callq 0x10a30
cmpl $0x1, %eax
adcl $0x0, %r14d
jmp 0x27f1c
xorl %r14d, %r14d
leaq 0x130(%rsp), %r15
pushq $0x1
popq %r12
cmpq 0x18(%rsp), %r12
jae 0x27f17
cmpl $0x2, %r14d
ja 0x27f17
movq %r15, %rdi
callq 0x27f39
pushq $0x2
popq %rcx
cmpl $0x8, %eax
je 0x27eea
cmpl $0x9, %eax
jne 0x27ef7
pushq $0xa
popq %rcx
movl %r14d, %eax
incl %r14d
movl %ecx, 0x5a4(%rbx,%rax,4)
incq %r12
addq $0x100, %r15            # imm = 0x100
jmp 0x27ec5
movzwl %r12w, %edx
movq %rbx, %rdi
leaq 0x130(%rsp), %rsi
callq 0xff10
movq 0x8(%rsp), %r14
cmpl $-0x1, %ebp
jne 0x27b2f
xorl %eax, %eax
addq $0x638, %rsp            # imm = 0x638
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq