// File: /workspace/github_c_makefile_star2_O1/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 $0x628, %rsp            # imm = 0x628
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0xf150
movq %rbx, (%rsp)
leaq 0x180(%rbx), %rax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
movq %r14, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movl $0x600, %edx            # imm = 0x600
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0xf750
xorl %r12d, %r12d
movl %r12d, %eax
xorl %r15d, %r15d
shlq $0x8, %rax
leaq (%rsp,%rax), %rbx
addq $0x20, %rbx
movq %r14, %rdi
callq 0xf360
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x2be74
cmpl $0xa, %ebp
je 0x2be74
callq 0xfe30
cmpl $0x2c, %ebp
je 0x2be56
movq (%rax), %rax
movzbl %bpl, %ecx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
jne 0x2be56
cmpl $0x3b, %ebp
je 0x2be7c
cmpl $0x23, %ebp
je 0x2be7c
cmpl $0xfe, %r15d
ja 0x2be79
movl %r15d, %eax
incl %r15d
movb %bpl, (%rax,%rbx)
jmp 0x2be07
testl %r15d, %r15d
movl $0x0, %r15d
je 0x2be07
leal 0x1(%r12), %r13d
cmpl $0x4, %r12d
movl %r13d, %r12d
jbe 0x2bdf5
xorl %r15d, %r15d
jmp 0x2be7f
movl %r12d, %r13d
jmp 0x2be93
xorl %r15d, %r15d
movl %r12d, %r13d
movq %r14, %rdi
callq 0xf360
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x2be93
cmpl $0xa, %ebp
jne 0x2be7f
cmpl $0x1, %r15d
sbbl $-0x1, %r13d
cmpl $0x2, %r13d
jb 0x2c297
leaq 0x20(%rsp), %rdi
callq 0x2c2b9
cmpl $0xa, %eax
ja 0x2bf92
movl %eax, %eax
leaq 0xac8f(%rip), %rcx      # 0x36b50
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x400, %edx            # imm = 0x400
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0xf750
movl %r13d, %r13d
movl $0x2, %r14d
xorl %ebx, %ebx
leaq (%rsp,%rbx), %r12
addq $0x120, %r12            # imm = 0x120
movq %r12, %rdi
callq 0xf560
testq %rax, %rax
je 0x2bf6c
movq %rax, %r15
movq (%rsp), %rax
leaq (%rax,%rbx), %rdi
addq $0x180, %rdi            # imm = 0x180
movl $0x100, %eax            # imm = 0x100
cmpq %rax, %r15
movl $0x100, %edx            # imm = 0x100
cmovbq %r15, %rdx
movq %r12, %rsi
callq 0xfa60
leaq 0x20(%rsp), %rax
addq %r15, %rax
cmpb $0x2e, 0xff(%rbx,%rax)
je 0x2bf53
cmpq $0xff, %r15
ja 0x2bf50
movq 0x18(%rsp), %rax
addq %r15, %rax
movb $0x2e, (%rbx,%rax)
incq %r15
movl $0xff, %eax
cmpq %rax, %r15
cmovaeq %rax, %r15
addq (%rsp), %r15
movb $0x0, 0x180(%rbx,%r15)
cmpq %r13, %r14
jae 0x2c292
leaq -0x2(%r14), %rax
addq $0x100, %rbx            # imm = 0x100
incq %r14
cmpq $0x3, %rax
jb 0x2bee6
jmp 0x2c292
cmpl $0x14, %eax
jne 0x2c297
callq 0xfe30
movq (%rax), %rax
movzbl 0x220(%rsp), %edx
xorl %ecx, %ecx
testb $0x8, 0x1(%rax,%rdx,2)
movq 0x8(%rsp), %rbx
je 0x2bfdd
movl $0x1, %esi
leal (%rcx,%rcx,4), %ecx
movsbl %dl, %edx
leal (%rdx,%rcx,2), %ecx
addl $-0x30, %ecx
movl %esi, %edx
movzbl 0x220(%rsp,%rdx), %edx
incl %esi
testb $0x8, 0x1(%rax,%rdx,2)
jne 0x2bfbe
movzwl %cx, %edx
movq (%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0xfe80
jmp 0x2c29c
movl %r13d, %r12d
movl $0x1, %r13d
movq %r13, %rbx
shlq $0x8, %rbx
leaq (%rsp,%rbx), %r15
addq $0x20, %r15
movq %r15, %rdi
callq 0x2c2b9
addl $-0xb, %eax
cmpl $0x8, %eax
ja 0x2c183
leaq 0xab53(%rip), %rcx      # 0x36b7c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
movb $0x1, 0x5b0(%rax)
jmp 0x2c183
movq (%rsp), %rax
movb $0x1, 0x5c0(%rax)
jmp 0x2c183
callq 0xfe30
movq (%rax), %rax
movzbl 0x28(%rsp,%rbx), %edx
xorl %ecx, %ecx
testb $0x8, 0x1(%rax,%rdx,2)
je 0x2c08b
xorl %ecx, %ecx
movl $0x9, %esi
leal (%rcx,%rcx,4), %ecx
movsbl %dl, %edx
leal (%rdx,%rcx,2), %ecx
addl $-0x30, %ecx
movl %esi, %edx
movzbl (%rdx,%r15), %edx
incl %esi
testb $0x8, 0x1(%rax,%rdx,2)
jne 0x2c06f
movq (%rsp), %rax
movl %ecx, 0x5b8(%rax)
jmp 0x2c183
callq 0xfe30
movq (%rax), %rax
movzbl 0x29(%rsp,%rbx), %edx
xorl %ecx, %ecx
testb $0x8, 0x1(%rax,%rdx,2)
je 0x2c0d3
xorl %ecx, %ecx
movl $0xa, %esi
leal (%rcx,%rcx,4), %ecx
movsbl %dl, %edx
leal (%rdx,%rcx,2), %ecx
addl $-0x30, %ecx
movl %esi, %edx
movzbl (%rdx,%r15), %edx
incl %esi
testb $0x8, 0x1(%rax,%rdx,2)
jne 0x2c0b7
movq (%rsp), %rax
movl %ecx, 0x5bc(%rax)
jmp 0x2c183
callq 0xfe30
movq (%rax), %rax
movzbl 0x26(%rsp,%rbx), %edx
xorl %ecx, %ecx
testb $0x8, 0x1(%rax,%rdx,2)
je 0x2c11b
xorl %ecx, %ecx
movl $0x7, %esi
leal (%rcx,%rcx,4), %ecx
movsbl %dl, %edx
leal (%rdx,%rcx,2), %ecx
addl $-0x30, %ecx
movl %esi, %edx
movzbl (%rdx,%r15), %edx
incl %esi
testb $0x8, 0x1(%rax,%rdx,2)
jne 0x2c0ff
movq (%rsp), %rax
movl %ecx, 0x5b4(%rax)
jmp 0x2c183
movq (%rsp), %rax
movb $0x1, 0x5c1(%rax)
jmp 0x2c183
movq (%rsp), %rax
movb $0x1, 0x5c2(%rax)
jmp 0x2c183
addq $0x4, %r15
movq %r15, %rdi
callq 0x2c2b9
addl $-0x15, %eax
cmpl $0x4, %eax
ja 0x2c183
leaq 0xaa44(%rip), %rcx      # 0x36ba0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
movl $0x2, 0x5c4(%rax)
jmp 0x2c183
movq (%rsp), %rax
movl $0x1, 0x5c4(%rax)
incq %r13
cmpq %r12, %r13
jne 0x2bfff
jmp 0x2c297
movq (%rsp), %rax
movl $0x0, 0x5c4(%rax)
jmp 0x2c183
movl %r13d, %r12d
xorl %r13d, %r13d
movl $0x2, %r14d
leaq 0x120(%rsp), %r15
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x2c2b9
cmpl $0x4, %eax
je 0x2c1d9
cmpl $0x6, %eax
je 0x2c1d5
cmpl $0x5, %eax
jne 0x2c1e9
movb $0x62, %al
jmp 0x2c1db
movb $0x63, %al
jmp 0x2c1db
movb $0x66, %al
incl %ebx
movq (%rsp), %rcx
movb %al, 0x580(%rcx,%r13)
cmpq %r12, %r14
jae 0x2c292
addq $0x100, %r15            # imm = 0x100
incq %r14
movl %ebx, %r13d
cmpl $0x24, %ebx
jb 0x2c1ba
jmp 0x2c292
movq 0x8(%rsp), %rbx
cmpl $0x2, %ebx
ja 0x2c29c
movl %ebx, %edi
shlq $0x7, %rdi
addq (%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x10950
cmpl $0x1, %eax
adcl $0x0, %ebx
jmp 0x2c29c
movl %r13d, %ebx
xorl %r13d, %r13d
movl $0x2, %r14d
leaq 0x120(%rsp), %r15
xorl %r12d, %r12d
movq %r15, %rdi
callq 0x2c2b9
cmpl $0x8, %eax
je 0x2c266
cmpl $0x9, %eax
jne 0x2c27a
movl $0xa, %eax
jmp 0x2c26b
movl $0x2, %eax
incl %r12d
movq (%rsp), %rcx
movl %eax, 0x5a4(%rcx,%r13,4)
cmpq %rbx, %r14
jae 0x2c292
addq $0x100, %r15            # imm = 0x100
incq %r14
movl %r12d, %r13d
cmpl $0x3, %r12d
jb 0x2c24d
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rbx
cmpl $-0x1, %ebp
jne 0x2bddc
xorl %eax, %eax
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq