// File: /workspace/github_c_makefile_star2_O3/FH0[P]tun_direct/lwip-2.1.2/src/core/tcp.c
// Function: tcp_bind
err_t
tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
{
  int i;
  int max_pcb_list = NUM_TCP_PCB_LISTS;
  struct tcp_pcb *cpcb;
#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("tcp_bind: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
#endif /* LWIP_IPV4 */

  LWIP_ERROR("tcp_bind: invalid pcb", pcb != NULL, return ERR_ARG);

  LWIP_ERROR("tcp_bind: can only bind in state CLOSED", pcb->state == CLOSED, return ERR_VAL);

#if SO_REUSE
  /* Unless the REUSEADDR flag is set,
     we have to check the pcbs in TIME-WAIT state, also.
     We do not dump TIME_WAIT pcb's; they can still be matched by incoming
     packets using both local and remote IP addresses and ports to distinguish.
   */
  if (ip_get_option(pcb, SOF_REUSEADDR)) {
    max_pcb_list = NUM_TCP_PCB_LISTS_NO_TIME_WAIT;
  }
#endif /* SO_REUSE */

#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_UNICAST)) {
    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 */

  if (port == 0) {
    port = tcp_new_port();
    if (port == 0) {
      return ERR_BUF;
    }
  } else {
    /* Check if the address already is in use (on all lists) */
    for (i = 0; i < max_pcb_list; i++) {
      for (cpcb = *tcp_pcb_lists[i]; cpcb != NULL; cpcb = cpcb->next) {
        if (cpcb->local_port == port) {
#if SO_REUSE
          /* Omit checking for the same port if both pcbs have REUSEADDR set.
             For SO_REUSEADDR, the duplicate-check for a 5-tuple is done in
             tcp_connect. */
          if (!ip_get_option(pcb, SOF_REUSEADDR) ||
              !ip_get_option(cpcb, SOF_REUSEADDR))
#endif /* SO_REUSE */
          {
            /* @todo: check accept_any_ip_version */
            if ((IP_IS_V6(ipaddr) == IP_IS_V6_VAL(cpcb->local_ip)) &&
                (ip_addr_isany(&cpcb->local_ip) ||
                 ip_addr_isany(ipaddr) ||
                 ip_addr_cmp(&cpcb->local_ip, ipaddr))) {
              return ERR_USE;
            }
          }
        }
      }
    }
  }

  if (!ip_addr_isany(ipaddr)
#if LWIP_IPV4 && LWIP_IPV6
      || (IP_GET_TYPE(ipaddr) != IP_GET_TYPE(&pcb->local_ip))
#endif /* LWIP_IPV4 && LWIP_IPV6 */
     ) {
    ip_addr_set(&pcb->local_ip, ipaddr);
  }
  pcb->local_port = port;
  TCP_REG(&tcp_bound_pcbs, pcb);
  LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %"U16_F"\n", port));
  return ERR_OK;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movl %edx, %ebp
movq %rdi, %rbx
testq %rsi, %rsi
jne 0x74b3
leaq 0xeead(%rip), %rsi      # 0x16360
testq %rbx, %rbx
je 0x7708
cmpl $0x0, 0x48(%rbx)
jne 0x7724
cmpb $0x6, 0x14(%rsi)
jne 0x7555
cmpb $0x0, 0x10(%rsi)
jne 0x7555
movl (%rsi), %eax
movl %eax, %ecx
andl $0xc0ff, %ecx           # imm = 0xC0FF
cmpl $0x80fe, %ecx           # imm = 0x80FE
jne 0x7555
leaq 0x8(%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 0xf744
testq %rax, %rax
je 0x7558
movl 0x8(%rsp), %ecx
movl %ecx, %edx
andl $0xc0ff, %edx           # imm = 0xC0FF
cmpl $0x80fe, %edx           # imm = 0x80FE
je 0x7547
andl $0x8fff, %ecx           # imm = 0x8FFF
cmpl $0x2ff, %ecx            # imm = 0x2FF
je 0x7547
cmpl $0x1ff, %ecx            # imm = 0x1FF
jne 0x7701
movb 0xee(%rax), %al
incb %al
movb %al, 0x18(%rsp)
jmp 0x7558
movq %rsi, %r14
testw %bp, %bp
je 0x765e
xorl %eax, %eax
leaq 0x147f6(%rip), %rcx     # 0x1bd60
movq (%rcx,%rax,8), %rdx
movq (%rdx), %rdx
testq %rdx, %rdx
je 0x7648
cmpw %bp, 0x4e(%rdx)
jne 0x763f
movb 0x14(%r14), %dil
movb 0x14(%rdx), %sil
cmpb $0x6, %sil
sete %r8b
cmpb $0x6, %dil
setne %r9b
cmpb %r8b, %r9b
je 0x763f
movl (%rdx), %r8d
cmpb $0x6, %sil
jne 0x75cd
testl %r8d, %r8d
jne 0x75d6
xorl %r8d, %r8d
cmpl $0x0, 0x4(%rdx)
jne 0x75d6
cmpl $0x0, 0x8(%rdx)
jne 0x75d6
cmpl $0x0, 0xc(%rdx)
jne 0x75d6
jmp 0x7657
testl %r8d, %r8d
je 0x7657
movl (%r14), %r9d
cmpb $0x6, %dil
jne 0x75fe
testl %r9d, %r9d
jne 0x7603
xorl %r9d, %r9d
cmpl $0x0, 0x4(%r14)
jne 0x7603
cmpl $0x0, 0x8(%r14)
jne 0x7603
cmpl $0x0, 0xc(%r14)
jne 0x7603
jmp 0x7657
testl %r9d, %r9d
je 0x7657
cmpb %dil, %sil
jne 0x763f
cmpb $0x6, %sil
jne 0x763a
cmpl %r9d, %r8d
jne 0x763f
movl 0x4(%rdx), %esi
cmpl 0x4(%r14), %esi
jne 0x763f
movl 0x8(%rdx), %esi
cmpl 0x8(%r14), %esi
jne 0x763f
movl 0xc(%rdx), %esi
cmpl 0xc(%r14), %esi
jne 0x763f
movb 0x10(%rdx), %sil
cmpb 0x10(%r14), %sil
jne 0x763f
jmp 0x7657
cmpl %r9d, %r8d
je 0x7657
movq 0x38(%rdx), %rdx
jmp 0x7571
incq %rax
cmpq $0x4, %rax
jne 0x756a
jmp 0x766e
movb $-0x8, %al
jmp 0x76f8
callq 0x7751
movl %eax, %ebp
testw %ax, %ax
je 0x76f6
movb 0x14(%r14), %al
movl (%r14), %ecx
cmpb $0x6, %al
jne 0x7694
testl %ecx, %ecx
jne 0x769d
cmpl $0x0, 0x4(%r14)
jne 0x769d
cmpl $0x0, 0x8(%r14)
jne 0x769d
cmpl $0x0, 0xc(%r14)
jne 0x769d
jmp 0x7698
testl %ecx, %ecx
jne 0x769d
cmpb 0x14(%rbx), %al
je 0x76d7
movb %al, 0x14(%rbx)
cmpb $0x6, 0x14(%r14)
movl (%r14), %eax
movl %eax, (%rbx)
jne 0x76ca
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
movb %al, 0x10(%rbx)
jmp 0x76d7
leaq 0x4(%rbx), %rax
xorl %ecx, %ecx
movq %rcx, 0x5(%rax)
movq %rcx, (%rax)
movw %bp, 0x4e(%rbx)
movq 0x1521e(%rip), %rax     # 0x1c900
movq %rax, 0x38(%rbx)
movq %rbx, 0x15213(%rip)     # 0x1c900
callq 0xcba0
xorl %eax, %eax
jmp 0x76f8
movb $-0x2, %al
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
xorl %eax, %eax
jmp 0x754f
leaq 0xcbbd(%rip), %rdi      # 0x142cc
leaq 0xd607(%rip), %rsi      # 0x14d1d
leaq 0xd56b(%rip), %rcx      # 0x14c88
movl $0x2a9, %edx            # imm = 0x2A9
jmp 0x773e
leaq 0xcba1(%rip), %rdi      # 0x142cc
leaq 0xd601(%rip), %rsi      # 0x14d33
leaq 0xd54f(%rip), %rcx      # 0x14c88
movl $0x2ab, %edx            # imm = 0x2AB
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050