// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/scripting.c
// Function: ldbRepl
int ldbRepl(lua_State *lua) {
    sds *argv;
    int argc;

    /* We continue processing commands until a command that should return
     * to the Lua interpreter is found. */
    while(1) {
        while((argv = ldbReplParseCommand(&argc)) == NULL) {
            char buf[1024];
            int nread = read(ldb.fd,buf,sizeof(buf));
            if (nread <= 0) {
                /* Make sure the script runs without user input since the
                 * client is no longer connected. */
                ldb.step = 0;
                ldb.bpcount = 0;
                return C_ERR;
            }
            ldb.cbuf = sdscatlen(ldb.cbuf,buf,nread);
        }

        /* Flush the old buffer. */
        sdsfree(ldb.cbuf);
        ldb.cbuf = sdsempty();

        /* Execute the command. */
        if (!strcasecmp(argv[0],"h") || !strcasecmp(argv[0],"help")) {
ldbLog(sdsnew("Redis Lua debugger help:"));
ldbLog(sdsnew("[h]elp               Show this help."));
ldbLog(sdsnew("[s]tep               Run current line and stop again."));
ldbLog(sdsnew("[n]ext               Alias for step."));
ldbLog(sdsnew("[c]continue          Run till next breakpoint."));
ldbLog(sdsnew("[l]list              List source code around current line."));
ldbLog(sdsnew("[l]list [line]       List source code around [line]."));
ldbLog(sdsnew("                     line = 0 means: current position."));
ldbLog(sdsnew("[l]list [line] [ctx] In this form [ctx] specifies how many lines"));
ldbLog(sdsnew("                     to show before/after [line]."));
ldbLog(sdsnew("[w]hole              List all source code. Alias for 'list 1 1000000'."));
ldbLog(sdsnew("[p]rint              Show all the local variables."));
ldbLog(sdsnew("[p]rint <var>        Show the value of the specified variable."));
ldbLog(sdsnew("                     Can also show global vars KEYS and ARGV."));
ldbLog(sdsnew("[b]reak              Show all breakpoints."));
ldbLog(sdsnew("[b]reak <line>       Add a breakpoint to the specified line."));
ldbLog(sdsnew("[b]reak -<line>      Remove breakpoint from the specified line."));
ldbLog(sdsnew("[b]reak 0            Remove all breakpoints."));
ldbLog(sdsnew("[t]race              Show a backtrace."));
ldbLog(sdsnew("[e]eval <code>       Execute some Lua code (in a different callframe)."));
ldbLog(sdsnew("[r]edis <cmd>        Execute a Redis command."));
ldbLog(sdsnew("[m]axlen [len]       Trim logged Redis replies and Lua var dumps to len."));
ldbLog(sdsnew("                     Specifying zero as <len> means unlimited."));
ldbLog(sdsnew("[a]bort              Stop the execution of the script. In sync"));
ldbLog(sdsnew("                     mode dataset changes will be retained."));
ldbLog(sdsnew(""));
ldbLog(sdsnew("Debugger functions you can call from Lua scripts:"));
ldbLog(sdsnew("redis.debug()        Produce logs in the debugger console."));
ldbLog(sdsnew("redis.breakpoint()   Stop execution like if there was a breakpoing."));
ldbLog(sdsnew("                     in the next line of code."));
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"s") || !strcasecmp(argv[0],"step") ||
                   !strcasecmp(argv[0],"n") || !strcasecmp(argv[0],"next")) {
            ldb.step = 1;
            break;
        } else if (!strcasecmp(argv[0],"c") || !strcasecmp(argv[0],"continue")){
            break;
        } else if (!strcasecmp(argv[0],"t") || !strcasecmp(argv[0],"trace")) {
            ldbTrace(lua);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"m") || !strcasecmp(argv[0],"maxlen")) {
            ldbMaxlen(argv,argc);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"b") || !strcasecmp(argv[0],"break")) {
            ldbBreak(argv,argc);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"e") || !strcasecmp(argv[0],"eval")) {
            ldbEval(lua,argv,argc);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"a") || !strcasecmp(argv[0],"abort")) {
            lua_pushstring(lua, "script aborted for user request");
            lua_error(lua);
        } else if (argc > 1 &&
                   (!strcasecmp(argv[0],"r") || !strcasecmp(argv[0],"redis"))) {
            ldbRedis(lua,argv,argc);
            ldbSendLogs();
        } else if ((!strcasecmp(argv[0],"p") || !strcasecmp(argv[0],"print"))) {
            if (argc == 2)
                ldbPrint(lua,argv[1]);
            else
                ldbPrintAll(lua);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"l") || !strcasecmp(argv[0],"list")){
            int around = ldb.currentline, ctx = 5;
            if (argc > 1) {
                int num = atoi(argv[1]);
                if (num > 0) around = num;
            }
            if (argc > 2) ctx = atoi(argv[2]);
            ldbList(around,ctx);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"w") || !strcasecmp(argv[0],"whole")){
            ldbList(1,1000000);
            ldbSendLogs();
        } else {
            ldbLog(sdsnew("<error> Unknown Redis Lua debugger command or "
                          "wrong number of arguments."));
            ldbSendLogs();
        }

        /* Free the command vector. */
        sdsfreesplitres(argv,argc);
    }

    /* Free the current command argv if we break inside the while loop. */
    sdsfreesplitres(argv,argc);
    return C_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
