// File: /workspace/github_c_makefile_star2_O1/loversmile[P]sugarcrm/sugar_stdsoap2.c
// Function: soap_accept
SOAP_FMAC2
soap_accept(struct soap *soap)
{ int n = (int)sizeof(soap->peer);
#ifndef WITH_LEAN
  int len = SOAP_BUFLEN;
  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 (;;)
    { 
#ifndef WITH_LEAN
      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->send_timeout || soap->recv_timeout)
        SOAP_SOCKNONBLOCK(soap->master)
      else
        SOAP_SOCKBLOCK(soap->master)
#endif
      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);
        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 $0x28, %rsp
movq %rdi, %rbx
movl $0x10, 0x14(%rsp)
movl $0x10000, 0x10(%rsp)    # imm = 0x10000
movl $0x1, 0xc(%rsp)
movl $0x0, 0x19214(%rdi)
testb $0x4, 0xc(%rdi)
jne 0x3e435
xorps %xmm0, %xmm0
movups %xmm0, 0x1b324(%rbx)
movl $0xffffffff, 0x60d4(%rbx) # imm = 0xFFFFFFFF
movl $0x0, 0x19218(%rbx)
movw $0x0, 0x191cc(%rbx)
cmpl $-0x1, 0x60d0(%rbx)
je 0x3e443
leaq 0x1b324(%rbx), %rax
movq %rax, 0x18(%rsp)
movl $0x3c, %r14d
leaq 0x14ee5(%rip), %r13     # 0x53184
leaq 0x14ece(%rip), %r12     # 0x53174
leaq 0x14114(%rip), %r15     # 0x523c1
leaq 0x14115(%rip), %rbp     # 0x523c9
cmpl $0x0, 0x5c(%rbx)
jne 0x3e2ca
cmpl $0x0, 0x54(%rbx)
jne 0x3e2ca
cmpl $0x0, 0x50(%rbx)
je 0x3e36f
movl 0x60d0(%rbx), %esi
movl 0x5c(%rbx), %ecx
testl %ecx, %ecx
cmovel %r14d, %ecx
movq %rbx, %rdi
movl $0x7, %edx
callq 0x3dfc3
movl $0x4, %ecx
testl %eax, %eax
jg 0x3e35e
je 0x3e331
xorl %ecx, %ecx
testl %eax, %eax
jns 0x3e35e
cmpl $0x4, 0x1921c(%rbx)
je 0x3e35e
movq %rbx, %rdi
callq 0x3ba2e
movq %rbx, %rdi
callq 0x3df32
cmpw $0x2, 0x2(%rbx)
leaq 0x1483f(%rip), %rsi     # 0x52b5b
leaq 0x14828(%rip), %rcx     # 0x52b4b
cmoveq %rcx, %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %rax, %rcx
jmp 0x3e34b
cmpl $0x0, 0x5c(%rbx)
je 0x3e2f1
cmpw $0x2, 0x2(%rbx)
movq %r12, %rsi
cmoveq %r13, %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %rcx
movq %rbp, %r8
movl $0x1c, %r9d
callq 0x4b05a
movl $0x1, %ecx
testl %ecx, %ecx
je 0x3e2ca
cmpl $0x4, %ecx
jne 0x3e486
movq %r12, %r13
cmpl $0x0, 0x5c(%rbx)
jne 0x3e388
cmpl $0x0, 0x54(%rbx)
jne 0x3e388
cmpl $0x0, 0x50(%rbx)
je 0x3e415
movl 0x60d0(%rbx), %r12d
movl %r12d, %edi
movl $0x3, %esi
xorl %eax, %eax
callq 0x30d0
orl $0x800, %eax            # imm = 0x800
movl %r12d, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x30d0
movl 0x60d0(%rbx), %esi
movq %rbx, %rdi
movq 0x18(%rsp), %rdx
leaq 0x14(%rsp), %rcx
callq *0x5ff0(%rbx)
movl %eax, 0x60d4(%rbx)
movslq 0x14(%rsp), %rcx
movq %rcx, 0x1b338(%rbx)
cmpl $-0x1, %eax
movq %r13, %r12
jne 0x3e49a
callq 0x3060
movl (%rax), %eax
cmpl $0xb, %eax
leaq 0x14d88(%rip), %r13     # 0x53184
ja 0x3e61a
movl $0x811, %ecx            # imm = 0x811
btl %eax, %ecx
jb 0x3e2b4
jmp 0x3e61a
movl 0x60d0(%rbx), %r12d
movl %r12d, %edi
movl $0x3, %esi
xorl %eax, %eax
callq 0x30d0
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
jmp 0x3e3a3
movl 0x60d0(%rbx), %eax
movl %eax, 0x60d4(%rbx)
jmp 0x3e48b
movl $0x0, 0x1921c(%rbx)
movq %rbx, %rdi
callq 0x3df32
cmpw $0x2, 0x2(%rbx)
leaq 0x14d23(%rip), %rcx     # 0x53184
leaq 0x14d0c(%rip), %rsi     # 0x53174
cmoveq %rcx, %rsi
leaq 0x1407e(%rip), %r8      # 0x524f1
movq %rbx, %rdi
xorl %edx, %edx
movq %rax, %rcx
movl $0x1c, %r9d
callq 0x4b05a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x1b328(%rbx), %ecx
bswapl %ecx
movq %rcx, 0x191c0(%rbx)
movzwl 0x1b326(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movl %ecx, 0x191c8(%rbx)
movl 0x6c(%rbx), %edx
testl %edx, %edx
leaq 0x14cbb(%rip), %r14     # 0x53184
je 0x3e577
cmpl $0xd, %edx
jne 0x3e532
leaq 0x20(%rsp), %rcx
movq $0x0, (%rcx)
movl $0x1, (%rcx)
movzwl 0x70(%rbx), %edx
movl %edx, 0x4(%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0xd, %edx
movl $0x8, %r8d
callq 0x30c0
testl %eax, %eax
je 0x3e577
callq 0x3060
movl (%rax), %eax
movl %eax, 0x1921c(%rbx)
movq %rbx, %rdi
callq 0x3df32
cmpw $0x2, 0x2(%rbx)
cmoveq %r14, %r12
leaq 0x13ebb(%rip), %r8      # 0x523e8
jmp 0x3e683
leaq 0xc(%rsp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x4, %r8d
callq 0x30c0
testl %eax, %eax
je 0x3e577
callq 0x3060
movl (%rax), %eax
movl %eax, 0x1921c(%rbx)
movq %rbx, %rdi
callq 0x3df32
cmpw $0x2, 0x2(%rbx)
cmoveq %r14, %r12
leaq 0x13ea3(%rip), %r8      # 0x52415
jmp 0x3e683
movl 0xc(%rbx), %eax
orl 0x8(%rbx), %eax
testb $0x10, %al
je 0x3e5cf
movl 0x60d4(%rbx), %edi
leaq 0xc(%rsp), %rcx
movl $0x1, %esi
movl $0x9, %edx
movl $0x4, %r8d
callq 0x30c0
testl %eax, %eax
je 0x3e5cf
callq 0x3060
movl (%rax), %eax
movl %eax, 0x1921c(%rbx)
movq %rbx, %rdi
callq 0x3df32
cmpw $0x2, 0x2(%rbx)
cmoveq %r14, %r12
leaq 0x13e6e(%rip), %r8      # 0x52438
jmp 0x3e683
movl 0x60d4(%rbx), %edi
leaq 0x10(%rsp), %rcx
movl $0x1, %esi
movl $0x7, %edx
movl $0x4, %r8d
callq 0x30c0
testl %eax, %eax
je 0x3e63a
callq 0x3060
movl (%rax), %eax
movl %eax, 0x1921c(%rbx)
movq %rbx, %rdi
callq 0x3df32
cmpw $0x2, 0x2(%rbx)
cmoveq %r14, %r12
leaq 0x13e50(%rip), %r8      # 0x52468
jmp 0x3e683
movl %eax, 0x1921c(%rbx)
movq %rbx, %rdi
callq 0x3df32
cmpw $0x2, 0x2(%rbx)
cmoveq %r13, %r12
leaq 0x13d91(%rip), %r8      # 0x523c9
jmp 0x3e683
movl 0x60d4(%rbx), %edi
leaq 0x10(%rsp), %rcx
movl $0x1, %esi
movl $0x8, %edx
movl $0x4, %r8d
callq 0x30c0
testl %eax, %eax
je 0x3e6a6
callq 0x3060
movl (%rax), %eax
movl %eax, 0x1921c(%rbx)
movq %rbx, %rdi
callq 0x3df32
cmpw $0x2, 0x2(%rbx)
cmoveq %r14, %r12
leaq 0x13e12(%rip), %r8      # 0x52495
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rax, %rcx
movl $0x1c, %r9d
callq 0x4b05a
movq %rbx, %rdi
callq 0x3ba2e
jmp 0x3e486
testb $0x4, 0xc(%rbx)
jne 0x3e6f7
movl 0x60d4(%rbx), %edi
leaq 0xc(%rsp), %rcx
movl $0x6, %esi
movl $0x1, %edx
movl $0x4, %r8d
callq 0x30c0
testl %eax, %eax
je 0x3e6f7
callq 0x3060
movl (%rax), %eax
movl %eax, 0x1921c(%rbx)
movq %rbx, %rdi
callq 0x3df32
cmpw $0x2, 0x2(%rbx)
cmoveq %r14, %r12
leaq 0x13dcd(%rip), %r8      # 0x524c2
jmp 0x3e683
movzwl 0x8(%rbx), %eax
movzwl 0xc(%rbx), %ecx
orl %eax, %ecx
shrl $0x4, %ecx
andl $0x1, %ecx
movw %cx, 0x191cc(%rbx)
movl 0x60d4(%rbx), %eax
jmp 0x3e48b