// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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 0x52aa1
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x5222f
jle 0x52ac4
leaq 0xb4806(%rip), %rax     # 0x1072b0
movq 0x80(%rax), %rsi
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x3fc19
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
leaq 0xb47dd(%rip), %rax     # 0x1072b0
movq 0x50(%rax), %rdx
movq %rbx, %rdi
callq 0x44fbb
testq %rax, %rax
je 0x52c26
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x2, %edx
callq 0x441ab
testl %eax, %eax
jne 0x52c26
leaq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x51c7b
cmpl $0x6, %eax
jne 0x52b40
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x43bb7
movq %rax, 0x8(%rsp)
movq 0x8(%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x688f4
movq %rax, 0x8(%r14)
jmp 0x52b58
movq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x43c0c
movq %r14, %rdi
movq %r15, %rsi
callq 0x519c8
movq 0x10(%rbx), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x6ca71(%rip), %rsi     # 0xbf5df
movl $0x20, %edi
callq 0x800c9
leaq 0x73977(%rip), %rdi     # 0xc64f6
movl $0x4, %esi
callq 0x43ba8
movq %rax, %r15
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rcx
movq 0x8(%rsp), %r12
movq %rbx, %rdi
movl $0x3, %esi
movq %r15, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x42a6f
movq %r12, %rdi
callq 0x440f3
movq %r15, %rdi
callq 0x440f3
movq %rbx, %rdi
movq %r12, %rsi
callq 0x40537
movq %r14, %rdi
callq 0x51cf6
testq %rax, %rax
jne 0x52c07
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x452f3
movq 0x10(%rbx), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x6e8b9(%rip), %rsi     # 0xc14b6
movl $0x4, %edi
callq 0x800c9
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x45220
leaq 0xb3c39(%rip), %rax     # 0x106858
incq 0x710(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq