// File: /workspace/github_c_makefile_star2_O3/wahern[P]cqueues/src/lib/dns.c
// Function: dns_p_push
int dns_p_push(struct dns_packet *P, enum dns_section section, const void *dn, size_t dnlen, enum dns_type type, enum dns_class class, unsigned ttl, const void *any) {
	size_t end = P->end;
	int error;

	if ((error = dns_d_push(P, dn, dnlen)))
		goto error;

	if (P->size - P->end < 4)
		goto nobufs;

	P->data[P->end++] = 0xff & (type >> 8);
	P->data[P->end++] = 0xff & (type >> 0);

	P->data[P->end++] = 0xff & (class >> 8);
	P->data[P->end++] = 0xff & (class >> 0);

	if (section == DNS_S_QD)
		goto update;

	if (P->size - P->end < 6)
		goto nobufs;

	if (type != DNS_T_OPT)
		ttl = DNS_PP_MIN(ttl, 0x7fffffffU);
	P->data[P->end++] = ttl >> 24;
	P->data[P->end++] = ttl >> 16;
	P->data[P->end++] = ttl >> 8;
	P->data[P->end++] = ttl >> 0;

	if ((error = dns_any_push(P, (union dns_any *)any, type)))
		goto error;

update:
	switch (section) {
	case DNS_S_QD:
		if (dns_p_count(P, DNS_S_AN|DNS_S_NS|DNS_S_AR))
			goto order;

		if (!P->memo.qd.base && (error = dns_p_study(P)))
			goto error;

		dns_header(P)->qdcount = htons(ntohs(dns_header(P)->qdcount) + 1);

		P->memo.qd.end  = P->end;
		P->memo.an.base = P->end;
		P->memo.an.end  = P->end;
		P->memo.ns.base = P->end;
		P->memo.ns.end  = P->end;
		P->memo.ar.base = P->end;
		P->memo.ar.end  = P->end;

		break;
	case DNS_S_AN:
		if (dns_p_count(P, DNS_S_NS|DNS_S_AR))
			goto order;

		if (!P->memo.an.base && (error = dns_p_study(P)))
			goto error;

		dns_header(P)->ancount = htons(ntohs(dns_header(P)->ancount) + 1);

		P->memo.an.end  = P->end;
		P->memo.ns.base = P->end;
		P->memo.ns.end  = P->end;
		P->memo.ar.base = P->end;
		P->memo.ar.end  = P->end;

		break;
	case DNS_S_NS:
		if (dns_p_count(P, DNS_S_AR))
			goto order;

		if (!P->memo.ns.base && (error = dns_p_study(P)))
			goto error;

		dns_header(P)->nscount = htons(ntohs(dns_header(P)->nscount) + 1);

		P->memo.ns.end  = P->end;
		P->memo.ar.base = P->end;
		P->memo.ar.end  = P->end;

		break;
	case DNS_S_AR:
		if (!P->memo.ar.base && (error = dns_p_study(P)))
			goto error;

		dns_header(P)->arcount = htons(ntohs(dns_header(P)->arcount) + 1);

		P->memo.ar.end = P->end;

		if (type == DNS_T_OPT && !P->memo.opt.p) {
			P->memo.opt.p = end;
			P->memo.opt.maxudp = class;
			P->memo.opt.ttl = ttl;
		}

		break;
	default:
		error = DNS_ESECTION;

		goto error;
	} /* switch() */

	return 0;
nobufs:
	error = DNS_ENOBUFS;

	goto error;
order:
	error = DNS_EORDER;

	goto error;
error:
	P->end = end;

	return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %r15d
movl %r8d, %r12d
movl %esi, %ebp
movq %rdi, %rbx
movq 0x50(%rdi), %r14
movq %rdx, %rsi
movq %rcx, %rdx
callq 0xf390
testl %eax, %eax
jne 0x26fa1
movq 0x48(%rbx), %rdx
movq 0x50(%rbx), %rcx
subq %rcx, %rdx
movl $0x9b918cc0, %eax       # imm = 0x9B918CC0
cmpq $0x4, %rdx
jb 0x26fa1
movl %r12d, %r13d
movl %r15d, %r12d
leaq 0x1(%rcx), %rdx
movq %rdx, 0x50(%rbx)
movl %r13d, %edx
movb %dh, 0x5c(%rbx,%rcx)
movl %r13d, %esi
movq 0x50(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x50(%rbx)
movb %sil, 0x5c(%rbx,%rcx)
movq 0x50(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x50(%rbx)
movl %r15d, %edx
movb %dh, 0x5c(%rbx,%rcx)
movl %r12d, %esi
movq 0x50(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x50(%rbx)
movb %sil, 0x5c(%rbx,%rcx)
cmpl $0x1, %ebp
jne 0x26f19
movq 0x5c(%rbx), %rcx
movq %rcx, %rax
shrq $0x30, %rax
rolw $0x8, %ax
movzwl %ax, %eax
movl 0x64(%rbx), %edx
movl %edx, %esi
rolw $0x8, %si
movzwl %si, %esi
shrl $0x10, %edx
rolw $0x8, %dx
addl %eax, %esi
movzwl %dx, %edx
movl $0x9b918cc2, %eax       # imm = 0x9B918CC2
orl %esi, %edx
jne 0x26fa1
cmpw $0x0, 0x20(%rbx)
jne 0x26ec9
movq %rbx, %rdi
callq 0xf7a0
movq 0x5c(%rbx), %rcx
movq %rcx, %rax
shrq $0x20, %rax
rolw $0x8, %ax
incl %eax
rolw $0x8, %ax
movzwl %ax, %eax
shlq $0x20, %rax
movabsq $-0xffff00000001, %rdx  # imm = 0xFFFF0000FFFFFFFF
andq %rcx, %rdx
orq %rax, %rdx
movq %rdx, 0x5c(%rbx)
movl 0x50(%rbx), %eax
movd %eax, %xmm0
pshuflw $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0,4,5,6,7]
movq %xmm0, 0x22(%rbx)
movw %ax, 0x2a(%rbx)
movw %ax, 0x2c(%rbx)
movw %ax, 0x2e(%rbx)
xorl %eax, %eax
jmp 0x26fa5
movq 0x48(%rbx), %rdx
movq 0x50(%rbx), %rcx
subq %rcx, %rdx
cmpq $0x6, %rdx
jb 0x26fa1
movl 0x40(%rsp), %r15d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl %eax, %r15d
cmovbl %r15d, %eax
movl %r13d, %edx
cmpl $0x29, %r13d
cmovel %r15d, %eax
movq 0x48(%rsp), %rsi
movl %eax, %r8d
shrl $0x18, %r8d
leaq 0x1(%rcx), %rdi
movq %rdi, 0x50(%rbx)
movb %r8b, 0x5c(%rbx,%rcx)
movl %eax, %ecx
shrl $0x10, %ecx
movq 0x50(%rbx), %r8
leaq 0x1(%r8), %rdi
movq %rdi, 0x50(%rbx)
movb %cl, 0x5c(%rbx,%r8)
movq 0x50(%rbx), %rcx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x50(%rbx)
movb %ah, 0x5c(%rbx,%rcx)
movq 0x50(%rbx), %rcx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x50(%rbx)
movb %al, 0x5c(%rbx,%rcx)
movq %rbx, %rdi
callq 0xfc80
testl %eax, %eax
je 0x26fb4
movq %r14, 0x50(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %ebp
je 0x27069
cmpl $0x4, %ebp
je 0x27014
movl $0x9b918cc3, %eax       # imm = 0x9B918CC3
cmpl $0x8, %ebp
jne 0x26fa1
cmpw $0x0, 0x2c(%rbx)
jne 0x26fdb
movq %rbx, %rdi
callq 0xf7a0
movzwl 0x66(%rbx), %ecx
rolw $0x8, %cx
movzwl 0x50(%rbx), %edx
incl %ecx
rolw $0x8, %cx
xorl %eax, %eax
movw %cx, 0x66(%rbx)
movw %dx, 0x2e(%rbx)
cmpl $0x29, %r13d
jne 0x26fa5
cmpw $0x0, 0x30(%rbx)
jne 0x26fa5
movw %r14w, 0x30(%rbx)
movw %r12w, 0x32(%rbx)
movl %r15d, 0x34(%rbx)
jmp 0x26fa5
movl 0x64(%rbx), %ecx
movl $0x9b918cc2, %eax       # imm = 0x9B918CC2
cmpl $0xffff, %ecx           # imm = 0xFFFF
ja 0x26fa1
cmpw $0x0, 0x28(%rbx)
jne 0x2703a
movq %rbx, %rdi
callq 0xf7a0
movl 0x64(%rbx), %ecx
movl %ecx, %eax
rolw $0x8, %ax
incl %eax
rolw $0x8, %ax
movzwl %ax, %eax
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %eax, %ecx
movl %ecx, 0x64(%rbx)
movzwl 0x50(%rbx), %eax
movw %ax, 0x2a(%rbx)
movw %ax, 0x2c(%rbx)
movw %ax, 0x2e(%rbx)
jmp 0x26f12
movl 0x64(%rbx), %eax
movzwl %ax, %ecx
movl %eax, %edx
shrl $0x10, %edx
movl $0x9b918cc2, %eax       # imm = 0x9B918CC2
orl %edx, %ecx
jne 0x26fa1
cmpw $0x0, 0x24(%rbx)
jne 0x27090
movq %rbx, %rdi
callq 0xf7a0
movzwl 0x62(%rbx), %eax
rolw $0x8, %ax
incl %eax
rolw $0x8, %ax
movw %ax, 0x62(%rbx)
movl 0x50(%rbx), %eax
movd %eax, %xmm0
pshuflw $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0,4,5,6,7]
movq %xmm0, 0x26(%rbx)
jmp 0x26f0e