// File: /workspace/github_c_makefile_star2_O1/wahern[P]cqueues/src/lib/dns.c
// Function: dns_so_check
int dns_so_check(struct dns_socket *so) {
	int error;
	long n;

retry:
	switch (so->state) {
	case DNS_SO_UDP_INIT:
		so->state++;
		/* FALL THROUGH */
	case DNS_SO_UDP_CONN:
		if (0 != connect(so->udp, (struct sockaddr *)&so->remote, dns_sa_len(&so->remote)))
			goto soerr;

		so->state++;
		/* FALL THROUGH */
	case DNS_SO_UDP_SEND:
		if (0 > (n = send(so->udp, (void *)so->query->data, so->query->end, 0)))
			goto soerr;

		so->stat.udp.sent.bytes += n;
		so->stat.udp.sent.count++;

		so->state++;
		/* FALL THROUGH */
	case DNS_SO_UDP_RECV:
		if (0 > (n = recv(so->udp, (void *)so->answer->data, so->answer->size, 0)))
			goto soerr;

		so->stat.udp.rcvd.bytes += n;
		so->stat.udp.rcvd.count++;

		if ((so->answer->end = n) < 12)
			goto trash;

		if ((error = dns_so_verify(so, so->answer)))
			goto trash;

		so->state++;
		/* FALL THROUGH */
	case DNS_SO_UDP_DONE:
		if (!dns_header(so->answer)->tc || so->type == SOCK_DGRAM)
			return 0;

		so->state++;
		/* FALL THROUGH */
	case DNS_SO_TCP_INIT:
		if (dns_so_tcp_keep(so)) {
			so->state = DNS_SO_TCP_SEND;

			goto retry;
		}

		if ((error = dns_so_closefd(so, &so->tcp)))
			goto error;

		if (-1 == (so->tcp = dns_socket((struct sockaddr *)&so->local, SOCK_STREAM, &error)))
			goto error;

		so->state++;
		/* FALL THROUGH */
	case DNS_SO_TCP_CONN:
		if (0 != connect(so->tcp, (struct sockaddr *)&so->remote, dns_sa_len(&so->remote))) {
			if (dns_soerr() != DNS_EISCONN)
				goto soerr;
		}

		so->state++;
		/* FALL THROUGH */
	case DNS_SO_TCP_SEND:
		if ((error = dns_so_tcp_send(so)))
			goto error;

		so->state++;
		/* FALL THROUGH */
	case DNS_SO_TCP_RECV:
		if ((error = dns_so_tcp_recv(so)))
			goto error;

		so->state++;
		/* FALL THROUGH */
	case DNS_SO_TCP_DONE:
		/* close unless DNS_RESCONF_TCP_ONLY (see dns_res_tcp2type) */
		if (so->type != SOCK_STREAM) {
			if ((error = dns_so_closefd(so, &so->tcp)))
				goto error;
		}

		if (so->answer->end < 12)
			return DNS_EILLEGAL;

		if ((error = dns_so_verify(so, so->answer)))
			goto error;

		return 0;
	default:
		error	= DNS_EUNKNOWN;

		goto error;
	} /* switch() */

trash:
	DNS_CARP("discarding packet");
	goto retry;
soerr:
	error	= dns_soerr();

	goto error;
error:
	switch (error) {
	case DNS_EINTR:
		goto retry;
	case DNS_EINPROGRESS:
		/* FALL THROUGH */
	case DNS_EALREADY:
		/* FALL THROUGH */
#if DNS_EWOULDBLOCK != DNS_EAGAIN
	case DNS_EWOULDBLOCK:
		/* FALL THROUGH */
#endif
		error	= DNS_EAGAIN;

		break;
	} /* switch() */

	return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rdi, %rbx
leaq 0xb8(%rdi), %r14
leaq 0x1c(%rdi), %r15
leaq 0xba(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x38(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x885c(%rip), %r13      # 0x36bc4
movl 0x1b0(%rbx), %eax
decl %eax
cmpl $0x9, %eax
ja 0x2e5b4
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x2, 0x1b0(%rbx)
movl 0x18(%rbx), %edi
movzwl 0xb8(%rbx), %eax
leaq 0xa442(%rip), %rcx      # 0x387e0
movl (%rcx,%rax,8), %edx
movq %r14, %rsi
callq 0xfaa0
testl %eax, %eax
jne 0x2e5a4
incl 0x1b0(%rbx)
movl 0x18(%rbx), %edi
movq 0x2c8(%rbx), %rsi
movq 0x50(%rsi), %rdx
addq $0x5c, %rsi
xorl %ecx, %ecx
callq 0xf600
testq %rax, %rax
js 0x2e5a4
addq %rax, 0x178(%rbx)
incq 0x170(%rbx)
incl 0x1b0(%rbx)
movl 0x18(%rbx), %edi
movq 0x2e8(%rbx), %rsi
movq 0x48(%rsi), %rdx
addq $0x5c, %rsi
xorl %ecx, %ecx
callq 0xf440
testq %rax, %rax
js 0x2e5a4
addq %rax, 0x188(%rbx)
incq 0x180(%rbx)
movq 0x2e8(%rbx), %rsi
movq %rax, 0x50(%rsi)
cmpq $0xc, %rax
jb 0x2e368
movq %rbx, %rdi
callq 0x2e8ba
movl %eax, 0x8(%rsp)
testl %eax, %eax
jne 0x2e368
incl 0x1b0(%rbx)
movq 0x2e8(%rbx), %rcx
xorl %eax, %eax
testb $0x2, 0x5e(%rcx)
je 0x2e89d
cmpl $0x2, 0x30(%rbx)
je 0x2e89d
incl 0x1b0(%rbx)
movl (%r15), %edi
cmpl $-0x1, %edi
je 0x2e4b2
movl $0x80, 0xc(%rsp)
leaq 0x20(%rsp), %rsi
leaq 0xc(%rsp), %rdx
callq 0xf970
testl %eax, %eax
jne 0x2e4b2
movzwl 0x20(%rsp), %ecx
movzwl 0xb8(%rbx), %r12d
movl %ecx, %eax
subl %r12d, %eax
je 0x2e70d
testl %eax, %eax
je 0x2e771
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2e985
movl %eax, 0x8(%rsp)
testl %eax, %eax
jne 0x2e6eb
movq 0x18(%rsp), %rdi
movl $0x1, %esi
leaq 0x8(%rsp), %rdx
callq 0x2ea25
movl %eax, (%r15)
cmpl $-0x1, %eax
je 0x2e6eb
incl 0x1b0(%rbx)
movl 0x1c(%rbx), %edi
movzwl 0xb8(%rbx), %eax
leaq 0xa2e0(%rip), %rcx      # 0x387e0
movl (%rcx,%rax,8), %edx
movq %r14, %rsi
callq 0xfaa0
testl %eax, %eax
je 0x2e51d
callq 0xf0a0
cmpl $0x6a, (%rax)
jne 0x2e5a4
incl 0x1b0(%rbx)
movq 0x2c8(%rbx), %rax
movb 0x51(%rax), %cl
movb %cl, 0x5a(%rax)
movq 0x2c8(%rbx), %rax
movb 0x50(%rax), %cl
movb %cl, 0x5b(%rax)
movq 0x2c8(%rbx), %rax
movq 0x2d0(%rbx), %rcx
movq 0x50(%rax), %r12
addq $0x2, %r12
cmpq %r12, %rcx
jae 0x2e599
leaq (%rax,%rcx), %rbp
addq $0x5a, %rbp
movl 0x1c(%rbx), %edi
leaq (%rcx,%rbp), %rsi
movq %r12, %rdx
subq %rcx, %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0xf600
testq %rax, %rax
js 0x2e5c1
movq 0x2d0(%rbx), %rcx
addq %rax, %rcx
movq %rcx, 0x2d0(%rbx)
addq %rax, 0x198(%rbx)
cmpq %r12, %rcx
jb 0x2e560
incq 0x190(%rbx)
xorl %eax, %eax
jmp 0x2e5c8
callq 0xf0a0
movl (%rax), %eax
movl %eax, 0x8(%rsp)
jmp 0x2e6eb
movl $0x9b918cc4, 0x8(%rsp)  # imm = 0x9B918CC4
jmp 0x2e6eb
callq 0xf0a0
movl (%rax), %eax
movl %eax, 0x8(%rsp)
testl %eax, %eax
jne 0x2e6eb
incl 0x1b0(%rbx)
movq 0x2f0(%rbx), %rbp
movq 0x2f8(%rbx), %rax
addq $0x2, %rbp
cmpq %rbp, %rax
jae 0x2e683
movq 0x2e8(%rbx), %rcx
movl 0x1c(%rbx), %edi
leaq (%rcx,%rax), %rsi
addq $0x5a, %rsi
movq %rbp, %rdx
subq %rax, %rdx
xorl %ecx, %ecx
callq 0xf440
testq %rax, %rax
js 0x2e6fd
je 0x2e706
movq 0x2f8(%rbx), %rcx
addq %rax, %rcx
movq %rcx, 0x2f8(%rbx)
addq %rax, 0x1a8(%rbx)
cmpq $0x0, 0x2f0(%rbx)
jne 0x2e677
cmpq $0x2, %rcx
jb 0x2e677
movq 0x2e8(%rbx), %rax
movzwl 0x5a(%rax), %eax
rolw $0x8, %ax
movzwl %ax, %ebp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x2e2af
testl %eax, %eax
jne 0x2e69e
movq %rbp, 0x2f0(%rbx)
addq $0x2, %rbp
movq 0x2f8(%rbx), %rax
jmp 0x2e5ec
movq 0x2e8(%rbx), %rax
movq 0x2f0(%rbx), %rcx
movq %rcx, 0x50(%rax)
incq 0x1a0(%rbx)
xorl %eax, %eax
movl %eax, 0x8(%rsp)
testl %eax, %eax
jne 0x2e6eb
incl 0x1b0(%rbx)
cmpl $0x1, 0x30(%rbx)
je 0x2e6c5
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2e985
movl %eax, 0x8(%rsp)
testl %eax, %eax
jne 0x2e6eb
movq 0x2e8(%rbx), %rsi
cmpq $0xc, 0x50(%rsi)
jb 0x2e8af
movq %rbx, %rdi
callq 0x2e8ba
movl %eax, 0x8(%rsp)
testl %eax, %eax
je 0x2e8b6
movl 0x8(%rsp), %eax
cmpl $0x4, %eax
je 0x2e368
jmp 0x2e889
callq 0xf0a0
movl (%rax), %eax
jmp 0x2e69e
movl $0x9b918cc4, %eax       # imm = 0x9B918CC4
jmp 0x2e69e
cmpl $0x1, %ecx
je 0x2e7c9
cmpl $0xa, %ecx
je 0x2e780
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x2, %ecx
jne 0x2e4aa
movzwl 0x22(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movzwl 0xba(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
subl %ecx, %eax
jne 0x2e4aa
movl 0x24(%rsp), %ecx
bswapl %ecx
movl 0xbc(%rbx), %edx
bswapl %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %edx, %ecx
jb 0x2e4aa
seta %al
movzbl %al, %eax
jmp 0x2e4aa
movl $0x8, 0x1b0(%rbx)
jmp 0x2e368
movzwl 0x22(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movzwl 0xba(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
subl %ecx, %eax
jne 0x2e4aa
xorl %ecx, %ecx
movzbl 0x28(%rsp,%rcx), %eax
movzbl 0xc0(%rbx,%rcx), %edx
subl %edx, %eax
jne 0x2e4aa
incq %rcx
xorl %eax, %eax
cmpq $0x10, %rcx
jne 0x2e7a4
jmp 0x2e4aa
movl $0x0, %esi
leaq 0x22(%rsp), %rax
cmoveq %rax, %rsi
cmpb $0x0, (%rsi)
movl $0x0, %ebp
je 0x2e7f7
xorl %eax, %eax
leaq 0x1(%rax), %rbp
cmpb $0x0, 0x1(%rsi,%rax)
je 0x2e7f7
cmpq $0x6b, %rax
movq %rbp, %rax
jb 0x2e7e3
cmpq $0x6c, %rbp
movl $0x6c, %eax
cmovaeq %rax, %rbp
leaq 0xa0(%rsp), %rdi
movq %rbp, %rdx
callq 0xfa60
cmpw $0x1, %r12w
movl $0x0, %esi
cmoveq 0x10(%rsp), %rsi
movb $0x0, 0xa0(%rsp,%rbp)
cmpb $0x0, (%rsi)
movl $0x0, %ebp
je 0x2e84c
xorl %eax, %eax
leaq 0x1(%rax), %rbp
cmpb $0x0, 0x1(%rsi,%rax)
je 0x2e84c
cmpq $0x6b, %rax
movq %rbp, %rax
jb 0x2e838
cmpq $0x6c, %rbp
movl $0x6c, %eax
cmovaeq %rax, %rbp
leaq 0x110(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rdx
callq 0xfa60
movb $0x0, 0x110(%rsp,%rbp)
leaq 0xa0(%rsp), %rdi
movq %r12, %rsi
callq 0x10250
jmp 0x2e4aa
addl $-0x72, %eax
cmpl $0x1, %eax
ja 0x2e899
movl $0xb, 0x8(%rsp)
movl 0x8(%rsp), %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x9b918cc1, %eax       # imm = 0x9B918CC1
jmp 0x2e89d
xorl %eax, %eax
jmp 0x2e89d