// File: /workspace/github_c_makefile_star2_O3/FH0[P]tun_direct/lwip-2.1.2/src/core/tcp_out.c
// Function: tcp_create_segment
static struct tcp_seg *
tcp_create_segment(const struct tcp_pcb *pcb, struct pbuf *p, u8_t hdrflags, u32_t seqno, u8_t optflags)
{
  struct tcp_seg *seg;
  u8_t optlen;

  LWIP_ASSERT("tcp_create_segment: invalid pcb", pcb != NULL);
  LWIP_ASSERT("tcp_create_segment: invalid pbuf", p != NULL);

  optlen = LWIP_TCP_OPT_LENGTH_SEGMENT(optflags, pcb);

  if ((seg = (struct tcp_seg *)memp_malloc(MEMP_TCP_SEG)) == NULL) {
    LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("tcp_create_segment: no memory.\n"));
    pbuf_free(p);
    return NULL;
  }
  seg->flags = optflags;
  seg->next = NULL;
  seg->p = p;
  LWIP_ASSERT("p->tot_len >= optlen", p->tot_len >= optlen);
  seg->len = p->tot_len - optlen;
#if TCP_OVERSIZE_DBGCHECK
  seg->oversize_left = 0;
#endif /* TCP_OVERSIZE_DBGCHECK */
#if TCP_CHECKSUM_ON_COPY
  seg->chksum = 0;
  seg->chksum_swapped = 0;
  /* check optflags */
  LWIP_ASSERT("invalid optflags passed: TF_SEG_DATA_CHECKSUMMED",
              (optflags & TF_SEG_DATA_CHECKSUMMED) == 0);
#endif /* TCP_CHECKSUM_ON_COPY */

  /* build TCP header */
  if (pbuf_add_header(p, TCP_HLEN)) {
    LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("tcp_create_segment: no room for TCP header in pbuf.\n"));
    TCP_STATS_INC(tcp.err);
    tcp_seg_free(seg);
    return NULL;
  }
  seg->tcphdr = (struct tcp_hdr *)seg->p->payload;
  seg->tcphdr->src = lwip_htons(pcb->local_port);
  seg->tcphdr->dest = lwip_htons(pcb->remote_port);
  seg->tcphdr->seqno = lwip_htonl(seqno);
  /* ackno is set in tcp_output */
  TCPH_HDRLEN_FLAGS_SET(seg->tcphdr, (5 + optlen / 4), hdrflags);
  /* wnd and chksum are set in tcp_output */
  seg->tcphdr->urgp = 0;
  return seg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rsi, %rsi
je 0xb735
movl %r8d, %r13d
movl %ecx, %r14d
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r15
movl $0x4, %edi
callq 0x3c6e
testq %rax, %rax
je 0xb6ad
movq %rax, %rbx
movl %ebp, 0x4(%rsp)
leal (,%r13,4), %ecx
andb $0x4, %cl
movb %r13b, 0x17(%rax)
movq $0x0, (%rax)
movq %r12, 0x8(%rax)
movzwl 0x10(%r12), %eax
movzbl %cl, %ebp
cmpw %bp, %ax
jb 0xb751
movzwl %bp, %ecx
subl %ecx, %eax
movw %ax, 0x10(%rbx)
movl $0x0, 0x12(%rbx)
movb $0x0, 0x16(%rbx)
testb $0x4, %r13b
jne 0xb76d
movl $0x14, %esi
movq %r12, %rdi
callq 0x5208
testb %al, %al
je 0xb6b9
movq %rbx, %rdi
callq 0x817c
jmp 0xb6b5
movq %r12, %rdi
callq 0x4fdf
xorl %ebx, %ebx
jmp 0xb723
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rbx)
movzwl 0x4e(%r15), %edi
callq 0x135b4
movq 0x18(%rbx), %rcx
movw %ax, (%rcx)
movzwl 0x50(%r15), %edi
callq 0x135b4
movq 0x18(%rbx), %rcx
movw %ax, 0x2(%rcx)
movl %r14d, %edi
callq 0x135bb
movq 0x18(%rbx), %rcx
movl %eax, 0x4(%rcx)
shrb $0x2, %bpl
addb $0x5, %bpl
movzbl %bpl, %eax
shll $0xc, %eax
movzbl 0x4(%rsp), %ecx
orl %eax, %ecx
movzwl %cx, %edi
callq 0x135b4
movq 0x18(%rbx), %rcx
movw %ax, 0xc(%rcx)
movw $0x0, 0x12(%rcx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8b90(%rip), %rdi      # 0x142cc
leaq 0xa63a(%rip), %rsi      # 0x15d7d
leaq 0xa035(%rip), %rcx      # 0x1577f
movl $0xa4, %edx
jmp 0xb787
leaq 0x8b74(%rip), %rdi      # 0x142cc
leaq 0xa63f(%rip), %rsi      # 0x15d9e
leaq 0xa019(%rip), %rcx      # 0x1577f
movl $0xb0, %edx
jmp 0xb787
leaq 0x8b58(%rip), %rdi      # 0x142cc
leaq 0xa638(%rip), %rsi      # 0x15db3
leaq 0x9ffd(%rip), %rcx      # 0x1577f
movl $0xba, %edx
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050