// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/intset.c
// Function: intsetSearch
static uint8_t intsetSearch(intset *is, int64_t value, uint32_t *pos) {
    int min = 0, max = intrev32ifbe(is->length)-1, mid = -1;
    int64_t cur = -1;

    /* The value can never be found when the set is empty */
    if (intrev32ifbe(is->length) == 0) {
        if (pos) *pos = 0;
        return 0;
    } else {
        /* Check for the case where we know we cannot find the value,
         * but do know the insert position. */
        if (value > _intsetGet(is,intrev32ifbe(is->length)-1)) {
            if (pos) *pos = intrev32ifbe(is->length);
            return 0;
        } else if (value < _intsetGet(is,0)) {
            if (pos) *pos = 0;
            return 0;
        }
    }

    while(max >= min) {
        mid = ((unsigned int)min + (unsigned int)max) >> 1;
        cur = _intsetGet(is,mid);
        if (value > cur) {
            min = mid+1;
        } else if (value < cur) {
            max = mid-1;
        } else {
            break;
        }
    }

    if (value == cur) {
        if (pos) *pos = mid;
        return 1;
    } else {
        if (pos) *pos = min;
        return 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq $-0x1, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x7b57b
cmpq $0x0, -0x20(%rbp)
je 0x7b572
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0x7b685
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %esi
subl $0x1, %esi
callq 0x7b9a0
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jle 0x7b5bf
cmpq $0x0, -0x20(%rbp)
je 0x7b5b6
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0x7b685
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7b9a0
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jge 0x7b5f8
cmpq $0x0, -0x20(%rbp)
je 0x7b5ef
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0x7b685
jmp 0x7b5fa
jmp 0x7b5fc
jmp 0x7b5fe
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x7b651
movl -0x24(%rbp), %eax
addl -0x28(%rbp), %eax
shrl %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x7b9a0
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x38(%rbp), %rax
jle 0x7b636
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x7b64f
movq -0x18(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x7b64b
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x7b64d
jmp 0x7b651
jmp 0x7b64f
jmp 0x7b5fe
movq -0x18(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0x7b671
cmpq $0x0, -0x20(%rbp)
je 0x7b66b
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x7b685
cmpq $0x0, -0x20(%rbp)
je 0x7b681
movl -0x24(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x50, %rsp
popq %rbp
retq
nop