// File: /workspace/github_c_makefile_star2_O3/wahern[P]cqueues/src/dns.c
// Function: res_new
static int res_new(lua_State *L) {
	struct resolver *R = res_prep(L);
	struct dns_resolv_conf *resconf = resconf_test(L, 1);
	struct dns_hosts *hosts = hosts_test(L, 2);
	struct dns_hints *hints = hints_test(L, 3);
	int error;

	if (resconf)
		dns_resconf_acquire(resconf);
	if (hosts)
		dns_hosts_acquire(hosts);
	if (hints)
		dns_hints_acquire(hints);

	if (!resconf && !(resconf = dns_resconf_local(&error)))
		goto error;

	if (!hosts) {
		if (resconf->options.recurse)
			hosts = dns_hosts_open(&error);
		else
			hosts = dns_hosts_local(&error);

		if (!hosts)
			goto error;
	}

	if (!hints) {
		if (resconf->options.recurse)
			hints = dns_hints_root(resconf, &error);
		else
			hints = dns_hints_local(resconf, &error);

		if (!hints)
			goto error;
	}

	if (!(R->res = dns_res_open(resconf, hosts, hints, NULL, dns_opts(.closefd = { R, &res_closefd }), &error)))
		goto error;

	dns_resconf_close(resconf);
	dns_hosts_close(hosts);
	dns_hints_close(hints);

	return 1;
error:
	dns_resconf_close(resconf);
	dns_hosts_close(hosts);
	dns_hints_close(hints);

	lua_pushnil(L);
	lua_pushinteger(L, error);

	return 2;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movl $0x10, %esi
callq 0xfb00
movq %rax, %r14
movq $0x0, (%rax)
movl $0x1, %edx
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0xf450
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xf460
movq %rax, 0x8(%r14)
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
leaq 0x13921(%rip), %rsi     # 0x3623c
movq %rbx, %rdi
callq 0x101f0
leaq 0x138a5(%rip), %rdx     # 0x361cf
movq %rbx, %rdi
movl $0x1, %esi
callq 0x10720
testq %rax, %rax
je 0x22941
movq (%rax), %r15
jmp 0x22944
xorl %r15d, %r15d
leaq 0x138c9(%rip), %rdx     # 0x36214
movq %rbx, %rdi
movl $0x2, %esi
callq 0x10720
testq %rax, %rax
je 0x22962
movq (%rax), %r12
jmp 0x22965
xorl %r12d, %r12d
leaq 0x138b2(%rip), %rdx     # 0x3621e
movq %rbx, %rdi
movl $0x3, %esi
callq 0x10720
testq %rax, %rax
je 0x22983
movq (%rax), %r13
jmp 0x22986
xorl %r13d, %r13d
testq %r15, %r15
je 0x22993
movq %r15, %rdi
callq 0xfab0
testq %r12, %r12
je 0x229a0
movq %r12, %rdi
callq 0xfa90
testq %r13, %r13
je 0x229ad
movq %r13, %rdi
callq 0xf730
testq %r15, %r15
jne 0x229c4
leaq 0x4(%rsp), %rdi
callq 0xf2d0
movq %rax, %r15
testq %rax, %rax
je 0x22a13
testq %r12, %r12
jne 0x229f5
cmpb $0x1, 0x5c1(%r15)
jne 0x229df
leaq 0x4(%rsp), %rdi
callq 0xf790
jmp 0x229e9
leaq 0x4(%rsp), %rdi
callq 0x10210
movq %rax, %r12
testq %rax, %rax
je 0x22a84
testq %r13, %r13
jne 0x22a2d
cmpb $0x1, 0x5c1(%r15)
jne 0x22a18
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0xf220
jmp 0x22a25
xorl %r15d, %r15d
jmp 0x22a8c
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0xf240
movq %rax, %r13
testq %rax, %rax
je 0x22a89
leaq 0x8(%rsp), %r8
movq %r14, (%r8)
leaq 0x157(%rip), %rax       # 0x22b93
movq %rax, 0x8(%r8)
movl $0x0, 0x10(%r8)
leaq 0x4(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xf960
movq %rax, (%r14)
testq %rax, %rax
je 0x22a8c
movq %r15, %rdi
callq 0xfee0
movq %r12, %rdi
callq 0x10730
movq %r13, %rdi
callq 0xfba0
movl $0x1, %eax
jmp 0x22abe
xorl %r12d, %r12d
jmp 0x22a8c
xorl %r13d, %r13d
movq %r15, %rdi
callq 0xfee0
movq %r12, %rdi
callq 0x10730
movq %r13, %rdi
callq 0xfba0
movq %rbx, %rdi
callq 0xf980
movslq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0xf910
movl $0x2, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq