// File: /workspace/github_c_makefile_star2_O2/FH0[P]tun_direct/lwip-2.1.2/src/core/tcp.c
// Function: tcp_listen_with_backlog_and_err
struct tcp_pcb *
tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
{
  struct tcp_pcb_listen *lpcb = NULL;
  err_t res;

  LWIP_UNUSED_ARG(backlog);

  LWIP_ASSERT_CORE_LOCKED();

  LWIP_ERROR("tcp_listen_with_backlog_and_err: invalid pcb", pcb != NULL, res = ERR_ARG; goto done);
  LWIP_ERROR("tcp_listen_with_backlog_and_err: pcb already connected", pcb->state == CLOSED, res = ERR_CLSD; goto done);

  /* already listening? */
  if (pcb->state == LISTEN) {
    lpcb = (struct tcp_pcb_listen *)pcb;
    res = ERR_ALREADY;
    goto done;
  }
#if SO_REUSE
  if (ip_get_option(pcb, SOF_REUSEADDR)) {
    /* Since SOF_REUSEADDR allows reusing a local address before the pcb's usage
       is declared (listen-/connection-pcb), we have to make sure now that
       this port is only used once for every local IP. */
    for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
      if ((lpcb->local_port == pcb->local_port) &&
          ip_addr_cmp(&lpcb->local_ip, &pcb->local_ip)) {
        /* this address/port is already used */
        lpcb = NULL;
        res = ERR_USE;
        goto done;
      }
    }
  }
#endif /* SO_REUSE */
  lpcb = (struct tcp_pcb_listen *)memp_malloc(MEMP_TCP_PCB_LISTEN);
  if (lpcb == NULL) {
    res = ERR_MEM;
    goto done;
  }
  lpcb->callback_arg = pcb->callback_arg;
  lpcb->local_port = pcb->local_port;
  lpcb->state = LISTEN;
  lpcb->prio = pcb->prio;
  lpcb->so_options = pcb->so_options;
  lpcb->netif_idx = NETIF_NO_INDEX;
  lpcb->ttl = pcb->ttl;
  lpcb->tos = pcb->tos;
#if LWIP_IPV4 && LWIP_IPV6
  IP_SET_TYPE_VAL(lpcb->remote_ip, pcb->local_ip.type);
#endif /* LWIP_IPV4 && LWIP_IPV6 */
  ip_addr_copy(lpcb->local_ip, pcb->local_ip);
  if (pcb->local_port != 0) {
    TCP_RMV(&tcp_bound_pcbs, pcb);
  }
#if LWIP_TCP_PCB_NUM_EXT_ARGS
  /* copy over ext_args to listening pcb  */
  memcpy(&lpcb->ext_args, &pcb->ext_args, sizeof(pcb->ext_args));
#endif
  tcp_free(pcb);
#if LWIP_CALLBACK_API
  lpcb->accept = tcp_accept_null;
#endif /* LWIP_CALLBACK_API */
#if TCP_LISTEN_BACKLOG
  lpcb->accepts_pending = 0;
  tcp_backlog_set(lpcb, backlog);
#endif /* TCP_LISTEN_BACKLOG */
  TCP_REG(&tcp_listen_pcbs.pcbs, (struct tcp_pcb *)lpcb);
  res = ERR_OK;
done:
  if (err != NULL) {
    *err = res;
  }
  return (struct tcp_pcb *)lpcb;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
testq %rdi, %rdi
je 0x764c
movq %rdi, %r15
cmpl $0x0, 0x48(%rdi)
jne 0x7668
movq %rdx, %rbx
pushq $0x3
popq %rdi
callq 0x3b4a
movq %rax, %r14
testq %rax, %rax
je 0x75bb
movq 0x40(%r15), %rax
movq %rax, 0x40(%r14)
movzwl 0x4e(%r15), %eax
movw %ax, 0x4e(%r14)
movl $0x1, 0x48(%r14)
movb 0x4c(%r15), %al
movb %al, 0x4c(%r14)
movb 0x31(%r15), %al
movb %al, 0x31(%r14)
movb $0x0, 0x30(%r14)
movb 0x33(%r15), %al
movb %al, 0x33(%r14)
movb 0x32(%r15), %al
movb %al, 0x32(%r14)
movb 0x14(%r15), %al
movb %al, 0x2c(%r14)
movb %al, 0x14(%r14)
movl (%r15), %ecx
movl %ecx, (%r14)
cmpb $0x6, %al
jne 0x75bf
movl 0x4(%r15), %eax
movl %eax, 0x4(%r14)
movl 0x8(%r15), %eax
movl %eax, 0x8(%r14)
movl 0xc(%r15), %eax
movl %eax, 0xc(%r14)
movb 0x10(%r15), %al
jmp 0x75cb
movb $-0x1, %al
jmp 0x763c
andl $0x0, 0xc(%r14)
andq $0x0, 0x4(%r14)
xorl %eax, %eax
movb %al, 0x10(%r14)
cmpw $0x0, 0x4e(%r15)
je 0x7610
movq 0x16322(%rip), %rcx     # 0x1d900
cmpq %r15, %rcx
je 0x75fd
testq %rcx, %rcx
je 0x760b
movq %rcx, %rax
movq 0x38(%rcx), %rcx
cmpq %r15, %rcx
jne 0x75e3
addq $0x38, %rax
movq %r15, %rcx
jmp 0x7604
leaq 0x162fc(%rip), %rax     # 0x1d900
movq 0x38(%rcx), %rcx
movq %rcx, (%rax)
andq $0x0, 0x38(%r15)
movq %r15, %rdi
callq 0x6530
leaq 0x76(%rip), %rax        # 0x7695
movq %rax, 0x50(%r14)
movq 0x162ce(%rip), %rax     # 0x1d8f8
movq %rax, 0x38(%r14)
movq %r14, 0x162c3(%rip)     # 0x1d8f8
callq 0xc634
xorl %eax, %eax
testq %rbx, %rbx
je 0x7643
movb %al, (%rbx)
movq %r14, %rax
popq %rbx
popq %r14
popq %r15
retq
leaq 0xcc79(%rip), %rdi      # 0x142cc
leaq 0xd718(%rip), %rsi      # 0x14d72
leaq 0xd63e(%rip), %rcx      # 0x14c9f
movl $0x359, %edx            # imm = 0x359
jmp 0x7682
leaq 0xcc5d(%rip), %rdi      # 0x142cc
leaq 0xd729(%rip), %rsi      # 0x14d9f
leaq 0xd622(%rip), %rcx      # 0x14c9f
movl $0x35a, %edx            # imm = 0x35A
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050