// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/scripting.c
// Function: luaReplyToRedisReply
void luaReplyToRedisReply(client *c, lua_State *lua) {
    int t = lua_type(lua,-1);

    switch(t) {
    case LUA_TSTRING:
        addReplyBulkCBuffer(c,(char*)lua_tostring(lua,-1),lua_strlen(lua,-1));
        break;
    case LUA_TBOOLEAN:
        addReply(c,lua_toboolean(lua,-1) ? shared.cone : shared.nullbulk);
        break;
    case LUA_TNUMBER:
        addReplyLongLong(c,(long long)lua_tonumber(lua,-1));
        break;
    case LUA_TTABLE:
        /* We need to check if it is an array, an error, or a status reply.
         * Error are returned as a single element table with 'err' field.
         * Status replies are returned as single element table with 'ok'
         * field. */
        lua_pushstring(lua,"err");
        lua_gettable(lua,-2);
        t = lua_type(lua,-1);
        if (t == LUA_TSTRING) {
            sds err = sdsnew(lua_tostring(lua,-1));
            sdsmapchars(err,"\r\n","  ",2);
            addReplySds(c,sdscatprintf(sdsempty(),"-%s\r\n",err));
            sdsfree(err);
            lua_pop(lua,2);
            return;
        }

        lua_pop(lua,1);
        lua_pushstring(lua,"ok");
        lua_gettable(lua,-2);
        t = lua_type(lua,-1);
        if (t == LUA_TSTRING) {
            sds ok = sdsnew(lua_tostring(lua,-1));
            sdsmapchars(ok,"\r\n","  ",2);
            addReplySds(c,sdscatprintf(sdsempty(),"+%s\r\n",ok));
            sdsfree(ok);
            lua_pop(lua,1);
        } else {
            void *replylen = addDeferredMultiBulkLength(c);
            int j = 1, mbulklen = 0;

            lua_pop(lua,1); /* Discard the 'ok' field value we popped */
            while(1) {
                lua_pushnumber(lua,j++);
                lua_gettable(lua,-2);
                t = lua_type(lua,-1);
                if (t == LUA_TNIL) {
                    lua_pop(lua,1);
                    break;
                }
                luaReplyToRedisReply(c, lua);
                mbulklen++;
            }
            setDeferredMultiBulkLength(c,replylen,mbulklen);
        }
        break;
    default:
        addReply(c,shared.nullbulk);
    }
    lua_pop(lua,1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x786b8
decl %eax
cmpl $0x4, %eax
ja 0x62a06
leaq 0x57da5(%rip), %rcx     # 0xba6a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x788bd
testl %eax, %eax
leaq 0x979f8(%rip), %rax     # 0xfa310
pushq $0x50
popq %rcx
pushq $0x28
popq %rdx
cmoveq %rcx, %rdx
movq (%rax,%rdx), %rsi
jmp 0x62a11
pushq $-0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x788e1
movq %rax, %r15
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7894f
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x3716c
jmp 0x62a19
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x7885f
cvttsd2si %xmm0, %rsi
movq %r14, %rdi
callq 0x370a6
jmp 0x62a19
leaq 0x4d40a(%rip), %rsi     # 0xafd88
movq %rbx, %rdi
callq 0x78aec
pushq $-0x2
popq %rsi
movq %rbx, %rdi
callq 0x78d02
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x786b8
cmpl $0x4, %eax
jne 0x62a34
pushq $-0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x788e1
movq %rax, %rdi
callq 0x3115a
movq %rax, %r15
leaq 0x527cc(%rip), %rsi     # 0xb5190
leaq 0x58bc0(%rip), %rdx     # 0xbb58b
pushq $0x2
popq %rcx
movq %rax, %rdi
callq 0x3269b
callq 0x3114c
leaq 0x57dc0(%rip), %rsi     # 0xba7a2
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x31a38
movq %r14, %rdi
movq %rax, %rsi
callq 0x36a9d
movq %r15, %rdi
callq 0x311c8
pushq $-0x3
jmp 0x62a1b
leaq 0x97903(%rip), %rax     # 0xfa310
movq 0x50(%rax), %rsi
movq %r14, %rdi
callq 0x36987
pushq $-0x2
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x78478
pushq $-0x2
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x78478
leaq 0x5f24f(%rip), %rsi     # 0xc1c97
movq %rbx, %rdi
callq 0x78aec
movq %rbx, %rdi
movl %ebp, %esi
callq 0x78d02
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x786b8
cmpl $0x4, %eax
jne 0x62ad6
pushq $-0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x788e1
movq %rax, %rdi
callq 0x3115a
movq %rax, %r15
leaq 0x52707(%rip), %rsi     # 0xb5190
leaq 0x58afb(%rip), %rdx     # 0xbb58b
pushq $0x2
popq %rcx
movq %rax, %rdi
callq 0x3269b
callq 0x3114c
leaq 0x57d01(%rip), %rsi     # 0xba7a8
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x31a38
movq %r14, %rdi
movq %rax, %rsi
callq 0x36a9d
movq %r15, %rdi
callq 0x311c8
movq %rbx, %rdi
movl %ebp, %esi
callq 0x78478
jmp 0x62a1c
movq %r14, %rdi
callq 0x36dad
movq %rax, %r15
pushq $-0x2
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x78478
xorl %r12d, %r12d
pushq $-0x1
popq %r13
leal 0x1(%r12), %eax
cvtsi2sd %eax, %xmm0
movq %rbx, %rdi
callq 0x78a66
movq %rbx, %rdi
movl %ebp, %esi
callq 0x78d02
movq %rbx, %rdi
movl %r13d, %esi
callq 0x786b8
testl %eax, %eax
je 0x62b2f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x628cd
incq %r12
jmp 0x62af5
movq %rbx, %rdi
movl %ebp, %esi
callq 0x78478
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x36de9
jmp 0x62a1c