// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/bitops.c
// Function: bitposCommand
void bitposCommand(client *c) {
    robj *o;
    long bit, start, end, strlen;
    unsigned char *p;
    char llbuf[LONG_STR_SIZE];
    int end_given = 0;

    /* Parse the bit argument to understand what we are looking for, set
     * or clear bits. */
    if (getLongFromObjectOrReply(c,c->argv[2],&bit,NULL) != C_OK)
        return;
    if (bit != 0 && bit != 1) {
        addReplyError(c, "The bit argument must be 1 or 0.");
        return;
    }

    /* If the key does not exist, from our point of view it is an infinite
     * array of 0 bits. If the user is looking for the fist clear bit return 0,
     * If the user is looking for the first set bit, return -1. */
    if ((o = lookupKeyRead(c->db,c->argv[1])) == NULL) {
        addReplyLongLong(c, bit ? -1 : 0);
        return;
    }
    if (checkType(c,o,OBJ_STRING)) return;
    p = getObjectReadOnlyString(o,&strlen,llbuf);

    /* Parse start/end range if any. */
    if (c->argc == 4 || c->argc == 5) {
        if (getLongFromObjectOrReply(c,c->argv[3],&start,NULL) != C_OK)
            return;
        if (c->argc == 5) {
            if (getLongFromObjectOrReply(c,c->argv[4],&end,NULL) != C_OK)
                return;
            end_given = 1;
        } else {
            end = strlen-1;
        }
        /* Convert negative indexes */
        if (start < 0) start = strlen+start;
        if (end < 0) end = strlen+end;
        if (start < 0) start = 0;
        if (end < 0) end = 0;
        if (end >= strlen) end = strlen-1;
    } else if (c->argc == 3) {
        /* The whole string. */
        start = 0;
        end = strlen-1;
    } else {
        /* Syntax error. */
        addReply(c,shared.syntaxerr);
        return;
    }

    /* For empty ranges (start > end) we return -1 as an empty range does
     * not contain a 0 nor a 1. */
    if (start > end) {
        addReplyLongLong(c, -1);
    } else {
        long bytes = end-start+1;
        long pos = redisBitpos(p+start,bytes,bit);

        /* If we are looking for clear bits, and the user specified an exact
         * range with start-end, we can't consider the right of the range as
         * zero padded (as we do when no explicit end is given).
         *
         * So if redisBitpos() returns the first bit outside the range,
         * we return -1 to the caller, to mean, in the specified range there
         * is not a single "0" bit. */
        if (end_given && bit == 0 && pos == bytes*8) {
            addReplyLongLong(c,-1);
            return;
        }
        if (pos != -1) pos += start*8; /* Adjust for the bytes we skipped. */
        addReplyLongLong(c,pos);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x10(%rax), %rsi
leaq -0x18(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x49f20
cmpl $0x0, %eax
je 0x9212a
jmp 0x9237b
cmpq $0x0, -0x18(%rbp)
je 0x9214d
cmpq $0x1, -0x18(%rbp)
je 0x9214d
movq -0x8(%rbp), %rdi
leaq 0xb3d8b(%rip), %rsi     # 0x145ece
callq 0x42f90
jmp 0x9237b
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x4a6c0
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x92193
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movslq %eax, %rsi
callq 0x43780
jmp 0x9237b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x490a0
cmpl $0x0, %eax
je 0x921ac
jmp 0x9237b
movq -0x10(%rbp), %rdi
leaq -0x50(%rbp), %rdx
leaq -0x30(%rbp), %rsi
callq 0x91090
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x4, 0x38(%rax)
je 0x921d9
movq -0x8(%rbp), %rax
cmpl $0x5, 0x38(%rax)
jne 0x922a2
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x18(%rax), %rsi
leaq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x49f20
cmpl $0x0, %eax
je 0x92200
jmp 0x9237b
movq -0x8(%rbp), %rax
cmpl $0x5, 0x38(%rax)
jne 0x9223a
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x20(%rax), %rsi
leaq -0x28(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x49f20
cmpl $0x0, %eax
je 0x92231
jmp 0x9237b
movl $0x1, -0x54(%rbp)
jmp 0x92246
movq -0x30(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0x92259
movq -0x30(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x28(%rbp)
jge 0x9226c
movq -0x30(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0x9227b
movq $0x0, -0x20(%rbp)
cmpq $0x0, -0x28(%rbp)
jge 0x9228a
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jl 0x922a0
movq -0x30(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x922e0
movq -0x8(%rbp), %rax
cmpl $0x3, 0x38(%rax)
jne 0x922c2
movq $0x0, -0x20(%rbp)
movq -0x30(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x922de
movq -0x8(%rbp), %rdi
leaq 0xe6973(%rip), %rax     # 0x178c40
movq 0x80(%rax), %rsi
callq 0x42cc0
jmp 0x9237b
jmp 0x922e0
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0x922fc
movq -0x8(%rbp), %rdi
movq $-0x1, %rsi
callq 0x43780
jmp 0x9237b
movq -0x28(%rbp), %rax
subq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rdi
addq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rax
movl %eax, %edx
callq 0x904e0
movq %rax, -0x68(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0x92357
cmpq $0x0, -0x18(%rbp)
jne 0x92357
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
shlq $0x3, %rcx
cmpq %rcx, %rax
jne 0x92357
movq -0x8(%rbp), %rdi
movq $-0x1, %rsi
callq 0x43780
jmp 0x9237b
cmpq $-0x1, -0x68(%rbp)
je 0x9236e
movq -0x20(%rbp), %rax
shlq $0x3, %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x43780
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)