// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/lib/dns.c
// Function: dns_res_glue
static struct dns_packet *dns_res_glue(struct dns_resolver *R, struct dns_packet *Q) {
	struct dns_packet *P	= dns_p_new(512);
	char qname[DNS_D_MAXNAME + 1];
	size_t qlen;
	enum dns_type qtype;
	struct dns_rr rr;
	unsigned sp;
	int error;

	if (!(qlen = dns_d_expand(qname, sizeof qname, 12, Q, &error))
	||  qlen >= sizeof qname)
		return 0;

	if (!(qtype = dns_rr_type(12, Q)))
		return 0;

	if ((error = dns_p_push(P, DNS_S_QD, qname, strlen(qname), qtype, DNS_C_IN, 0, 0)))
		return 0;

	for (sp = 0; sp <= R->sp; sp++) {
		if (!R->stack[sp].answer)
			continue;

		dns_rr_foreach(&rr, R->stack[sp].answer, .name = qname, .type = qtype, .section = (DNS_S_ALL & ~DNS_S_QD)) {
			rr.section	= DNS_S_AN;

			if ((error = dns_rr_copy(P, &rr, R->stack[sp].answer)))
				return 0;
		}
	}

	if (dns_p_count(P, DNS_S_AN) > 0)
		goto copy;

	/* Otherwise, look for a CNAME */
	for (sp = 0; sp <= R->sp; sp++) {
		if (!R->stack[sp].answer)
			continue;

		dns_rr_foreach(&rr, R->stack[sp].answer, .name = qname, .type = DNS_T_CNAME, .section = (DNS_S_ALL & ~DNS_S_QD)) {
			rr.section	= DNS_S_AN;

			if ((error = dns_rr_copy(P, &rr, R->stack[sp].answer)))
				return 0;
		}
	}

