// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/ipv6/ip6_frag.c
// Function: ip6_reass_free_complete_datagram
static void
ip6_reass_free_complete_datagram(struct ip6_reassdata *ipr)
{
  struct ip6_reassdata *prev;
  u16_t pbufs_freed = 0;
  u16_t clen;
  struct pbuf *p;
  struct ip6_reass_helper *iprh;

#if LWIP_ICMP6
  iprh = (struct ip6_reass_helper *)ipr->p->payload;
  if (iprh->start == 0) {
    /* The first fragment was received, send ICMP time exceeded. */
    /* First, de-queue the first pbuf from r->p. */
    p = ipr->p;
    ipr->p = iprh->next_pbuf;
    /* Restore the part that we've overwritten with our helper structure, or we
     * might send garbage (and disclose a pointer) in the ICMPv6 reply. */
    MEMCPY(p->payload, ipr->orig_hdr, sizeof(iprh));
    /* Then, move back to the original ipv6 header (we are now pointing to Fragment header).
       This cannot fail since we already checked when receiving this fragment. */
    if (pbuf_header_force(p, (s16_t)((u8_t*)p->payload - (u8_t*)ipr->iphdr))) {
      LWIP_ASSERT("ip6_reass_free: moving p->payload to ip6 header failed\n", 0);
    }
    else {
      /* Reconstruct the zoned source and destination addresses, so that we do
       * not end up sending the ICMP response over the wrong link. */
      ip6_addr_t src_addr, dest_addr;
      ip6_addr_copy_from_packed(src_addr, IPV6_FRAG_SRC(ipr));
      ip6_addr_set_zone(&src_addr, ipr->src_zone);
      ip6_addr_copy_from_packed(dest_addr, IPV6_FRAG_DEST(ipr));
      ip6_addr_set_zone(&dest_addr, ipr->dest_zone);
      /* Send the actual ICMP response. */
      icmp6_time_exceeded_with_addrs(p, ICMP6_TE_FRAG, &src_addr, &dest_addr);
    }
    clen = pbuf_clen(p);
    LWIP_ASSERT("pbufs_freed + clen <= 0xffff", pbufs_freed + clen <= 0xffff);
    pbufs_freed = (u16_t)(pbufs_freed + clen);
    pbuf_free(p);
  }
#endif /* LWIP_ICMP6 */

  /* First, free all received pbufs.  The individual pbufs need to be released
     separately as they have not yet been chained */
  p = ipr->p;
  while (p != NULL) {
    struct pbuf *pcur;
    iprh = (struct ip6_reass_helper *)p->payload;
    pcur = p;
    /* get the next pointer before freeing */
    p = iprh->next_pbuf;
    clen = pbuf_clen(pcur);
    LWIP_ASSERT("pbufs_freed + clen <= 0xffff", pbufs_freed + clen <= 0xffff);
    pbufs_freed = (u16_t)(pbufs_freed + clen);
    pbuf_free(pcur);
  }

  /* Then, unchain the struct ip6_reassdata from the list and free it. */
  if (ipr == reassdatagrams) {
    reassdatagrams = ipr->next;
  } else {
    prev = reassdatagrams;
    while (prev != NULL) {
      if (prev->next == ipr) {
        break;
      }
      prev = prev->next;
    }
    if (prev != NULL) {
      prev->next = ipr->next;
    }
  }
  memp_free(MEMP_IP6_REASSDATA, ipr);

  /* Finally, update number of pbufs in reassembly queue */
  LWIP_ASSERT("ip_reass_pbufcount >= clen", ip6_reass_pbufcount >= pbufs_freed);
  ip6_reass_pbufcount = (u16_t)(ip6_reass_pbufcount - pbufs_freed);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movw $0x0, -0x12(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzwl 0x8(%rax), %eax
cmpl $0x0, %eax
jne 0x1e703
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movswl %ax, %esi
callq 0x7b00
cmpb $0x0, %al
je 0x1e617
jmp 0x1e5e6
jmp 0x1e5e8
leaq 0x8cdd(%rip), %rdi      # 0x272cc
leaq 0xb58c(%rip), %rsi      # 0x29b82
movl $0xa9, %edx
leaq 0xb4a6(%rip), %rcx      # 0x29aa8
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x1e619
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x30(%rbp)
movb $0x0, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movb 0x50(%rax), %al
movb %al, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0x34(%rax), %eax
movl %eax, -0x44(%rbp)
movb $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
movb 0x51(%rax), %al
movb %al, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
leaq -0x3c(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x1bf90
movq -0x20(%rbp), %rdi
callq 0x7bf0
movw %ax, -0x14(%rbp)
movzwl -0x12(%rbp), %eax
movzwl -0x14(%rbp), %ecx
addl %ecx, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jle 0x1e6ea
jmp 0x1e6bb
leaq 0x8c0a(%rip), %rdi      # 0x272cc
leaq 0xb1b4(%rip), %rsi      # 0x2987d
movl $0xb7, %edx
leaq 0xb3d3(%rip), %rcx      # 0x29aa8
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x1e6ec
movzwl -0x12(%rbp), %eax
movzwl -0x14(%rbp), %ecx
addl %ecx, %eax
movw %ax, -0x12(%rbp)
movq -0x20(%rbp), %rdi
callq 0x7260
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1e7a6
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x58(%rbp), %rdi
callq 0x7bf0
movw %ax, -0x14(%rbp)
movzwl -0x12(%rbp), %eax
movzwl -0x14(%rbp), %ecx
addl %ecx, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jle 0x1e788
jmp 0x1e759
leaq 0x8b6c(%rip), %rdi      # 0x272cc
leaq 0xb116(%rip), %rsi      # 0x2987d
movl $0xc7, %edx
leaq 0xb335(%rip), %rcx      # 0x29aa8
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x1e78a
movzwl -0x12(%rbp), %eax
movzwl -0x14(%rbp), %ecx
addl %ecx, %eax
movw %ax, -0x12(%rbp)
movq -0x58(%rbp), %rdi
callq 0x7260
jmp 0x1e70f
movq -0x8(%rbp), %rax
cmpq 0x11257(%rip), %rax     # 0x2fa08
jne 0x1e7c3
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x11247(%rip)     # 0x2fa08
jmp 0x1e808
movq 0x1123e(%rip), %rax     # 0x2fa08
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x1e7f1
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x1e7e4
jmp 0x1e7f1
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x1e7ce
cmpq $0x0, -0x10(%rbp)
je 0x1e806
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x1e808
movq -0x8(%rbp), %rsi
movl $0x9, %edi
callq 0x4a80
movzwl 0x111f3(%rip), %eax     # 0x2fa10
movzwl -0x12(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1e856
jmp 0x1e827
leaq 0x8a9e(%rip), %rdi      # 0x272cc
leaq 0xaf75(%rip), %rsi      # 0x297aa
movl $0xde, %edx
leaq 0xb267(%rip), %rcx      # 0x29aa8
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x1e858
movzwl 0x111b1(%rip), %eax     # 0x2fa10
movzwl -0x12(%rbp), %ecx
subl %ecx, %eax
movw %ax, 0x111a4(%rip)      # 0x2fa10
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)