// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/tcp_out.c
// Function: tcp_enqueue_flags
err_t
tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)
{
  struct pbuf *p;
  struct tcp_seg *seg;
  u8_t optflags = 0;
  u8_t optlen = 0;

  LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue_flags: queuelen: %"U16_F"\n", (u16_t)pcb->snd_queuelen));

  LWIP_ASSERT("tcp_enqueue_flags: need either TCP_SYN or TCP_FIN in flags (programmer violates API)",
              (flags & (TCP_SYN | TCP_FIN)) != 0);
  LWIP_ASSERT("tcp_enqueue_flags: invalid pcb", pcb != NULL);

  /* No need to check pcb->snd_queuelen if only SYN or FIN are allowed! */

  /* Get options for this segment. This is a special case since this is the
     only place where a SYN can be sent. */
  if (flags & TCP_SYN) {
    optflags = TF_SEG_OPTS_MSS;
#if LWIP_WND_SCALE
    if ((pcb->state != SYN_RCVD) || (pcb->flags & TF_WND_SCALE)) {
      /* In a <SYN,ACK> (sent in state SYN_RCVD), the window scale option may only
         be sent if we received a window scale option from the remote host. */
      optflags |= TF_SEG_OPTS_WND_SCALE;
    }
#endif /* LWIP_WND_SCALE */
#if LWIP_TCP_SACK_OUT
    if ((pcb->state != SYN_RCVD) || (pcb->flags & TF_SACK)) {
      /* In a <SYN,ACK> (sent in state SYN_RCVD), the SACK_PERM option may only
         be sent if we received a SACK_PERM option from the remote host. */
      optflags |= TF_SEG_OPTS_SACK_PERM;
    }
#endif /* LWIP_TCP_SACK_OUT */
  }
#if LWIP_TCP_TIMESTAMPS
  if ((pcb->flags & TF_TIMESTAMP) || ((flags & TCP_SYN) && (pcb->state != SYN_RCVD))) {
    /* Make sure the timestamp option is only included in data segments if we
       agreed about it with the remote host (and in active open SYN segments). */
    optflags |= TF_SEG_OPTS_TS;
  }
#endif /* LWIP_TCP_TIMESTAMPS */
  optlen = LWIP_TCP_OPT_LENGTH_SEGMENT(optflags, pcb);

  /* Allocate pbuf with room for TCP header + options */
  if ((p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_RAM)) == NULL) {
    tcp_set_flags(pcb, TF_NAGLEMEMERR);
    TCP_STATS_INC(tcp.memerr);
    return ERR_MEM;
  }
  LWIP_ASSERT("tcp_enqueue_flags: check that first pbuf can hold optlen",
              (p->len >= optlen));

  /* Allocate memory for tcp_seg, and fill in fields. */
  if ((seg = tcp_create_segment(pcb, p, flags, pcb->snd_lbb, optflags)) == NULL) {
    tcp_set_flags(pcb, TF_NAGLEMEMERR);
    TCP_STATS_INC(tcp.memerr);
    return ERR_MEM;
  }
  LWIP_ASSERT("seg->tcphdr not aligned", ((mem_ptr_t)seg->tcphdr % LWIP_MIN(MEM_ALIGNMENT, 4)) == 0);
  LWIP_ASSERT("tcp_enqueue_flags: invalid segment length", seg->len == 0);

  LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_TRACE,
              ("tcp_enqueue_flags: queueing %"U32_F":%"U32_F" (0x%"X16_F")\n",
               lwip_ntohl(seg->tcphdr->seqno),
               lwip_ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg),
               (u16_t)flags));

  /* Now append seg to pcb->unsent queue */
  if (pcb->unsent == NULL) {
    pcb->unsent = seg;
  } else {
    struct tcp_seg *useg;
    for (useg = pcb->unsent; useg->next != NULL; useg = useg->next);
    useg->next = seg;
  }
#if TCP_OVERSIZE
  /* The new unsent tail has no space */
  pcb->unsent_oversize = 0;
#endif /* TCP_OVERSIZE */

  /* SYN and FIN bump the sequence number */
  if ((flags & TCP_SYN) || (flags & TCP_FIN)) {
    pcb->snd_lbb++;
    /* optlen does not influence snd_buf */
  }
  if (flags & TCP_FIN) {
    tcp_set_flags(pcb, TF_FIN);
  }

  /* update number of segments on the queues */
  pcb->snd_queuelen += pbuf_clen(seg->p);
  LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue_flags: %"S16_F" (after enqueued)\n", pcb->snd_queuelen));
  if (pcb->snd_queuelen != 0) {
    LWIP_ASSERT("tcp_enqueue_flags: invalid queue length",
                pcb->unacked != NULL || pcb->unsent != NULL);
  }

  return ERR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movb $0x0, -0x29(%rbp)
