// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/scripting.c
// Function: ldbStartSession
int ldbStartSession(client *c) {
    ldb.forked = (c->flags & CLIENT_LUA_DEBUG_SYNC) == 0;
    if (ldb.forked) {
        pid_t cp = fork();
        if (cp == -1) {
            addReplyError(c,"Fork() failed: can't run EVAL in debugging mode.");
            return 0;
        } else if (cp == 0) {
            /* Child. Let's ignore important signals handled by the parent. */
            struct sigaction act;
            sigemptyset(&act.sa_mask);
            act.sa_flags = 0;
            act.sa_handler = SIG_IGN;
            sigaction(SIGTERM, &act, NULL);
            sigaction(SIGINT, &act, NULL);

            /* Log the creation of the child and close the listening
             * socket to make sure if the parent crashes a reset is sent
             * to the clients. */
            serverLog(LL_WARNING,"Redis forked for debugging eval");
            closeListeningSockets(0);
        } else {
            /* Parent */
            listAddNodeTail(ldb.children,(void*)(unsigned long)cp);
            freeClientAsync(c); /* Close the client in the parent side. */
            return 0;
        }
    } else {
        serverLog(LL_WARNING,
            "Redis synchronous debugging eval session started");
    }

    /* Setup our debugging session. */
    anetBlock(NULL,ldb.fd);
    anetSendTimeout(NULL,ldb.fd,5000);
    ldb.active = 1;

    /* First argument of EVAL is the script itself. We split it into different
     * lines since this is the way the debugger accesses the source code. */
    sds srcstring = sdsdup(c->argv[1]->ptr);
    size_t srclen = sdslen(srcstring);
    while(srclen && (srcstring[srclen-1] == '\n' ||
                     srcstring[srclen-1] == '\r'))
    {
        srcstring[--srclen] = '\0';
    }
    sdssetlen(srcstring,srclen);
    ldb.src = sdssplitlen(srcstring,sdslen(srcstring),"\n",1,&ldb.lines);
    sdsfree(srcstring);
    return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0xa0, %rsp
movq %rdi, %rbx
movl 0x98(%rdi), %eax
shrl $0x1a, %eax
andl $0x1, %eax
movl %eax, %ecx
xorl $0x1, %ecx
movl %ecx, 0xa9373(%rip)     # 0x10e268
testl %eax, %eax
jne 0x64f1f
callq 0x26ab0
testl %eax, %eax
je 0x64f32
cmpl $-0x1, %eax
jne 0x6502e
leaq 0x56550(%rip), %rsi     # 0xbb462
movq %rbx, %rdi
callq 0x36b6f
jmp 0x65045
leaq 0x5658d(%rip), %rsi     # 0xbb4b3
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
jmp 0x64f86
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x26ac0
andl $0x0, 0x80(%r14)
movq $0x1, -0x8(%r14)
pushq $0xf
popq %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
xorl %edx, %edx
callq 0x266c0
pushq $0x2
popq %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x266c0
leaq 0x5651e(%rip), %rsi     # 0xbb493
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
xorl %edi, %edi
callq 0x2edf6
movl 0xa92d4(%rip), %esi     # 0x10e260
xorl %edi, %edi
callq 0x292a4
movl 0xa92c7(%rip), %esi     # 0x10e260
movl $0x1388, %edx           # imm = 0x1388
xorl %edi, %edi
callq 0x294a4
movl $0x1, 0xa92b5(%rip)     # 0x10e264
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3117b
movq %rax, %rbx
movq %rax, %rdi
callq 0x63370
movq %rax, %rcx
subq $0x1, %rcx
jb 0x64fed
movzbl -0x1(%rbx,%rax), %edx
cmpl $0xd, %edx
je 0x64fe3
cmpl $0xa, %edx
jne 0x64fed
movb $0x0, -0x1(%rbx,%rax)
movq %rcx, %rax
jmp 0x64fce
movq %rbx, %rdi
movq %rax, %rsi
callq 0x63338
movq %rbx, %rdi
callq 0x63370
leaq 0x4bdb2(%rip), %rdx     # 0xb0db9
leaq 0xa9392(%rip), %r8      # 0x10e3a0
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %eax, %esi
movl %ebp, %ecx
callq 0x32003
movq %rax, 0xa9374(%rip)     # 0x10e398
movq %rbx, %rdi
callq 0x311c8
jmp 0x65047
movq 0xa924b(%rip), %rdi     # 0x10e280
movslq %eax, %rsi
callq 0x26ecc
movq %rbx, %rdi
callq 0x378cf
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %rbp
retq