// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/t_set.c
// Function: spopCommand
void spopCommand(client *c) {
    robj *set, *ele, *aux;
    int64_t llele;
    int encoding;

    if (c->argc == 3) {
        spopWithCountCommand(c);
        return;
    } else if (c->argc > 3) {
        addReply(c,shared.syntaxerr);
        return;
    }

    /* Make sure a key with the name inputted exists, and that it's type is
     * indeed a set */
    if ((set = lookupKeyWriteOrReply(c,c->argv[1],shared.nullbulk)) == NULL ||
        checkType(c,set,OBJ_SET)) return;

    /* Get a random element from the set */
    encoding = setTypeRandomElement(set,&ele,&llele);

    /* Remove the element from the set */
    if (encoding == OBJ_ENCODING_INTSET) {
        ele = createStringObjectFromLongLong(llele);
        set->ptr = intsetRemove(set->ptr,llele,NULL);
    } else {
        incrRefCount(ele);
        setTypeRemove(set,ele);
    }

    notifyKeyspaceEvent(NOTIFY_SET,"spop",c->argv[1],c->db->id);

    /* Replicate/AOF this command as an SREM operation */
    aux = createStringObject("SREM",4);
    rewriteClientCommandVector(c,3,aux,c->argv[1],ele);
    decrRefCount(ele);
    decrRefCount(aux);

    /* Add the element to the reply */
    addReplyBulk(c,ele);

    /* Delete the set if it's empty */
    if (setTypeSize(set) == 0) {
        dbDelete(c->db,c->argv[1]);
        notifyKeyspaceEvent(NOTIFY_GENERIC,"del",c->argv[1],c->db->id);
    }

    /* Set has been modified */
    signalModifiedKey(c->db,c->argv[1]);
    server.dirty++;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x38(%rdi), %eax
cmpl $0x3, %eax
jne 0x46e7e
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x466b0
jle 0x46ea1
leaq 0xb3489(%rip), %rax     # 0xfa310
movq 0x80(%rax), %rsi
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x36987
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
leaq 0xb3460(%rip), %rax     # 0xfa310
movq 0x50(%rax), %rdx
movq %rbx, %rdi
callq 0x3af15
testq %rax, %rax
je 0x46ff2
movq %rax, %r14
pushq $0x2
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a311
testl %eax, %eax
jne 0x46ff2
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x46138
cmpl $0x6, %eax
jne 0x46f19
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x39e38
movq %rax, %r15
movq 0x8(%r14), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x5a8c4
movq %rax, 0x8(%r14)
jmp 0x46f31
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x39e74
movq %r14, %rdi
movq %r15, %rsi
callq 0x45ea1
movq 0x10(%rbx), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x675d8(%rip), %rsi     # 0xae51f
pushq $0x20
popq %rdi
callq 0x6fb58
leaq 0x6dbb4(%rip), %rdi     # 0xb4b0a
pushq $0x4
popq %rsi
callq 0x39e29
movq %rax, %r12
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rcx
pushq $0x3
popq %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %r8
xorl %eax, %eax
callq 0x38eb8
movq %r15, %rdi
callq 0x3a265
movq %r12, %rdi
callq 0x3a265
movq %rbx, %rdi
movq %r15, %rsi
callq 0x36fd9
movq %r14, %rdi
callq 0x461ae
testq %rax, %rax
jne 0x46fd3
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x3b1df
movq 0x10(%rbx), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x6944d(%rip), %rsi     # 0xb0418
pushq $0x4
popq %rdi
callq 0x6fb58
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x3b125
leaq 0xb28bd(%rip), %rax     # 0xf98a8
incq 0x720(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq