// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl $0x10000, -0x24(%rbp)   # imm = 0x10000
movl $0x1, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0xc130(%rax)
je 0x1d78d
movq -0x10(%rbp), %rax
movq 0xc000(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl 0xc130(%rcx), %esi
callq *%rax
movq -0x10(%rbp), %rax
movl $0xffffffff, 0xc130(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl $0xffffffff, 0xc134(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl $0x1, 0x1f278(%rax)
movq -0x10(%rbp), %rdi
callq 0x1dd00
cmpl $0x0, %eax
je 0x1d7ec
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x30(%rbp), %rdi
movq %rax, %rsi
leaq 0x1bd00(%rip), %rdx     # 0x394d6
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1d817
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x3370
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc130(%rax)
jmp 0x1d834
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x3370
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc130(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x1f278(%rax)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0xc130(%rax)
jne 0x1d895
callq 0x3050
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x38(%rbp), %rdi
movq %rax, %rsi
leaq 0x1bc76(%rip), %rdx     # 0x394f5
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1d8b8
movq -0x10(%rbp), %rax
movl 0xc130(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc134(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x1d932
movq -0x10(%rbp), %rax
movl 0xc130(%rax), %edi
movq -0x10(%rbp), %rax
movl 0x68(%rax), %edx
movl $0x1, %esi
leaq -0x28(%rbp), %rcx
movl $0x4, %r8d
callq 0x30a0
cmpl $0x0, %eax
je 0x1d932
callq 0x3050
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x40(%rbp), %rdi
movq %rax, %rsi
leaq 0x1bbf6(%rip), %rdx     # 0x39512
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
orl 0xc(%rcx), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x1d9b6
movq -0x10(%rbp), %rax
movl 0xc130(%rax), %edi
movl $0x1, %esi
movl $0x9, %edx
leaq -0x28(%rbp), %rcx
movl $0x4, %r8d
callq 0x30a0
cmpl $0x0, %eax
je 0x1d9b6
callq 0x3050
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x48(%rbp), %rdi
movq %rax, %rsi
leaq 0x1bb93(%rip), %rdx     # 0x39533
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
movq -0x10(%rbp), %rax
movl 0xc130(%rax), %edi
movl $0x1, %esi
movl $0x7, %edx
leaq -0x24(%rbp), %rcx
movl $0x4, %r8d
callq 0x30a0
cmpl $0x0, %eax
je 0x1da24
callq 0x3050
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x50(%rbp), %rdi
movq %rax, %rsi
leaq 0x1bb53(%rip), %rdx     # 0x39561
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
movq -0x10(%rbp), %rax
movl 0xc130(%rax), %edi
movl $0x1, %esi
movl $0x8, %edx
leaq -0x24(%rbp), %rcx
movl $0x4, %r8d
callq 0x30a0
cmpl $0x0, %eax
je 0x1da92
callq 0x3050
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x58(%rbp), %rdi
movq %rax, %rsi
leaq 0x1bb10(%rip), %rdx     # 0x3958c
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x1db0f
movq -0x10(%rbp), %rax
movl 0xc130(%rax), %edi
movl $0x6, %esi
movl $0x1, %edx
leaq -0x28(%rbp), %rcx
movl $0x4, %r8d
callq 0x30a0
cmpl $0x0, %eax
je 0x1db0f
callq 0x3050
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x60(%rbp), %rdi
movq %rax, %rsi
leaq 0x1babe(%rip), %rdx     # 0x395b7
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
movq -0x10(%rbp), %rax
movq $0x10, 0x27398(%rax)
movq -0x10(%rbp), %rdi
addq $0x27384, %rdi          # imm = 0x27384
xorl %esi, %esi
movl $0x10, %edx
callq 0x3190
movq -0x10(%rbp), %rax
movw $0x2, 0x27384(%rax)
movq -0x10(%rbp), %rax
movl $0x2, 0x1f278(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x1dbb7
movq -0x10(%rbp), %rax
movq 0xbfe8(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
addq $0x27384, %rdx          # imm = 0x27384
addq $0x4, %rdx
callq *%rax
cmpl $0x0, %eax
je 0x1dbb5
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x68(%rbp), %rdi
movq %rax, %rsi
leaq 0x1ba45(%rip), %rdx     # 0x395e4
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
jmp 0x1dbca
xorl %edi, %edi
callq 0x3180
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x27388(%rax)
movl -0x1c(%rbp), %eax
movzwl %ax, %edi
callq 0x3110
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x27386(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x1f278(%rax)
movq -0x10(%rbp), %rax
movl 0xc130(%rax), %edi
movq -0x10(%rbp), %rsi
addq $0x27384, %rsi          # imm = 0x27384
movq -0x10(%rbp), %rax
movq 0x27398(%rax), %rax
movl %eax, %edx
callq 0x32b0
cmpl $0x0, %eax
je 0x1dc69
callq 0x3050
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movq -0x10(%rbp), %rdi
callq 0x1de40
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x70(%rbp), %rdi
movq %rax, %rsi
leaq 0x1b9b5(%rip), %rdx     # 0x3960b
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x1dcdb
movq -0x10(%rbp), %rax
movl 0xc130(%rax), %edi
movl -0x20(%rbp), %esi
callq 0x3270
cmpl $0x0, %eax
je 0x1dcdb
callq 0x3050
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movq -0x10(%rbp), %rdi
callq 0x1de40
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1dd80
movq -0x78(%rbp), %rdi
movq %rax, %rsi
leaq 0x1b95e(%rip), %rdx     # 0x39626
movl $0x1c, %ecx
callq 0x1dd20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dce8
movq -0x10(%rbp), %rax
movl 0xc130(%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)