// File: /workspace/github_c_makefile_star2_O1/FH0[P]tun_direct/lwip-2.1.2/src/core/pbuf.c
// Function: pbuf_copy
err_t
pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
{
  size_t offset_to = 0, offset_from = 0, len;

  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy(%p, %p)\n",
              (const void *)p_to, (const void *)p_from));

  /* is the target big enough to hold the source? */
  LWIP_ERROR("pbuf_copy: target not big enough to hold source", ((p_to != NULL) &&
             (p_from != NULL) && (p_to->tot_len >= p_from->tot_len)), return ERR_ARG;);

  /* iterate through pbuf chain */
  do {
    /* copy one part of the original chain */
    if ((p_to->len - offset_to) >= (p_from->len - offset_from)) {
      /* complete current p_from fits into current p_to */
      len = p_from->len - offset_from;
    } else {
      /* current p_from does not fit into current p_to */
      len = p_to->len - offset_to;
    }
    MEMCPY((u8_t *)p_to->payload + offset_to, (u8_t *)p_from->payload + offset_from, len);
    offset_to += len;
    offset_from += len;
    LWIP_ASSERT("offset_to <= p_to->len", offset_to <= p_to->len);
    LWIP_ASSERT("offset_from <= p_from->len", offset_from <= p_from->len);
    if (offset_from >= p_from->len) {
      /* on to next p_from (if any) */
      offset_from = 0;
      p_from = p_from->next;
    }
    if (offset_to == p_to->len) {
      /* on to next p_to (if any) */
      offset_to = 0;
      p_to = p_to->next;
      LWIP_ERROR("p_to != NULL", (p_to != NULL) || (p_from == NULL), return ERR_ARG;);
    }

    if ((p_from != NULL) && (p_from->len == p_from->tot_len)) {
      /* don't copy more than one packet! */
      LWIP_ERROR("pbuf_copy() does not allow packet queues!",
                 (p_from->next == NULL), return ERR_VAL;);
    }
    if ((p_to != NULL) && (p_to->len == p_to->tot_len)) {
      /* don't copy more than one packet! */
      LWIP_ERROR("pbuf_copy() does not allow packet queues!",
                 (p_to->next == NULL), return ERR_VAL;);
    }
  } while (p_from);
  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy: end of chain reached.\n"));
  return ERR_OK;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x573e
movq %rsi, %rbx
testq %rsi, %rsi
je 0x573e
movq %rdi, %r14
movzwl 0x10(%rdi), %eax
cmpw 0x10(%rbx), %ax
jb 0x573e
xorl %r13d, %r13d
xorl %r12d, %r12d
movzwl 0x12(%r14), %eax
subq %r13, %rax
movzwl 0x12(%rbx), %r15d
subq %r12, %r15
cmpq %r15, %rax
cmovbq %rax, %r15
movq 0x8(%r14), %rdi
addq %r13, %rdi
movq 0x8(%rbx), %rsi
addq %r12, %rsi
movq %r15, %rdx
callq 0x2180
addq %r15, %r13
movzwl 0x12(%r14), %eax
cmpq %rax, %r13
ja 0x56a1
addq %r15, %r12
movzwl 0x12(%rbx), %ecx
cmpq %rcx, %r12
ja 0x56bd
jb 0x563d
movq (%rbx), %rbx
xorl %r12d, %r12d
cmpq %rax, %r13
jne 0x565c
movq (%r14), %r14
testq %r14, %r14
setne %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
je 0x56d9
xorl %r13d, %r13d
testq %rbx, %rbx
je 0x5675
movzwl 0x12(%rbx), %eax
cmpw 0x10(%rbx), %ax
jne 0x5675
cmpq $0x0, (%rbx)
jne 0x5711
testq %r14, %r14
je 0x568c
movzwl 0x12(%r14), %eax
cmpw 0x10(%r14), %ax
jne 0x568c
cmpq $0x0, (%r14)
jne 0x56f5
testq %rbx, %rbx
jne 0x55eb
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xfc24(%rip), %rdi      # 0x152cc
leaq 0x10384(%rip), %rsi     # 0x15a33
leaq 0x10173(%rip), %rcx     # 0x15829
movl $0x3d9, %edx            # imm = 0x3D9
jmp 0x572b
leaq 0xfc08(%rip), %rdi      # 0x152cc
leaq 0x1037f(%rip), %rsi     # 0x15a4a
leaq 0x10157(%rip), %rcx     # 0x15829
movl $0x3da, %edx            # imm = 0x3DA
jmp 0x572b
leaq 0xfbec(%rip), %rdi      # 0x152cc
leaq 0x1037e(%rip), %rsi     # 0x15a65
leaq 0x1013b(%rip), %rcx     # 0x15829
movl $0x3e4, %edx            # imm = 0x3E4
jmp 0x572b
leaq 0xfbd0(%rip), %rdi      # 0x152cc
leaq 0x1036f(%rip), %rsi     # 0x15a72
leaq 0x1011f(%rip), %rcx     # 0x15829
movl $0x3ef, %edx            # imm = 0x3EF
jmp 0x572b
leaq 0xfbb4(%rip), %rdi      # 0x152cc
leaq 0x10353(%rip), %rsi     # 0x15a72
leaq 0x10103(%rip), %rcx     # 0x15829
movl $0x3ea, %edx            # imm = 0x3EA
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050
leaq 0xfb87(%rip), %rdi      # 0x152cc
leaq 0x102b7(%rip), %rsi     # 0x15a03
leaq 0x100d6(%rip), %rcx     # 0x15829
movl $0x3ca, %edx            # imm = 0x3CA
jmp 0x572b