// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x9, %eax
ja 0x3d911
movq -0x38(%rbp), %rax
leaq 0xca76(%rip), %rcx      # 0x49ff8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
addq $0xb8, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzwl 0xb8(%rax), %edi
callq 0x3c6e0
movl -0x3c(%rbp), %edi
movl %eax, %edx
movq -0x28(%rbp), %rsi
callq 0xfb80
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x3d5e1
jmp 0x3d91f
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edi
movq -0x10(%rbp), %rax
movq 0x2c8(%rax), %rsi
addq $0x5c, %rsi
movq -0x10(%rbp), %rax
movq 0x2c8(%rax), %rax
movq 0x50(%rax), %rdx
xorl %ecx, %ecx
callq 0xf680
movq %rax, %rcx
movq %rcx, -0x20(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jle 0x3d633
jmp 0x3d91f
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x178(%rax), %rcx
movq %rcx, 0x178(%rax)
movq -0x10(%rbp), %rax
movq 0x170(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x170(%rax)
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edi
movq -0x10(%rbp), %rax
movq 0x2e8(%rax), %rsi
addq $0x5c, %rsi
movq -0x10(%rbp), %rax
movq 0x2e8(%rax), %rax
movq 0x48(%rax), %rdx
xorl %ecx, %ecx
callq 0xf490
movq %rax, %rcx
movq %rcx, -0x20(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jle 0x3d6b1
jmp 0x3d91f
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x188(%rax), %rcx
movq %rcx, 0x188(%rax)
movq -0x10(%rbp), %rax
movq 0x180(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x180(%rax)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x2e8(%rcx), %rcx
movq %rax, 0x50(%rcx)
cmpq $0xc, %rax
jae 0x3d6fb
jmp 0x3d91a
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x2e8(%rax), %rsi
callq 0x3d960
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0x3d71c
jmp 0x3d91a
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rax
movq 0x2e8(%rax), %rax
movq 0x5c(%rax), %rax
shrq $0x11, %rax
andq $0x1, %rax
cmpl $0x0, %eax
je 0x3d755
movq -0x10(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x3d761
movl $0x0, -0x4(%rbp)
jmp 0x3d955
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rdi
callq 0x3dac0
testb $0x1, %al
jne 0x3d783
jmp 0x3d796
movq -0x10(%rbp), %rax
movl $0x8, 0x1b0(%rax)
jmp 0x3d55c
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x1c, %rsi
callq 0x3db60
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0x3d7b4
jmp 0x3d929
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movl $0x1, %esi
leaq -0x14(%rbp), %rdx
callq 0x3dc90
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x3d7e1
jmp 0x3d929
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
addq $0xb8, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzwl 0xb8(%rax), %edi
callq 0x3c6e0
movl -0x40(%rbp), %edi
movl %eax, %edx
movq -0x30(%rbp), %rsi
callq 0xfb80
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x3d843
callq 0xf0a0
cmpl $0x6a, (%rax)
je 0x3d841
jmp 0x3d91f
jmp 0x3d843
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rdi
callq 0x3deb0
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0x3d86c
jmp 0x3d929
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rdi
callq 0x3e000
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0x3d895
jmp 0x3d929
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x30(%rax)
je 0x3d8cf
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x1c, %rsi
callq 0x3db60
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0x3d8cd
jmp 0x3d929
jmp 0x3d8cf
movq -0x10(%rbp), %rax
movq 0x2e8(%rax), %rax
cmpq $0xc, 0x50(%rax)
jae 0x3d8ea
movl $0x9b918cc1, -0x4(%rbp) # imm = 0x9B918CC1
jmp 0x3d955
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x2e8(%rax), %rsi
callq 0x3d960
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0x3d908
jmp 0x3d929
movl $0x0, -0x4(%rbp)
jmp 0x3d955
movl $0x9b918cc4, -0x14(%rbp) # imm = 0x9B918CC4
jmp 0x3d929
jmp 0x3d55c
callq 0xf0a0
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x44(%rbp)
subl $0x4, %eax
je 0x3d943
jmp 0x3d936
movl -0x44(%rbp), %eax
addl $-0x72, %eax
subl $0x2, %eax
jb 0x3d948
jmp 0x3d94f
jmp 0x3d55c
movl $0xb, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop