// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/scripting.c
// Function: luaReplyToRedisReply
void luaReplyToRedisReply(redisClient *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 0x662f0
decl %eax
cmpl $0x4, %eax
ja 0x57fe1
leaq 0x4571c(%rip), %rcx     # 0x9d5dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x66508
testl %eax, %eax
leaq 0x72921(%rip), %rax     # 0xca800
movl $0x50, %ecx
movl $0x28, %edx
cmoveq %rcx, %rdx
movq (%rax,%rdx), %rsi
jmp 0x57fec
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x6652e
movq %rax, %r15
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x6659f
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2dfa7
jmp 0x57ff4
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x664aa
cvttsd2si %xmm0, %rsi
movq %r14, %rdi
callq 0x2dea3
jmp 0x57ff4
leaq 0x3d9cf(%rip), %rsi     # 0x9591d
movq %rbx, %rdi
callq 0x66757
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6696e
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x662f0
cmpl $0x4, %eax
jne 0x58011
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x6652e
movq %rax, %rdi
callq 0x281da
movq %rax, %r15
leaq 0x4172d(%rip), %rsi     # 0x996c7
leaq 0x43380(%rip), %rdx     # 0x9b321
movl $0x2, %ecx
movq %rax, %rdi
callq 0x29653
callq 0x281b2
leaq 0x45d30(%rip), %rsi     # 0x9dcea
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x28760
movq %r14, %rdi
movq %rax, %rsi
callq 0x2d894
movq %r15, %rdi
callq 0x28204
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
jmp 0x57ff9
leaq 0x72818(%rip), %rax     # 0xca800
movq 0x50(%rax), %rsi
movq %r14, %rdi
callq 0x2d6f0
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 0x660a2
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x660a2
leaq 0x49bb1(%rip), %rsi     # 0xa1bdb
movq %rbx, %rdi
callq 0x66757
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6696e
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x662f0
cmpl $0x4, %eax
jne 0x580c4
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x6652e
movq %rax, %rdi
callq 0x281da
movq %rax, %r15
leaq 0x41655(%rip), %rsi     # 0x996c7
leaq 0x432a8(%rip), %rdx     # 0x9b321
movl $0x2, %ecx
movq %rax, %rdi
callq 0x29653
callq 0x281b2
leaq 0x45c5e(%rip), %rsi     # 0x9dcf0
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x28760
movq %r14, %rdi
movq %rax, %rsi
callq 0x2d894
movq %r15, %rdi
callq 0x28204
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x660a2
jmp 0x57ff9
movq %r14, %rdi
callq 0x2dc0a
movq %rax, %r15
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x660a2
movsd 0x3f1c7(%rip), %xmm0    # 0x972b0
movq %rbx, %rdi
callq 0x666d1
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6696e
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x662f0
xorl %r12d, %r12d
testl %eax, %eax
je 0x58151
leal 0x2(%r12), %r13d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x57e90
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movq %rbx, %rdi
callq 0x666d1
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6696e
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x662f0
incq %r12
jmp 0x5810e
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x660a2
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2dc46
jmp 0x57ff9