// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
leaq 0x38(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x8c31(%rip), %rbp      # 0x36b74
movl 0x1b0(%rbx), %eax
decl %eax
cmpl $0x9, %eax
ja 0x2e497
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
movl $0x2, 0x1b0(%rbx)
movl 0x18(%rbx), %edi
movzwl 0xb8(%rbx), %eax
leaq 0xa817(%rip), %rcx      # 0x38790
movl (%rcx,%rax,8), %edx
movq %r14, %rsi
callq 0xfaa0
testl %eax, %eax
jne 0x2e274
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 0x2e274
movdqu 0x170(%rbx), %xmm0
movq %rax, %xmm1
movdqa 0xac77(%rip), %xmm2     # 0x38c40
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
paddq %xmm0, %xmm2
movdqu %xmm2, 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 0x2e274
movdqu 0x180(%rbx), %xmm0
movq %rax, %xmm1
movdqa 0xac2a(%rip), %xmm2     # 0x38c40
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
paddq %xmm0, %xmm2
movdqu %xmm2, 0x180(%rbx)
movq 0x2e8(%rbx), %rsi
movq %rax, 0x50(%rsi)
cmpq $0xc, %rax
jb 0x2df43
movq %rbx, %rdi
callq 0x2e49e
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x2df43
movl 0x1b0(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x1b0(%rbx)
addl $0x2, %eax
jmp 0x2e070
movl (%r15), %edi
jmp 0x2e111
movl $0x6, %eax
movq 0x2e8(%rbx), %rdx
xorl %ecx, %ecx
testb $0x2, 0x5e(%rdx)
je 0x2e478
cmpl $0x2, 0x30(%rbx)
je 0x2e478
movl %eax, 0x1b0(%rbx)
movl (%r15), %edi
cmpl $-0x1, %edi
je 0x2e0d2
movl $0x80, 0x14(%rsp)
leaq 0x20(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0xf970
testl %eax, %eax
jne 0x2e0d2
movzwl 0x20(%rsp), %ecx
movzwl (%r14), %r13d
movl %ecx, %eax
subl %r13d, %eax
je 0x2e31b
testl %eax, %eax
je 0x2e3b5
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2e568
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x2e2d8
movq 0x18(%rsp), %rdi
movl $0x1, %esi
leaq 0x4(%rsp), %rdx
callq 0x2e601
movl %eax, (%r15)
cmpl $-0x1, %eax
je 0x2e315
movl %eax, %edi
incl 0x1b0(%rbx)
movzwl (%r14), %eax
leaq 0xa674(%rip), %rcx      # 0x38790
movl (%rcx,%rax,8), %edx
movq %r14, %rsi
callq 0xfaa0
testl %eax, %eax
je 0x2e139
callq 0xf0a0
cmpl $0x6a, (%rax)
jne 0x2e274
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 0x2e1b9
leaq (%rax,%rcx), %r13
addq $0x5a, %r13
movl (%r15), %edi
leaq (%rcx,%r13), %rsi
movq %r12, %rdx
subq %rcx, %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0xf600
testq %rax, %rax
js 0x2e2e6
movq 0x2d0(%rbx), %rcx
addq %rax, %rcx
movq %rcx, 0x2d0(%rbx)
addq %rax, 0x198(%rbx)
cmpq %r12, %rcx
jb 0x2e17c
incq 0x190(%rbx)
incl 0x1b0(%rbx)
movq 0x2f0(%rbx), %r12
movq 0x2f8(%rbx), %rcx
leaq 0x2(%r12), %r13
cmpq %r13, %rcx
jae 0x2e281
movq 0x2e8(%rbx), %rax
movl 0x1c(%rbx), %edi
leaq (%rax,%rcx), %rsi
addq $0x5a, %rsi
movq %r13, %rdx
subq %rcx, %rdx
xorl %ecx, %ecx
callq 0xf440
testq %rax, %rax
js 0x2e2fa
je 0x2e30b
movq 0x2f8(%rbx), %rcx
addq %rax, %rcx
movq %rcx, 0x2f8(%rbx)
addq %rax, 0x1a8(%rbx)
movq 0x2f0(%rbx), %r12
testq %r12, %r12
jne 0x2e1d9
cmpq $0x2, %rcx
jb 0x2e1d9
movq 0x2e8(%rbx), %rax
movzwl 0x5a(%rax), %eax
rolw $0x8, %ax
movzwl %ax, %r12d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2de8c
testl %eax, %eax
jne 0x2e27b
movq %r12, 0x2f0(%rbx)
leaq 0x2(%r12), %r13
movq 0x2f8(%rbx), %rcx
jmp 0x2e1d9
callq 0xf0a0
movl (%rax), %eax
movl %eax, 0x4(%rsp)
jmp 0x2e2d8
movq 0x2e8(%rbx), %rax
movq %r12, 0x50(%rax)
incq 0x1a0(%rbx)
incl 0x1b0(%rbx)
cmpl $0x1, 0x30(%rbx)
je 0x2e2b2
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2e568
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x2e2d8
movq 0x2e8(%rbx), %rsi
cmpq $0xc, 0x50(%rsi)
jb 0x2e48c
movq %rbx, %rdi
callq 0x2e49e
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0x2e493
cmpl $0x4, %eax
je 0x2df43
jmp 0x2e469
callq 0xf0a0
movl (%rax), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x2e2d8
jmp 0x2e1c0
callq 0xf0a0
movl (%rax), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x2e2d8
jmp 0x2e293
movl $0x9b918cc4, %eax       # imm = 0x9B918CC4
jmp 0x2e27b
movl 0x4(%rsp), %eax
jmp 0x2e2d8
cmpl $0x1, %ecx
je 0x2e3c4
cmpl $0xa, %ecx
je 0x2e376
cmpl $0x2, %ecx
jne 0x2e0d2
movzwl 0x22(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movq 0x8(%rsp), %rcx
movzwl (%rcx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
subl %ecx, %eax
jne 0x2e0ca
movl 0x24(%rsp), %eax
bswapl %eax
movl 0xbc(%rbx), %ecx
bswapl %ecx
cmpl %ecx, %eax
jb 0x2e0d2
seta %al
movzbl %al, %eax
jmp 0x2e0ca
movzwl 0x22(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movq 0x8(%rsp), %rcx
movzwl (%rcx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
subl %ecx, %eax
jne 0x2e0ca
xorl %eax, %eax
movb 0x28(%rsp,%rax), %cl
cmpb 0xc0(%rbx,%rax), %cl
jne 0x2e0d2
incq %rax
cmpq $0x10, %rax
jne 0x2e39b
movl $0x8, 0x1b0(%rbx)
jmp 0x2df43
cmpb $0x0, 0x22(%rsp)
je 0x2e3e3
xorl %eax, %eax
leaq 0x1(%rax), %r12
cmpb $0x0, 0x23(%rsp,%rax)
je 0x2e3e6
cmpq $0x6b, %rax
movq %r12, %rax
jb 0x2e3cd
jmp 0x2e3e6
xorl %r12d, %r12d
leaq 0xa0(%rsp), %rdi
leaq 0x22(%rsp), %rsi
movq %r12, %rdx
callq 0xfa60
cmpw $0x1, %r13w
movl $0x0, %esi
cmoveq 0x8(%rsp), %rsi
movb $0x0, 0xa0(%rsp,%r12)
cmpb $0x0, (%rsi)
movl $0x0, %r12d
je 0x2e438
xorl %eax, %eax
leaq 0x1(%rax), %r12
cmpb $0x0, 0xbb(%rbx,%rax)
je 0x2e438
cmpq $0x6b, %rax
movq %r12, %rax
jb 0x2e421
leaq 0x110(%rsp), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0xfa60
movb $0x0, 0x110(%rsp,%r12)
leaq 0xa0(%rsp), %rdi
movq %r13, %rsi
callq 0x10250
jmp 0x2e0ca
movl $0xb, %ecx
leal -0x72(%rax), %edx
cmpl $0x2, %edx
jb 0x2e478
movl %eax, %ecx
movl %ecx, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x9b918cc1, %ecx       # imm = 0x9B918CC1
jmp 0x2e478
xorl %ecx, %ecx
jmp 0x2e478
movl $0x9b918cc4, %ecx       # imm = 0x9B918CC4
jmp 0x2e478