// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/ipv6/nd6.c
// Function: nd6_queue_packet
static err_t
nd6_queue_packet(s8_t neighbor_index, struct pbuf *q)
{
  err_t result = ERR_MEM;
  struct pbuf *p;
  int copy_needed = 0;
#if LWIP_ND6_QUEUEING
  struct nd6_q_entry *new_entry, *r;
#endif /* LWIP_ND6_QUEUEING */

  if ((neighbor_index < 0) || (neighbor_index >= LWIP_ND6_NUM_NEIGHBORS)) {
    return ERR_ARG;
  }

  /* IF q includes a pbuf that must be copied, we have to copy the whole chain
   * into a new PBUF_RAM. See the definition of PBUF_NEEDS_COPY for details. */
  p = q;
  while (p) {
    if (PBUF_NEEDS_COPY(p)) {
      copy_needed = 1;
      break;
    }
    p = p->next;
  }
  if (copy_needed) {
    /* copy the whole packet into new pbufs */
    p = pbuf_clone(PBUF_LINK, PBUF_RAM, q);
    while ((p == NULL) && (neighbor_cache[neighbor_index].q != NULL)) {
      /* Free oldest packet (as per RFC recommendation) */
#if LWIP_ND6_QUEUEING
      r = neighbor_cache[neighbor_index].q;
      neighbor_cache[neighbor_index].q = r->next;
      r->next = NULL;
      nd6_free_q(r);
#else /* LWIP_ND6_QUEUEING */
      pbuf_free(neighbor_cache[neighbor_index].q);
      neighbor_cache[neighbor_index].q = NULL;
#endif /* LWIP_ND6_QUEUEING */
      p = pbuf_clone(PBUF_LINK, PBUF_RAM, q);
    }
  } else {
    /* referencing the old pbuf is enough */
    p = q;
    pbuf_ref(p);
  }
  /* packet was copied/ref'd? */
  if (p != NULL) {
    /* queue packet ... */
#if LWIP_ND6_QUEUEING
    /* allocate a new nd6 queue entry */
    new_entry = (struct nd6_q_entry *)memp_malloc(MEMP_ND6_QUEUE);
    if ((new_entry == NULL) && (neighbor_cache[neighbor_index].q != NULL)) {
      /* Free oldest packet (as per RFC recommendation) */
      r = neighbor_cache[neighbor_index].q;
      neighbor_cache[neighbor_index].q = r->next;
      r->next = NULL;
      nd6_free_q(r);
      new_entry = (struct nd6_q_entry *)memp_malloc(MEMP_ND6_QUEUE);
    }
    if (new_entry != NULL) {
      new_entry->next = NULL;
      new_entry->p = p;
      if (neighbor_cache[neighbor_index].q != NULL) {
        /* queue was already existent, append the new entry to the end */
        r = neighbor_cache[neighbor_index].q;
        while (r->next != NULL) {
          r = r->next;
        }
        r->next = new_entry;
      } else {
        /* queue did not exist, first item in queue */
        neighbor_cache[neighbor_index].q = new_entry;
      }
      LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: queued packet %p on neighbor entry %"S16_F"\n", (void *)p, (s16_t)neighbor_index));
      result = ERR_OK;
    } else {
      /* the pool MEMP_ND6_QUEUE is empty */
      pbuf_free(p);
      LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: could not queue a copy of packet %p (out of memory)\n", (void *)p));
      /* { result == ERR_MEM } through initialization */
    }
#else /* LWIP_ND6_QUEUEING */
    /* Queue a single packet. If an older packet is already queued, free it as per RFC. */
    if (neighbor_cache[neighbor_index].q != NULL) {
      pbuf_free(neighbor_cache[neighbor_index].q);
    }
    neighbor_cache[neighbor_index].q = p;
    LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: queued packet %p on neighbor entry %"S16_F"\n", (void *)p, (s16_t)neighbor_index));
    result = ERR_OK;
#endif /* LWIP_ND6_QUEUEING */
  } else {
    LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: could not queue a copy of packet %p (out of memory)\n", (void *)q));
    /* { result == ERR_MEM } through initialization */
  }

  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %dil, %al
movb %al, -0x2(%rbp)
movq %rsi, -0x10(%rbp)
movb $-0x1, -0x11(%rbp)
movl $0x0, -0x24(%rbp)
movsbl -0x2(%rbp), %eax
cmpl $0x0, %eax
jl 0x2469f
movsbl -0x2(%rbp), %eax
cmpl $0xa, %eax
jl 0x246a8
movb $-0x10, -0x1(%rbp)
jmp 0x248fd
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x246dd
movq -0x20(%rbp), %rax
movzbl 0x14(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x246d0
movl $0x1, -0x24(%rbp)
jmp 0x246dd
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x246b0
cmpl $0x0, -0x24(%rbp)
je 0x2479c
movq -0x10(%rbp), %rdx
movl $0xe, %edi
movl $0x280, %esi            # imm = 0x280
callq 0x8a20
movq %rax, -0x20(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x20(%rbp)
movb %al, -0x39(%rbp)
jne 0x24728
movsbq -0x2(%rbp), %rcx
leaq 0xb30a(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x28(%rax)
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x24731
jmp 0x2479a
movsbq -0x2(%rbp), %rcx
leaq 0xb2e3(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movsbq -0x2(%rbp), %rdx
leaq 0xb2c1(%rip), %rax      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movq -0x38(%rbp), %rdi
callq 0x24db0
movq -0x10(%rbp), %rdx
movl $0xe, %edi
movl $0x280, %esi            # imm = 0x280
callq 0x8a20
movq %rax, -0x20(%rbp)
jmp 0x246fe
jmp 0x247ad
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x7c30
cmpq $0x0, -0x20(%rbp)
je 0x248f1
movl $0x8, %edi
callq 0x4930
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x24842
movsbq -0x2(%rbp), %rcx
leaq 0xb247(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x28(%rax)
je 0x24842
movsbq -0x2(%rbp), %rcx
leaq 0xb22d(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movsbq -0x2(%rbp), %rdx
leaq 0xb20b(%rip), %rax      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movq -0x38(%rbp), %rdi
callq 0x24db0
movl $0x8, %edi
callq 0x4930
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x248e2
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movsbq -0x2(%rbp), %rcx
leaq 0xb1b0(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x28(%rax)
je 0x248bd
movsbq -0x2(%rbp), %rcx
leaq 0xb196(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
je 0x248b0
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x24899
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
jmp 0x248d8
movq -0x30(%rbp), %rcx
movsbq -0x2(%rbp), %rdx
leaq 0xb153(%rip), %rax      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
jmp 0x248da
jmp 0x248dc
movb $0x0, -0x11(%rbp)
jmp 0x248ef
movq -0x20(%rbp), %rdi
callq 0x7260
jmp 0x248ed
jmp 0x248ef
jmp 0x248f7
jmp 0x248f3
jmp 0x248f5
jmp 0x248f7
movb -0x11(%rbp), %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)