// File: /workspace/github_c_makefile_star2_O3/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
movq %rsi, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x860ba
decl %eax
cmpl $0x4, %eax
ja 0x6dc66
leaq 0x5bb8b(%rip), %rcx     # 0xc96d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x862d2
testl %eax, %eax
leaq 0x947ac(%rip), %rax     # 0x102310
movl $0x50, %ecx
movl $0x28, %edx
cmoveq %rcx, %rdx
movq (%rax,%rdx), %rsi
jmp 0x6dc71
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x862f8
movq %rax, %r15
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x86369
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x3d346
jmp 0x6dc79
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x86274
cvttsd2si %xmm0, %rsi
movq %r14, %rdi
callq 0x3d23f
jmp 0x6dc79
leaq 0x502c5(%rip), %rsi     # 0xbde98
movq %rbx, %rdi
callq 0x86521
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x8673f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x860ba
cmpl $0x4, %eax
jne 0x6dc96
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x862f8
movq %rax, %rdi
callq 0x362b0
movq %rax, %r15
leaq 0x561bd(%rip), %rsi     # 0xc3ddc
leaq 0x5cb35(%rip), %rdx     # 0xca75b
movl $0x2, %ecx
movq %rax, %rdi
callq 0x3812f
callq 0x3628d
leaq 0x5bd33(%rip), %rsi     # 0xc9972
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x36f2d
movq %r14, %rdi
movq %rax, %rsi
callq 0x3ca86
movq %r15, %rdi
callq 0x36330
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
jmp 0x6dc7e
leaq 0x946a3(%rip), %rax     # 0x102310
movq 0x50(%rax), %rsi
movq %r14, %rdi
callq 0x3c854
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movq %rbx, %rdi
movl %ebp, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x85d59
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x85d59
leaq 0x63528(%rip), %rsi     # 0xd11d7
movq %rbx, %rdi
callq 0x86521
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x8673f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x860ba
cmpl $0x4, %eax
jne 0x6dd49
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x862f8
movq %rax, %rdi
callq 0x362b0
movq %rax, %r15
leaq 0x560e5(%rip), %rsi     # 0xc3ddc
leaq 0x5ca5d(%rip), %rdx     # 0xca75b
movl $0x2, %ecx
movq %rax, %rdi
callq 0x3812f
callq 0x3628d
leaq 0x5bc61(%rip), %rsi     # 0xc9978
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x36f2d
movq %r14, %rdi
movq %rax, %rsi
callq 0x3ca86
movq %r15, %rdi
callq 0x36330
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x85d59
jmp 0x6dc7e
movq %r14, %rdi
callq 0x3cee9
movq %rax, %r15
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x85d59
movsd 0x52cb2(%rip), %xmm0    # 0xc0a20
movq %rbx, %rdi
callq 0x8649b
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x8673f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x860ba
xorl %r12d, %r12d
testl %eax, %eax
je 0x6ddd6
leal 0x2(%r12), %r13d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6db15
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movq %rbx, %rdi
callq 0x8649b
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x8673f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x860ba
incq %r12
jmp 0x6dd93
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x85d59
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3cf25
jmp 0x6dc7e