// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/classes/misc/array.cpp
// Function: smooth::IndexArray::GetEntryNumberByIndex(int) const
S::Int S::IndexArray::GetEntryNumberByIndex(Int index) const
{
	ReadLock	 lock(*this);

	if (nOfEntries == 0) return -1;

	Int	 entryNumber  = -1;
	Int	 lastAccessed = lastAccessedEntry;

	/* Check entries around last accessed entry.
	 */
	if	(lastAccessed     <  nOfEntries && indices[lastAccessed    ] == index) entryNumber = lastAccessed;
	else if (lastAccessed     >  0 &&
		 lastAccessed     <= nOfEntries && indices[lastAccessed - 1] == index) entryNumber = lastAccessed - 1;
	else if (lastAccessed + 1 <  nOfEntries && indices[lastAccessed + 1] == index) entryNumber = lastAccessed + 1;

	/* Binary search for sorted lists.
	 */
	else if (sorted)
	{
		Int	 bottom = 0;
		Int	 top	= nOfEntries - 1;

		while (top >= bottom)
		{
			Int	 i = (top + bottom) / 2;
			Int	 e = indices[i];

			if (e == index) { entryNumber = i; break; }

			if (e < index) bottom = i + 1;
			else	       top    = i - 1;
		}
	}

	/* Linear search otherwise.
	 */
	else
	{
		for (Int i = 0; i < nOfEntries; i++)
		{
			if (indices[i] == index) { entryNumber = i; break; }
		}
	}

	if (entryNumber >= 0) lastAccessedEntry = entryNumber;

	return entryNumber;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rsi
movq %rsi, -0x58(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x5c8f0
movq -0x58(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xed40d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x24(%rbp)
jmp 0xed5d2
movq -0x58(%rbp), %rcx
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl 0x14(%rcx), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0xed468
movq -0x58(%rbp), %rdi
addq $0x18, %rdi
movl -0x2c(%rbp), %esi
callq 0xeddf0
movl %eax, -0x5c(%rbp)
jmp 0xed43b
movl -0x5c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0xed468
movl -0x2c(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0xed5b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x5c0b0
jmp 0xed5e4
cmpl $0x0, -0x2c(%rbp)
jle 0xed4a7
movq -0x58(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x8(%rcx), %eax
jg 0xed4a7
movq -0x58(%rbp), %rdi
addq $0x18, %rdi
movl -0x2c(%rbp), %esi
decl %esi
callq 0xeddf0
movl %eax, -0x60(%rbp)
jmp 0xed491
movl -0x60(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0xed4a7
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xed5b3
movq -0x58(%rbp), %rcx
movl -0x2c(%rbp), %eax
addl $0x1, %eax
cmpl 0x8(%rcx), %eax
jge 0xed4e3
movq -0x58(%rbp), %rdi
addq $0x18, %rdi
movl -0x2c(%rbp), %esi
incl %esi
callq 0xeddf0
movl %eax, -0x64(%rbp)
jmp 0xed4cd
movl -0x64(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0xed4e3
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xed5b1
movq -0x58(%rbp), %rax
testb $0x1, 0x10(%rax)
je 0xed568
movq -0x58(%rbp), %rax
movl $0x0, -0x40(%rbp)
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x40(%rbp), %eax
jl 0xed566
movq -0x58(%rbp), %rdi
movl -0x44(%rbp), %eax
movl -0x40(%rbp), %ecx
addl %ecx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %ecx, %eax
sarl %eax
movl %eax, -0x48(%rbp)
addq $0x18, %rdi
movl -0x48(%rbp), %esi
callq 0xeddf0
movl %eax, -0x68(%rbp)
jmp 0xed532
movl -0x68(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0xed548
movl -0x48(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0xed566
movl -0x4c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xed55b
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xed564
movl -0x48(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xed501
jmp 0xed5af
movl $0x0, -0x50(%rbp)
movq -0x58(%rbp), %rcx
movl -0x50(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0xed5ad
movq -0x58(%rbp), %rdi
addq $0x18, %rdi
movl -0x50(%rbp), %esi
callq 0xeddf0
movl %eax, -0x6c(%rbp)
jmp 0xed590
movl -0x6c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0xed5a0
movl -0x50(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0xed5ad
jmp 0xed5a2
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xed56f
jmp 0xed5af
jmp 0xed5b1
jmp 0xed5b3
jmp 0xed5b5
cmpl $0x0, -0x28(%rbp)
jl 0xed5c5
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, 0x14(%rax)
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x24(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x5c0b0
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x5b6b0
nopl (%rax)