leaq 0x10(%rsp), %r15
leaq 0x60580(%rip), %r12     # 0xd212b
movq %r14, %rdi
callq 0x70a14
testq %rax, %rax
jne 0x71bf3
movl 0xa46a2(%rip), %edi     # 0x116260
movl $0x400, %edx            # imm = 0x400
movq %r15, %rsi
callq 0x26340
testl %eax, %eax
jle 0x72293
movq 0xa47ce(%rip), %rdi     # 0x1163a8
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rsi
movq %rax, %rdx
callq 0x36ad1
movq %rax, 0xa47b7(%rip)     # 0x1163a8
jmp 0x71bab
movq %rax, %rbp
movq 0xa47ab(%rip), %rdi     # 0x1163a8
callq 0x36330
callq 0x3628d
movq %rax, 0xa479a(%rip)     # 0x1163a8
movq (%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x262f0
testl %eax, %eax
je 0x71e7d
movq %r13, %rdi
leaq 0x4d538(%rip), %rsi     # 0xbf167
callq 0x262f0
testl %eax, %eax
je 0x71e7d
movq %r13, %rdi
leaq 0x5ad35(%rip), %rsi     # 0xcc97b
callq 0x262f0
testl %eax, %eax
je 0x722a5
movq %r13, %rdi
leaq 0x59394(%rip), %rsi     # 0xcaff1
callq 0x262f0
testl %eax, %eax
je 0x722a5
movq %r13, %rdi
leaq 0x58cd3(%rip), %rsi     # 0xca947
callq 0x262f0
testl %eax, %eax
je 0x722a5
movq %r13, %rdi
leaq 0x5936b(%rip), %rsi     # 0xcaff6
callq 0x262f0
testl %eax, %eax
je 0x722a5
movq %r13, %rdi
leaq 0x4ddb5(%rip), %rsi     # 0xbfa57
callq 0x262f0
testl %eax, %eax
je 0x722af
movq %r13, %rdi
leaq 0x54f37(%rip), %rsi     # 0xc6bf0
callq 0x262f0
testl %eax, %eax
je 0x722af
movq %r13, %rdi
leaq 0x4dd90(%rip), %rsi     # 0xbfa60
callq 0x262f0
testl %eax, %eax
je 0x721a9
movq %r13, %rdi
leaq 0x61cf6(%rip), %rsi     # 0xd39dd
callq 0x262f0
testl %eax, %eax
je 0x721a9
movq %r13, %rdi
leaq 0x5d55e(%rip), %rsi     # 0xcf25c
callq 0x262f0
testl %eax, %eax
je 0x721b3
movq %r13, %rdi
leaq 0x592e6(%rip), %rsi     # 0xcaffb
callq 0x262f0
testl %eax, %eax
je 0x721b3
movq %r13, %rdi
leaq 0x5fb5f(%rip), %rsi     # 0xd188b
callq 0x262f0
testl %eax, %eax
je 0x721c1
movq %r13, %rdi
leaq 0x5ec59(%rip), %rsi     # 0xd099c
callq 0x262f0
testl %eax, %eax
je 0x721c1
movq %r13, %rdi
leaq 0x5fb3b(%rip), %rsi     # 0xd1895
callq 0x262f0
testl %eax, %eax
je 0x721cf
movq %r13, %rdi
leaq 0x5890d(%rip), %rsi     # 0xca67e
callq 0x262f0
testl %eax, %eax
je 0x721cf
movq %r13, %rdi
leaq 0x5fb61(%rip), %rsi     # 0xd18e9
callq 0x262f0
testl %eax, %eax
je 0x721f4
movq %r13, %rdi
leaq 0x61aca(%rip), %rsi     # 0xd3869
callq 0x262f0
testl %eax, %eax
je 0x721f4
movl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
cmpl $0x2, %eax
jl 0x71de7
movq %r13, %rdi
leaq 0x4dc9a(%rip), %rsi     # 0xbfa5d
callq 0x262f0
testl %eax, %eax
je 0x72222
movq %r13, %rdi
leaq 0x4b2ee(%rip), %rsi     # 0xbd0c8
callq 0x262f0
testl %eax, %eax
je 0x72222
movq %r13, %rdi
leaq 0x55fe4(%rip), %rsi     # 0xc7dd5
callq 0x262f0
testl %eax, %eax
je 0x7220d
movq %r13, %rdi
leaq 0x61b3a(%rip), %rsi     # 0xd3942
callq 0x262f0
testl %eax, %eax
je 0x7220d
movq %r13, %rdi
leaq 0x57b2e(%rip), %rsi     # 0xc994d
callq 0x262f0
testl %eax, %eax
je 0x7223d
movq %r13, %rdi
leaq 0x4ef98(%rip), %rsi     # 0xc0dce
callq 0x262f0
testl %eax, %eax
je 0x7223d
movq %r13, %rdi
leaq 0x4ef7a(%rip), %rsi     # 0xc0dc7
callq 0x262f0
testl %eax, %eax
je 0x7226f
movq %r13, %rdi
leaq 0x591be(%rip), %rsi     # 0xcb022
callq 0x262f0
testl %eax, %eax
je 0x7226f
leaq 0x591b0(%rip), %rdi     # 0xcb028
jmp 0x72193
leaq 0x58b40(%rip), %rdi     # 0xca9c4
callq 0x362b0
movq 0xa43e0(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58b3e(%rip), %rdi     # 0xca9dd
callq 0x362b0
movq 0xa43c5(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58b48(%rip), %rdi     # 0xcaa02
callq 0x362b0
movq 0xa43aa(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58b63(%rip), %rdi     # 0xcaa38
callq 0x362b0
movq 0xa438f(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58b6d(%rip), %rdi     # 0xcaa5d
callq 0x362b0
movq 0xa4374(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58b81(%rip), %rdi     # 0xcaa8c
callq 0x362b0
movq 0xa4359(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58ba1(%rip), %rdi     # 0xcaac7
callq 0x362b0
movq 0xa433e(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58bbb(%rip), %rdi     # 0xcaafc
callq 0x362b0
movq 0xa4323(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58bd7(%rip), %rdi     # 0xcab33
callq 0x362b0
movq 0xa4308(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58bfd(%rip), %rdi     # 0xcab74
callq 0x362b0
movq 0xa42ed(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58c14(%rip), %rdi     # 0xcaba6
callq 0x362b0
movq 0xa42d2(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58c40(%rip), %rdi     # 0xcabed
callq 0x362b0
movq 0xa42b7(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58c58(%rip), %rdi     # 0xcac20
callq 0x362b0
movq 0xa429c(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58c7c(%rip), %rdi     # 0xcac5f
callq 0x362b0
movq 0xa4281(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58c9f(%rip), %rdi     # 0xcac9d
callq 0x362b0
movq 0xa4266(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58caf(%rip), %rdi     # 0xcacc8
callq 0x362b0
movq 0xa424b(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58cd1(%rip), %rdi     # 0xcad05
callq 0x362b0
movq 0xa4230(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58cf6(%rip), %rdi     # 0xcad45
callq 0x362b0
movq 0xa4215(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58d08(%rip), %rdi     # 0xcad72
callq 0x362b0
movq 0xa41fa(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58d14(%rip), %rdi     # 0xcad99
callq 0x362b0
movq 0xa41df(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58d40(%rip), %rdi     # 0xcade0
callq 0x362b0
movq 0xa41c4(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58d53(%rip), %rdi     # 0xcae0e
callq 0x362b0
movq 0xa41a9(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58d81(%rip), %rdi     # 0xcae57
callq 0x362b0
movq 0xa418e(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58da5(%rip), %rdi     # 0xcae96
callq 0x362b0
movq 0xa4173(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58dc9(%rip), %rdi     # 0xcaed5
callq 0x362b0
movq 0xa4158(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x4e98e(%rip), %rdi     # 0xc0ab5
callq 0x362b0
movq 0xa413d(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58dcf(%rip), %rdi     # 0xcaf11
callq 0x362b0
movq 0xa4122(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58de6(%rip), %rdi     # 0xcaf43
callq 0x362b0
movq 0xa4107(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58e06(%rip), %rdi     # 0xcaf7e
callq 0x362b0
movq 0xa40ec(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
leaq 0x58e2f(%rip), %rdi     # 0xcafc2
callq 0x362b0
movq 0xa40d1(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
jmp 0x721de
movq %rbx, %rdi
callq 0x719f9
jmp 0x721de
movl 0x8(%rsp), %esi
movq %rbp, %rdi
callq 0x71b05
jmp 0x721de
movl 0x8(%rsp), %esi
movq %rbp, %rdi
callq 0x7151f
jmp 0x721de
movl 0x8(%rsp), %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7171f
callq 0x70422
movl 0x8(%rsp), %esi
movq %rbp, %rdi
callq 0x37c04
jmp 0x71bab
movq %rbx, %rdi
leaq 0x58e04(%rip), %rsi     # 0xcb002
callq 0x86521
movq %rbx, %rdi
callq 0x86e29
jmp 0x721e3
cmpl $0x2, 0xc(%rsp)
jne 0x72233
movq 0x8(%rbp), %rsi
movq %rbx, %rdi
callq 0x7132a
jmp 0x721de
movq %rbx, %rdi
movq %rbp, %rsi
movl 0xc(%rsp), %edx
callq 0x718ee
jmp 0x721de
movq %rbx, %rdi
callq 0x71439
jmp 0x721de
movl $0x5, %esi
movl 0xa415b(%rip), %r13d    # 0x1163a4
movl 0xc(%rsp), %eax
cmpl $0x2, %eax
jl 0x72286
movq 0x8(%rbp), %rdi
callq 0x26760
testl %eax, %eax
cmovgl %eax, %r13d
cmpl $0x2, 0xc(%rsp)
jne 0x7227b
movl $0x5, %esi
jmp 0x72286
movl $0x1, %edi
movl $0xf4240, %esi          # imm = 0xF4240
jmp 0x72289
movq 0x10(%rbp), %rdi
callq 0x26760
movl %eax, %esi
movl %r13d, %edi
callq 0x70c2a
jmp 0x721de
movq $0x0, 0xa40ea(%rip) # 0x116388
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x722bd
movl $0x1, 0xa40dd(%rip)     # 0x11638c
movl 0x8(%rsp), %esi
movq %rbp, %rdi
callq 0x37c04
xorl %eax, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop