// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xf3d0
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x32bc0
jmp 0x33123
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x50(%rcx), %rax
cmpq $0x4, %rax
jae 0x32bdb
jmp 0x33113
movl -0x2c(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movq 0x50(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x50(%rsi)
movb %dl, 0x5c(%rax,%rcx)
movl -0x2c(%rbp), %eax
shrl $0x0, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movq 0x50(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x50(%rsi)
movb %dl, 0x5c(%rax,%rcx)
movl -0x30(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movq 0x50(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x50(%rsi)
movb %dl, 0x5c(%rax,%rcx)
movl -0x30(%rbp), %eax
shrl $0x0, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movq 0x50(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x50(%rsi)
movb %dl, 0x5c(%rax,%rcx)
cmpl $0x1, -0x14(%rbp)
jne 0x32c86
jmp 0x32d73
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x50(%rcx), %rax
cmpq $0x6, %rax
jae 0x32ca1
jmp 0x33113
cmpl $0x29, -0x2c(%rbp)
je 0x32cc8
cmpl $0x7fffffff, 0x10(%rbp) # imm = 0x7FFFFFFF
jae 0x32cb8
movl 0x10(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x32cc2
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x40(%rbp)
jmp 0x32cc2
movl -0x40(%rbp), %eax
movl %eax, 0x10(%rbp)
movl 0x10(%rbp), %eax
shrl $0x18, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movq 0x50(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x50(%rsi)
movb %dl, 0x5c(%rax,%rcx)
movl 0x10(%rbp), %eax
shrl $0x10, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movq 0x50(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x50(%rsi)
movb %dl, 0x5c(%rax,%rcx)
movl 0x10(%rbp), %eax
shrl $0x8, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movq 0x50(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x50(%rsi)
movb %dl, 0x5c(%rax,%rcx)
movl 0x10(%rbp), %eax
shrl $0x0, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movq 0x50(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x50(%rsi)
movb %dl, 0x5c(%rax,%rcx)
movq -0x10(%rbp), %rdi
movq 0x18(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0xfd80
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x32d71
jmp 0x33123
jmp 0x32d73
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x7, %eax
ja 0x33101
movq -0x48(%rbp), %rax
leaq 0x170ee(%rip), %rcx     # 0x49e80
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
movl $0xe, %esi
callq 0x10950
cmpl $0x0, %eax
je 0x32db3
jmp 0x3311c
movq -0x10(%rbp), %rax
cmpw $0x0, 0x20(%rax)
jne 0x32dd4
movq -0x10(%rbp), %rdi
callq 0xf820
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x32dd4
jmp 0x33123
movq -0x10(%rbp), %rax
movq 0x5c(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movzwl %ax, %edi
callq 0x10a80
movzwl %ax, %eax
addl $0x1, %eax
movzwl %ax, %edi
callq 0xf0e0
movzwl %ax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x5c(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
shlq $0x20, %rdx
movabsq $-0xffff00000001, %rsi  # imm = 0xFFFF0000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x5c(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x22(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x24(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x26(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2a(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2e(%rax)
jmp 0x3310a
movq -0x10(%rbp), %rdi
movl $0xc, %esi
callq 0x10950
cmpl $0x0, %eax
je 0x32ecc
jmp 0x3311c
movq -0x10(%rbp), %rax
cmpw $0x0, 0x24(%rax)
jne 0x32eed
movq -0x10(%rbp), %rdi
callq 0xf820
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x32eed
jmp 0x33123
movq -0x10(%rbp), %rax
movq 0x5c(%rax), %rax
shrq $0x30, %rax
movzwl %ax, %edi
callq 0x10a80
movzwl %ax, %eax
addl $0x1, %eax
movzwl %ax, %edi
callq 0xf0e0
movzwl %ax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x5c(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
shlq $0x30, %rdx
movabsq $0xffffffffffff, %rsi   # imm = 0xFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x5c(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x26(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2a(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2e(%rax)
jmp 0x3310a
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x10950
cmpl $0x0, %eax
je 0x32fb9
jmp 0x3311c
movq -0x10(%rbp), %rax
cmpw $0x0, 0x28(%rax)
jne 0x32fda
movq -0x10(%rbp), %rdi
callq 0xf820
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x32fda
jmp 0x33123
movq -0x10(%rbp), %rax
movl 0x64(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movzwl %ax, %edi
callq 0x10a80
movzwl %ax, %eax
addl $0x1, %eax
movzwl %ax, %edi
callq 0xf0e0
movzwl %ax, %edx
movq -0x10(%rbp), %rax
movl 0x64(%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, 0x64(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2a(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2e(%rax)
jmp 0x3310a
movq -0x10(%rbp), %rax
cmpw $0x0, 0x2c(%rax)
jne 0x33076
movq -0x10(%rbp), %rdi
callq 0xf820
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x33076
jmp 0x33123
movq -0x10(%rbp), %rax
movl 0x64(%rax), %eax
shrl $0x10, %eax
movzwl %ax, %edi
callq 0x10a80
movzwl %ax, %eax
addl $0x1, %eax
movzwl %ax, %edi
callq 0xf0e0
movzwl %ax, %edx
movq -0x10(%rbp), %rax
movl 0x64(%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
shll $0x10, %edx
andl $0xffff, %ecx           # imm = 0xFFFF
orl %edx, %ecx
movl %ecx, 0x64(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2e(%rax)
cmpl $0x29, -0x2c(%rbp)
jne 0x330ff
movq -0x10(%rbp), %rax
cmpw $0x0, 0x30(%rax)
jne 0x330ff
movq -0x38(%rbp), %rax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x30(%rax)
movl -0x30(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x32(%rax)
movl 0x10(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x34(%rax)
jmp 0x3310a
movl $0x9b918cc3, -0x3c(%rbp) # imm = 0x9B918CC3
jmp 0x33123
movl $0x0, -0x4(%rbp)
jmp 0x33135
movl $0x9b918cc0, -0x3c(%rbp) # imm = 0x9B918CC0
jmp 0x33123
movl $0x9b918cc2, -0x3c(%rbp) # imm = 0x9B918CC2
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x50(%rax)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop