// File: /workspace/github_c_makefile_star2_O1/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 0x525e
movl %esi, %ebp
movq %rdi, %rbx
movzwl 0x10(%rdi), %ecx
cmpw %cx, %bp
jae 0x5257
movl %ebp, %eax
subl %ecx, %eax
movzwl 0x12(%rbx), %ecx
cmpw %cx, %bp
jbe 0x5212
addw %ax, 0x10(%rbx)
subl %ecx, %ebp
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x51ce
leaq 0x100e0(%rip), %rdi     # 0x152cc
leaq 0x106ca(%rip), %rsi     # 0x158bd
leaq 0x1062f(%rip), %rcx     # 0x15829
movl $0x1af, %edx            # imm = 0x1AF
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050
je 0x523b
movb 0x14(%rbx), %al
andb $0xf, %al
jne 0x523b
testb $0x2, 0x15(%rbx)
jne 0x523b
movzwl %bp, %esi
subq %rbx, %rsi
addq 0x8(%rbx), %rsi
movq %rbx, %rdi
callq 0x3c19
movq %rax, %rbx
testq %rax, %rax
je 0x527a
movw %bp, 0x12(%rbx)
movw %bp, 0x10(%rbx)
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x5250
callq 0x5069
movq $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x10067(%rip), %rdi     # 0x152cc
leaq 0x10639(%rip), %rsi     # 0x158a5
leaq 0x105b6(%rip), %rcx     # 0x15829
movl $0x198, %edx            # imm = 0x198
jmp 0x51ff
leaq 0x1004b(%rip), %rdi     # 0x152cc
leaq 0x1064d(%rip), %rsi     # 0x158d5
leaq 0x1059a(%rip), %rcx     # 0x15829
movl $0x1bd, %edx            # imm = 0x1BD
jmp 0x51ff