// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/tcp_in.c
// Function: tcp_listen_input
static void
tcp_listen_input(struct tcp_pcb_listen *pcb)
{
  struct tcp_pcb *npcb;
  u32_t iss;
  err_t rc;

  if (flags & TCP_RST) {
    /* An incoming RST should be ignored. Return. */
    return;
  }

  LWIP_ASSERT("tcp_listen_input: invalid pcb", pcb != NULL);

  /* In the LISTEN state, we check for incoming SYN segments,
     creates a new PCB, and responds with a SYN|ACK. */
  if (flags & TCP_ACK) {
    /* For incoming segments with the ACK flag set, respond with a
       RST. */
    LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n"));
    tcp_rst((const struct tcp_pcb *)pcb, ackno, seqno + tcplen, ip_current_dest_addr(),
            ip_current_src_addr(), tcphdr->dest, tcphdr->src);
  } else if (flags & TCP_SYN) {
    LWIP_DEBUGF(TCP_DEBUG, ("TCP connection request %"U16_F" -> %"U16_F".\n", tcphdr->src, tcphdr->dest));
#if TCP_LISTEN_BACKLOG
    if (pcb->accepts_pending >= pcb->backlog) {
      LWIP_DEBUGF(TCP_DEBUG, ("tcp_listen_input: listen backlog exceeded for port %"U16_F"\n", tcphdr->dest));
      return;
    }
#endif /* TCP_LISTEN_BACKLOG */
    npcb = tcp_alloc(pcb->prio);
    /* If a new PCB could not be created (probably due to lack of memory),
       we don't do anything, but rely on the sender will retransmit the
       SYN at a time when we have more memory available. */
    if (npcb == NULL) {
      err_t err;
      LWIP_DEBUGF(TCP_DEBUG, ("tcp_listen_input: could not allocate PCB\n"));
      TCP_STATS_INC(tcp.memerr);
      TCP_EVENT_ACCEPT(pcb, NULL, pcb->callback_arg, ERR_MEM, err);
      LWIP_UNUSED_ARG(err); /* err not useful here */
      return;
    }
#if TCP_LISTEN_BACKLOG
    pcb->accepts_pending++;
    tcp_set_flags(npcb, TF_BACKLOGPEND);
#endif /* TCP_LISTEN_BACKLOG */
    /* Set up the new PCB. */
    ip_addr_copy(npcb->local_ip, *ip_current_dest_addr());
    ip_addr_copy(npcb->remote_ip, *ip_current_src_addr());
    npcb->local_port = pcb->local_port;

#if TUN2SOCKS
    // go-tun2socks logic
    // Always reset local port to the dest of the connection, because we are
    // accepting all incomming connections, regardless of there destination addresses,
    // as such, npcb is acting as the server socket that communicates with the
    // client socket.
    npcb->local_port = tcphdr->dest;
#endif /* TUN2SOCKS */

    npcb->remote_port = tcphdr->src;
    npcb->state = SYN_RCVD;
    npcb->rcv_nxt = seqno + 1;
    npcb->rcv_ann_right_edge = npcb->rcv_nxt;
    iss = tcp_next_iss(npcb);
    npcb->snd_wl2 = iss;
    npcb->snd_nxt = iss;
    npcb->lastack = iss;
    npcb->snd_lbb = iss;
    npcb->snd_wl1 = seqno - 1;/* initialise to seqno-1 to force window update */
    npcb->callback_arg = pcb->callback_arg;
#if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG
    npcb->listener = pcb;
#endif /* LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG */
    /* inherit socket options */
    npcb->so_options = pcb->so_options & SOF_INHERITED;
    npcb->netif_idx = pcb->netif_idx;
    /* Register the new PCB so that we can begin receiving segments
       for it. */
    TCP_REG_ACTIVE(npcb);

    /* Parse any options in the SYN. */
    tcp_parseopt(npcb);
    npcb->snd_wnd = tcphdr->wnd;
    npcb->snd_wnd_max = npcb->snd_wnd;

#if TCP_CALCULATE_EFF_SEND_MSS
    npcb->mss = tcp_eff_send_mss(npcb->mss, &npcb->local_ip, &npcb->remote_ip);
#endif /* TCP_CALCULATE_EFF_SEND_MSS */

    MIB2_STATS_INC(mib2.tcppassiveopens);

#if LWIP_TCP_PCB_NUM_EXT_ARGS
    if (tcp_ext_arg_invoke_callbacks_passive_open(pcb, npcb) != ERR_OK) {
      tcp_abandon(npcb, 0);
      return;
    }
#endif

    /* Send a SYN|ACK together with the MSS option. */
    rc = tcp_enqueue_flags(npcb, TCP_SYN | TCP_ACK);
    if (rc != ERR_OK) {
      tcp_abandon(npcb, 0);
      return;
    }
    tcp_output(npcb);
  }
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movzbl 0x1fed9(%rip), %eax     # 0x2f94c
andl $0x4, %eax
cmpl $0x0, %eax
je 0xfa80
jmp 0xfefd
jmp 0xfa82
cmpq $0x0, -0x8(%rbp)
jne 0xfaba
jmp 0xfa8b
leaq 0x1783a(%rip), %rdi     # 0x272cc
leaq 0x18cb7(%rip), %rsi     # 0x28750
movl $0x287, %edx            # imm = 0x287
leaq 0x18aff(%rip), %rcx     # 0x285a4
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0xfabc
movzbl 0x1fe89(%rip), %eax     # 0x2f94c
andl $0x10, %eax
cmpl $0x0, %eax
je 0xfb21
jmp 0xfacd
jmp 0xfacf
movq -0x8(%rbp), %rdi
movl 0x1fe6f(%rip), %esi     # 0x2f948
movl 0x1fe65(%rip), %edx     # 0x2f944
movzwl 0x1fe68(%rip), %eax     # 0x2f94e
addl %eax, %edx
movq 0x1fe39(%rip), %rax     # 0x2f928
movw 0x2(%rax), %r9w
movq 0x1fe2d(%rip), %rax     # 0x2f928
leaq 0x1fc6e(%rip), %r8      # 0x2f770
movq %r8, %rcx
addq $0x3c, %rcx
addq $0x24, %r8
movzwl %r9w, %r9d
movzwl (%rax), %eax
movl %eax, (%rsp)
callq 0x16110
jmp 0xfefb
movzbl 0x1fe24(%rip), %eax     # 0x2f94c
andl $0x2, %eax
cmpl $0x0, %eax
je 0xfef9
jmp 0xfb36
jmp 0xfb38
movq -0x8(%rbp), %rax
movzbl 0x4c(%rax), %edi
callq 0xd900
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xfb8c
jmp 0xfb52
jmp 0xfb54
jmp 0xfb56
movq -0x8(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0xfb81
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x40(%rcx), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *%rax
movb %al, -0x16(%rbp)
jmp 0xfb85
movb $-0x10, -0x16(%rbp)
jmp 0xfb87
jmp 0xfefd
jmp 0xfb8e
jmp 0xfb90
leaq 0x1fbd9(%rip), %rax     # 0x2f770
movb 0x50(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x14(%rax)
leaq 0x1fbc8(%rip), %rax     # 0x2f770
movzbl 0x50(%rax), %eax
cmpl $0x6, %eax
jne 0xfc09
jmp 0xfbb3
leaq 0x1fbb6(%rip), %rax     # 0x2f770
movl 0x3c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
leaq 0x1fba6(%rip), %rax     # 0x2f770
movl 0x40(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
leaq 0x1fb95(%rip), %rax     # 0x2f770
movl 0x44(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
leaq 0x1fb84(%rip), %rax     # 0x2f770
movl 0x48(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
leaq 0x1fb73(%rip), %rax     # 0x2f770
movb 0x4c(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x10(%rax)
jmp 0xfc44
leaq 0x1fb60(%rip), %rax     # 0x2f770
movl 0x3c(%rax), %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 0xfc44
jmp 0xfc46
jmp 0xfc48
jmp 0xfc4a
leaq 0x1fb1f(%rip), %rax     # 0x2f770
movb 0x38(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2c(%rax)
leaq 0x1fb0e(%rip), %rax     # 0x2f770
movzbl 0x38(%rax), %eax
cmpl $0x6, %eax
jne 0xfcc4
jmp 0xfc6d
leaq 0x1fafc(%rip), %rax     # 0x2f770
movl 0x24(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
leaq 0x1faeb(%rip), %rax     # 0x2f770
movl 0x28(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
leaq 0x1fada(%rip), %rax     # 0x2f770
movl 0x2c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
leaq 0x1fac9(%rip), %rax     # 0x2f770
movl 0x30(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
leaq 0x1fab8(%rip), %rax     # 0x2f770
movb 0x34(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x28(%rax)
jmp 0xfd00
leaq 0x1faa5(%rip), %rax     # 0x2f770
movl 0x24(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x24(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x28(%rax)
jmp 0xfd00
jmp 0xfd02
movq -0x8(%rbp), %rax
movw 0x4e(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x4e(%rax)
movq 0x1fc0f(%rip), %rax     # 0x2f928
movw 0x2(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x4e(%rax)
movq 0x1fbfc(%rip), %rax     # 0x2f928
movw (%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x50(%rax)
movq -0x10(%rbp), %rax
movl $0x3, 0x48(%rax)
movl 0x1fbfc(%rip), %ecx     # 0x2f944
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x10(%rbp), %rdi
callq 0xd0d0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x90(%rax)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x88(%rax)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x7c(%rax)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x94(%rax)
movl 0x1fba1(%rip), %ecx     # 0x2f944
subl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8c(%rax)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x8(%rbp), %rax
movzbl 0x31(%rax), %eax
andl $0xc, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x31(%rax)
movq -0x8(%rbp), %rax
movb 0x30(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x30(%rax)
jmp 0xfdf3
leaq 0x1fb0e(%rip), %rax     # 0x2f908
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rcx
leaq 0x1faf8(%rip), %rax     # 0x2f908
movq %rcx, (%rax)
callq 0x16a90
leaq 0x1fafa(%rip), %rax     # 0x2f919
movb $0x1, (%rax)
movq -0x10(%rbp), %rdi
callq 0x10cc0
movq 0x1faf6(%rip), %rax     # 0x2f928
movw 0xe(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x98(%rax)
movq -0x10(%rbp), %rax
movw 0x98(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x9a(%rax)
movq -0x10(%rbp), %rax
movw 0x6a(%rax), %ax
movw %ax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x18, %rax
cmpq $0x0, %rax
je 0xfe95
movq -0x10(%rbp), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x6, %eax
jne 0xfe95
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
callq 0x1c270
movq %rax, -0x20(%rbp)
jmp 0xfea6
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
callq 0x196c0
movq %rax, -0x20(%rbp)
movw -0x18(%rbp), %ax
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
addq $0x18, %rdx
movzwl %ax, %edi
callq 0xd140
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x6a(%rax)
movq -0x10(%rbp), %rdi
movl $0x12, %esi
callq 0x147d0
movb %al, -0x15(%rbp)
movsbl -0x15(%rbp), %eax
cmpl $0x0, %eax
je 0xfef0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xb750
jmp 0xfefd
movq -0x10(%rbp), %rdi
callq 0x14b70
jmp 0xfefb
jmp 0xfefd
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)