// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/scripting.c
// Function: luaLdbLineHook
void luaLdbLineHook(lua_State *lua, lua_Debug *ar) {
    lua_getstack(lua,0,ar);
    lua_getinfo(lua,"Sl",ar);
    ldb.currentline = ar->currentline;

    int bp = ldbIsBreakpoint(ldb.currentline) || ldb.luabp;
    int timeout = 0;

    /* Events outside our script are not interesting. */
    if(strstr(ar->short_src,"user_script") == NULL) return;

    /* Check if a timeout occurred. */
    if (ar->event == LUA_HOOKCOUNT && ldb.step == 0 && bp == 0) {
        mstime_t elapsed = mstime() - server.lua_time_start;
        mstime_t timelimit = server.lua_time_limit ?
                             server.lua_time_limit : 5000;
        if (elapsed >= timelimit) {
            timeout = 1;
            ldb.step = 1;
        } else {
            return; /* No timeout, ignore the COUNT event. */
        }
    }

    if (ldb.step || bp) {
        char *reason = "step over";
        if (bp) reason = ldb.luabp ? "redis.breakpoint() called" :
                                     "break point";
        else if (timeout) reason = "timeout reached, infinite loop?";
        ldb.step = 0;
        ldb.luabp = 0;
        ldbLog(sdscatprintf(sdsempty(),
            "* Stopped at %d, stop reason = %s",
            ldb.currentline, reason));
        ldbLogSourceLine(ldb.currentline);
        ldbSendLogs();
        if (ldbRepl(lua) == C_ERR && timeout) {
            /* If the client closed the connection and we have a timeout
             * connection, let's kill the script otherwise the process
             * will remain blocked indefinitely. */
            lua_pushstring(lua, "timeout during Lua debugging with client closing connection");
            lua_error(lua);
        }
        server.lua_time_start = mstime();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
xorl %ebp, %ebp
xorl %esi, %esi
movq %r14, %rdx
callq 0x870c1
leaq 0x59c6b(%rip), %rsi     # 0xc994c
movq %rbx, %rdi
movq %r14, %rdx
callq 0x8723a
movl 0x28(%r14), %eax
movl %eax, 0xa66ae(%rip)     # 0x1163a4
movslq 0xa668b(%rip), %rcx     # 0x116388
testq %rcx, %rcx
jle 0x6fd24
decq %rcx
xorl %edx, %edx
leaq 0xa6552(%rip), %rsi     # 0x116260
cmpl %eax, 0x28(%rsi,%rdx,4)
sete %bpl
je 0x6fd24
leaq 0x1(%rdx), %rdi
cmpq %rdx, %rcx
movq %rdi, %rdx
jne 0x6fd0e
cmpl $0x0, 0xa6665(%rip)     # 0x116390
setne %r15b
leaq 0x38(%r14), %rdi
leaq 0x5a4f5(%rip), %rsi     # 0xca22f
callq 0x266b0
testq %rax, %rax
je 0x6fe68
orb %r15b, %bpl
movl (%r14), %ecx
xorl $0x3, %ecx
movl 0xa6635(%rip), %eax     # 0x11638c
orl %eax, %ecx
setne %r12b
movl %r12d, %r15d
orb %bpl, %r15b
testb $0x1, %r15b
je 0x6fd7a
testl %eax, %eax
setne %al
orb %bpl, %al
testb $0x1, %al
jne 0x6fda9
jmp 0x6fe68
callq 0x2ffce
leaq 0x91b22(%rip), %rcx     # 0x1018a8
subq 0x9f0(%rcx), %rax
movq 0x9e8(%rcx), %rcx
testq %rcx, %rcx
movl $0x1388, %edx           # imm = 0x1388
cmovneq %rcx, %rdx
cmpq %rdx, %rax
jl 0x6fe68
cmpl $0x0, 0xa65e0(%rip)     # 0x116390
leaq 0x5b2de(%rip), %rax     # 0xcb095
leaq 0x5b2bd(%rip), %rcx     # 0xcb07b
cmoveq %rax, %rcx
leaq 0x5b2a8(%rip), %rax     # 0xcb071
leaq 0x5b2d1(%rip), %r14     # 0xcb0a1
testb %r12b, %r12b
cmovneq %rax, %r14
testb %bpl, %bpl
cmovneq %rcx, %r14
movq $0x0, 0xa65a3(%rip) # 0x11638c
callq 0x3628d
movl 0xa65b0(%rip), %edx     # 0x1163a4
leaq 0x5b2c6(%rip), %rsi     # 0xcb0c1
movq %rax, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x36f2d
movq 0xa6461(%rip), %rdi     # 0x116270
movq %rax, %rsi
callq 0x2b24b
movl 0xa6587(%rip), %edi     # 0x1163a4
callq 0x70b7f
callq 0x70422
movq %rbx, %rdi
callq 0x71b86
cmpl $-0x1, %eax
setne %al
orb %al, %r15b
testb $0x1, %r15b
jne 0x6fe55
leaq 0x5b29e(%rip), %rsi     # 0xcb0e3
movq %rbx, %rdi
callq 0x86521
movq %rbx, %rdi
callq 0x86e29
callq 0x2ffce
leaq 0x91a47(%rip), %rcx     # 0x1018a8
movq %rax, 0x9f0(%rcx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq