// File: /workspace/github_c_makefile_star2_O0/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
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 0x491d8
jmp 0x49203
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
leaq 0xf1839(%rip), %rdx     # 0x13aa20
leaq 0xf24a8(%rip), %rcx     # 0x13b696
movl $0x170, %r8d            # imm = 0x170
callq 0x78360
movl $0x1, %edi
callq 0x263c0
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x49232
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x8, %eax
je 0x49232
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x493f3
movq -0x10(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jle 0x49249
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x493f3
movq -0x20(%rbp), %rdi
callq 0x48aa0
movq %rax, -0x28(%rbp)
cmpq $0x14, -0x28(%rbp)
ja 0x49342
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x18(%rbp), %rdx
callq 0x47be0
cmpl $0x0, %eax
je 0x49342
leaq 0x12ef56(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x908(%rax)
je 0x492ac
leaq 0x12ef45(%rip), %rax    # 0x1781d8
cmpl $0x0, 0x910(%rax)
je 0x492fa
leaq 0x12ef35(%rip), %rax    # 0x1781d8
cmpl $0x3, 0x910(%rax)
je 0x492fa
cmpq $0x0, -0x18(%rbp)
jl 0x492fa
cmpq $0x2710, -0x18(%rbp)    # imm = 0x2710
jge 0x492fa
movq -0x10(%rbp), %rdi
callq 0x48f70
movq -0x18(%rbp), %rcx
leaq 0x12f96f(%rip), %rax    # 0x178c40
movq 0x1b0(%rax,%rcx,8), %rdi
callq 0x487b0
movq -0x18(%rbp), %rcx
leaq 0x12f957(%rip), %rax    # 0x178c40
movq 0x1b0(%rax,%rcx,8), %rax
movq %rax, -0x8(%rbp)
jmp 0x493f3
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x49318
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x38620
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 0x493f3
cmpq $0x2c, -0x28(%rbp)
ja 0x4939b
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0x49367
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x493f3
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x48aa0
movq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x48570
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x48f70
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x493f3
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x493eb
movq -0x20(%rbp), %rdi
callq 0x49400
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 0x493eb
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x38a90
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)