// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
xorl %esi, %esi
callq 0xaec40
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0xb835e(%rip), %rsi     # 0x14386c
callq 0xaef40
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, 0x1017b4(%rip)    # 0x18ccd4
movl 0x1017ae(%rip), %edi    # 0x18ccd4
callq 0x8c3e0
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x31(%rbp)
jne 0x8b544
cmpl $0x0, 0x101782(%rip)    # 0x18ccc0
setne %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
leaq 0xb8bea(%rip), %rsi     # 0x14414f
callq 0x266c0
cmpq $0x0, %rax
jne 0x8b575
jmp 0x8b6eb
movq -0x10(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x8b604
cmpl $0x0, 0x101733(%rip)    # 0x18ccbc
jne 0x8b604
cmpl $0x0, -0x14(%rbp)
jne 0x8b604
callq 0x2ff70
leaq 0xecc3b(%rip), %rcx     # 0x1781d8
subq 0x9f0(%rcx), %rax
movq %rax, -0x20(%rbp)
leaq 0xecc29(%rip), %rax     # 0x1781d8
cmpq $0x0, 0x9e8(%rax)
je 0x8b5cd
leaq 0xecc18(%rip), %rax     # 0x1781d8
movq 0x9e8(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x8b5d8
movl $0x1388, %eax           # imm = 0x1388
movq %rax, -0x40(%rbp)
jmp 0x8b5d8
movq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jl 0x8b5fd
movl $0x1, -0x18(%rbp)
movl $0x1, 0x1016c1(%rip)    # 0x18ccbc
jmp 0x8b602
jmp 0x8b6eb
jmp 0x8b604
cmpl $0x0, 0x1016b1(%rip)    # 0x18ccbc
jne 0x8b617
cmpl $0x0, -0x14(%rbp)
je 0x8b6eb
leaq 0xb9973(%rip), %rax     # 0x144f91
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x8b649
movl 0x101692(%rip), %edx    # 0x18ccc0
leaq 0xb9980(%rip), %rax     # 0x144fb5
leaq 0xb995f(%rip), %rcx     # 0x144f9b
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x8b65c
cmpl $0x0, -0x18(%rbp)
je 0x8b65a
leaq 0xb996b(%rip), %rax     # 0x144fc1
movq %rax, -0x30(%rbp)
jmp 0x8b65c
movl $0x0, 0x101656(%rip)    # 0x18ccbc
movl $0x0, 0x101650(%rip)    # 0x18ccc0
callq 0x384f0
movq %rax, %rdi
movl 0x101656(%rip), %edx    # 0x18ccd4
movq -0x30(%rbp), %rcx
leaq 0xb9958(%rip), %rsi     # 0x144fe1
movb $0x0, %al
callq 0x395b0
movq %rax, %rdi
callq 0x88530
movl 0x101636(%rip), %edi    # 0x18ccd4
callq 0x8c770
callq 0x8be40
movq -0x8(%rbp), %rdi
callq 0x8d970
cmpl $-0x1, %eax
jne 0x8b6d5
cmpl $0x0, -0x18(%rbp)
je 0x8b6d5
movq -0x8(%rbp), %rdi
leaq 0xb993c(%rip), %rsi     # 0x145003
callq 0xad410
movq -0x8(%rbp), %rdi
callq 0xae670
callq 0x2ff70
movq %rax, %rcx
leaq 0xecaf4(%rip), %rax     # 0x1781d8
movq %rcx, 0x9f0(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)