movb $0x0, -0x2a(%rbp)
jmp 0x147ec
jmp 0x147ee
movzbl -0x11(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x1482b
jmp 0x147fc
leaq 0x12ac9(%rip), %rdi     # 0x272cc
leaq 0x144db(%rip), %rsi     # 0x28ce5
movl $0x412, %edx            # imm = 0x412
leaq 0x141bc(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x1482d
jmp 0x1482f
cmpq $0x0, -0x10(%rbp)
jne 0x14867
jmp 0x14838
leaq 0x12a8d(%rip), %rdi     # 0x272cc
leaq 0x144f4(%rip), %rsi     # 0x28d3a
movl $0x413, %edx            # imm = 0x413
leaq 0x14180(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x14869
movzbl -0x11(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x14879
movb $0x1, -0x29(%rbp)
movzbl -0x29(%rbp), %edx
andl $0x1, %edx
xorl %eax, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movzbl -0x29(%rbp), %edx
andl $0x2, %edx
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %ecx
addl %ecx, %eax
movzbl -0x29(%rbp), %edx
andl $0x8, %edx
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %ecx
addl %ecx, %eax
movzbl -0x29(%rbp), %edx
andl $0x10, %edx
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %ecx
addl %ecx, %eax
movb %al, -0x2a(%rbp)
movzbl -0x2a(%rbp), %eax
movl $0x4a, %edi
movl $0x280, %edx            # imm = 0x280
movzwl %ax, %esi
callq 0x6e20
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x14906
jmp 0x148e5
movq -0x10(%rbp), %rax
movzwl 0x52(%rax), %eax
orl $0x80, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x52(%rax)
movb $-0x1, -0x1(%rbp)
jmp 0x14b64
jmp 0x14908
movq -0x20(%rbp), %rax
movzwl 0x12(%rax), %eax
movzbl -0x2a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x14949
jmp 0x1491a
leaq 0x129ab(%rip), %rdi     # 0x272cc
leaq 0x14431(%rip), %rsi     # 0x28d59
movl $0x43a, %edx            # imm = 0x43A
leaq 0x1409e(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x1494b
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rcx
movl 0x94(%rcx), %ecx
movzbl %al, %edx
movzbl -0x29(%rbp), %r8d
callq 0x13de0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x1499a
jmp 0x14979
movq -0x10(%rbp), %rax
movzwl 0x52(%rax), %eax
orl $0x80, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x52(%rax)
movb $-0x1, -0x1(%rbp)
jmp 0x14b64
jmp 0x1499c
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
andq $0x0, %rax
cmpq $0x0, %rax
je 0x149df
jmp 0x149b0
leaq 0x12915(%rip), %rdi     # 0x272cc
leaq 0x143d4(%rip), %rsi     # 0x28d92
movl $0x442, %edx            # imm = 0x442
leaq 0x14008(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x149e1
jmp 0x149e3
movq -0x28(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x0, %eax
je 0x14a21
jmp 0x149f2
leaq 0x128d3(%rip), %rdi     # 0x272cc
leaq 0x143aa(%rip), %rsi     # 0x28daa
movl $0x443, %edx            # imm = 0x443
leaq 0x13fc6(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x14a23
jmp 0x14a25
jmp 0x14a27
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
jne 0x14a46
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xa8(%rax)
jmp 0x14a79
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
je 0x14a6e
jmp 0x14a61
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x14a55
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movw $0x0, 0xa0(%rax)
movzbl -0x11(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x14a9e
movzbl -0x11(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x14ab1
movq -0x10(%rbp), %rax
movl 0x94(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x94(%rax)
movzbl -0x11(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x14ad7
jmp 0x14abf
movq -0x10(%rbp), %rax
movzwl 0x52(%rax), %eax
orl $0x20, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x52(%rax)
jmp 0x14ad7
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x7bf0
movzwl %ax, %edx
movq -0x10(%rbp), %rax
movzwl 0x9e(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x9e(%rax)
jmp 0x14afd
movq -0x10(%rbp), %rax
movzwl 0x9e(%rax), %eax
cmpl $0x0, %eax
je 0x14b60
jmp 0x14b0f
movq -0x10(%rbp), %rax
cmpq $0x0, 0xb0(%rax)
jne 0x14b5c
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
jne 0x14b5c
jmp 0x14b2d
leaq 0x12798(%rip), %rdi     # 0x272cc
leaq 0x14299(%rip), %rsi     # 0x28dd4
movl $0x466, %edx            # imm = 0x466
leaq 0x13e8b(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x14b5e
jmp 0x14b60
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)