// File: /workspace/github_c_makefile_star2_O1/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 0x13820(%rip), %rsi     # 0x36274
movq %rbx, %rdi
callq 0x101f0
leaq 0x137a4(%rip), %rdx     # 0x36207
movq %rbx, %rdi
movl $0x1, %esi
callq 0x10720
testq %rax, %rax
je 0x22a7a
movq (%rax), %r15
jmp 0x22a7d
xorl %r15d, %r15d
leaq 0x137c8(%rip), %rdx     # 0x3624c
movq %rbx, %rdi
movl $0x2, %esi
callq 0x10720
testq %rax, %rax
je 0x22a9b
movq (%rax), %r12
jmp 0x22a9e
xorl %r12d, %r12d
leaq 0x137b1(%rip), %rdx     # 0x36256
movq %rbx, %rdi
movl $0x3, %esi
callq 0x10720
testq %rax, %rax
je 0x22abc
movq (%rax), %r13
jmp 0x22abf
xorl %r13d, %r13d
testq %r15, %r15
je 0x22acc
movq %r15, %rdi
callq 0xfab0
testq %r12, %r12
je 0x22ad9
movq %r12, %rdi
callq 0xfa90
testq %r13, %r13
je 0x22ae6
movq %r13, %rdi
callq 0xf730
testq %r15, %r15
jne 0x22afd
leaq 0x4(%rsp), %rdi
callq 0xf2d0
movq %rax, %r15
testq %rax, %rax
je 0x22b4c
testq %r12, %r12
jne 0x22b2e
cmpb $0x1, 0x5c1(%r15)
jne 0x22b18
leaq 0x4(%rsp), %rdi
callq 0xf790
jmp 0x22b22
leaq 0x4(%rsp), %rdi
callq 0x10210
movq %rax, %r12
testq %rax, %rax
je 0x22bbd
testq %r13, %r13
jne 0x22b66
cmpb $0x1, 0x5c1(%r15)
jne 0x22b51
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0xf220
jmp 0x22b5e
xorl %r15d, %r15d
jmp 0x22bc5
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0xf240
movq %rax, %r13
testq %rax, %rax
je 0x22bc2
leaq 0x8(%rsp), %r8
movq %r14, (%r8)
leaq 0x157(%rip), %rax       # 0x22ccc
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 0x22bc5
movq %r15, %rdi
callq 0xfee0
movq %r12, %rdi
callq 0x10730
movq %r13, %rdi
callq 0xfba0
movl $0x1, %eax
jmp 0x22bf7
xorl %r12d, %r12d
jmp 0x22bc5
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