	if (!dns_p_count(P, DNS_S_AN))
		return 0;

copy:
	return dns_p_copy(dns_p_make(P->end, &error), P);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x540, %rsp            # imm = 0x540
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x280(%rbp), %rdi
xorl %esi, %esi
movl $0x260, %edx            # imm = 0x260
callq 0xf7d0
leaq -0x280(%rbp), %rdi
movl $0x25c, %esi            # imm = 0x25C
callq 0x10c30
movq %rax, -0x20(%rbp)
leaq -0x380(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
movl $0xc, %edx
leaq -0x3ac(%rbp), %r8
callq 0xffd0
movq %rax, -0x388(%rbp)
cmpq $0x0, %rax
je 0x445a6
cmpq $0x100, -0x388(%rbp) # imm = 0x100
jb 0x445b3
movq $0x0, -0x8(%rbp)
jmp 0x4498a
movq -0x18(%rbp), %rsi
movl $0xc, %edi
callq 0x449a0
movl %eax, -0x38c(%rbp)
cmpl $0x0, %eax
jne 0x445d9
movq $0x0, -0x8(%rbp)
jmp 0x4498a
movq -0x20(%rbp), %rax
movq %rax, -0x530(%rbp)
leaq -0x380(%rbp), %rax
movq %rax, -0x528(%rbp)
leaq -0x380(%rbp), %rdi
callq 0xf5c0
movq -0x530(%rbp), %rdi
movq -0x528(%rbp), %rdx
movq %rax, %rcx
movl -0x38c(%rbp), %r8d
movl $0x1, %r9d
xorl %eax, %eax
xorl %eax, %eax
movl %r9d, %esi
movl $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x10880
movl %eax, -0x3ac(%rbp)
cmpl $0x0, %eax
je 0x44650
movq $0x0, -0x8(%rbp)
jmp 0x4498a
movl $0x0, -0x3a8(%rbp)
movl -0x3a8(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4b0(%rcx), %eax
ja 0x447c2
movq -0x10(%rbp), %rax
addq $0x4b8, %rax            # imm = 0x4B8
movl -0x3a8(%rbp), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
cmpq $0x0, 0x20(%rax)
jne 0x44696
jmp 0x447ae
leaq -0x460(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0xf7d0
movl $0xe, -0x460(%rbp)
leaq -0x380(%rbp), %rax
movq %rax, -0x458(%rbp)
movl -0x38c(%rbp), %eax
movl %eax, -0x450(%rbp)
movq -0x10(%rbp), %rax
addq $0x4b8, %rax            # imm = 0x4B8
movl -0x3a8(%rbp), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
movq 0x20(%rax), %rsi
leaq -0x460(%rbp), %rdi
callq 0x10750
movq %rax, %rsi
leaq -0x408(%rbp), %rdi
movl $0x58, %edx
callq 0xfb40
movq -0x10(%rbp), %rax
addq $0x4b8, %rax            # imm = 0x4B8
movl -0x3a8(%rbp), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
movq 0x20(%rax), %rcx
movl $0x0, -0x464(%rbp)
leaq -0x3a4(%rbp), %rdi
movl $0x1, %esi
leaq -0x408(%rbp), %rdx
leaq -0x464(%rbp), %r8
callq 0xfe80
cmpl $0x0, %eax
je 0x447ac
movl $0x2, -0x3a4(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
addq $0x4b8, %rax            # imm = 0x4B8
movl -0x3a8(%rbp), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
movq 0x20(%rax), %rdx
leaq -0x3a4(%rbp), %rsi
callq 0x104d0
movl %eax, -0x3ac(%rbp)
cmpl $0x0, %eax
je 0x447a7
movq $0x0, -0x8(%rbp)
jmp 0x4498a
jmp 0x4470b
jmp 0x447ae
movl -0x3a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3a8(%rbp)
jmp 0x4465a
movq -0x20(%rbp), %rdi
movl $0x2, %esi
callq 0x10950
cmpl $0x0, %eax
jbe 0x447da
jmp 0x44966
movl $0x0, -0x3a8(%rbp)
movl -0x3a8(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4b0(%rcx), %eax
ja 0x44947
movq -0x10(%rbp), %rax
addq $0x4b8, %rax            # imm = 0x4B8
movl -0x3a8(%rbp), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
cmpq $0x0, 0x20(%rax)
jne 0x44820
jmp 0x44933
leaq -0x518(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0xf7d0
movl $0xe, -0x518(%rbp)
leaq -0x380(%rbp), %rax
movq %rax, -0x510(%rbp)
movl $0x5, -0x508(%rbp)
movq -0x10(%rbp), %rax
addq $0x4b8, %rax            # imm = 0x4B8
movl -0x3a8(%rbp), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
movq 0x20(%rax), %rsi
leaq -0x518(%rbp), %rdi
callq 0x10750
movq %rax, %rsi
leaq -0x4c0(%rbp), %rdi
movl $0x58, %edx
callq 0xfb40
movq -0x10(%rbp), %rax
addq $0x4b8, %rax            # imm = 0x4B8
movl -0x3a8(%rbp), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
movq 0x20(%rax), %rcx
movl $0x0, -0x51c(%rbp)
leaq -0x3a4(%rbp), %rdi
movl $0x1, %esi
leaq -0x4c0(%rbp), %rdx
leaq -0x51c(%rbp), %r8
callq 0xfe80
cmpl $0x0, %eax
je 0x44931
movl $0x2, -0x3a4(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
addq $0x4b8, %rax            # imm = 0x4B8
movl -0x3a8(%rbp), %ecx
imulq $0x110, %rcx, %rcx      # imm = 0x110
addq %rcx, %rax
movq 0x20(%rax), %rdx
leaq -0x3a4(%rbp), %rsi
callq 0x104d0
movl %eax, -0x3ac(%rbp)
cmpl $0x0, %eax
je 0x4492c
movq $0x0, -0x8(%rbp)
jmp 0x4498a
jmp 0x44893
jmp 0x44933
movl -0x3a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3a8(%rbp)
jmp 0x447e4
movq -0x20(%rbp), %rdi
movl $0x2, %esi
callq 0x10950
cmpl $0x0, %eax
jne 0x44964
movq $0x0, -0x8(%rbp)
jmp 0x4498a
jmp 0x44966
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rdi
leaq -0x3ac(%rbp), %rsi
callq 0xfb10
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x10300
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x540, %rsp            # imm = 0x540
popq %rbp
retq
nopw (%rax,%rax)