// File: /workspace/github_c_makefile_star2_O2/hkshenSmart[P]ONVIF-discovery_cs/stdsoap2.c
// Function: soap_accept
SOAP_FMAC2
soap_accept(struct soap *soap)
{ int n = (int)sizeof(soap->peer);
#ifndef WITH_LEAN
#ifndef WITH_WIN32
  int len = SOAP_BUFLEN;
#else
  int len = SOAP_BUFLEN + 1; /* speeds up windows xfer */
#endif
  int set = 1;
#endif
  soap->error = SOAP_OK;
#ifndef WITH_LEAN
  if ((soap->omode & SOAP_IO_UDP))
    return soap->socket = soap->master;
#endif
  memset((void*)&soap->peer, 0, sizeof(soap->peer));
  soap->socket = SOAP_INVALID_SOCKET;
  soap->errmode = 0;
  soap->keep_alive = 0;
  if (soap_valid_socket(soap->master))
  { register int err;
    for (;;)
    { if (soap->accept_timeout || soap->send_timeout || soap->recv_timeout)
      { for (;;)
        { register int r;
          r = tcp_select(soap, soap->master, SOAP_TCP_SELECT_ALL, soap->accept_timeout ? soap->accept_timeout : 60);
          if (r > 0)
            break;
          if (!r && soap->accept_timeout)
          { soap_set_receiver_error(soap, "Timeout", "accept failed in soap_accept()", SOAP_TCP_ERROR);
            return SOAP_INVALID_SOCKET;
          }
          if (r < 0)
          { r = soap->errnum;
            if (r != SOAP_EINTR)
            { soap_closesock(soap);
              soap_set_sender_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR);
              return SOAP_INVALID_SOCKET;
            }
          }
        }
      }
      if (soap->accept_timeout)
        SOAP_SOCKNONBLOCK(soap->master)
      else
        SOAP_SOCKBLOCK(soap->master)
      soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&soap->peer, &n);
      soap->peerlen = (size_t)n;
      if (soap_valid_socket(soap->socket))
      {
#ifdef WITH_IPV6
/* Use soap->host to store the numeric form of the remote host */
        getnameinfo((struct sockaddr*)&soap->peer, n, soap->host, sizeof(soap->host), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV);
        DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket %d from %s\n", soap->socket, soap->host));
        soap->ip = 0; /* info stored in soap->peer and soap->host */
        soap->port = 0; /* info stored in soap->peer and soap->host */
#else
        soap->ip = ntohl(soap->peer.sin_addr.s_addr);
        soap->port = (int)ntohs(soap->peer.sin_port); /* does not return port number on some systems */
        DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket %d at port %d from IP %d.%d.%d.%d\n", soap->socket, soap->port, (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF));
#endif
#ifndef WITH_LEAN
        if (soap->accept_flags == SO_LINGER)
        { struct linger linger;
          memset((void*)&linger, 0, sizeof(linger));
          linger.l_onoff = 1;
          linger.l_linger = soap->linger_time;
          if (setsockopt(soap->socket, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
          { soap->errnum = soap_socket_errno(soap->socket);
            soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR);
            soap_closesock(soap);
            return SOAP_INVALID_SOCKET;
          }
        }
        else if (soap->accept_flags && setsockopt(soap->socket, SOL_SOCKET, soap->accept_flags, (char*)&set, sizeof(int)))
        { soap->errnum = soap_socket_errno(soap->socket);
          soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_accept()", SOAP_TCP_ERROR);
          soap_closesock(soap);
          return SOAP_INVALID_SOCKET;
        }
        if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt(soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
        { soap->errnum = soap_socket_errno(soap->socket);
          soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR);
          soap_closesock(soap);
          return SOAP_INVALID_SOCKET;
        }
        if (setsockopt(soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
        { soap->errnum = soap_socket_errno(soap->socket);
          soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR);
          soap_closesock(soap);
          return SOAP_INVALID_SOCKET;
        }
        if (setsockopt(soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
        { soap->errnum = soap_socket_errno(soap->socket);
          soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR);
          soap_closesock(soap);
          return SOAP_INVALID_SOCKET;
        }
#ifdef TCP_NODELAY
        if (!(soap->omode & SOAP_IO_UDP) && setsockopt(soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
        { soap->errnum = soap_socket_errno(soap->socket);
          soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR);
          soap_closesock(soap);
          return SOAP_INVALID_SOCKET;
        }
#endif
#endif
        soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0);
        if (soap->send_timeout || soap->recv_timeout)
          SOAP_SOCKNONBLOCK(soap->socket)
        else
          SOAP_SOCKBLOCK(soap->socket)
        return soap->socket;
      }
      err = soap_socket_errno(soap->socket);
      if (err != 0 && err != SOAP_EINTR && err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK)
      { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host));
        soap->errnum = err;
        soap_set_receiver_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR);
        soap_closesock(soap);
        return SOAP_INVALID_SOCKET;
      }
    }
  }
  else
  { soap->errnum = 0;
    soap_set_receiver_error(soap, tcp_error(soap), "no master socket in soap_accept()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl $0x10, 0xc(%rsp)
movl $0x10000, 0x8(%rsp)     # imm = 0x10000
movl $0x1, 0x4(%rsp)
andl $0x0, 0x1f274(%rdi)
testb $0x4, 0xc(%rdi)
jne 0x13b20
xorps %xmm0, %xmm0
movups %xmm0, 0x27384(%rbx)
orl $-0x1, 0xc134(%rbx)
andl $0x0, 0x1f278(%rbx)
andw $0x0, 0x1f22c(%rbx)
cmpl $-0x1, 0xc130(%rbx)
je 0x13b2e
leaq 0x27384(%rbx), %r14
leaq 0xc(%rsp), %r12
pushq $0x3c
popq %r15
pushq $0x7
popq %r13
movl 0x5c(%rbx), %ecx
testl %ecx, %ecx
jne 0x13a3c
cmpl $0x0, 0x54(%rbx)
jne 0x13a3c
cmpl $0x0, 0x50(%rbx)
je 0x13a97
movl 0xc130(%rbx), %esi
testl %ecx, %ecx
cmovel %r15d, %ecx
movq %rbx, %rdi
movl %r13d, %edx
callq 0x137d1
testl %eax, %eax
jg 0x13a78
je 0x13a6b
cmpl $0x4, 0x1f27c(%rbx)
jne 0x13b4f
movl 0x5c(%rbx), %ecx
jmp 0x13a3c
xorl %ecx, %ecx
cmpl $0x0, 0x5c(%rbx)
je 0x13a3c
jmp 0x13b76
cmpl $0x0, 0x5c(%rbx)
je 0x13a97
movl 0xc130(%rbx), %ebp
movl %ebp, %edi
pushq $0x3
popq %rsi
xorl %eax, %eax
callq 0x30d0
orl $0x800, %eax            # imm = 0x800
jmp 0x13aae
movl 0xc130(%rbx), %ebp
movl %ebp, %edi
pushq $0x3
popq %rsi
xorl %eax, %eax
callq 0x30d0
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
movl %ebp, %edi
pushq $0x4
popq %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x30d0
movl 0xc130(%rbx), %esi
movq %rbx, %rdi
movq %r14, %rdx
movq %r12, %rcx
callq *0xc018(%rbx)
movl %eax, 0xc134(%rbx)
movslq 0xc(%rsp), %rcx
movq %rcx, 0x27398(%rbx)
cmpl $-0x1, %eax
jne 0x13ba1
callq 0x3050
movl (%rax), %eax
cmpl $0xb, %eax
ja 0x13b06
movl $0x811, %ecx            # imm = 0x811
btl %eax, %ecx
jb 0x13a29
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x135f2
leaq 0xf71e(%rip), %rdx      # 0x23239
jmp 0x13d11
movl 0xc130(%rbx), %eax
movl %eax, 0xc134(%rbx)
jmp 0x13b92
andl $0x0, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x135f2
leaq 0xf81d(%rip), %rdx      # 0x23361
pushq $0x1c
popq %rcx
movq %rbx, %rdi
movq %rax, %rsi
jmp 0x13b8a
movq %rbx, %rdi
callq 0x13665
movq %rbx, %rdi
callq 0x135f2
leaq 0xf6d3(%rip), %rdx      # 0x23239
pushq $0x1c
popq %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x13ddd
jmp 0x13b8f
leaq 0xf6b4(%rip), %rsi      # 0x23231
leaq 0xf6b5(%rip), %rdx      # 0x23239
pushq $0x1c
popq %rcx
movq %rbx, %rdi
callq 0x135cb
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x27388(%rbx), %ecx
bswapl %ecx
movq %rcx, 0x1f220(%rbx)
movzwl 0x27386(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movl %ecx, 0x1f228(%rbx)
movl 0x6c(%rbx), %edx
testl %edx, %edx
je 0x13c55
cmpl $0xd, %edx
jne 0x13c1d
leaq 0x10(%rsp), %rcx
movq $0x1, (%rcx)
movzwl 0x70(%rbx), %edx
movl %edx, 0x4(%rcx)
pushq $0x1
popq %rsi
pushq $0xd
popq %rdx
pushq $0x8
popq %r8
movl %eax, %edi
callq 0x30b0
testl %eax, %eax
je 0x13c55
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x135f2
leaq 0xf640(%rip), %rdx      # 0x23258
jmp 0x13d11
pushq $0x1
popq %rsi
leaq 0x4(%rsp), %rcx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x30b0
testl %eax, %eax
je 0x13c55
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x135f2
leaq 0xf635(%rip), %rdx      # 0x23285
jmp 0x13d11
movl 0xc(%rbx), %eax
orl 0x8(%rbx), %eax
movl 0xc134(%rbx), %edi
testb $0x10, %al
je 0x13ca1
pushq $0x1
popq %rsi
pushq $0x9
popq %rdx
leaq 0x4(%rsp), %rcx
pushq $0x4
popq %r8
callq 0x30b0
testl %eax, %eax
je 0x13c9b
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x135f2
leaq 0xf60f(%rip), %rdx      # 0x232a8
jmp 0x13d11
movl 0xc134(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x7
popq %rdx
leaq 0x8(%rsp), %rcx
pushq $0x4
popq %r8
callq 0x30b0
testl %eax, %eax
je 0x13cd7
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x135f2
leaq 0xf603(%rip), %rdx      # 0x232d8
jmp 0x13d11
movl 0xc134(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
leaq 0x8(%rsp), %rcx
pushq $0x4
popq %r8
callq 0x30b0
testl %eax, %eax
je 0x13d2c
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x135f2
leaq 0xf5f4(%rip), %rdx      # 0x23305
pushq $0x1c
popq %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x135cb
movq %rbx, %rdi
callq 0x13665
jmp 0x13b8f
movl 0xc(%rbx), %eax
testb $0x4, %al
jne 0x13d72
movl 0xc134(%rbx), %edi
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
leaq 0x4(%rsp), %rcx
pushq $0x4
popq %r8
callq 0x30b0
testl %eax, %eax
je 0x13d6f
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x135f2
leaq 0xf5c5(%rip), %rdx      # 0x23332
jmp 0x13d11
movl 0xc(%rbx), %eax
movzwl 0x8(%rbx), %ecx
movzwl %ax, %eax
orl %ecx, %eax
shrl $0x4, %eax
andl $0x1, %eax
movw %ax, 0x1f22c(%rbx)
cmpl $0x0, 0x54(%rbx)
jne 0x13d94
cmpl $0x0, 0x50(%rbx)
je 0x13dc4
movl 0xc134(%rbx), %ebp
pushq $0x3
popq %rsi
movl %ebp, %edi
xorl %eax, %eax
callq 0x30d0
orl $0x800, %eax            # imm = 0x800
pushq $0x4
popq %rsi
movl %ebp, %edi
movl %eax, %edx
xorl %eax, %eax
callq 0x30d0
movl 0xc134(%rbx), %eax
jmp 0x13b92
movl 0xc134(%rbx), %ebp
pushq $0x3
popq %rsi
movl %ebp, %edi
xorl %eax, %eax
callq 0x30d0
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
jmp 0x13dab