// File: /workspace/github_c_makefile_star2_O3/hkshenSmart[P]ONVIF-discovery_cs/stdsoap2.c
// Function: soap_bind
SOAP_FMAC2
soap_bind(struct soap *soap, const char *host, int port, int backlog)
{
#ifdef WITH_IPV6
  struct addrinfo *addrinfo = NULL;
  struct addrinfo hints;
  struct addrinfo res;
  int err;
#ifdef WITH_NO_IPV6_V6ONLY
  int unset = 0;
#endif
#endif
#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
  if (soap_valid_socket(soap->master))
  { soap->fclosesocket(soap, soap->master);
    soap->master = SOAP_INVALID_SOCKET;
  }
  soap->socket = SOAP_INVALID_SOCKET;
  soap->errmode = 1;
  if (tcp_init(soap))
  { soap_set_receiver_error(soap, tcp_error(soap), "TCP init failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
#ifdef WITH_IPV6
  memset((void*)&hints, 0, sizeof(hints));
  hints.ai_family = PF_UNSPEC;
#ifndef WITH_LEAN
  if ((soap->omode & SOAP_IO_UDP))
    hints.ai_socktype = SOCK_DGRAM;
  else
#endif
    hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  soap->errmode = 2;
  err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
  if (err || !addrinfo)
  { soap_set_receiver_error(soap, SOAP_GAI_STRERROR(err), "getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
  res = *addrinfo;
  memcpy(&soap->peer, addrinfo->ai_addr, addrinfo->ai_addrlen);
  soap->peerlen = addrinfo->ai_addrlen;
  res.ai_addr = (struct sockaddr*)&soap->peer;
  res.ai_addrlen = soap->peerlen;
  freeaddrinfo(addrinfo);
  soap->master = (int)socket(res.ai_family, res.ai_socktype, res.ai_protocol);
#else
#ifndef WITH_LEAN
  if ((soap->omode & SOAP_IO_UDP))
    soap->master = (int)socket(AF_INET, SOCK_DGRAM, 0);
  else
#endif
    soap->master = (int)socket(AF_INET, SOCK_STREAM, 0);
#endif
  soap->errmode = 0;
  if (!soap_valid_socket(soap->master))
  { soap->errnum = soap_socket_errno(soap->master);
    soap_set_receiver_error(soap, tcp_error(soap), "socket failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
#ifndef WITH_LEAN
  if ((soap->omode & SOAP_IO_UDP))
    soap->socket = soap->master;
#endif
#ifdef SOCKET_CLOSE_ON_EXEC
#ifdef WIN32
#ifndef UNDER_CE
  SetHandleInformation((HANDLE)soap->master, HANDLE_FLAG_INHERIT, 0);
#endif
#else
  fcntl(soap->master, F_SETFD, 1);
#endif
#endif
#ifndef WITH_LEAN
  if (soap->bind_flags && setsockopt(soap->master, SOL_SOCKET, soap->bind_flags, (char*)&set, sizeof(int)))
  { soap->errnum = soap_socket_errno(soap->master);
    soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
  if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt(soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
  { soap->errnum = soap_socket_errno(soap->master);
    soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
  if (setsockopt(soap->master, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
  { soap->errnum = soap_socket_errno(soap->master);
    soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
  if (setsockopt(soap->master, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
  { soap->errnum = soap_socket_errno(soap->master);
    soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
#ifdef TCP_NODELAY
  if (!(soap->omode & SOAP_IO_UDP) && setsockopt(soap->master, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
  { soap->errnum = soap_socket_errno(soap->master);
    soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
#endif
#endif
#ifdef WITH_IPV6
#ifdef WITH_IPV6_V6ONLY
  if (setsockopt(soap->master, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&set, sizeof(int)))
  { soap->errnum = soap_socket_errno(soap->master);
    soap_set_receiver_error(soap, tcp_error(soap), "setsockopt IPV6_V6ONLY failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
#endif
#ifdef WITH_NO_IPV6_V6ONLY
  if (setsockopt(soap->master, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&unset, sizeof(int)))
  { soap->errnum = soap_socket_errno(soap->master);
    soap_set_receiver_error(soap, tcp_error(soap), "setsockopt IPV6_V6ONLY failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
#endif
  soap->errmode = 0;
  if (bind(soap->master, res.ai_addr, (int)res.ai_addrlen))
  { soap->errnum = soap_socket_errno(soap->master);
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
    soap_closesock(soap);
    soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
#else
  soap->peerlen = sizeof(soap->peer);
  memset((void*)&soap->peer, 0, sizeof(soap->peer));
  soap->peer.sin_family = AF_INET;
  soap->errmode = 2;
  if (host)
  { if (soap->fresolve(soap, host, &soap->peer.sin_addr))
    { soap_set_receiver_error(soap, tcp_error(soap), "get host by name failed in soap_bind()", SOAP_TCP_ERROR);
      return SOAP_INVALID_SOCKET;
    }
  }
  else
    soap->peer.sin_addr.s_addr = htonl(INADDR_ANY);
  soap->peer.sin_port = htons((short)port);
  soap->errmode = 0;
  if (bind(soap->master, (struct sockaddr*)&soap->peer, (int)soap->peerlen))
  { soap->errnum = soap_socket_errno(soap->master);
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
    soap_closesock(soap);
    soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
#endif
  if (!(soap->omode & SOAP_IO_UDP) && listen(soap->master, backlog))
  { soap->errnum = soap_socket_errno(soap->master);
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
    soap_closesock(soap);
    soap_set_receiver_error(soap, tcp_error(soap), "listen failed in soap_bind()", SOAP_TCP_ERROR);
    return SOAP_INVALID_SOCKET;
  }
  return soap->master;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
movl $0x10000, 0x4(%rsp)     # imm = 0x10000
movl $0x1, (%rsp)
movl 0xc130(%rdi), %esi
cmpl $-0x1, %esi
je 0x142ac
movq %rbx, %rdi
callq *0xc000(%rbx)
movl $0xffffffff, 0xc130(%rbx) # imm = 0xFFFFFFFF
movl $0xffffffff, 0xc134(%rbx) # imm = 0xFFFFFFFF
movl $0x1, 0x1f278(%rbx)
movl 0xc(%rbx), %eax
andl $0x4, %eax
cmpl $0x1, %eax
movl $0x2, %esi
sbbl $0x0, %esi
movl $0x2, %edi
xorl %edx, %edx
callq 0x3350
movl %eax, 0xc130(%rbx)
movl $0x0, 0x1f278(%rbx)
cmpl $-0x1, %eax
je 0x1435c
movl 0xc(%rbx), %ecx
testb $0x4, %cl
je 0x14300
movl %eax, 0xc134(%rbx)
movl 0x68(%rbx), %edx
testl %edx, %edx
je 0x1439d
movq %rsp, %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x4, %r8d
callq 0x30b0
testl %eax, %eax
je 0x14394
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x1469f
cmpw $0x2, 0x2(%rbx)
leaq 0x12cfe(%rip), %rcx     # 0x27043
leaq 0x12ce7(%rip), %rsi     # 0x27033
cmoveq %rcx, %rsi
leaq 0x11d8c(%rip), %r8      # 0x260e3
jmp 0x144ad
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x1469f
cmpw $0x2, 0x2(%rbx)
leaq 0x12cc6(%rip), %rcx     # 0x27043
leaq 0x12caf(%rip), %rsi     # 0x27033
cmoveq %rcx, %rsi
leaq 0x11d37(%rip), %r8      # 0x260c6
jmp 0x144ad
movl 0xc(%rbx), %ecx
movl 0xc130(%rbx), %eax
orl 0x8(%rbx), %ecx
testb $0x10, %cl
je 0x14401
movq %rsp, %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x9, %edx
movl $0x4, %r8d
callq 0x30b0
testl %eax, %eax
je 0x143fb
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x1469f
cmpw $0x2, 0x2(%rbx)
leaq 0x12c5f(%rip), %rcx     # 0x27043
leaq 0x12c48(%rip), %rsi     # 0x27033
cmoveq %rcx, %rsi
leaq 0x11d0e(%rip), %r8      # 0x26104
jmp 0x144ad
movl 0xc130(%rbx), %eax
leaq 0x4(%rsp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x7, %edx
movl $0x4, %r8d
callq 0x30b0
testl %eax, %eax
je 0x14456
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x1469f
cmpw $0x2, 0x2(%rbx)
leaq 0x12c01(%rip), %rcx     # 0x27043
leaq 0x12bea(%rip), %rsi     # 0x27033
cmoveq %rcx, %rsi
leaq 0x11cde(%rip), %r8      # 0x26132
jmp 0x144ad
movl 0xc130(%rbx), %edi
leaq 0x4(%rsp), %rcx
movl $0x1, %esi
movl $0x8, %edx
movl $0x4, %r8d
callq 0x30b0
testl %eax, %eax
je 0x144d0
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x1469f
cmpw $0x2, 0x2(%rbx)
leaq 0x12ba8(%rip), %rcx     # 0x27043
leaq 0x12b91(%rip), %rsi     # 0x27033
cmoveq %rcx, %rsi
leaq 0x11cb0(%rip), %r8      # 0x2615d
movq %rbx, %rdi
xorl %edx, %edx
movq %rax, %rcx
movl $0x1c, %r9d
callq 0x23c4f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
testb $0x4, 0xc(%rbx)
jne 0x1452d
movl 0xc130(%rbx), %edi
movq %rsp, %rcx
movl $0x6, %esi
movl $0x1, %edx
movl $0x4, %r8d
callq 0x30b0
testl %eax, %eax
je 0x1452d
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x1469f
cmpw $0x2, 0x2(%rbx)
leaq 0x12b2a(%rip), %rcx     # 0x27043
leaq 0x12b13(%rip), %rsi     # 0x27033
cmoveq %rcx, %rsi
leaq 0x11c5d(%rip), %r8      # 0x26188
jmp 0x144ad
movq $0x10, 0x27398(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x27384(%rbx)
movw $0x2, 0x27384(%rbx)
movl $0x2, 0x1f278(%rbx)
testq %r15, %r15
je 0x1459c
leaq 0x27388(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq *0xbfe8(%rbx)
testl %eax, %eax
je 0x145a3
movq %rbx, %rdi
callq 0x1469f
cmpw $0x2, 0x2(%rbx)
leaq 0x12abe(%rip), %rcx     # 0x27043
leaq 0x12aa7(%rip), %rsi     # 0x27033
cmoveq %rcx, %rsi
leaq 0x11c1e(%rip), %r8      # 0x261b5
jmp 0x144ad
movl $0x10, %edx
jmp 0x145a9
movl 0x27398(%rbx), %edx
rolw $0x8, %r14w
leaq 0x27384(%rbx), %rsi
movw %r14w, 0x27386(%rbx)
movl $0x0, 0x1f278(%rbx)
movl 0xc130(%rbx), %edi
callq 0x3290
testl %eax, %eax
je 0x14616
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x14730
movq %rbx, %rdi
callq 0x1469f
cmpw $0x2, 0x2(%rbx)
leaq 0x12a44(%rip), %rcx     # 0x27043
leaq 0x12a2d(%rip), %rsi     # 0x27033
cmoveq %rcx, %rsi
leaq 0x11bcb(%rip), %r8      # 0x261dc
jmp 0x144ad
testb $0x4, 0xc(%rbx)
jne 0x1466d
movl 0xc130(%rbx), %edi
movl %ebp, %esi
callq 0x3260
testl %eax, %eax
je 0x1466d
callq 0x3050
movl (%rax), %eax
movl %eax, 0x1f27c(%rbx)
movq %rbx, %rdi
callq 0x14730
movq %rbx, %rdi
callq 0x1469f
cmpw $0x2, 0x2(%rbx)
leaq 0x129ed(%rip), %rcx     # 0x27043
leaq 0x129d6(%rip), %rsi     # 0x27033
cmoveq %rcx, %rsi
leaq 0x11b8f(%rip), %r8      # 0x261f7
jmp 0x144ad
movl 0xc130(%rbx), %eax
jmp 0x144c5