// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/ipv4/ip4_frag.c
// Function: ip_reass_remove_oldest_datagram
static int
ip_reass_remove_oldest_datagram(struct ip_hdr *fraghdr, int pbufs_needed)
{
  /* @todo Can't we simply remove the last datagram in the
   *       linked list behind reassdatagrams?
   */
  struct ip_reassdata *r, *oldest, *prev, *oldest_prev;
  int pbufs_freed = 0, pbufs_freed_current;
  int other_datagrams;

  /* Free datagrams until being allowed to enqueue 'pbufs_needed' pbufs,
   * but don't free the datagram that 'fraghdr' belongs to! */
  do {
    oldest = NULL;
    prev = NULL;
    oldest_prev = NULL;
    other_datagrams = 0;
    r = reassdatagrams;
    while (r != NULL) {
      if (!IP_ADDRESSES_AND_ID_MATCH(&r->iphdr, fraghdr)) {
        /* Not the same datagram as fraghdr */
        other_datagrams++;
        if (oldest == NULL) {
          oldest = r;
          oldest_prev = prev;
        } else if (r->timer <= oldest->timer) {
          /* older than the previous oldest */
          oldest = r;
          oldest_prev = prev;
        }
      }
      if (r->next != NULL) {
        prev = r;
      }
      r = r->next;
    }
    if (oldest != NULL) {
      pbufs_freed_current = ip_reass_free_complete_datagram(oldest, oldest_prev);
      pbufs_freed += pbufs_freed_current;
    }
  } while ((pbufs_freed < pbufs_needed) && (other_datagrams > 1));
  return pbufs_freed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x34(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movq 0x149d4(%rip), %rax     # 0x2f9d0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1b0bb
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x1b03f
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x1b03f
movq -0x18(%rbp), %rax
movzwl 0x14(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0x4(%rcx), %ecx
cmpl %ecx, %eax
je 0x1b047
movb $0x1, %al
testb $0x1, %al
jne 0x1b04f
jmp 0x1b099
xorl %eax, %eax
testb $0x1, %al
jne 0x1b04f
jmp 0x1b099
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x1b071
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x1b097
movq -0x18(%rbp), %rax
movzbl 0x27(%rax), %eax
movq -0x20(%rbp), %rcx
movzbl 0x27(%rcx), %ecx
cmpl %ecx, %eax
jg 0x1b095
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x1b097
jmp 0x1b099
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1b0ab
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x1b000
cmpq $0x0, -0x20(%rbp)
je 0x1b0db
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1a840
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x1b0dd
movl -0x34(%rbp), %ecx
xorl %eax, %eax
cmpl -0xc(%rbp), %ecx
movb %al, -0x3d(%rbp)
jge 0x1b0f4
cmpl $0x1, -0x3c(%rbp)
setg %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x1afd6
movl -0x34(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)