// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/udp.c
// Function: udp_bind
err_t
udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
{
  struct udp_pcb *ipcb;
  u8_t rebind;
#if LWIP_IPV6 && LWIP_IPV6_SCOPES
  ip_addr_t zoned_ipaddr;
#endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */

  LWIP_ASSERT_CORE_LOCKED();

#if LWIP_IPV4
  /* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */
  if (ipaddr == NULL) {
    ipaddr = IP4_ADDR_ANY;
  }
#else /* LWIP_IPV4 */
  LWIP_ERROR("udp_bind: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
#endif /* LWIP_IPV4 */

  LWIP_ERROR("udp_bind: invalid pcb", pcb != NULL, return ERR_ARG);

  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
  ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_TRACE, ipaddr);
  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port));

  rebind = 0;
  /* Check for double bind and rebind of the same pcb */
  for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
    /* is this UDP PCB already on active list? */
    if (pcb == ipcb) {
      rebind = 1;
      break;
    }
  }

#if LWIP_IPV6 && LWIP_IPV6_SCOPES
  /* If the given IP address should have a zone but doesn't, assign one now.
   * This is legacy support: scope-aware callers should always provide properly
   * zoned source addresses. Do the zone selection before the address-in-use
   * check below; as such we have to make a temporary copy of the address. */
  if (IP_IS_V6(ipaddr) && ip6_addr_lacks_zone(ip_2_ip6(ipaddr), IP6_UNKNOWN)) {
    ip_addr_copy(zoned_ipaddr, *ipaddr);
    ip6_addr_select_zone(ip_2_ip6(&zoned_ipaddr), ip_2_ip6(&zoned_ipaddr));
    ipaddr = &zoned_ipaddr;
  }
#endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */

  /* no port specified? */
  if (port == 0) {
    port = udp_new_port();
    if (port == 0) {
      /* no more ports available in local range */
      LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
      return ERR_USE;
    }
  } else {
    for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
      if (pcb != ipcb) {
        /* By default, we don't allow to bind to a port that any other udp
           PCB is already bound to, unless *all* PCBs with that port have tha
           REUSEADDR flag set. */
#if SO_REUSE
        if (!ip_get_option(pcb, SOF_REUSEADDR) ||
            !ip_get_option(ipcb, SOF_REUSEADDR))
#endif /* SO_REUSE */
        {
          /* port matches that of PCB in list and REUSEADDR not set -> reject */
          if ((ipcb->local_port == port) &&
              /* IP address matches or any IP used? */
              (ip_addr_cmp(&ipcb->local_ip, ipaddr) || ip_addr_isany(ipaddr) ||
              ip_addr_isany(&ipcb->local_ip))) {
            /* other PCB already binds to this local IP and port */
            LWIP_DEBUGF(UDP_DEBUG,
                        ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
            return ERR_USE;
          }
        }
      }
    }
  }

  ip_addr_set_ipaddr(&pcb->local_ip, ipaddr);

  pcb->local_port = port;
  mib2_udp_bind(pcb);
  /* pcb not active yet? */
  if (rebind == 0) {
    /* place the PCB on the active list if not already there */
    pcb->next = udp_pcbs;
    udp_pcbs = pcb;
  }
  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_bind: bound to "));
  ip_addr_debug_print_val(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, pcb->local_ip);
  LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->local_port));
  return ERR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x17ff9
