// File: /workspace/github_c_makefile_star2_O2/wahern[P]cqueues/src/lib/dns.c
// Function: dns_p_merge
struct dns_packet *dns_p_merge(struct dns_packet *A, enum dns_section Amask, struct dns_packet *B, enum dns_section Bmask, int *error_) {
	size_t bufsiz = DNS_PP_MIN(65535, ((A)? A->end : 0) + ((B)? B->end : 0));
	struct dns_packet *M;
	enum dns_section section;
	struct dns_rr rr, mr;
	int error, copy;

	if (!A && B) {
		A = B;
		Amask = Bmask;
		B = 0;
	}

merge:
	if (!(M = dns_p_make(bufsiz, &error)))
		goto error;

	for (section = DNS_S_QD; (DNS_S_ALL & section); section <<= 1) {
		if (A && (section & Amask)) {
			dns_rr_foreach(&rr, A, .section = section) {
				if ((error = dns_rr_copy(M, &rr, A)))
					goto error;
			}
		}

		if (B && (section & Bmask)) {
			dns_rr_foreach(&rr, B, .section = section) {
				copy = 1;

				dns_rr_foreach(&mr, M, .type = rr.type, .section = DNS_S_ALL) {
					if (!(copy = dns_rr_cmp(&rr, B, &mr, M)))
						break;
				}

				if (copy && (error = dns_rr_copy(M, &rr, B)))
					goto error;
			}
		}
	}

	return M;
error:
	dns_p_setptr(&M, NULL);

	if (error == DNS_ENOBUFS && bufsiz < 65535) {
		bufsiz = DNS_PP_MIN(65535, bufsiz * 2);

		goto merge;
	}

	*error_	= error;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %r8, 0x20(%rsp)
movl %ecx, 0x14(%rsp)
movq %rdx, %r14
movl %esi, 0x8(%rsp)
testq %rdi, %rdi
je 0x2363e
movq 0x50(%rdi), %rax
jmp 0x23640
xorl %eax, %eax
testq %r14, %r14
je 0x2364b
movq 0x50(%r14), %rcx
jmp 0x2364d
xorl %ecx, %ecx
addq %rax, %rcx
movl $0xffff, %edx           # imm = 0xFFFF
cmpq $0xffff, %rcx           # imm = 0xFFFF
ja 0x2367b
testq %rdi, %rdi
je 0x23669
movq 0x50(%rdi), %rax
jmp 0x2366b
xorl %eax, %eax
testq %r14, %r14
je 0x23676
movq 0x50(%r14), %rdx
jmp 0x23678
xorl %edx, %edx
addq %rax, %rdx
testq %r14, %r14
setne %al
testq %rdi, %rdi
sete %cl
movq %r14, %r13
cmoveq %rdi, %r13
testb %al, %cl
movl 0x8(%rsp), %eax
cmovnel 0x14(%rsp), %eax
movl %eax, 0x8(%rsp)
cmoveq %rdi, %r14
pushq $0x1
popq %rbp
leaq 0x118(%rsp), %r15
leaq 0x1e0(%rsp), %r12
movq %r14, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
movq %rdx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xfaa0
movq %rax, %rbx
testq %rax, %rax
je 0x238e7
testb $0xf, %bpl
je 0x2392e
testq %r14, %r14
je 0x23782
movl %ebp, %eax
andl 0x8(%rsp), %eax
je 0x23782
xorps %xmm0, %xmm0
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xe0(%rsp)
andl $0x0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
leaq 0x104(%rsp), %rax
movups %xmm0, (%rax)
leaq 0x134(%rsp), %rdi
movups %xmm0, 0x44(%rdi)
movl %ebp, 0xc(%rsp)
movl %ebp, 0x130(%rsp)
pushq $0x11
popq %rcx
leaq 0xd0(%rsp), %rsi
rep  movsl (%rsi), %es:(%rdi)
movq %r15, %rdi
pushq $0x1
popq %rsi
leaq 0x130(%rsp), %rdx
movq %r14, %rcx
leaq 0x3c(%rsp), %r8
callq 0xfe00
testl %eax, %eax
je 0x2377e
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x10410
testl %eax, %eax
je 0x23748
jmp 0x238df
movl 0xc(%rsp), %ebp
testq %r13, %r13
sete %al
testl %ebp, 0x14(%rsp)
sete %cl
orb %al, %cl
jne 0x238d8
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
andl $0x0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
leaq 0xb4(%rsp), %rax
movups %xmm0, (%rax)
leaq 0x134(%rsp), %rax
movups %xmm0, 0x44(%rax)
movl %ebp, 0xc(%rsp)
movl %ebp, 0x130(%rsp)
pushq $0x11
popq %rcx
leaq 0x134(%rsp), %rdi
leaq 0x80(%rsp), %rsi
rep  movsl (%rsi), %es:(%rdi)
movq 0x18(%rsp), %r14
pushq $0x1
popq %rbp
movq %r15, %rdi
movl %ebp, %esi
leaq 0x130(%rsp), %rdx
movq %r13, %rcx
leaq 0x38(%rsp), %r8
callq 0xfe00
testl %eax, %eax
je 0x238d4
leaq 0x18c(%rsp), %rdx
andl $0x0, 0x8(%rdx)
andq $0x0, (%rdx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
andl $0x0, 0x60(%rsp)
movl 0x120(%rsp), %eax
leaq 0x64(%rsp), %rcx
movups %xmm0, (%rcx)
movups %xmm0, 0x44(%rdx)
movl $0xf, 0x188(%rsp)
movl %eax, 0x198(%rsp)
movl 0x70(%rsp), %eax
movl %eax, 0x40(%rdx)
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movaps 0x60(%rsp), %xmm2
movups %xmm2, 0x30(%rdx)
movups %xmm1, 0x20(%rdx)
movups %xmm0, 0x10(%rdx)
movq %r12, %rdi
movl %ebp, %esi
leaq 0x188(%rsp), %rdx
movq %rbx, %rcx
leaq 0x34(%rsp), %r8
callq 0xfe00
testl %eax, %eax
je 0x238bc
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x10ac0
testl %eax, %eax
jne 0x23884
jmp 0x237f9
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x10410
testl %eax, %eax
je 0x237f1
jmp 0x238df
movl 0xc(%rsp), %ebp
addl %ebp, %ebp
jmp 0x236d7
movl %eax, %ebp
movl %eax, 0x10(%rsp)
jmp 0x238eb
movl 0x10(%rsp), %ebp
movq %rbx, %rdi
callq 0xffc0
movq 0x28(%rsp), %rdx
cmpq $0xfffe, %rdx           # imm = 0xFFFE
ja 0x23925
cmpl $0x9b918cc0, %ebp       # imm = 0x9B918CC0
jne 0x23925
addq %rdx, %rdx
movl $0xffff, %eax           # imm = 0xFFFF
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movq 0x18(%rsp), %r14
pushq $0x1
popq %rbp
jmp 0x236b9
movq 0x20(%rsp), %rax
movl %ebp, (%rax)
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq