// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %dl, -0x19(%rbp)
movl %ecx, -0x20(%rbp)
movb %al, -0x21(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x13e34
jmp 0x13e05
leaq 0x134c0(%rip), %rdi     # 0x272cc
leaq 0x1524a(%rip), %rsi     # 0x2905d
movl $0xa3, %edx
leaq 0x14bb3(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x13e36
jmp 0x13e38
cmpq $0x0, -0x18(%rbp)
jne 0x13e70
jmp 0x13e41
leaq 0x13484(%rip), %rdi     # 0x272cc
leaq 0x1522e(%rip), %rsi     # 0x2907d
movl $0xa4, %edx
leaq 0x14b77(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x13e72
movzbl -0x21(%rbp), %edx
andl $0x1, %edx
xorl %eax, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movzbl -0x21(%rbp), %edx
andl $0x2, %edx
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %ecx
addl %ecx, %eax
movzbl -0x21(%rbp), %edx
andl $0x8, %edx
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %ecx
addl %ecx, %eax
movzbl -0x21(%rbp), %edx
andl $0x10, %edx
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %ecx
addl %ecx, %eax
movb %al, -0x31(%rbp)
movl $0x4, %edi
callq 0x4930
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x13eea
jmp 0x13ed2
jmp 0x13ed4
movq -0x18(%rbp), %rdi
callq 0x7260
movq $0x0, -0x8(%rbp)
jmp 0x14096
movb -0x21(%rbp), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x17(%rax)
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %eax
movzbl -0x31(%rbp), %ecx
cmpl %ecx, %eax
jge 0x13f4c
jmp 0x13f1d
leaq 0x133a8(%rip), %rdi     # 0x272cc
leaq 0x15173(%rip), %rsi     # 0x2909e
movl $0xb0, %edx
leaq 0x14a9b(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x13f4e
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %eax
movzbl -0x31(%rbp), %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, 0x10(%rax)
movq -0x30(%rbp), %rax
movw $0x0, 0x12(%rax)
movq -0x30(%rbp), %rax
movw $0x0, 0x14(%rax)
movq -0x30(%rbp), %rax
movb $0x0, 0x16(%rax)
movzbl -0x21(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x13fc0
jmp 0x13f91
leaq 0x13334(%rip), %rdi     # 0x272cc
leaq 0x15114(%rip), %rsi     # 0x290b3
movl $0xba, %edx
leaq 0x14a27(%rip), %rcx     # 0x289d2
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x13fc2
movq -0x18(%rbp), %rdi
movl $0x14, %esi
callq 0x7780
cmpb $0x0, %al
je 0x13fee
jmp 0x13fd6
jmp 0x13fd8
movq -0x30(%rbp), %rdi
callq 0xd7a0
movq $0x0, -0x8(%rbp)
jmp 0x14096
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movzwl 0x4e(%rax), %edi
callq 0x251c0
movw %ax, %cx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movzwl 0x50(%rax), %edi
callq 0x251c0
movw %ax, %cx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movw %cx, 0x2(%rax)
movl -0x20(%rbp), %edi
callq 0x251f0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, 0x4(%rax)
movzbl -0x31(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
addl $0x5, %eax
shll $0xc, %eax
movzwl %ax, %eax
movzbl -0x19(%rbp), %ecx
orl %ecx, %eax
movzwl %ax, %edi
callq 0x251c0
movw %ax, %cx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movw %cx, 0xc(%rax)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movw $0x0, 0x12(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq