// File: /workspace/github_c_makefile_star2_O2/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)
pushq $0x6
popq %r12
leaq 0x8073(%rip), %r13      # 0x31b74
movl 0x1b0(%rbx), %eax
decl %eax
cmpl $0x9, %eax
ja 0x29fd5
movslq (%r13,%rax,4), %rcx
addq %r13, %rcx
movl %r12d, %eax
jmpq *%rcx
movl $0x2, 0x1b0(%rbx)
movl 0x18(%rbx), %edi
movzwl 0xb8(%rbx), %eax
leaq 0x9c56(%rip), %rcx      # 0x33790
movl (%rcx,%rax,8), %edx
movq %r14, %rsi
callq 0xfb10
testl %eax, %eax
jne 0x29d5e
incl 0x1b0(%rbx)
movl 0x18(%rbx), %edi
movq 0x2c8(%rbx), %rsi
movq 0x50(%rsi), %rdx
addq $0x5c, %rsi
xorl %ecx, %ecx
callq 0xf640
testq %rax, %rax
js 0x29d5e
movdqu 0x170(%rbx), %xmm0
movq %rax, %xmm1
movdqa 0xa0b6(%rip), %xmm2     # 0x33c40
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 0xf460
testq %rax, %rax
js 0x29d5e
movdqu 0x180(%rbx), %xmm0
movq %rax, %xmm1
movdqa 0xa069(%rip), %xmm2     # 0x33c40
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 0x29b01
movq %rbx, %rdi
callq 0x29fdc
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x29b01
movl 0x1b0(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x1b0(%rbx)
addl $0x2, %eax
movq 0x2e8(%rbx), %rdx
xorl %ecx, %ecx
testb $0x2, 0x5e(%rdx)
je 0x29fb6
cmpl $0x2, 0x30(%rbx)
je 0x29fb6
movl %eax, 0x1b0(%rbx)
movl (%r15), %edi
cmpl $-0x1, %edi
je 0x29c83
movl $0x80, 0x14(%rsp)
leaq 0x20(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0xf9c0
testl %eax, %eax
jne 0x29c83
movzwl 0x20(%rsp), %ecx
movzwl (%r14), %ebp
movl %ecx, %eax
subl %ebp, %eax
je 0x29eb5
testl %eax, %eax
je 0x29f54
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2a0a1
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x29ea1
movq 0x18(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x4(%rsp), %rdx
callq 0x2a135
movl %eax, (%r15)
cmpl $-0x1, %eax
je 0x29eaf
movl %eax, %edi
incl 0x1b0(%rbx)
jmp 0x29cc5
movl (%r15), %edi
movzwl (%r14), %eax
leaq 0x9ac0(%rip), %rcx      # 0x33790
movl (%rcx,%rax,8), %edx
movq %r14, %rsi
callq 0xfb10
testl %eax, %eax
je 0x29ce9
callq 0xf0a0
cmpl $0x6a, (%rax)
jne 0x29d5e
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), %rsi
leaq (%rax,%rsi), %r12
addq $0x5a, %r12
movq 0x50(%rax), %rbp
addq $0x2, %rbp
movq %rbp, %rdx
subq %rsi, %rdx
jbe 0x29d6a
movl (%r15), %edi
addq %r12, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0xf640
testq %rax, %rax
js 0x29d78
movq 0x2d0(%rbx), %rsi
addq %rax, %rsi
movq %rsi, 0x2d0(%rbx)
addq %rax, 0x198(%rbx)
jmp 0x29d27
callq 0xf0a0
movl (%rax), %eax
jmp 0x29e9d
incq 0x190(%rbx)
andl $0x0, 0x4(%rsp)
jmp 0x29d8f
callq 0xf0a0
movl (%rax), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
pushq $0x6
popq %r12
jne 0x29ea1
incl 0x1b0(%rbx)
movq 0x2f0(%rbx), %rbp
leaq 0x2(%rbp), %r12
movq 0x2e8(%rbx), %rax
movq 0x2f8(%rbx), %rcx
movq %r12, %rdx
subq %rcx, %rdx
jbe 0x29e2a
movl (%r15), %edi
leaq (%rax,%rcx), %rsi
addq $0x5a, %rsi
xorl %ecx, %ecx
callq 0xf460
testq %rax, %rax
js 0x29e3b
je 0x29e94
movq 0x2f8(%rbx), %rcx
addq %rax, %rcx
movq %rcx, 0x2f8(%rbx)
addq %rax, 0x1a8(%rbx)
movq 0x2f0(%rbx), %rbp
testq %rbp, %rbp
jne 0x29da0
cmpq $0x2, %rcx
jb 0x29da0
movq 0x2e8(%rbx), %rax
movzwl 0x5a(%rax), %eax
rolw $0x8, %ax
movzwl %ax, %ebp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x29a56
testl %eax, %eax
jne 0x29e99
movq %rbp, 0x2f0(%rbx)
jmp 0x29d9c
movq %rbp, 0x50(%rax)
incq 0x1a0(%rbx)
pushq $0x6
popq %r12
jmp 0x29e4e
callq 0xf0a0
movl (%rax), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
pushq $0x6
popq %r12
jne 0x29ea1
incl 0x1b0(%rbx)
cmpl $0x1, 0x30(%rbx)
je 0x29e6d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2a0a1
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x29ea1
movq 0x2e8(%rbx), %rsi
cmpq $0xc, 0x50(%rsi)
jb 0x29fca
movq %rbx, %rdi
callq 0x29fdc
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x29ea1
jmp 0x29fd1
movl $0x9b918cc4, %eax       # imm = 0x9B918CC4
pushq $0x6
popq %r12
movl %eax, 0x4(%rsp)
cmpl $0x4, %eax
je 0x29b01
jmp 0x29fa9
movl 0x4(%rsp), %eax
jmp 0x29ea1
cmpl $0x1, %ecx
je 0x29f63
cmpl $0xa, %ecx
je 0x29f10
cmpl $0x2, %ecx
jne 0x29c83
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 0x29c7b
movl 0x24(%rsp), %eax
bswapl %eax
movl 0xbc(%rbx), %ecx
bswapl %ecx
cmpl %ecx, %eax
jb 0x29c83
seta %al
movzbl %al, %eax
jmp 0x29c7b
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 0x29c7b
xorl %eax, %eax
cmpq $0x10, %rax
je 0x29f54
movb 0x28(%rsp,%rax), %cl
leaq 0x1(%rax), %rdx
cmpb 0xc0(%rbx,%rax), %cl
movq %rdx, %rax
je 0x29f35
jmp 0x29c83
movl $0x8, 0x1b0(%rbx)
jmp 0x29b01
leaq 0xa0(%rsp), %rdi
leaq 0x22(%rsp), %rsi
callq 0x2e186
cmpw $0x1, %bp
movl $0x0, %esi
cmoveq 0x8(%rsp), %rsi
leaq 0x110(%rsp), %rbp
movq %rbp, %rdi
callq 0x2e186
leaq 0xa0(%rsp), %rdi
movq %rbp, %rsi
callq 0x102e0
jmp 0x29c7b
leal -0x72(%rax), %edx
pushq $0xb
popq %rcx
cmpl $0x2, %edx
jb 0x29fb6
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 0x29fb6
xorl %ecx, %ecx
jmp 0x29fb6
movl $0x9b918cc4, %ecx       # imm = 0x9B918CC4
jmp 0x29fb6