// File: /workspace/github_c_makefile_star2_O2/FH0[P]tun_direct/lwip-2.1.2/src/core/pbuf.c
// Function: pbuf_realloc
void
pbuf_realloc(struct pbuf *p, u16_t new_len)
{
  struct pbuf *q;
  u16_t rem_len; /* remaining length */
  u16_t shrink;

  LWIP_ASSERT("pbuf_realloc: p != NULL", p != NULL);

  /* desired length larger than current length? */
  if (new_len >= p->tot_len) {
    /* enlarging not yet supported */
    return;
  }

  /* the pbuf chain grows by (new_len - p->tot_len) bytes
   * (which may be negative in case of shrinking) */
  shrink = (u16_t)(p->tot_len - new_len);

  /* first, step over any pbufs that should remain in the chain */
  rem_len = new_len;
  q = p;
  /* should this pbuf be kept? */
  while (rem_len > q->len) {
    /* decrease remaining length by pbuf length */
    rem_len = (u16_t)(rem_len - q->len);
    /* decrease total length indicator */
    q->tot_len = (u16_t)(q->tot_len - shrink);
    /* proceed to next pbuf in chain */
    q = q->next;
    LWIP_ASSERT("pbuf_realloc: q != NULL", q != NULL);
  }
  /* we have now reached the new last pbuf (in q) */
  /* rem_len == desired length for pbuf q */

  /* shrink allocated memory for PBUF_RAM */
  /* (other types merely adjust their length fields */
  if (pbuf_match_allocsrc(q, PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP) && (rem_len != q->len)
#if LWIP_SUPPORT_CUSTOM_PBUF
      && ((q->flags & PBUF_FLAG_IS_CUSTOM) == 0)
#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
     ) {
    /* reallocate and adjust the length of the pbuf that will be split */
    q = (struct pbuf *)mem_trim(q, (mem_size_t)(((u8_t *)q->payload - (u8_t *)q) + rem_len));
    LWIP_ASSERT("mem_trim returned q == NULL", q != NULL);
  }
  /* adjust length fields for new last pbuf */
  q->len = rem_len;
  q->tot_len = q->len;

  /* any remaining pbufs in chain? */
  if (q->next != NULL) {
    /* free remaining pbufs in chain */
    pbuf_free(q->next);
  }
  /* q is last packet in chain */
  q->next = NULL;

}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x5011
movl %esi, %ebp
movq %rdi, %rbx
movzwl 0x10(%rdi), %ecx
cmpw %cx, %bp
jae 0x500a
movl %ebp, %eax
subl %ecx, %eax
movzwl 0x12(%rbx), %ecx
cmpw %cx, %bp
jbe 0x4fc8
addw %ax, 0x10(%rbx)
subl %ecx, %ebp
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x4f84
leaq 0xf32a(%rip), %rdi      # 0x142cc
leaq 0xf914(%rip), %rsi      # 0x148bd
leaq 0xf879(%rip), %rcx      # 0x14829
movl $0x1af, %edx            # imm = 0x1AF
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050
je 0x4ff1
movb 0x14(%rbx), %al
andb $0xf, %al
jne 0x4ff1
testb $0x2, 0x15(%rbx)
jne 0x4ff1
movzwl %bp, %esi
subq %rbx, %rsi
addq 0x8(%rbx), %rsi
movq %rbx, %rdi
callq 0x3ac5
movq %rax, %rbx
testq %rax, %rax
je 0x502d
movw %bp, 0x12(%rbx)
movw %bp, 0x10(%rbx)
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x5006
callq 0x4e16
andq $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0xf2b4(%rip), %rdi      # 0x142cc
leaq 0xf886(%rip), %rsi      # 0x148a5
leaq 0xf803(%rip), %rcx      # 0x14829
movl $0x198, %edx            # imm = 0x198
jmp 0x4fb5
leaq 0xf298(%rip), %rdi      # 0x142cc
leaq 0xf89a(%rip), %rsi      # 0x148d5
leaq 0xf7e7(%rip), %rcx      # 0x14829
movl $0x1bd, %edx            # imm = 0x1BD
jmp 0x4fb5