// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movw %si, %ax
movq %rdi, -0x8(%rbp)
movw %ax, -0xa(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x75eb
jmp 0x75bc
leaq 0x1fd09(%rip), %rdi     # 0x272cc
leaq 0x20386(%rip), %rsi     # 0x27950
movl $0x198, %edx            # imm = 0x198
leaq 0x202d3(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x75ed
movzwl -0xa(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jl 0x7602
jmp 0x7775
movq -0x8(%rbp), %rax
movzwl 0x10(%rax), %eax
movzwl -0xa(%rbp), %ecx
subl %ecx, %eax
movw %ax, -0x1c(%rbp)
movw -0xa(%rbp), %ax
movw %ax, -0x1a(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movzwl -0x1a(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
cmpl %ecx, %eax
jle 0x76a9
movzwl -0x1a(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
subl %ecx, %eax
movw %ax, -0x1a(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %eax
movzwl -0x1c(%rbp), %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x76a2
jmp 0x7673
leaq 0x1fc52(%rip), %rdi     # 0x272cc
leaq 0x202e7(%rip), %rsi     # 0x27968
movl $0x1af, %edx            # imm = 0x1AF
leaq 0x2021c(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x76a4
jmp 0x7624
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x7738
movzwl -0x1a(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
cmpl %ecx, %eax
je 0x7738
movq -0x18(%rbp), %rax
movzbl 0x15(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x7738
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
subq %rax, %rsi
movzwl -0x1a(%rbp), %eax
addq %rax, %rsi
callq 0x4630
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x7734
jmp 0x7705
leaq 0x1fbc0(%rip), %rdi     # 0x272cc
leaq 0x2026d(%rip), %rsi     # 0x27980
movl $0x1bd, %edx            # imm = 0x1BD
leaq 0x2018a(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x7736
jmp 0x7738
movw -0x1a(%rbp), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x12(%rax)
movq -0x18(%rbp), %rax
movw 0x12(%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x10(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x776a
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x7260
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)