// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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]abort             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, 0x8(%rsp)
movq %rsp, %r14
leaq 0x10(%rsp), %r15
leaq 0x4caad(%rip), %r12     # 0xc2101
leaq 0x4caa0(%rip), %r13     # 0xc20fb
movq %r14, %rdi
callq 0x74495
testq %rax, %rax
je 0x75c20
movq %rax, %rbp
movq 0xa5cd2(%rip), %rdi     # 0x11b348
callq 0x392b6
callq 0x39222
movq %rax, 0xa5cc1(%rip)     # 0x11b348
movq (%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x26300
testl %eax, %eax
je 0x758f1
movq %rbx, %rdi
movq %r13, %rsi
callq 0x26300
testl %eax, %eax
je 0x758f1
movq %rbx, %rdi
leaq 0x5a1c0(%rip), %rsi     # 0xcf87b
callq 0x26300
testl %eax, %eax
je 0x75d5f
movq %rbx, %rdi
leaq 0x58887(%rip), %rsi     # 0xcdf59
callq 0x26300
testl %eax, %eax
je 0x75d5f
movq %rbx, %rdi
leaq 0x581c6(%rip), %rsi     # 0xcd8af
callq 0x26300
testl %eax, %eax
je 0x75d5f
movq %rbx, %rdi
leaq 0x5885e(%rip), %rsi     # 0xcdf5e
callq 0x26300
testl %eax, %eax
je 0x75d5f
movq %rbx, %rdi
leaq 0x4d2d8(%rip), %rsi     # 0xc29ef
callq 0x26300
testl %eax, %eax
je 0x75d69
movq %rbx, %rdi
leaq 0x54466(%rip), %rsi     # 0xc9b94
callq 0x26300
testl %eax, %eax
je 0x75d69
movq %rbx, %rdi
leaq 0x4d2b3(%rip), %rsi     # 0xc29f8
callq 0x26300
testl %eax, %eax
je 0x75c72
movq %rbx, %rdi
leaq 0x61e16(%rip), %rsi     # 0xd7572
callq 0x26300
testl %eax, %eax
je 0x75c72
movq %rbx, %rdi
leaq 0x5c9d1(%rip), %rsi     # 0xd2144
callq 0x26300
testl %eax, %eax
je 0x75c7e
movq %rbx, %rdi
leaq 0x587d9(%rip), %rsi     # 0xcdf63
callq 0x26300
testl %eax, %eax
je 0x75c7e
movq %rbx, %rdi
leaq 0x5ef8a(%rip), %rsi     # 0xd472b
callq 0x26300
testl %eax, %eax
je 0x75c8b
movq %rbx, %rdi
leaq 0x5e0b4(%rip), %rsi     # 0xd386c
callq 0x26300
testl %eax, %eax
je 0x75c8b
movq %rbx, %rdi
leaq 0x5ef66(%rip), %rsi     # 0xd4735
callq 0x26300
testl %eax, %eax
je 0x75c98
movq %rbx, %rdi
leaq 0x57e00(%rip), %rsi     # 0xcd5e6
callq 0x26300
testl %eax, %eax
je 0x75c98
movq %rbx, %rdi
leaq 0x5ef8c(%rip), %rsi     # 0xd4789
callq 0x26300
testl %eax, %eax
je 0x75cbd
movq %rbx, %rdi
leaq 0x61dea(%rip), %rsi     # 0xd75fe
callq 0x26300
testl %eax, %eax
je 0x75cbd
movl (%rsp), %eax
movl %eax, 0x4(%rsp)
cmpl $0x2, %eax
jl 0x7585b
movq %rbx, %rdi
leaq 0x4d1be(%rip), %rsi     # 0xc29f5
callq 0x26300
testl %eax, %eax
je 0x75cf2
movq %rbx, %rdi
leaq 0x4a808(%rip), %rsi     # 0xc0056
callq 0x26300
testl %eax, %eax
je 0x75cf2
movq %rbx, %rdi
leaq 0x554e8(%rip), %rsi     # 0xcad4d
callq 0x26300
testl %eax, %eax
je 0x75cdb
movq %rbx, %rdi
leaq 0x623c4(%rip), %rsi     # 0xd7c40
callq 0x26300
testl %eax, %eax
je 0x75cdb
movq %rbx, %rdi
leaq 0x57022(%rip), %rsi     # 0xcc8b5
callq 0x26300
testl %eax, %eax
je 0x75d11
movq %rbx, %rdi
leaq 0x4e4d4(%rip), %rsi     # 0xc3d7e
callq 0x26300
testl %eax, %eax
je 0x75d11
movq %rbx, %rdi
leaq 0x4e4b6(%rip), %rsi     # 0xc3d77
callq 0x26300
testl %eax, %eax
je 0x75d4b
movq %rbx, %rdi
leaq 0x586b2(%rip), %rsi     # 0xcdf8a
callq 0x26300
testl %eax, %eax
je 0x75d4b
leaq 0x586a4(%rip), %rdi     # 0xcdf90
jmp 0x75c07
leaq 0x58034(%rip), %rdi     # 0xcd92c
callq 0x39245
movq 0xa590c(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58032(%rip), %rdi     # 0xcd945
callq 0x39245
movq 0xa58f1(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x5803c(%rip), %rdi     # 0xcd96a
callq 0x39245
movq 0xa58d6(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58057(%rip), %rdi     # 0xcd9a0
callq 0x39245
movq 0xa58bb(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58061(%rip), %rdi     # 0xcd9c5
callq 0x39245
movq 0xa58a0(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58075(%rip), %rdi     # 0xcd9f4
callq 0x39245
movq 0xa5885(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58095(%rip), %rdi     # 0xcda2f
callq 0x39245
movq 0xa586a(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x580af(%rip), %rdi     # 0xcda64
callq 0x39245
movq 0xa584f(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x580cb(%rip), %rdi     # 0xcda9b
callq 0x39245
movq 0xa5834(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x580f1(%rip), %rdi     # 0xcdadc
callq 0x39245
movq 0xa5819(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58108(%rip), %rdi     # 0xcdb0e
callq 0x39245
movq 0xa57fe(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58134(%rip), %rdi     # 0xcdb55
callq 0x39245
movq 0xa57e3(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x5814c(%rip), %rdi     # 0xcdb88
callq 0x39245
movq 0xa57c8(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58170(%rip), %rdi     # 0xcdbc7
callq 0x39245
movq 0xa57ad(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58193(%rip), %rdi     # 0xcdc05
callq 0x39245
movq 0xa5792(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x581a3(%rip), %rdi     # 0xcdc30
callq 0x39245
movq 0xa5777(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x581c5(%rip), %rdi     # 0xcdc6d
callq 0x39245
movq 0xa575c(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x581ea(%rip), %rdi     # 0xcdcad
callq 0x39245
movq 0xa5741(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x581fc(%rip), %rdi     # 0xcdcda
callq 0x39245
movq 0xa5726(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58208(%rip), %rdi     # 0xcdd01
callq 0x39245
movq 0xa570b(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58234(%rip), %rdi     # 0xcdd48
callq 0x39245
movq 0xa56f0(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58247(%rip), %rdi     # 0xcdd76
callq 0x39245
movq 0xa56d5(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58275(%rip), %rdi     # 0xcddbf
callq 0x39245
movq 0xa56ba(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58299(%rip), %rdi     # 0xcddfe
callq 0x39245
movq 0xa569f(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x582bd(%rip), %rdi     # 0xcde3d
callq 0x39245
movq 0xa5684(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x4ded2(%rip), %rdi     # 0xc3a6d
callq 0x39245
movq 0xa5669(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x582c3(%rip), %rdi     # 0xcde79
callq 0x39245
movq 0xa564e(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x582da(%rip), %rdi     # 0xcdeab
callq 0x39245
movq 0xa5633(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x582fa(%rip), %rdi     # 0xcdee6
callq 0x39245
movq 0xa5618(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
leaq 0x58323(%rip), %rdi     # 0xcdf2a
callq 0x39245
movq 0xa55fd(%rip), %rdi     # 0x11b210
movq %rax, %rsi
callq 0x2e40f
jmp 0x75ca8
movl 0xa55da(%rip), %edi     # 0x11b200
movl $0x400, %edx            # imm = 0x400
movq %r15, %rsi
callq 0x26350
movq %rax, %rbx
testl %ebx, %ebx
jle 0x75c5a
movq 0xa5707(%rip), %rdi     # 0x11b348
movl %ebx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %r15, %rsi
callq 0x39a56
movq %rax, 0xa56f0(%rip)     # 0x11b348
jmp 0x75c65
movq $0x0, 0xa56c3(%rip) # 0x11b328
testl %ebx, %ebx
jg 0x7565b
jmp 0x75d78
movq 0x8(%rsp), %rdi
callq 0x754a4
jmp 0x75ca8
movl (%rsp), %esi
movq %rbp, %rdi
callq 0x755b0
jmp 0x75ca8
movl (%rsp), %esi
movq %rbp, %rdi
callq 0x74fca
jmp 0x75ca8
movl (%rsp), %edx
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x751ca
callq 0x73ece
movl (%rsp), %esi
movq %rbp, %rdi
callq 0x3ab7f
jmp 0x7565b
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x5829e(%rip), %rsi     # 0xcdf6a
callq 0x8a02b
movq %rbx, %rdi
callq 0x8a922
jmp 0x75cad
cmpl $0x2, 0x4(%rsp)
jne 0x75d05
movq 0x8(%rbp), %rsi
movq 0x8(%rsp), %rdi
callq 0x74dd5
jmp 0x75ca8
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
movl 0x4(%rsp), %edx
callq 0x75399
jmp 0x75ca8
movq 0x8(%rsp), %rdi
callq 0x74ee4
jmp 0x75ca8
movl 0xa562d(%rip), %ebx     # 0x11b344
movl 0x4(%rsp), %ecx
cmpl $0x2, %ecx
jl 0x75d32
movq 0x8(%rbp), %rdi
callq 0x26770
movl 0x4(%rsp), %ecx
testl %eax, %eax
cmovgl %eax, %ebx
movl $0x5, %esi
cmpl $0x3, %ecx
jl 0x75d47
movq 0x10(%rbp), %rdi
callq 0x26770
movl %eax, %esi
movl %ebx, %edi
jmp 0x75d55
movl $0x1, %edi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x746d4
jmp 0x75ca8
movl $0x1, 0xa55c3(%rip)     # 0x11b32c
movl (%rsp), %esi
movq %rbp, %rdi
callq 0x3ab7f
xorl %eax, %eax
jmp 0x75d7d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop