// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rdi, %rbx
testq %rsi, %rsi
jne 0xd145
leaq 0x9233(%rip), %rsi      # 0x16378
testq %rbx, %rbx
je 0xd3a3
leaq 0x10853(%rip), %rax     # 0x1d9a8
movq (%rax), %r15
testq %r15, %r15
je 0xd166
leaq 0x38(%r15), %rax
cmpq %rbx, %r15
jne 0xd155
cmpb $0x6, 0x14(%rsi)
jne 0xd176
cmpb $0x0, 0x10(%rsi)
je 0xd306
movq %rsi, %r14
testw %bp, %bp
je 0xd254
leaq 0x1081f(%rip), %rax     # 0x1d9a8
movq (%rax), %rax
testq %rax, %rax
je 0xd2a1
cmpq %rbx, %rax
je 0xd24b
cmpw %bp, 0x42(%rax)
jne 0xd24b
movb 0x14(%rax), %cl
movb 0x14(%r14), %dl
cmpb %dl, %cl
jne 0xd1f3
movl (%rax), %esi
movl (%r14), %edi
cmpb $0x6, %cl
jne 0xd1eb
cmpl %edi, %esi
jne 0xd1f3
movl 0x4(%rax), %esi
cmpl 0x4(%r14), %esi
jne 0xd1f3
movl 0x8(%rax), %esi
cmpl 0x8(%r14), %esi
jne 0xd1f3
movl 0xc(%rax), %esi
cmpl 0xc(%r14), %esi
jne 0xd1f3
movb 0x10(%rax), %sil
cmpb 0x10(%r14), %sil
jne 0xd1f3
jmp 0xd2f9
cmpl %edi, %esi
je 0xd2f9
movl (%r14), %esi
cmpb $0x6, %dl
jne 0xd219
testl %esi, %esi
jne 0xd221
cmpl $0x0, 0x4(%r14)
jne 0xd221
cmpl $0x0, 0x8(%r14)
jne 0xd221
cmpl $0x0, 0xc(%r14)
jne 0xd221
jmp 0xd2f9
testl %esi, %esi
je 0xd2f9
movl (%rax), %edx
cmpb $0x6, %cl
jne 0xd243
testl %edx, %edx
jne 0xd24b
cmpl $0x0, 0x4(%rax)
jne 0xd24b
cmpl $0x0, 0x8(%rax)
jne 0xd24b
cmpl $0x0, 0xc(%rax)
jne 0xd24b
jmp 0xd2f9
testl %edx, %edx
je 0xd2f9
addq $0x38, %rax
jmp 0xd189
movzwl 0xfef5(%rip), %ebp      # 0x1d150
xorl %eax, %eax
movl $0xc000, %ecx           # imm = 0xC000
leaq 0x1073f(%rip), %rdx     # 0x1d9a8
incw %bp
cmovel %ecx, %ebp
movq %rdx, %rsi
movq (%rsi), %rdi
testq %rdi, %rdi
je 0xd295
leaq 0x38(%rdi), %rsi
cmpw %bp, 0x42(%rdi)
jne 0xd272
incl %eax
cmpw $0x4000, %ax            # imm = 0x4000
jne 0xd269
movw %bp, 0xfebd(%rip)       # 0x1d150
jmp 0xd2f9
movw %bp, 0xfeb4(%rip)       # 0x1d150
testw %bp, %bp
je 0xd2f9
movb 0x14(%r14), %al
movb %al, 0x14(%rbx)
movl (%r14), %ecx
movl %ecx, (%rbx)
cmpb $0x6, %al
jne 0xd2cc
movl 0x4(%r14), %eax
movl %eax, 0x4(%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%r14), %eax
movl %eax, 0xc(%rbx)
movb 0x10(%r14), %al
jmp 0xd2d7
andl $0x0, 0xc(%rbx)
andq $0x0, 0x4(%rbx)
xorl %eax, %eax
movb %al, 0x10(%rbx)
movw %bp, 0x42(%rbx)
testq %r15, %r15
jne 0xd2f5
movq 0x106be(%rip), %rax     # 0x1d9a8
movq %rax, 0x38(%rbx)
movq %rbx, 0x106b3(%rip)     # 0x1d9a8
xorl %eax, %eax
jmp 0xd2fb
movb $-0x8, %al
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl (%rsi), %eax
movl %eax, %ecx
andl $0xc0ff, %ecx           # imm = 0xC0FF
cmpl $0x80fe, %ecx           # imm = 0x80FE
je 0xd333
movl %eax, %ecx
andl $0x8fff, %ecx           # imm = 0x8FFF
cmpw $0x2ff, %cx             # imm = 0x2FF
je 0xd333
cmpl $0x1ff, %ecx            # imm = 0x1FF
jne 0xd176
movq %rsp, %r14
movb $0x6, 0x14(%r14)
movl %eax, (%r14)
movq 0x4(%rsi), %rax
movq %rax, 0x4(%r14)
movl 0xc(%rsi), %eax
movl %eax, 0xc(%r14)
movb $0x0, 0x10(%r14)
movq %r14, %rdi
movq %r14, %rsi
callq 0xf144
testq %rax, %rax
je 0xd179
movl (%rsp), %ecx
movl %ecx, %edx
andl $0xc0ff, %edx           # imm = 0xC0FF
cmpl $0x80fe, %edx           # imm = 0x80FE
je 0xd38e
andl $0x8fff, %ecx           # imm = 0x8FFF
cmpw $0x2ff, %cx             # imm = 0x2FF
je 0xd38e
cmpl $0x1ff, %ecx            # imm = 0x1FF
jne 0xd39f
movb 0xee(%rax), %al
incb %al
movb %al, 0x10(%rsp)
jmp 0xd179
xorl %eax, %eax
jmp 0xd396
leaq 0x6f22(%rip), %rdi      # 0x142cc
leaq 0x8e15(%rip), %rsi      # 0x161c6
leaq 0x8bc8(%rip), %rcx      # 0x15f80
movl $0x425, %edx            # imm = 0x425
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050