// File: /workspace/github_c_makefile_star2_O2/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 %esi, %esi
movq %r14, %rdx
callq 0x7967b
leaq 0x55fba(%rip), %rsi     # 0xba77c
movq %rbx, %rdi
movq %r14, %rdx
callq 0x797e8
movl 0x28(%r14), %edi
movl %edi, 0xa9bcd(%rip)     # 0x10e3a4
callq 0x651d6
orl 0xa9bae(%rip), %eax     # 0x10e390
setne %r15b
leaq 0x38(%r14), %rdi
leaq 0x5686e(%rip), %rsi     # 0xbb05f
callq 0x266b0
testq %rax, %rax
je 0x64912
movl (%r14), %ecx
xorl $0x3, %ecx
movl 0xa9b81(%rip), %eax     # 0x10e38c
orl %eax, %ecx
setne %r12b
movl %r12d, %ebp
orb %r15b, %bpl
testb $0x1, %bpl
je 0x6482e
testl %eax, %eax
setne %al
orb %r15b, %al
testb $0x1, %al
jne 0x6485d
jmp 0x64912
callq 0x2b8ae
leaq 0x9506e(%rip), %rcx     # 0xf98a8
subq 0x9f0(%rcx), %rax
movq 0x9e8(%rcx), %rcx
testq %rcx, %rcx
movl $0x1388, %edx           # imm = 0x1388
cmovneq %rcx, %rdx
cmpq %rdx, %rax
jl 0x64912
cmpl $0x0, 0xa9b2c(%rip)     # 0x10e390
leaq 0x5765a(%rip), %rax     # 0xbbec5
leaq 0x57639(%rip), %rcx     # 0xbbeab
cmoveq %rax, %rcx
leaq 0x57624(%rip), %rax     # 0xbbea1
leaq 0x5764d(%rip), %r14     # 0xbbed1
testb %r12b, %r12b
cmovneq %rax, %r14
testb %r15b, %r15b
cmovneq %rcx, %r14
andq $0x0, 0xa9af2(%rip)     # 0x10e38c
callq 0x3114c
movl 0xa9aff(%rip), %edx     # 0x10e3a4
leaq 0x57645(%rip), %rsi     # 0xbbef1
movq %rax, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x31a38
movq %rax, %rdi
callq 0x627e8
movl 0xa9add(%rip), %edi     # 0x10e3a4
callq 0x653e7
callq 0x64df5
movq %rbx, %rdi
callq 0x66081
cmpl $-0x1, %eax
setne %al
orb %al, %bpl
testb $0x1, %bpl
jne 0x648ff
leaq 0x57624(%rip), %rsi     # 0xbbf13
movq %rbx, %rdi
callq 0x78aec
movq %rbx, %rdi
callq 0x793e7
callq 0x2b8ae
leaq 0x94f9d(%rip), %rcx     # 0xf98a8
movq %rax, 0x9f0(%rcx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq