// File: /workspace/github_c_makefile_star2_O2/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
xorl %edx, %edx
divl 0x10(%rbx)
movslq %edx, %r13
shlq $0x2, %r13
addq 0x18(%rbx), %r13
leaq 0x28(%rbx), %r12
leaq 0x40(%rbx), %r15
movl (%r13), %esi
testl %esi, %esi
je 0x8915
decl %esi
movq %r12, %rdi
callq 0x831b
movq %rax, %r14
movl (%r13), %esi
decl %esi
movq %r15, %rdi
callq 0x831b
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
je 0x88ea
cmpl %ebp, (%r14)
jne 0x88e1
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq *%rcx
testl %eax, %eax
jne 0x88ea
addq $0x4, %r14
movq %r14, %r13
jmp 0x88a2
movl (%r13), %ecx
movl 0x4(%r14), %eax
movl %eax, (%r13)
movl 0x38(%rbx), %r13d
movl 0x50(%rbx), %edx
cmpl %edx, %r13d
jne 0x89cc
leal -0x1(%rcx), %ebp
cmpl %r13d, %ecx
jne 0x891d
movl %ebp, %eax
jmp 0x899c
pushq $0x1
popq %rax
jmp 0x89a7
movq %rcx, 0x10(%rsp)
leal -0x1(%r13), %esi
movl %esi, 0x8(%rsp)
movq %r12, %rdi
callq 0x831b
movq %r12, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x8348
movq %r15, %rdi
movl 0x8(%rsp), %esi
callq 0x831b
movq %r15, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x8348
movq 0x18(%rbx), %rcx
movl (%r14), %eax
xorl %edx, %edx
divl 0x10(%rbx)
movslq %edx, %rdx
movl (%rcx,%rdx,4), %eax
testl %eax, %eax
je 0x89df
addq $0x4, %r14
leaq (%rcx,%rdx,4), %rcx
testl %eax, %eax
je 0x89b6
cmpl %r13d, %eax
je 0x8987
movl (%r14), %eax
movq %r14, %rcx
jmp 0x8976
movq 0x10(%rsp), %rax
movl %eax, (%rcx)
testl %eax, %eax
je 0x89b6
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 0x28bd(%rip), %rdi      # 0xb27a
xorl %eax, %eax
callq 0x7514
pushq $-0x1
popq %rdi
callq 0x21f0
leaq 0x2831(%rip), %rdi      # 0xb204
movl %r13d, %esi
xorl %eax, %eax
callq 0x7514
jmp 0x89c4
leaq 0x2855(%rip), %rdi      # 0xb23b
jmp 0x89bd