// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/scripting.c
// Function: ldbCatStackValueRec
sds ldbCatStackValueRec(sds s, lua_State *lua, int idx, int level) {
    int t = lua_type(lua,idx);

    if (level++ == LDB_MAX_VALUES_DEPTH)
        return sdscat(s,"<max recursion level reached! Nested table?>");

    switch(t) {
    case LUA_TSTRING:
        {
        size_t strl;
        char *strp = (char*)lua_tolstring(lua,idx,&strl);
        s = sdscatrepr(s,strp,strl);
        }
        break;
    case LUA_TBOOLEAN:
        s = sdscat(s,lua_toboolean(lua,idx) ? "true" : "false");
        break;
    case LUA_TNUMBER:
        s = sdscatprintf(s,"%g",(double)lua_tonumber(lua,idx));
        break;
    case LUA_TNIL:
        s = sdscatlen(s,"nil",3);
        break;
    case LUA_TTABLE:
        {
        int expected_index = 1; /* First index we expect in an array. */
        int is_array = 1; /* Will be set to null if check fails. */
        /* Note: we create two representations at the same time, one
         * assuming the table is an array, one assuming it is not. At the
         * end we know what is true and select the right one. */
        sds repr1 = sdsempty();
        sds repr2 = sdsempty();
        lua_pushnil(lua); /* The first key to start the iteration is nil. */
        while (lua_next(lua,idx-1)) {
            /* Test if so far the table looks like an array. */
            if (is_array &&
                (lua_type(lua,-2) != LUA_TNUMBER ||
                 lua_tonumber(lua,-2) != expected_index)) is_array = 0;
            /* Stack now: table, key, value */
            /* Array repr. */
            repr1 = ldbCatStackValueRec(repr1,lua,-1,level);
            repr1 = sdscatlen(repr1,"; ",2);
            /* Full repr. */
            repr2 = sdscatlen(repr2,"[",1);
            repr2 = ldbCatStackValueRec(repr2,lua,-2,level);
            repr2 = sdscatlen(repr2,"]=",2);
            repr2 = ldbCatStackValueRec(repr2,lua,-1,level);
            repr2 = sdscatlen(repr2,"; ",2);
            lua_pop(lua,1); /* Stack: table, key. Ready for next iteration. */
            expected_index++;
        }
        /* Strip the last " ;" from both the representations. */
        if (sdslen(repr1)) sdsrange(repr1,0,-3);
        if (sdslen(repr2)) sdsrange(repr2,0,-3);
        /* Select the right one and discard the other. */
        s = sdscatlen(s,"{",1);
        s = sdscatsds(s,is_array ? repr1 : repr2);
        s = sdscatlen(s,"}",1);
        sdsfree(repr1);
        sdsfree(repr2);
        }
        break;
    case LUA_TFUNCTION:
    case LUA_TUSERDATA:
    case LUA_TTHREAD:
    case LUA_TLIGHTUSERDATA:
        {
        const void *p = lua_topointer(lua,idx);
        char *typename = "unknown";
        if (t == LUA_TFUNCTION) typename = "function";
        else if (t == LUA_TUSERDATA) typename = "userdata";
        else if (t == LUA_TTHREAD) typename = "thread";
        else if (t == LUA_TLIGHTUSERDATA) typename = "light-userdata";
        s = sdscatprintf(s,"\"%s@%p\"",typename,p);
        }
        break;
    default:
        s = sdscat(s,"\"<unknown-lua-type>\"");
        break;
    }
    return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
movl %edx, 0x8(%rsp)
movl %edx, %esi
callq 0x786b8
movl %ebp, 0xc(%rsp)
cmpl $0xa, %ebp
jne 0x65509
leaq 0x560a5(%rip), %rsi     # 0xbb598
movq %r14, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x317b7
movl %eax, %ebx
cmpl $0x8, %eax
ja 0x657d8
movl %ebx, %eax
leaq 0x551d3(%rip), %rcx     # 0xba6f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
movl 0x8(%rsp), %esi
callq 0x78a0b
addl $-0x2, %ebx
cmpl $0x6, %ebx
ja 0x6554c
movl %ebx, %ecx
leaq 0x551f9(%rip), %rsi     # 0xba73c
movslq (%rsi,%rcx,4), %rdx
addq %rsi, %rdx
jmp 0x65553
leaq 0x4d168(%rip), %rdx     # 0xb26bb
leaq 0x56096(%rip), %rsi     # 0xbb5f0
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31a38
leaq 0x30(%rsp), %rbx
movq %r15, %rdi
movl 0x8(%rsp), %esi
movq %rbx, %rdx
callq 0x788e1
movq (%rbx), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x321f1
jmp 0x657c9
leaq 0x5bf2c(%rip), %rsi     # 0xc14cf
pushq $0x3
popq %rdx
movq %r14, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31758
movq %r15, %rdi
movl 0x8(%rsp), %esi
callq 0x788bd
testl %eax, %eax
leaq 0x55ff4(%rip), %rax     # 0xbb5c5
leaq 0x52635(%rip), %rsi     # 0xb7c0d
cmoveq %rax, %rsi
jmp 0x654f3
movq %r15, %rdi
movl 0x8(%rsp), %esi
callq 0x7885f
leaq 0x55fd7(%rip), %rsi     # 0xbb5cb
movq %r14, %rdi
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31a38
movq %r14, 0x28(%rsp)
incl 0xc(%rsp)
callq 0x3114c
movq %rax, 0x18(%rsp)
callq 0x3114c
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x78a55
decl 0x8(%rsp)
pushq $0x1
popq %r13
movl %r13d, %ebp
pushq $0x2
popq %r14
pushq $-0x2
popq %r12
movq %r15, %rdi
movl 0x8(%rsp), %esi
callq 0x793f1
testl %eax, %eax
je 0x65737
xorl %ebx, %ebx
testl %r13d, %r13d
je 0x6568b
movq %r15, %rdi
pushq $-0x2
popq %rsi
callq 0x786b8
cmpl $0x3, %eax
jne 0x65689
movq %r15, %rdi
pushq $-0x2
popq %rsi
callq 0x7885f
cvtsi2sd %ebp, %xmm1
ucomisd %xmm1, %xmm0
pushq $0x1
popq %rbx
jne 0x65689
jnp 0x6568b
xorl %ebx, %ebx
movl %ebx, 0x24(%rsp)
movq 0x18(%rsp), %rdi
movq %r15, %rsi
pushq $-0x1
popq %rdx
movl 0xc(%rsp), %r13d
movl %r13d, %ecx
callq 0x654bf
movq %rax, %rdi
movl %ebp, %ebx
leaq 0x55f1b(%rip), %rbp     # 0xbb5ce
movq %rbp, %rsi
movq %r14, %rdx
callq 0x31758
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x55f02(%rip), %rsi     # 0xbb5d1
pushq $0x1
popq %rdx
callq 0x31758
movq %rax, %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x654bf
movq %rax, %rdi
leaq 0x55ee1(%rip), %rsi     # 0xbb5d3
movq %r14, %rdx
callq 0x31758
movq %rax, %rdi
movq %r15, %rsi
pushq $-0x1
popq %rdx
movl %r13d, %ecx
callq 0x654bf
movq %rax, %rdi
movq %rbp, %rsi
movl %ebx, %ebp
movq %r14, %rdx
callq 0x31758
movq %rax, 0x10(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x78478
incl %ebp
movl 0x24(%rsp), %r13d
jmp 0x65644
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x63370
testq %rax, %rax
je 0x65756
pushq $-0x3
popq %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x31e8e
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
callq 0x63370
testq %rax, %rax
movq 0x28(%rsp), %r14
je 0x6577a
pushq $-0x3
popq %rdx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x31e8e
leaq 0x55e55(%rip), %rsi     # 0xbb5d6
pushq $0x1
popq %rbx
movq %r14, %rdi
movq %rbx, %rdx
callq 0x31758
testl %r13d, %r13d
movq %r15, %rsi
cmoveq %rbp, %rsi
movq %rax, %rdi
callq 0x317de
leaq 0x55e30(%rip), %rsi     # 0xbb5d8
movq %rax, %rdi
movq %rbx, %rdx
callq 0x31758
movq %rax, %rbx
movq %r15, %rdi
callq 0x311c8
movq %rbp, %rdi
callq 0x311c8
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x55e19(%rip), %rsi     # 0xbb5f8
jmp 0x654f3