leaq 0x11757(%rip), %rax     # 0x2974c
movq %rax, -0x18(%rbp)
jmp 0x17ffb
cmpq $0x0, -0x10(%rbp)
jne 0x18033
jmp 0x18004
leaq 0xf2c1(%rip), %rdi      # 0x272cc
leaq 0x11584(%rip), %rsi     # 0x29596
movl $0x425, %edx            # imm = 0x425
leaq 0x11332(%rip), %rcx     # 0x29350
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x18035
jmp 0x18037
jmp 0x18039
jmp 0x1803b
cmpq $0x0, -0x18(%rbp)
je 0x18055
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0x18055
jmp 0x18051
jmp 0x18053
jmp 0x1805b
jmp 0x18057
jmp 0x18059
jmp 0x1805b
jmp 0x1805d
jmp 0x1805f
jmp 0x18061
movb $0x0, -0x29(%rbp)
movq 0x1793c(%rip), %rax     # 0x2f9a8
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x18097
movq -0x10(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x18087
movb $0x1, -0x29(%rbp)
jmp 0x18097
jmp 0x18089
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x18070
cmpq $0x0, -0x18(%rbp)
je 0x181f4
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0x181f4
movq -0x18(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0x181f4
movq -0x18(%rbp), %rax
movl (%rax), %eax
andq $0xc0ff, %rax           # imm = 0xC0FF
cmpq $0x80fe, %rax           # imm = 0x80FE
je 0x18104
movq -0x18(%rbp), %rax
movl (%rax), %eax
andq $0x8fff, %rax           # imm = 0x8FFF
cmpq $0x1ff, %rax            # imm = 0x1FF
je 0x18104
movq -0x18(%rbp), %rax
movl (%rax), %eax
andq $0x8fff, %rax           # imm = 0x8FFF
cmpq $0x2ff, %rax            # imm = 0x2FF
jne 0x181f4
jmp 0x18106
jmp 0x18108
movq -0x18(%rbp), %rax
movb 0x14(%rax), %al
movb %al, -0x30(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0x18154
jmp 0x18121
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
movb %al, -0x34(%rbp)
jmp 0x18178
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movb $0x0, -0x34(%rbp)
jmp 0x18178
jmp 0x1817a
jmp 0x1817c
leaq -0x44(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x1c270
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x181ea
movl -0x44(%rbp), %eax
andq $0xc0ff, %rax           # imm = 0xC0FF
cmpq $0x80fe, %rax           # imm = 0x80FE
je 0x181c7
movl -0x44(%rbp), %eax
andq $0x8fff, %rax           # imm = 0x8FFF
cmpq $0x1ff, %rax            # imm = 0x1FF
je 0x181c7
movl -0x44(%rbp), %eax
andq $0x8fff, %rax           # imm = 0x8FFF
cmpq $0x2ff, %rax            # imm = 0x2FF
jne 0x181dd
movq -0x50(%rbp), %rax
movzbl 0xee(%rax), %eax
addl $0x1, %eax
movzbl %al, %eax
movl %eax, -0x54(%rbp)
jmp 0x181e4
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0x181e4
movl -0x54(%rbp), %eax
movb %al, -0x34(%rbp)
jmp 0x181ec
leaq -0x44(%rbp), %rax
movq %rax, -0x18(%rbp)
movzwl -0x1a(%rbp), %eax
cmpl $0x0, %eax
jne 0x18221
callq 0x185b0
movw %ax, -0x1a(%rbp)
movzwl -0x1a(%rbp), %eax
cmpl $0x0, %eax
jne 0x1821c
jmp 0x18211
jmp 0x18213
movb $-0x8, -0x1(%rbp)
jmp 0x1859c
jmp 0x183f8
movq 0x17780(%rip), %rax     # 0x2f9a8
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x183f6
movq -0x10(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x183e3
movq -0x28(%rbp), %rax
movzwl 0x42(%rax), %eax
movzwl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
jne 0x183e1
movq -0x28(%rbp), %rax
movzbl 0x14(%rax), %eax
movq -0x18(%rbp), %rcx
movzbl 0x14(%rcx), %ecx
cmpl %ecx, %eax
je 0x18279
xorl %eax, %eax
testb $0x1, %al
jne 0x183d4
jmp 0x182f0
movq -0x28(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0x182de
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x182f0
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x182f0
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x182f0
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x182f0
movq -0x28(%rbp), %rax
movzbl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
movzbl 0x10(%rcx), %ecx
cmpl %ecx, %eax
je 0x183d4
jmp 0x182f0
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x183d4
cmpq $0x0, -0x18(%rbp)
jne 0x18303
movb $0x1, %al
testb $0x1, %al
jne 0x183d4
jmp 0x18365
cmpq $0x0, -0x18(%rbp)
je 0x18352
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0x18352
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
je 0x183d4
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x18365
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x18365
movq -0x18(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x18365
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x183d4
jmp 0x18365
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
je 0x183d4
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x183d4
movq -0x28(%rbp), %rax
cmpq $0x0, %rax
jne 0x18377
movb $0x1, %al
testb $0x1, %al
jne 0x183d4
jmp 0x183e1
movq -0x28(%rbp), %rax
cmpq $0x0, %rax
je 0x183c1
movq -0x28(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0x183c1
movq -0x28(%rbp), %rax
cmpq $0x0, %rax
je 0x183d4
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x183e1
movq -0x28(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x183e1
movq -0x28(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x183e1
movq -0x28(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x183d4
jmp 0x183e1
movq -0x28(%rbp), %rax
cmpq $0x0, %rax
je 0x183d4
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x183e1
jmp 0x183d6
jmp 0x183d8
movb $-0x8, -0x1(%rbp)
jmp 0x1859c
jmp 0x183e3
jmp 0x183e5
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x1822c
jmp 0x183f8
jmp 0x183fa
jmp 0x183fc
movq -0x10(%rbp), %rax
cmpq $0x0, %rax
je 0x18418
jmp 0x18408
movq -0x18(%rbp), %rax
movb 0x14(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x14(%rax)
jmp 0x18418
jmp 0x1841a
cmpq $0x0, -0x18(%rbp)
je 0x184f4
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0x184f4
jmp 0x18438
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0x18449
xorl %eax, %eax
movl %eax, -0x58(%rbp)
jmp 0x18452
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0x1846c
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0x18476
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0x18491
xorl %eax, %eax
movl %eax, -0x60(%rbp)
jmp 0x1849b
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0x184b6
xorl %eax, %eax
movl %eax, -0x64(%rbp)
jmp 0x184c0
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0x184db
xorl %eax, %eax
movl %eax, -0x68(%rbp)
jmp 0x184e6
movq -0x18(%rbp), %rax
movzbl 0x10(%rax), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x10(%rax)
jmp 0x18542
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0x18505
xorl %eax, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1850e
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x10(%rax)
jmp 0x18542
jmp 0x18544
movw -0x1a(%rbp), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x42(%rax)
movzbl -0x29(%rbp), %eax
cmpl $0x0, %eax
jne 0x18573
movq 0x17448(%rip), %rcx     # 0x2f9a8
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq %rax, 0x17435(%rip)     # 0x2f9a8
jmp 0x18575
jmp 0x18577
jmp 0x18579
movq -0x10(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0x1858c
jmp 0x18588
jmp 0x1858a
jmp 0x18592
jmp 0x1858e
jmp 0x18590
jmp 0x18592
jmp 0x18594
jmp 0x18596
jmp 0x18598
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)