// File: /workspace/github_c_makefile_star2_O1/atomlang[P]atomlang/src/pk_var.c
// Function: mapFindEntry
static bool _mapFindEntry(Map* self, Var key, MapEntry** result) {

  // An empty map won't contain the key.
  if (self->capacity == 0) return false;

  // The [start_index] is where the entry supposed to be if there wasn't any
  // collision occurred. It'll be the start index for the linear probing.
  uint32_t start_index = varHashValue(key) % self->capacity;
  uint32_t index = start_index;

  // Keep track of the first tombstone after the [start_index] if we don't find
  // the key anywhere. The tombstone would be the entry at where we will have
  // to insert the key/value pair.
  MapEntry* tombstone = NULL;

  do {
    MapEntry* entry = &self->entries[index];

    if (IS_UNDEF(entry->key)) {
      ASSERT(IS_BOOL(entry->value), OOPS);

      if (IS_TRUE(entry->value)) {

        // We've found a tombstone, if we haven't found one [tombstone] should
        // be updated. We still need to keep search for if the key exists.
        if (tombstone == NULL) tombstone = entry;

      } else {
        // We've found a new empty slot and the key isn't found. If we've
        // found a tombstone along the sequence we could use that entry
        // otherwise the entry at the current index.

        *result = (tombstone != NULL) ? tombstone : entry;
        return false;
      }

    } else if (isValuesEqual(entry->key, key)) {
      // We've found the key.
      *result = entry;
      return true;
    }

    index = (index + 1) % self->capacity;

  } while (index != start_index);

  // If we reach here means the map is filled with tombstone. Set the first
  // tombstone as result for the next insertion and return false.
  ASSERT(tombstone != NULL, OOPS);
  *result = tombstone;
  return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, (%rsp)
cmpl $0x0, 0x10(%rdi)
je 0xa03f
movq %rdi, %r15
movabsq $0x7ffd000000000000, %rbx # imm = 0x7FFD000000000000
movq %rsi, 0x20(%rsp)
movq %rsi, %rdi
callq 0x9eaa
movl 0x10(%r15), %ecx
xorl %r14d, %r14d
xorl %edx, %edx
movl %ecx, 0xc(%rsp)
divl %ecx
movl %edx, %r12d
leaq 0x2(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x3(%rbx), %rax
movq %rax, 0x10(%rsp)
movl %edx, %r13d
movq 0x18(%r15), %rax
movl %r13d, %ecx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rbx
movq (%rax,%rcx), %rdi
movabsq $0x7ffd000000000000, %rax # imm = 0x7FFD000000000000
cmpq %rax, %rdi
jne 0x9fee
movq 0x8(%rbx), %rax
movq %rax, %rcx
andq $-0x2, %rcx
cmpq 0x18(%rsp), %rcx
jne 0xa056
testq %r14, %r14
cmovneq %r14, %rbx
cmpq 0x10(%rsp), %rax
jne 0xa01b
movq %rbx, %r14
jmp 0xa008
movq 0x20(%rsp), %rsi
callq 0xaa90
testb %al, %al
je 0xa008
movq (%rsp), %rax
movq %rbx, (%rax)
movb $0x1, %bpl
jmp 0xa024
incl %r13d
movl %r13d, %eax
xorl %edx, %edx
divl 0xc(%rsp)
movb $0x1, %al
movl %edx, %r13d
jmp 0xa026
movq (%rsp), %rax
movq %rbx, (%rax)
xorl %ebp, %ebp
xorl %eax, %eax
testb %al, %al
je 0xa041
cmpl %r12d, %r13d
jne 0x9fa7
testq %r14, %r14
je 0xa05b
movq (%rsp), %rax
movq %r14, (%rax)
xorl %ebp, %ebp
andb $0x1, %bpl
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2688
callq 0x26be