// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/bitops.c
// Function: bitopCommand
void bitopCommand(client *c) {
    char *opname = c->argv[1]->ptr;
    robj *o, *targetkey = c->argv[2];
    unsigned long op, j, numkeys;
    robj **objects;      /* Array of source objects. */
    unsigned char **src; /* Array of source strings pointers. */
    unsigned long *len, maxlen = 0; /* Array of length of src strings,
                                       and max len. */
    unsigned long minlen = 0;    /* Min len among the input keys. */
    unsigned char *res = NULL; /* Resulting string. */

    /* Parse the operation name. */
    if ((opname[0] == 'a' || opname[0] == 'A') && !strcasecmp(opname,"and"))
        op = BITOP_AND;
    else if((opname[0] == 'o' || opname[0] == 'O') && !strcasecmp(opname,"or"))
        op = BITOP_OR;
    else if((opname[0] == 'x' || opname[0] == 'X') && !strcasecmp(opname,"xor"))
        op = BITOP_XOR;
    else if((opname[0] == 'n' || opname[0] == 'N') && !strcasecmp(opname,"not"))
        op = BITOP_NOT;
    else {
        addReply(c,shared.syntaxerr);
        return;
    }

    /* Sanity check: NOT accepts only a single key argument. */
    if (op == BITOP_NOT && c->argc != 4) {
        addReplyError(c,"BITOP NOT must be called with a single source key.");
        return;
    }

    /* Lookup keys, and store pointers to the string objects into an array. */
    numkeys = c->argc - 3;
    src = zmalloc(sizeof(unsigned char*) * numkeys);
    len = zmalloc(sizeof(long) * numkeys);
    objects = zmalloc(sizeof(robj*) * numkeys);
    for (j = 0; j < numkeys; j++) {
        o = lookupKeyRead(c->db,c->argv[j+3]);
        /* Handle non-existing keys as empty strings. */
        if (o == NULL) {
            objects[j] = NULL;
            src[j] = NULL;
            len[j] = 0;
            minlen = 0;
            continue;
        }
        /* Return an error if one of the keys is not a string. */
        if (checkType(c,o,OBJ_STRING)) {
            unsigned long i;
            for (i = 0; i < j; i++) {
                if (objects[i])
                    decrRefCount(objects[i]);
            }
            zfree(src);
            zfree(len);
            zfree(objects);
            return;
        }
        objects[j] = getDecodedObject(o);
        src[j] = objects[j]->ptr;
        len[j] = sdslen(objects[j]->ptr);
        if (len[j] > maxlen) maxlen = len[j];
        if (j == 0 || len[j] < minlen) minlen = len[j];
    }

    /* Compute the bit operation, if at least one string is not empty. */
    if (maxlen) {
        res = (unsigned char*) sdsnewlen(NULL,maxlen);
        unsigned char output, byte;
        unsigned long i;

        /* Fast path: as far as we have data for all the input bitmaps we
         * can take a fast path that performs much better than the
         * vanilla algorithm. */
        j = 0;
        if (minlen >= sizeof(unsigned long)*4 && numkeys <= 16) {
            unsigned long *lp[16];
            unsigned long *lres = (unsigned long*) res;

            /* Note: sds pointer is always aligned to 8 byte boundary. */
            memcpy(lp,src,sizeof(unsigned long*)*numkeys);
            memcpy(res,src[0],minlen);

            /* Different branches per different operations for speed (sorry). */
            if (op == BITOP_AND) {
                while(minlen >= sizeof(unsigned long)*4) {
                    for (i = 1; i < numkeys; i++) {
                        lres[0] &= lp[i][0];
                        lres[1] &= lp[i][1];
                        lres[2] &= lp[i][2];
                        lres[3] &= lp[i][3];
                        lp[i]+=4;
                    }
                    lres+=4;
                    j += sizeof(unsigned long)*4;
                    minlen -= sizeof(unsigned long)*4;
                }
            } else if (op == BITOP_OR) {
                while(minlen >= sizeof(unsigned long)*4) {
                    for (i = 1; i < numkeys; i++) {
                        lres[0] |= lp[i][0];
                        lres[1] |= lp[i][1];
                        lres[2] |= lp[i][2];
                        lres[3] |= lp[i][3];
                        lp[i]+=4;
                    }
                    lres+=4;
                    j += sizeof(unsigned long)*4;
                    minlen -= sizeof(unsigned long)*4;
                }
            } else if (op == BITOP_XOR) {
                while(minlen >= sizeof(unsigned long)*4) {
                    for (i = 1; i < numkeys; i++) {
                        lres[0] ^= lp[i][0];
                        lres[1] ^= lp[i][1];
                        lres[2] ^= lp[i][2];
                        lres[3] ^= lp[i][3];
                        lp[i]+=4;
                    }
                    lres+=4;
                    j += sizeof(unsigned long)*4;
                    minlen -= sizeof(unsigned long)*4;
                }
            } else if (op == BITOP_NOT) {
                while(minlen >= sizeof(unsigned long)*4) {
                    lres[0] = ~lres[0];
                    lres[1] = ~lres[1];
                    lres[2] = ~lres[2];
                    lres[3] = ~lres[3];
                    lres+=4;
                    j += sizeof(unsigned long)*4;
                    minlen -= sizeof(unsigned long)*4;
                }
            }
        }

        /* j is set to the next byte to process by the previous loop. */
        for (; j < maxlen; j++) {
            output = (len[0] <= j) ? 0 : src[0][j];
            if (op == BITOP_NOT) output = ~output;
            for (i = 1; i < numkeys; i++) {
                byte = (len[i] <= j) ? 0 : src[i][j];
                switch(op) {
                case BITOP_AND: output &= byte; break;
                case BITOP_OR:  output |= byte; break;
                case BITOP_XOR: output ^= byte; break;
                }
            }
            res[j] = output;
        }
    }
    for (j = 0; j < numkeys; j++) {
        if (objects[j])
            decrRefCount(objects[j]);
    }
    zfree(src);
    zfree(len);
    zfree(objects);

    /* Store the computed value into the target key */
    if (maxlen) {
        o = createObject(OBJ_STRING,res);
        setKey(c->db,targetkey,o);
        notifyKeyspaceEvent(NOTIFY_STRING,"set",targetkey,c->db->id);
        decrRefCount(o);
    } else if (dbDelete(c->db,targetkey)) {
        signalModifiedKey(c->db,targetkey);
        notifyKeyspaceEvent(NOTIFY_GENERIC,"del",targetkey,c->db->id);
    }
    server.dirty++;
    addReplyLongLong(c,maxlen); /* Return the output string length in bytes. */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %r15
movq 0x40(%rdi), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %r12
movq 0x8(%rcx), %r14
movzbl (%r14), %ebx
cmpl $0x60, %ebx
jg 0x7432d
cmpl $0x4e, %ebx
jg 0x7435f
cmpl $0x41, %ebx
je 0x74337
cmpl $0x4e, %ebx
je 0x743ab
jmp 0x743be
cmpl $0x6e, %ebx
jg 0x74366
cmpl $0x61, %ebx
jne 0x743a6
leaq 0x5de3e(%rip), %rsi     # 0xd217c
movq %r14, %rdi
callq 0x262f0
testl %eax, %eax
je 0x7445c
cmpl $0x4e, %ebx
je 0x743ab
cmpl $0x58, %ebx
je 0x74393
cmpl $0x4f, %ebx
jne 0x743be
jmp 0x74372
cmpl $0x4f, %ebx
jne 0x7438e
jmp 0x74372
cmpl $0x6f, %ebx
je 0x74372
cmpl $0x78, %ebx
je 0x74393
jmp 0x743be
leaq 0x5de08(%rip), %rsi     # 0xd2181
movq %r14, %rdi
callq 0x262f0
testl %eax, %eax
je 0x74436
cmpl $0x6e, %ebx
je 0x743ab
cmpl $0x58, %ebx
jne 0x743be
leaq 0x5ddeb(%rip), %rsi     # 0xd2185
movq %r14, %rdi
callq 0x262f0
testl %eax, %eax
je 0x7441c
cmpl $0x6e, %ebx
jne 0x743be
leaq 0x5ddc5(%rip), %rsi     # 0xd2177
movq %r14, %rdi
callq 0x262f0
testl %eax, %eax
je 0x743e5
leaq 0x8df4b(%rip), %rax     # 0x102310
movq 0x80(%rax), %rsi
movq %r15, %rdi
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3c854
cmpl $0x4, 0x38(%r15)
jne 0x74726
movq %r12, 0x28(%rsp)
movb $0x1, %al
movq %rax, 0x20(%rsp)
movl $0x3, %eax
movq %rax, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x38(%rsp)
jmp 0x74485
movq %r12, 0x28(%rsp)
movb $0x1, %al
movq %rax, 0x30(%rsp)
movl $0x2, %eax
movq %rax, 0x40(%rsp)
xorl %ebp, %ebp
jmp 0x74451
movq %r12, 0x28(%rsp)
movb $0x1, %bpl
movl $0x1, %eax
movq %rax, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
jmp 0x7447c
movq %r12, 0x28(%rsp)
movb $0x1, %al
movq %rax, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x20(%rsp)
movslq 0x38(%r15), %r12
leaq -0x18(,%r12,8), %rbx
addq $-0x3, %r12
movq %rbx, %rdi
callq 0x382d1
movq %rax, %r14
movq %rbx, %rdi
callq 0x382d1
movq %rax, %r13
movq %rbx, 0x58(%rsp)
movq %rbx, %rdi
callq 0x382d1
movq %rax, 0x18(%rsp)
testl %r12d, %r12d
je 0x746c4
movq %rbp, 0x50(%rsp)
movq %r14, 0x10(%rsp)
xorl %esi, %esi
xorl %ebp, %ebp
xorl %ebx, %ebx
movq %rsi, 0x8(%rsp)
movq 0x10(%r15), %rdi
movq 0x40(%r15), %rax
movq 0x18(%rax,%rbx,8), %rsi
callq 0x41acf
movq %r15, %rdi
testq %rax, %rax
je 0x74568
movq %rax, %r15
movq %r12, %r14
movq %rbp, %r12
movq %rdi, %rbp
movq %rax, %rsi
xorl %edx, %edx
callq 0x40d47
testl %eax, %eax
jne 0x746d6
movq %r15, %rdi
callq 0x41026
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x8(%rax), %rax
movq 0x10(%rsp), %rdx
movq %rax, (%rdx,%rbx,8)
movq (%rcx,%rbx,8), %rax
movq 0x8(%rax), %rcx
movzbl -0x1(%rcx), %eax
movl %eax, %edx
andl $0x7, %edx
cmpl $0x4, %edx
ja 0x745cb
leaq 0x578ba(%rip), %rsi     # 0xcbe0c
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
movq %rbp, %r15
movq 0x8(%rsp), %rsi
jmpq *%rdx
shrl $0x3, %eax
jmp 0x7459d
movq 0x18(%rsp), %rax
xorl %ecx, %ecx
movq %rcx, (%rax,%rbx,8)
movq 0x10(%rsp), %rax
movq %rcx, (%rax,%rbx,8)
movq %rcx, (%r13,%rbx,8)
xorl %esi, %esi
movq %rdi, %r15
jmp 0x745bd
movq -0x11(%rcx), %rax
jmp 0x7459d
movzwl -0x5(%rcx), %eax
jmp 0x7459d
movl -0x9(%rcx), %eax
jmp 0x7459d
movzbl -0x3(%rcx), %eax
movq %r12, %rbp
cmpq %rbp, %rax
cmovaq %rax, %rbp
cmpq %rsi, %rax
cmovbq %rax, %rsi
movq %rax, (%r13,%rbx,8)
testq %rbx, %rbx
cmoveq %rax, %rsi
movq %r14, %r12
incq %rbx
cmpq %rbx, %r12
jne 0x744d6
jmp 0x745da
xorl %eax, %eax
movq %rbp, %r15
movq %r12, %rbp
movq 0x8(%rsp), %rsi
jmp 0x745a0
testq %rbp, %rbp
sete 0x7(%rsp)
je 0x74746
movq %rsi, %r14
movq %r15, 0x48(%rsp)
xorl %r15d, %r15d
xorl %edi, %edi
movq %rbp, %rsi
callq 0x36178
movq %rax, 0x8(%rsp)
cmpl $0x10, %r12d
ja 0x7489f
cmpq $0x20, %r14
jb 0x7489f
leaq 0x60(%rsp), %rdi
movq 0x10(%rsp), %r15
movq %r15, %rsi
movq 0x58(%rsp), %rdx
callq 0x26c50
movq (%r15), %rsi
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
callq 0x26c50
cmpb $0x0, 0x38(%rsp)
je 0x7475b
cmpq $0x3, %r12
movl $0x2, %eax
cmovaeq %r12, %rax
movq %r15, %rcx
xorl %r15d, %r15d
cmpl $0x1, %r12d
je 0x746ad
movq (%rcx), %rdx
movq 0x8(%rcx), %rsi
movq 0x10(%rcx), %rdi
movq 0x18(%rcx), %r8
movl $0x1, %r9d
movq 0x60(%rsp,%r9,8), %r10
andq (%r10), %rdx
movq %rdx, (%rcx)
andq 0x8(%r10), %rsi
movq %rsi, 0x8(%rcx)
andq 0x10(%r10), %rdi
movq %rdi, 0x10(%rcx)
andq 0x18(%r10), %r8
movq %r8, 0x18(%rcx)
addq $0x20, %r10
movq %r10, 0x60(%rsp,%r9,8)
incq %r9
cmpq %r9, %rax
jne 0x74679
addq $0x20, %rcx
addq $0x20, %r15
addq $-0x20, %r14
cmpq $0x1f, %r14
ja 0x7465e
jmp 0x7489f
movb $0x1, %bl
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
jmp 0x74969
testq %rbx, %rbx
je 0x746f9
xorl %r14d, %r14d
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x746f1
callq 0x40c8f
incq %r14
cmpq %r14, %rbx
jne 0x746de
movq 0x10(%rsp), %rdi
callq 0x38413
movq %r13, %rdi
callq 0x38413
movq 0x18(%rsp), %rdi
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x38413
leaq 0x578dc(%rip), %rsi     # 0xcc009
movq %r15, %rdi
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cc06
xorl %ebp, %ebp
movb $0x1, 0x7(%rsp)
movq $0x0, 0x8(%rsp)
jmp 0x7493e
cmpb $0x0, 0x50(%rsp)
je 0x747dd
cmpq $0x3, %r12
movl $0x2, %eax
cmovaeq %r12, %rax
xorl %r15d, %r15d
movq 0x8(%rsp), %rcx
cmpl $0x1, %r12d
je 0x747c6
movq (%rcx), %rdx
movq 0x8(%rcx), %rsi
movq 0x10(%rcx), %rdi
movq 0x18(%rcx), %r8
movl $0x1, %r9d
movq 0x60(%rsp,%r9,8), %r10
orq (%r10), %rdx
movq %rdx, (%rcx)
orq 0x8(%r10), %rsi
movq %rsi, 0x8(%rcx)
orq 0x10(%r10), %rdi
movq %rdi, 0x10(%rcx)
orq 0x18(%r10), %r8
movq %r8, 0x18(%rcx)
addq $0x20, %r10
movq %r10, 0x60(%rsp,%r9,8)
incq %r9
cmpq %r9, %rax
jne 0x74792
addq $0x20, %rcx
addq $0x20, %r15
addq $-0x20, %r14
cmpq $0x1f, %r14
ja 0x74777
jmp 0x7489f
cmpb $0x0, 0x30(%rsp)
movq 0x8(%rsp), %rcx
je 0x7485c
cmpq $0x3, %r12
movl $0x2, %eax
cmovaeq %r12, %rax
xorl %r15d, %r15d
cmpl $0x1, %r12d
je 0x74848
movq (%rcx), %rdx
movq 0x8(%rcx), %rsi
movq 0x10(%rcx), %rdi
movq 0x18(%rcx), %r8
movl $0x1, %r9d
movq 0x60(%rsp,%r9,8), %r10
xorq (%r10), %rdx
movq %rdx, (%rcx)
xorq 0x8(%r10), %rsi
movq %rsi, 0x8(%rcx)
xorq 0x10(%r10), %rdi
movq %rdi, 0x10(%rcx)
xorq 0x18(%r10), %r8
movq %r8, 0x18(%rcx)
addq $0x20, %r10
movq %r10, 0x60(%rsp,%r9,8)
incq %r9
cmpq %r9, %rax
jne 0x74814
addq $0x20, %rcx
addq $0x20, %r15
addq $-0x20, %r14
cmpq $0x1f, %r14
ja 0x747f9
jmp 0x7489f
cmpb $0x0, 0x20(%rsp)
je 0x7489c
xorl %r15d, %r15d
pcmpeqd %xmm0, %xmm0
movdqu (%rcx,%r15), %xmm1
movdqu 0x10(%rcx,%r15), %xmm2
pxor %xmm0, %xmm1
movdqu %xmm1, (%rcx,%r15)
pxor %xmm0, %xmm2
movdqu %xmm2, 0x10(%rcx,%r15)
addq $0x20, %r15
addq $-0x20, %r14
cmpq $0x1f, %r14
ja 0x7486a
jmp 0x7489f
xorl %r15d, %r15d
cmpq %rbp, %r15
movq 0x40(%rsp), %r9
movq 0x20(%rsp), %r10
jae 0x74939
negb %r10b
cmpq $0x3, %r12
movl $0x2, %eax
cmovaeq %r12, %rax
leaq 0x57557(%rip), %rcx     # 0xcbe20
movq 0x10(%rsp), %r14
cmpq %r15, (%r13)
jbe 0x748dd
movq (%r14), %rdx
movb (%rdx,%r15), %dl
jmp 0x748df
xorl %edx, %edx
xorb %r10b, %dl
cmpl $0x1, %r12d
je 0x74921
movl $0x1, %esi
cmpq %r15, (%r13,%rsi,8)
jbe 0x748fe
movq (%r14,%rsi,8), %rdi
movb (%rdi,%r15), %dil
jmp 0x74900
xorl %edi, %edi
movslq (%rcx,%r9,4), %r8
addq %rcx, %r8
jmpq *%r8
andb %dl, %dil
jmp 0x74917
orb %dl, %dil
jmp 0x74917
xorb %dl, %dil
movl %edi, %edx
incq %rsi
cmpq %rsi, %rax
jne 0x748ed
movq 0x8(%rsp), %rsi
movb %dl, (%rsi,%r15)
incq %r15
cmpq %rbp, %r15
jne 0x748ce
movq 0x48(%rsp), %r15
jmp 0x74943
movq 0x48(%rsp), %r15
movq 0x10(%rsp), %r14
testl %r12d, %r12d
je 0x74965
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x7495d
callq 0x40c8f
incq %rbx
cmpq %rbx, %r12
jne 0x7494a
movb 0x7(%rsp), %bl
movq %r14, %rdi
callq 0x38413
movq %r13, %rdi
callq 0x38413
movq 0x18(%rsp), %rdi
callq 0x38413
testb %bl, %bl
je 0x749c5
movq 0x10(%r15), %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
callq 0x41e5f
testl %eax, %eax
je 0x74a0b
movq 0x10(%r15), %rdi
movq %rbx, %rsi
callq 0x41d90
movq 0x10(%r15), %rax
movl 0x30(%rax), %ecx
leaq 0x49b72(%rip), %rsi     # 0xbe528
movl $0x4, %edi
movq %rbx, %rdx
callq 0x7c665
jmp 0x74a0b
xorl %edi, %edi
movq 0x8(%rsp), %rsi
callq 0x40650
movq %rax, %r14
movq 0x10(%r15), %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
movq %rax, %rdx
callq 0x41cd2
movq 0x10(%r15), %rax
movl 0x30(%rax), %ecx
leaq 0x48ecf(%rip), %rsi     # 0xbd8c5
movl $0x8, %edi
movq %rbx, %rdx
callq 0x7c665
movq %r14, %rdi
callq 0x40c8f
leaq 0x8ce96(%rip), %rax     # 0x1018a8
incq 0x720(%rax)
movq %r15, %rdi
movq %rbp, %rsi
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3d23f