// File: /workspace/github_c_makefile_star2_O1/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, %ebp
movl %r8d, %r12d
movl %esi, %r14d
movq %rdi, %rbx
movq 0x50(%rdi), %r15
movq %rdx, %rsi
movq %rcx, %rdx
callq 0xf390
testl %eax, %eax
jne 0x270aa
movq 0x48(%rbx), %rdx
movq 0x50(%rbx), %rcx
subq %rcx, %rdx
movl $0x9b918cc0, %eax       # imm = 0x9B918CC0
cmpq $0x4, %rdx
jae 0x270bd
movq %r15, 0x50(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x40(%rsp), %r13d
leaq 0x1(%rcx), %rdx
movq %rdx, 0x50(%rbx)
movl %r12d, %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)
movq 0x50(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x50(%rbx)
movl %ebp, %edx
movb %dh, 0x5c(%rbx,%rcx)
movl %ebp, %esi
movq 0x50(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x50(%rbx)
movb %sil, 0x5c(%rbx,%rcx)
cmpl $0x1, %r14d
jne 0x2719c
movl $0x9b918cc3, %eax       # imm = 0x9B918CC3
decl %r14d
cmpl $0x7, %r14d
ja 0x270aa
leaq 0xfa07(%rip), %rcx      # 0x36b30
movslq (%rcx,%r14,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movzwl 0x62(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl 0x64(%rbx), %ecx
movl %ecx, %edx
rolw $0x8, %dx
movzwl %dx, %edx
shrl $0x10, %ecx
rolw $0x8, %cx
addl %eax, %edx
movzwl %cx, %ecx
movl $0x9b918cc2, %eax       # imm = 0x9B918CC2
orl %edx, %ecx
jne 0x270aa
cmpw $0x0, 0x20(%rbx)
jne 0x27171
movq %rbx, %rdi
callq 0xf7a0
movzwl 0x50(%rbx), %eax
movzwl 0x60(%rbx), %ecx
rolw $0x8, %cx
incl %ecx
rolw $0x8, %cx
movw %cx, 0x60(%rbx)
movw %ax, 0x22(%rbx)
movw %ax, 0x24(%rbx)
movw %ax, 0x26(%rbx)
movw %ax, 0x28(%rbx)
jmp 0x2726a
movq 0x48(%rbx), %rdx
movq 0x50(%rbx), %rcx
subq %rcx, %rdx
cmpq $0x6, %rdx
jb 0x270aa
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl %r13d, %eax
cmpl %esi, %r13d
cmovbl %r13d, %esi
movl %r12d, %edx
cmpl $0x29, %r12d
cmovnel %esi, %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, %r8d
shrl $0x10, %r8d
movq 0x50(%rbx), %rcx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x50(%rbx)
movb %r8b, 0x5c(%rbx,%rcx)
movq 0x50(%rbx), %rdi
leaq 0x1(%rdi), %rcx
movq %rcx, 0x50(%rbx)
movb %ah, 0x5c(%rbx,%rdi)
movq 0x50(%rbx), %rdi
leaq 0x1(%rdi), %rcx
movq %rcx, 0x50(%rbx)
movl %eax, %r13d
movb %al, 0x5c(%rbx,%rdi)
movq %rbx, %rdi
callq 0xfc80
testl %eax, %eax
jne 0x270aa
jmp 0x27114
movl $0x9b918cc2, %eax       # imm = 0x9B918CC2
cmpl $0xffff, 0x64(%rbx)     # imm = 0xFFFF
ja 0x270aa
cmpw $0x0, 0x28(%rbx)
jne 0x27254
movq %rbx, %rdi
callq 0xf7a0
movzwl 0x50(%rbx), %eax
movzwl 0x64(%rbx), %ecx
rolw $0x8, %cx
incl %ecx
rolw $0x8, %cx
movw %cx, 0x64(%rbx)
movw %ax, 0x2a(%rbx)
movw %ax, 0x2c(%rbx)
movw %ax, 0x2e(%rbx)
jmp 0x272c9
movl 0x64(%rbx), %eax
movzwl %ax, %ecx
movl %eax, %edx
shrl $0x10, %edx
movl $0x9b918cc2, %eax       # imm = 0x9B918CC2
orl %edx, %ecx
jne 0x270aa
cmpw $0x0, 0x24(%rbx)
jne 0x2729f
movq %rbx, %rdi
callq 0xf7a0
movzwl 0x62(%rbx), %eax
rolw $0x8, %ax
incl %eax
rolw $0x8, %ax
movzwl 0x50(%rbx), %ecx
movw %ax, 0x62(%rbx)
movw %cx, 0x26(%rbx)
movw %cx, 0x28(%rbx)
movw %cx, 0x2a(%rbx)
movw %cx, 0x2c(%rbx)
movw %cx, 0x2e(%rbx)
xorl %eax, %eax
jmp 0x270ae
cmpw $0x0, 0x2c(%rbx)
jne 0x272df
movq %rbx, %rdi
callq 0xf7a0
movzwl 0x66(%rbx), %eax
rolw $0x8, %ax
movzwl 0x50(%rbx), %ecx
incl %eax
rolw $0x8, %ax
movw %ax, 0x66(%rbx)
movw %cx, 0x2e(%rbx)
xorl %eax, %eax
cmpl $0x29, %r12d
jne 0x270ae
cmpw $0x0, 0x30(%rbx)
jne 0x270ae
movw %r15w, 0x30(%rbx)
movw %bp, 0x32(%rbx)
movl %r13d, 0x34(%rbx)
jmp 0x270ae