// File: /workspace/github_c_makefile_star2_O3/negge[P]xlink/src/util.c
// Function: xlink_set_remove
int xlink_set_remove(xlink_set *set, const void *key) {
  unsigned int hash;
  int *index;
  hash = set->hash_code(key);
  index = &set->table[xlink_set_index(set, hash)];
  while (*index != 0) {
    xlink_entry *entry;
    void *value;
    entry = xlink_list_get(&set->entries, *index - 1);
    value = xlink_list_get(&set->values, *index - 1);
    if (set->equals == NULL ||
     (entry->hash == hash && set->equals(key, value))) {
      int old;
      int last;
      /* Move the entry / value from the end into the empty slot and reindex */
      old = *index - 1;
      *index = entry->down;
      XLINK_ERROR(
       xlink_list_length(&set->entries) != xlink_list_length(&set->values),
       ("Invalid xlink_set state, entries = %i but values = %i\n",
       xlink_list_length(&set->entries), xlink_list_length(&set->values)));
      last = xlink_list_length(&set->entries) - 1;
      if (old != last) {
        xlink_list_set(&set->entries, old, xlink_list_get(&set->entries, last));
        xlink_list_set(&set->values, old, xlink_list_get(&set->values, last));
        index = &set->table[xlink_set_index(set, entry->hash)];
        XLINK_ERROR(*index == 0,
         ("Invalid xlink_set state, index = 0 but should contain an entry"));
        while (*index != 0) {
          if (*index == last + 1) {
            *index = old + 1;
            break;
          }
          index = &entry->down;
        }
        XLINK_ERROR(*index == 0,
         ("Invalid xlink_set state, cound not find last entry to reindex"));
      }
      set->entries.length--;
      set->values.length--;
      set->size--;
      return EXIT_SUCCESS;
    }
    index = &entry->down;
  }
  return EXIT_FAILURE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq %rsi, 0x8(%rsp)
movq %rsi, %rdi
callq *(%rbx)
movl %eax, %ebp
movq 0x18(%rbx), %rcx
xorl %edx, %edx
divl 0x10(%rbx)
movslq %edx, %rdx
movl (%rcx,%rdx,4), %esi
movl $0x1, %eax
testl %esi, %esi
je 0x9c4b
leaq (%rcx,%rdx,4), %r14
leaq 0x28(%rbx), %r12
leaq 0x40(%rbx), %r15
decl %esi
movq %r12, %rdi
callq 0x9507
movq %rax, %r13
movl (%r14), %esi
decl %esi
movq %r15, %rdi
callq 0x9507
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
je 0x9b8d
cmpl %ebp, (%r13)
jne 0x9b74
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq *%rcx
testl %eax, %eax
jne 0x9b8d
movq %r13, %r14
addq $0x4, %r14
movl 0x4(%r13), %esi
testl %esi, %esi
jne 0x9b3d
movl $0x1, %eax
jmp 0x9c4b
movl (%r14), %ecx
movl 0x4(%r13), %eax
movl %eax, (%r14)
movl 0x38(%rbx), %r14d
movl 0x50(%rbx), %edx
cmpl %edx, %r14d
jne 0x9c72
leal -0x1(%rcx), %ebp
cmpl %r14d, %ecx
jne 0x9bb6
movl %ebp, %eax
jmp 0x9c40
movq %rcx, 0x10(%rsp)
leal -0x1(%r14), %esi
movl %esi, 0x8(%rsp)
movq %r12, %rdi
callq 0x9507
movq %r12, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x9536
movq %r15, %rdi
movl 0x8(%rsp), %esi
callq 0x9507
movq %r15, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x9536
movq 0x18(%rbx), %rcx
movl (%r13), %eax
xorl %edx, %edx
divl 0x10(%rbx)
movslq %edx, %rax
movl (%rcx,%rax,4), %edx
testl %edx, %edx
je 0x9c85
cmpl %r14d, %edx
jne 0x9c18
leaq (%rcx,%rax,4), %r13
movq 0x10(%rsp), %rcx
jmp 0x9c2e
addq $0x4, %r13
movl (%r13), %eax
movq 0x10(%rsp), %rcx
testl %eax, %eax
je 0x9c5a
cmpl %r14d, %eax
jne 0x9c25
movl %ecx, (%r13)
testl %ecx, %ecx
je 0x9c5a
movl 0x38(%rbx), %eax
movl 0x50(%rbx), %ebp
decl %eax
decl %ebp
movl %eax, 0x38(%rbx)
movl %ebp, 0x50(%rbx)
decl 0x20(%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2649(%rip), %rdi      # 0xc2aa
xorl %eax, %eax
callq 0x22ef
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21f0
leaq 0x25bb(%rip), %rdi      # 0xc234
movl %r14d, %esi
xorl %eax, %eax
callq 0x22ef
jmp 0x9c68
leaq 0x25df(%rip), %rdi      # 0xc26b
jmp 0x9c61