// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl (%rdi), %ebp
testb $0xf, %bpl
jne 0x3a557
movl %ebp, %eax
shrl $0x4, %eax
testb $0x7, %al
jne 0x3a54b
cmpl $0x1, 0x4(%rbx)
jg 0x3a54b
movq 0x8(%rbx), %r14
movq %r14, %rdi
callq 0x3a000
cmpq $0x14, %rax
ja 0x3a46a
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x39976
testl %eax, %eax
je 0x3a4ac
leaq 0xbf49c(%rip), %rcx     # 0xf98a8
cmpq $0x0, 0x908(%rcx)
movq 0x8(%rsp), %rax
je 0x3a4e3
testq %rax, %rax
js 0x3a43f
movl 0x910(%rcx), %ecx
testl %ecx, %ecx
je 0x3a43f
cmpl $0x3, %ecx
je 0x3a43f
cmpq $0x270f, %rax           # imm = 0x270F
jbe 0x3a4ef
movl (%rbx), %ecx
testb $-0x10, %cl
jne 0x3a456
movq 0x8(%rbx), %rdi
callq 0x311c8
movl (%rbx), %ecx
movq 0x8(%rsp), %rax
andl $0xffffff0f, %ecx       # imm = 0xFFFFFF0F
orl $0x10, %ecx
movl %ecx, (%rbx)
movq %rax, 0x8(%rbx)
jmp 0x3a54b
cmpq $0x2c, %rax
jbe 0x3a4ae
testb $-0x10, %bpl
jne 0x3a54b
movzbl -0x1(%r14), %ecx
andl $0x7, %ecx
decl %ecx
cmpl $0x3, %ecx
ja 0x3a54b
leaq 0x78070(%rip), %rdx     # 0xb2504
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movzbl -0x2(%r14), %ecx
movzbl -0x3(%r14), %edx
jmp 0x3a52e
movl (%rbx), %ebp
andl $0xf0, %ebp
cmpl $0x80, %ebp
je 0x3a54b
movq %r14, %rdi
callq 0x3a000
movq %r14, %rdi
movq %rax, %rsi
callq 0x39da2
movq %rax, %r14
movq %rbx, %rdi
callq 0x3a265
movq %r14, %rbx
jmp 0x3a54b
cmpq $0x2710, %rax           # imm = 0x2710
jae 0x3a43f
movq %rbx, %rdi
callq 0x3a265
movq 0x8(%rsp), %rax
leaq 0xbfe0d(%rip), %rcx     # 0xfa310
movq 0x1b0(%rcx,%rax,8), %rbx
incl 0x4(%rbx)
jmp 0x3a54b
movl -0x5(%r14), %ecx
subl -0x9(%r14), %ecx
jmp 0x3a531
movq -0x9(%r14), %rcx
subq -0x11(%r14), %rcx
jmp 0x3a531
movzwl -0x3(%r14), %ecx
movzwl -0x5(%r14), %edx
subq %rdx, %rcx
pushq $0xa
popq %rsi
xorl %edx, %edx
divq %rsi
cmpq %rax, %rcx
jbe 0x3a54b
movq %r14, %rdi
callq 0x313d7
jmp 0x3a461
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x77386(%rip), %rdx     # 0xb18e4
leaq 0x77fe5(%rip), %rcx     # 0xb254a
xorl %edi, %edi
movq %rbx, %rsi
movl $0x170, %r8d            # imm = 0x170
callq 0x588a4
pushq $0x1
popq %rdi
callq 0x263c0