// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/object.c
// Function: tryObjectEncoding
robj *tryObjectEncoding(robj *o) {
    long value;
    sds s = o->ptr;
    size_t len;

    /* Make sure this is a string object, the only type we encode
     * in this function. Other types use encoded memory efficient
     * representations but are handled by the commands implementing
     * the type. */
    serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);

    /* We try some specialized encoding only for objects that are
     * RAW or EMBSTR encoded, in other words objects that are still
     * in represented by an actually array of chars. */
    if (!sdsEncodedObject(o)) return o;

    /* It's not safe to encode shared objects: shared objects can be shared
     * everywhere in the "object space" of Redis and may end in places where
     * they are not handled. We handle them only as values in the keyspace. */
     if (o->refcount > 1) return o;

    /* Check if we can represent this string as a long integer.
     * Note that we are sure that a string larger than 20 chars is not
     * representable as a 32 nor 64 bit integer. */
    len = sdslen(s);
    if (len <= 20 && string2l(s,len,&value)) {
        /* This object is encodable as a long. Try to use a shared object.
         * Note that we avoid using shared integers when maxmemory is used
         * because every object needs to have a private LRU field for the LRU
         * algorithm to work well. */
        if ((server.maxmemory == 0 ||
             (server.maxmemory_policy != MAXMEMORY_VOLATILE_LRU &&
              server.maxmemory_policy != MAXMEMORY_ALLKEYS_LRU)) &&
            value >= 0 &&
            value < OBJ_SHARED_INTEGERS)
        {
            decrRefCount(o);
            incrRefCount(shared.integers[value]);
            return shared.integers[value];
        } else {
            if (o->encoding == OBJ_ENCODING_RAW) sdsfree(o->ptr);
            o->encoding = OBJ_ENCODING_INT;
            o->ptr = (void*) value;
            return o;
        }
    }

    /* If the string is small and is still RAW encoded,
     * try the EMBSTR encoding which is more efficient.
     * In this representation the object and the SDS string are allocated
     * in the same chunk of memory to save space and cache misses. */
    if (len <= OBJ_ENCODING_EMBSTR_SIZE_LIMIT) {
        robj *emb;

        if (o->encoding == OBJ_ENCODING_EMBSTR) return o;
        emb = createEmbeddedStringObject(s,sdslen(s));
        decrRefCount(o);
        return emb;
    }

    /* We can't encode the object...
     *
     * Do the last try, and at least optimize the SDS string inside
     * the string object to require little space, in case there
     * is more than 10% of free space at the end of the SDS string.
     *
     * We do that only for relatively large strings as this branch
     * is only entered if the length of the string is greater than
     * OBJ_ENCODING_EMBSTR_SIZE_LIMIT. */
    if (o->encoding == OBJ_ENCODING_RAW &&
        sdsavail(s) > len/10)
    {
        o->ptr = sdsRemoveFreeSpace(o->ptr);
    }

    /* Return the original object. */
    return o;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl (%rdi), %eax
testb $0xf, %al
jne 0x4448a
shrl $0x4, %eax
testb $0x7, %al
jne 0x4447d
cmpl $0x1, 0x4(%rbx)
jg 0x4447d
movq 0x8(%rbx), %r14
movzbl -0x1(%r14), %r15d
movl %r15d, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x442dc
leaq 0x7f8d9(%rip), %rcx     # 0xc3b8c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %r15d
jmp 0x442df
movq -0x11(%r14), %r15
jmp 0x442df
movzwl -0x5(%r14), %r15d
jmp 0x442df
movl -0x9(%r14), %r15d
jmp 0x442df
movzbl -0x3(%r14), %r15d
jmp 0x442df
xorl %r15d, %r15d
cmpq $0x14, %r15
ja 0x44357
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x435b3
testl %eax, %eax
je 0x44357
leaq 0xc2558(%rip), %rcx     # 0x106858
cmpq $0x0, 0x8f8(%rcx)
movq 0x8(%rsp), %rax
je 0x443d1
testq %rax, %rax
js 0x44333
movl 0x900(%rcx), %ecx
testl %ecx, %ecx
je 0x44333
cmpl $0x3, %ecx
je 0x44333
cmpq $0x270f, %rax           # imm = 0x270F
jle 0x443dd
testb $-0x10, (%rbx)
jne 0x44341
movq 0x8(%rbx), %rdi
callq 0x392b6
movl $0xffffff0f, %eax       # imm = 0xFFFFFF0F
andl (%rbx), %eax
orl $0x10, %eax
movl %eax, (%rbx)
movq 0x8(%rsp), %rax
jmp 0x44479
movl $0xf0, %eax
andl (%rbx), %eax
cmpq $0x2c, %r15
ja 0x4439a
cmpl $0x80, %eax
je 0x4447d
movzbl -0x1(%r14), %esi
movl %esi, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x44418
leaq 0x7f827(%rip), %rcx     # 0xc3bb0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %esi
jmp 0x4441a
testl %eax, %eax
jne 0x4447d
movzbl -0x1(%r14), %eax
andl $0x7, %eax
decl %eax
cmpl $0x3, %eax
ja 0x44455
leaq 0x7f7e4(%rip), %rcx     # 0xc3ba0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl -0x2(%r14), %ecx
movzbl -0x3(%r14), %eax
jmp 0x44450
cmpq $0x2710, %rax           # imm = 0x2710
jae 0x44333
movq %rbx, %rdi
callq 0x440f3
movq 0x8(%rsp), %rax
leaq 0xc2ebf(%rip), %rcx     # 0x1072b0
movq 0x1b0(%rcx,%rax,8), %rbx
incl 0x4(%rbx)
jmp 0x4447d
movq -0x11(%r14), %rsi
jmp 0x4441a
movzwl -0x5(%r14), %esi
jmp 0x4441a
movl -0x9(%r14), %esi
jmp 0x4441a
movzbl -0x3(%r14), %esi
jmp 0x4441a
xorl %esi, %esi
movq %r14, %rdi
callq 0x43b21
movq %rax, %r14
movq %rbx, %rdi
callq 0x440f3
movq %r14, %rbx
jmp 0x4447d
movl -0x5(%r14), %ecx
subl -0x9(%r14), %ecx
jmp 0x44457
movq -0x9(%r14), %rcx
subq -0x11(%r14), %rcx
jmp 0x44457
movzwl -0x3(%r14), %ecx
movzwl -0x5(%r14), %eax
subq %rax, %rcx
jmp 0x44457
xorl %ecx, %ecx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
movq %r15, %rax
mulq %rdx
shrq $0x3, %rdx
cmpq %rdx, %rcx
jbe 0x4447d
movq 0x8(%rbx), %rdi
callq 0x39599
movq %rax, 0x8(%rbx)
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x7ea67(%rip), %rdx     # 0xc2ef8
leaq 0x7f78a(%rip), %rcx     # 0xc3c22
xorl %edi, %edi
movq %rbx, %rsi
movl $0x17b, %r8d            # imm = 0x17B
callq 0x66380
movl $0x1, %edi
callq 0x263d0