// File: /workspace/github_c_makefile_star2_O1/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 0x7a1b
movq %rdi, %r15
cmpl $0x0, 0x48(%rdi)
jne 0x7a37
movq %rdx, %rbx
movl $0x3, %edi
callq 0x3c9e
testq %rax, %rax
je 0x798a
movq %rax, %r14
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 0x7991
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
movb %al, 0x10(%r14)
jmp 0x799b
movb $-0x1, %al
xorl %r14d, %r14d
jmp 0x7a0b
xorl %eax, %eax
movq %rax, 0x9(%r14)
movq %rax, 0x4(%r14)
cmpw $0x0, 0x4e(%r15)
je 0x79df
movq 0x15f56(%rip), %rcx     # 0x1d900
cmpq %r15, %rcx
je 0x79c9
testq %rcx, %rcx
je 0x79d7
movq %rcx, %rax
movq 0x38(%rcx), %rcx
cmpq %r15, %rcx
jne 0x79af
addq $0x38, %rax
movq %r15, %rcx
jmp 0x79d0
leaq 0x15f30(%rip), %rax     # 0x1d900
movq 0x38(%rcx), %rcx
movq %rcx, (%rax)
movq $0x0, 0x38(%r15)
movq %r15, %rdi
callq 0x685c
leaq 0x76(%rip), %rax        # 0x7a64
movq %rax, 0x50(%r14)
movq 0x15eff(%rip), %rax     # 0x1d8f8
movq %rax, 0x38(%r14)
movq %r14, 0x15ef4(%rip)     # 0x1d8f8
callq 0xce20
xorl %eax, %eax
testq %rbx, %rbx
je 0x7a12
movb %al, (%rbx)
movq %r14, %rax
popq %rbx
popq %r14
popq %r15
retq
leaq 0xd8aa(%rip), %rdi      # 0x152cc
leaq 0xe349(%rip), %rsi      # 0x15d72
leaq 0xe26f(%rip), %rcx      # 0x15c9f
movl $0x359, %edx            # imm = 0x359
jmp 0x7a51
leaq 0xd88e(%rip), %rdi      # 0x152cc
leaq 0xe35a(%rip), %rsi      # 0x15d9f
leaq 0xe253(%rip), %rcx      # 0x15c9f
movl $0x35a, %edx            # imm = 0x35A
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050