// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x29908
jmp 0x29933
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
leaq 0x7bdcd(%rip), %rdx     # 0xa56e4
leaq 0x7c491(%rip), %rcx     # 0xa5daf
movl $0xf0, %r8d
callq 0x30050
movl $0x1, %edi
callq 0x12100
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x29962
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x2, %eax
je 0x29962
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x29af2
movq -0x10(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jle 0x29979
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x29af2
movq -0x20(%rbp), %rdi
callq 0x29630
movq %rax, -0x28(%rbp)
cmpq $0x15, -0x28(%rbp)
ja 0x29a41
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x18(%rbp), %rdx
callq 0x288b0
cmpl $0x0, %eax
je 0x29a41
cmpq $0x0, -0x18(%rbp)
jl 0x299f9
cmpq $0x2710, -0x18(%rbp)    # imm = 0x2710
jge 0x299f9
movq -0x10(%rbp), %rdi
callq 0x296f0
movq -0x18(%rbp), %rcx
leaq 0x95e28(%rip), %rax     # 0xbf7f8
movq 0x148(%rax,%rcx,8), %rdi
callq 0x29400
movq -0x18(%rbp), %rcx
leaq 0x95e10(%rip), %rax     # 0xbf7f8
movq 0x148(%rax,%rcx,8), %rax
movq %rax, -0x8(%rbp)
jmp 0x29af2
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x29a17
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1e3c0
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0xffffff0f, %ecx       # imm = 0xFFFFFF0F
orl $0x10, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x29af2
cmpq $0x2c, -0x28(%rbp)
ja 0x29a9a
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x29a66
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x29af2
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x29630
movq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x29200
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x296f0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x29af2
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x29aea
movq -0x20(%rbp), %rdi
callq 0x29b00
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movl $0xa, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jbe 0x29aea
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1e830
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)