// File: /workspace/github_c_makefile_star2_O3/erikdubbelboer[P]discnt/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 Disque 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 21 chars is not
     * representable as a 32 nor 64 bit integer. */
    len = sdslen(s);
    if (len <= 21 && 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 (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 %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl (%rdi), %eax
testb $0xf, %al
jne 0x25c43
movl %eax, %ecx
shrl $0x4, %ecx
testb $0xd, %cl
jne 0x25aa2
cmpl $0x1, 0x4(%rbx)
jle 0x25aad
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x8(%rbx), %r14
movzbl -0x1(%r14), %esi
movl %esi, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x25b23
leaq 0x2f861(%rip), %rdx     # 0x55328
movslq (%rdx,%rcx,4), %rdi
addq %rdx, %rdi
jmpq *%rdi
shrl $0x3, %esi
jmp 0x25aed
movq -0x11(%r14), %rsi
jmp 0x25aed
movzwl -0x5(%r14), %esi
jmp 0x25aed
movl -0x9(%r14), %esi
jmp 0x25aed
movzbl -0x3(%r14), %esi
cmpq $0x15, %rsi
jbe 0x25b25
cmpq $0x2c, %rsi
jbe 0x25b65
testb $-0x10, %al
jne 0x25aa2
decl %ecx
cmpl $0x3, %ecx
ja 0x25aa2
leaq 0x2f831(%rip), %rax     # 0x5533c
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movzbl -0x2(%r14), %ecx
movzbl -0x3(%r14), %eax
jmp 0x25c16
xorl %esi, %esi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x2516b
testl %eax, %eax
je 0x25b63
movq (%rsp), %rax
cmpq $0x270f, %rax           # imm = 0x270F
ja 0x25b97
movq %rbx, %rdi
callq 0x25945
movq (%rsp), %rax
leaq 0x49c45(%rip), %rcx     # 0x6f798
movq 0x148(%rcx,%rax,8), %rbx
incl 0x4(%rbx)
jmp 0x25aa2
movl (%rbx), %eax
andl $0xf0, %eax
cmpl $0x20, %eax
je 0x25aa2
movzbl -0x1(%r14), %esi
movl %esi, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x25bdb
leaq 0x2f7c3(%rip), %rcx     # 0x5534c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %esi
jmp 0x25bdd
movl (%rbx), %ecx
testb $-0x10, %cl
jne 0x25bad
movq 0x8(%rbx), %rdi
callq 0x1dc25
movl (%rbx), %ecx
movq (%rsp), %rax
andl $0xffffff0f, %ecx       # imm = 0xFFFFFF0F
orl $0x10, %ecx
movl %ecx, (%rbx)
movq %rax, 0x8(%rbx)
jmp 0x25aa2
movq -0x11(%r14), %rsi
jmp 0x25bdd
movzwl -0x5(%r14), %esi
jmp 0x25bdd
movl -0x9(%r14), %esi
jmp 0x25bdd
movzbl -0x3(%r14), %esi
jmp 0x25bdd
xorl %esi, %esi
movq %r14, %rdi
callq 0x2569b
movq %rax, %r14
movq %rbx, %rdi
callq 0x25945
movq %r14, %rbx
jmp 0x25aa2
movl -0x5(%r14), %ecx
subl -0x9(%r14), %ecx
jmp 0x25c19
movq -0x9(%r14), %rcx
subq -0x11(%r14), %rcx
jmp 0x25c19
movzwl -0x3(%r14), %ecx
movzwl -0x5(%r14), %eax
subq %rax, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
movq %rsi, %rax
mulq %rdx
shrq $0x3, %rdx
cmpq %rdx, %rcx
jbe 0x25aa2
movq %r14, %rdi
callq 0x1deef
jmp 0x25bb8
leaq 0x2efc6(%rip), %rdx     # 0x54c10
leaq 0x2f75e(%rip), %rcx     # 0x553af
xorl %edi, %edi
movq %rbx, %rsi
movl $0xf0, %r8d
callq 0x2a427
movl $0x1, %edi
callq 0x12120