// File: /workspace/github_c_makefile_star2_O3/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 0x790e
movq %rdi, %r15
cmpl $0x0, 0x48(%rdi)
jne 0x792a
movq %rdx, %rbx
movl $0x3, %edi
callq 0x3c6e
movq %rax, %r14
testq %rax, %rax
je 0x7871
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 0x7878
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 0x788a
movb $-0x1, %al
jmp 0x78fe
movl $0x0, 0xc(%r14)
movq $0x0, 0x4(%r14)
xorl %eax, %eax
movb %al, 0x10(%r14)
cmpw $0x0, 0x4e(%r15)
je 0x78d2
movq 0x15063(%rip), %rcx     # 0x1c900
cmpq %r15, %rcx
je 0x78bc
testq %rcx, %rcx
je 0x78ca
movq %rcx, %rax
movq 0x38(%rcx), %rcx
cmpq %r15, %rcx
jne 0x78a2
addq $0x38, %rax
movq %r15, %rcx
jmp 0x78c3
leaq 0x1503d(%rip), %rax     # 0x1c900
movq 0x38(%rcx), %rcx
movq %rcx, (%rax)
movq $0x0, 0x38(%r15)
movq %r15, %rdi
callq 0x6780
leaq 0x76(%rip), %rax        # 0x7957
movq %rax, 0x50(%r14)
movq 0x1500c(%rip), %rax     # 0x1c8f8
movq %rax, 0x38(%r14)
movq %r14, 0x15001(%rip)     # 0x1c8f8
callq 0xcba0
xorl %eax, %eax
testq %rbx, %rbx
je 0x7905
movb %al, (%rbx)
movq %r14, %rax
popq %rbx
popq %r14
popq %r15
retq
leaq 0xc9b7(%rip), %rdi      # 0x142cc
leaq 0xd43f(%rip), %rsi      # 0x14d5b
leaq 0xd365(%rip), %rcx      # 0x14c88
movl $0x359, %edx            # imm = 0x359
jmp 0x7944
leaq 0xc99b(%rip), %rdi      # 0x142cc
leaq 0xd450(%rip), %rsi      # 0x14d88
leaq 0xd349(%rip), %rcx      # 0x14c88
movl $0x35a, %edx            # imm = 0x35A
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050