// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/pbuf.c
// Function: pbuf_take
err_t
pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
{
  struct pbuf *p;
  size_t buf_copy_len;
  size_t total_copy_len = len;
  size_t copied_total = 0;

  LWIP_ERROR("pbuf_take: invalid buf", (buf != NULL), return ERR_ARG;);
  LWIP_ERROR("pbuf_take: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
  LWIP_ERROR("pbuf_take: buf not large enough", (buf->tot_len >= len), return ERR_MEM;);

  if ((buf == NULL) || (dataptr == NULL) || (buf->tot_len < len)) {
    return ERR_ARG;
  }

  /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
  for (p = buf; total_copy_len != 0; p = p->next) {
    LWIP_ASSERT("pbuf_take: invalid pbuf", p != NULL);
    buf_copy_len = total_copy_len;
    if (buf_copy_len > p->len) {
      /* this pbuf cannot hold all remaining data */
      buf_copy_len = p->len;
    }
    /* copy the necessary parts of the buffer */
    MEMCPY(p->payload, &((const char *)dataptr)[copied_total], buf_copy_len);
    total_copy_len -= buf_copy_len;
    copied_total += buf_copy_len;
  }
  LWIP_ASSERT("did not copy all data", total_copy_len == 0 && copied_total == len);
  return ERR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movzwl -0x1a(%rbp), %eax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x868f
jmp 0x8660
leaq 0x1ec65(%rip), %rdi     # 0x272cc
leaq 0x1f571(%rip), %rsi     # 0x27bdf
movl $0x4b3, %edx            # imm = 0x4B3
leaq 0x1f22f(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x8691
jmp 0x8693
cmpq $0x0, -0x18(%rbp)
jne 0x86cb
jmp 0x869c
leaq 0x1ec29(%rip), %rdi     # 0x272cc
leaq 0x1f54c(%rip), %rsi     # 0x27bf6
movl $0x4b4, %edx            # imm = 0x4B4
leaq 0x1f1f3(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x86cd
jmp 0x86cf
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
movzwl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x8710
jmp 0x86e1
leaq 0x1ebe4(%rip), %rdi     # 0x272cc
leaq 0x1f522(%rip), %rsi     # 0x27c11
movl $0x4b5, %edx            # imm = 0x4B5
leaq 0x1f1ae(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x8712
cmpq $0x0, -0x10(%rbp)
je 0x8730
cmpq $0x0, -0x18(%rbp)
je 0x8730
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
movzwl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x8739
movb $-0x10, -0x1(%rbp)
jmp 0x883e
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x87f1
jmp 0x874e
cmpq $0x0, -0x28(%rbp)
jne 0x8786
jmp 0x8757
leaq 0x1eb6e(%rip), %rdi     # 0x272cc
leaq 0x1f4cc(%rip), %rsi     # 0x27c31
movl $0x4bd, %edx            # imm = 0x4BD
leaq 0x1f138(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x8788
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x87ad
movq -0x28(%rbp), %rax
movzwl 0x12(%rax), %eax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
addq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x2180
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x8741
jmp 0x87f3
cmpq $0x0, -0x38(%rbp)
jne 0x8807
movq -0x40(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
cmpq %rcx, %rax
je 0x8838
jmp 0x8809
leaq 0x1eabc(%rip), %rdi     # 0x272cc
leaq 0x1f432(%rip), %rsi     # 0x27c49
movl $0x4c8, %edx            # imm = 0x4C8
leaq 0x1f086(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x883a
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)