// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movl $0x4, -0x24(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xbce0
leaq 0x1da70(%rip), %rax     # 0x2974c
movq %rax, -0x18(%rbp)
jmp 0xbce2
cmpq $0x0, -0x10(%rbp)
jne 0xbd1a
jmp 0xbceb
leaq 0x1b5da(%rip), %rdi     # 0x272cc
leaq 0x1c107(%rip), %rsi     # 0x27e00
movl $0x2a9, %edx            # imm = 0x2A9
leaq 0x1c066(%rip), %rcx     # 0x27d6b
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0xbd1c
jmp 0xbd1e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x48(%rax)
je 0xbd59
jmp 0xbd2a
leaq 0x1b59b(%rip), %rdi     # 0x272cc
leaq 0x1c0de(%rip), %rsi     # 0x27e16
movl $0x2ab, %edx            # imm = 0x2AB
leaq 0x1c027(%rip), %rcx     # 0x27d6b
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0xbd5b
cmpq $0x0, -0x18(%rbp)
je 0xbe90
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0xbe90
movq -0x18(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0xbe90
movq -0x18(%rbp), %rax
movl (%rax), %eax
andq $0xc0ff, %rax           # imm = 0xC0FF
cmpq $0x80fe, %rax           # imm = 0x80FE
jne 0xbe90
jmp 0xbda2
jmp 0xbda4
movq -0x18(%rbp), %rax
movb 0x14(%rax), %al
movb %al, -0x34(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0xbdf0
jmp 0xbdbd
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
movb %al, -0x38(%rbp)
jmp 0xbe14
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movb $0x0, -0x38(%rbp)
jmp 0xbe14
jmp 0xbe16
jmp 0xbe18
leaq -0x48(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1c270
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0xbe86
movl -0x48(%rbp), %eax
andq $0xc0ff, %rax           # imm = 0xC0FF
cmpq $0x80fe, %rax           # imm = 0x80FE
je 0xbe63
movl -0x48(%rbp), %eax
andq $0x8fff, %rax           # imm = 0x8FFF
cmpq $0x1ff, %rax            # imm = 0x1FF
je 0xbe63
movl -0x48(%rbp), %eax
andq $0x8fff, %rax           # imm = 0x8FFF
cmpq $0x2ff, %rax            # imm = 0x2FF
jne 0xbe79
movq -0x50(%rbp), %rax
movzbl 0xee(%rax), %eax
addl $0x1, %eax
movzbl %al, %eax
movl %eax, -0x54(%rbp)
jmp 0xbe80
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0xbe80
movl -0x54(%rbp), %eax
movb %al, -0x38(%rbp)
jmp 0xbe88
leaq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
movzwl -0x1a(%rbp), %eax
cmpl $0x0, %eax
jne 0xbeb9
callq 0xc310
movw %ax, -0x1a(%rbp)
movzwl -0x1a(%rbp), %eax
cmpl $0x0, %eax
jne 0xbeb4
movb $-0x2, -0x1(%rbp)
jmp 0xc2ff
jmp 0xc0fd
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xc0fb
movslq -0x20(%rbp), %rcx
leaq 0x22e39(%rip), %rax     # 0x2ed10
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xc0eb
movq -0x30(%rbp), %rax
movzwl 0x4e(%rax), %eax
movzwl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
jne 0xc0d8
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0x55(%rbp)
je 0xbf1e
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
sete %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movq -0x30(%rbp), %rcx
movzbl 0x14(%rcx), %ecx
cmpl $0x6, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0xc0d6
movq -0x30(%rbp), %rax
cmpq $0x0, %rax
jne 0xbf58
movb $0x1, %al
testb $0x1, %al
jne 0xc0cd
jmp 0xbfc5
movq -0x30(%rbp), %rax
cmpq $0x0, %rax
je 0xbfaa
movq -0x30(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0xbfaa
movq -0x30(%rbp), %rax
cmpq $0x0, %rax
je 0xc0cd
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xbfc5
movq -0x30(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xbfc5
movq -0x30(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xbfc5
movq -0x30(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0xc0cd
jmp 0xbfc5
movq -0x30(%rbp), %rax
cmpq $0x0, %rax
je 0xc0cd
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xc0cd
cmpq $0x0, -0x18(%rbp)
jne 0xbfd8
movb $0x1, %al
testb $0x1, %al
jne 0xc0cd
jmp 0xc042
cmpq $0x0, -0x18(%rbp)
je 0xc027
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0xc027
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
je 0xc0cd
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xc042
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xc042
movq -0x18(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xc042
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0xc0cd
jmp 0xc042
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
je 0xc0cd
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xc0cd
movq -0x30(%rbp), %rax
movzbl 0x14(%rax), %eax
movq -0x18(%rbp), %rcx
movzbl 0x14(%rcx), %ecx
cmpl %ecx, %eax
je 0xc05e
xorl %eax, %eax
testb $0x1, %al
jne 0xc0cd
jmp 0xc0d6
movq -0x30(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0xc0bf
movq -0x30(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0xc0d6
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0xc0d6
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0xc0d6
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0xc0d6
movq -0x30(%rbp), %rax
movzbl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
movzbl 0x10(%rcx), %ecx
cmpl %ecx, %eax
je 0xc0cd
jmp 0xc0d6
movq -0x30(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0xc0d6
movb $-0x8, -0x1(%rbp)
jmp 0xc2ff
jmp 0xc0d8
jmp 0xc0da
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0xbee2
jmp 0xc0ed
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xbec0
jmp 0xc0fd
cmpq $0x0, -0x18(%rbp)
jne 0xc10c
movb $0x1, %al
testb $0x1, %al
jne 0xc166
jmp 0xc17e
cmpq $0x0, -0x18(%rbp)
je 0xc153
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0xc153
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
je 0xc166
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xc17e
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xc17e
movq -0x18(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xc17e
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0xc166
jmp 0xc17e
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
je 0xc166
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xc17e
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x14(%rcx), %ecx
cmpl %ecx, %eax
je 0xc2cc
jmp 0xc180
jmp 0xc182
movq -0x10(%rbp), %rax
cmpq $0x0, %rax
je 0xc19e
jmp 0xc18e
movq -0x18(%rbp), %rax
movb 0x14(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x14(%rax)
jmp 0xc19e
jmp 0xc1a0
cmpq $0x0, -0x18(%rbp)
je 0xc27a
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0xc27a
jmp 0xc1be
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0xc1cf
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0xc1d8
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0xc1f2
xorl %eax, %eax
movl %eax, -0x60(%rbp)
jmp 0xc1fc
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0xc217
xorl %eax, %eax
movl %eax, -0x64(%rbp)
jmp 0xc221
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0xc23c
xorl %eax, %eax
movl %eax, -0x68(%rbp)
jmp 0xc246
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0xc261
xorl %eax, %eax
movl %eax, -0x6c(%rbp)
jmp 0xc26c
movq -0x18(%rbp), %rax
movzbl 0x10(%rax), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x10(%rax)
jmp 0xc2c8
movq -0x18(%rbp), %rax
cmpq $0x0, %rax
jne 0xc28b
xorl %eax, %eax
movl %eax, -0x70(%rbp)
jmp 0xc294
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x70(%rbp)
movl -0x70(%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 0xc2c8
jmp 0xc2ca
jmp 0xc2cc
movw -0x1a(%rbp), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x4e(%rax)
movq 0x23621(%rip), %rcx     # 0x2f900
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq %rax, 0x2360e(%rip)     # 0x2f900
callq 0x16a90
jmp 0xc2f9
jmp 0xc2fb
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)