// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
pushq $0x10
popq %rsi
callq 0xfb70
movq %rax, %r14
andq $0x0, (%rax)
pushq $0x1
popq %rdx
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0xf470
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xf480
movq %rax, 0x8(%r14)
pushq $-0x2
popq %rsi
movq %rbx, %rdi
callq 0x106f0
leaq 0x112f5(%rip), %rsi     # 0x3123c
movq %rbx, %rdi
callq 0x10280
movq %rbx, %rdi
callq 0x1f149
movq %rax, %r15
pushq $0x2
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1f507
movq %rax, %r12
pushq $0x3
popq %rsi
movq %rbx, %rdi
callq 0x1fa5e
movq %rax, %r13
testq %r15, %r15
je 0x1ff85
movq %r15, %rdi
callq 0xfb20
testq %r12, %r12
je 0x1ff92
movq %r12, %rdi
callq 0xfb00
testq %r13, %r13
je 0x1ff9f
movq %r13, %rdi
callq 0xf770
testq %r15, %r15
jne 0x1ffb6
leaq 0xc(%rsp), %rdi
callq 0xf2e0
movq %rax, %r15
testq %rax, %rax
je 0x20005
testq %r12, %r12
jne 0x1ffe7
cmpb $0x1, 0x5c1(%r15)
jne 0x1ffd1
leaq 0xc(%rsp), %rdi
callq 0xf7d0
jmp 0x1ffdb
leaq 0xc(%rsp), %rdi
callq 0x102a0
movq %rax, %r12
testq %rax, %rax
je 0x20071
testq %r13, %r13
jne 0x2001f
cmpb $0x1, 0x5c1(%r15)
jne 0x2000a
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
callq 0xf230
jmp 0x20017
xorl %r15d, %r15d
jmp 0x20079
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
callq 0xf250
movq %rax, %r13
testq %rax, %rax
je 0x20076
leaq 0x10(%rsp), %r8
movq %r14, (%r8)
leaq 0xe0(%rip), %rax        # 0x2010e
movq %rax, 0x8(%r8)
andl $0x0, 0x10(%r8)
leaq 0xc(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xf9b0
movq %rax, (%r14)
testq %rax, %rax
je 0x20079
movq %r15, %rdi
callq 0xff70
movq %r12, %rdi
callq 0x107f0
movq %r13, %rdi
callq 0xfc20
pushq $0x1
popq %rbp
jmp 0x200a6
xorl %r12d, %r12d
jmp 0x20079
xorl %r13d, %r13d
movq %r15, %rdi
callq 0xff70
movq %r12, %rdi
callq 0x107f0
movq %r13, %rdi
callq 0xfc20
movq %rbx, %rdi
callq 0xf9d0
movslq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0xf960
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq