// File: /workspace/github_c_makefile_star2_O3/erikdubbelboer[P]discnt/src/debug.c
// Function: sigsegvHandler
void sigsegvHandler(int sig, siginfo_t *info, void *secret) {
    ucontext_t *uc = (ucontext_t*) secret;
    sds infostring, clients;
    struct sigaction act;
    UNUSED(info);

    bugReportStart();
    serverLog(LL_WARNING,
        "    Discnt %s crashed by signal: %d", DISCNT_VERSION, sig);
    if (sig == SIGSEGV) {
        serverLog(LL_WARNING,
         "    SIGSEGV caused by address: %p", (void*)info->si_addr);
    }
    serverLog(LL_WARNING,
        "    Failed assertion: %s (%s:%d)", server.assert_failed,
                        server.assert_file, server.assert_line);

    /* Log the stack trace */
    serverLog(LL_WARNING, "--- STACK TRACE");
    logStackTrace(uc);

    /* Log INFO and CLIENT LIST */
    serverLog(LL_WARNING, "--- INFO OUTPUT");
    infostring = genDiscntInfoString("all");
    infostring = sdscatprintf(infostring, "hash_init_value: %u\n",
        dictGetHashFunctionSeed());
    serverLogRaw(LL_WARNING, infostring);
    serverLog(LL_WARNING, "--- CLIENT LIST OUTPUT");
    clients = getAllClientsInfoString();
    serverLogRaw(LL_WARNING, clients);
    sdsfree(infostring);
    sdsfree(clients);

    /* Log the current client */
    logCurrentClient();

    /* Log dump of processor registers */
    logRegisters(uc);

#if defined(HAVE_PROC_MAPS)
    /* Test memory */
    serverLog(LL_WARNING, "--- FAST MEMORY TEST");
    bioKillThreads();
    if (memtest_test_linux_anonymous_maps()) {
        serverLog(LL_WARNING,
            "!!! MEMORY ERROR DETECTED! Check your memory ASAP !!!");
    } else {
        serverLog(LL_WARNING,
            "Fast memory test PASSED, however your memory can still be broken. Please run a memory test for several hours if possible.");
    }
#endif

    serverLog(LL_WARNING,
"\n=== DISCNT BUG REPORT END. Make sure to include from START to END. ===\n\n"
"       Please report the crash by opening an issue on github:\n\n"
"           http://github.com/erikdubbelboer/discnt/issues\n\n"
"  Suspect RAM error? Use discnt-server --test-memory to verify it.\n\n"
);
    /* free(messages); Don't call free() with possibly corrupted memory. */
    if (server.daemonize && server.supervised == 0) unlink(server.pidfile);

    /* Make sure we exit with the right signal at the end. So for instance
     * the core will be dumped if enabled. */
    sigemptyset (&act.sa_mask);
    act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND;
    act.sa_handler = SIG_DFL;
    sigaction (sig, &act, NULL);
    kill(getpid(),sig);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movq %rdx, %r14
movq %rsi, %r15
movl %edi, %ebx
leaq 0x441b2(%rip), %r13     # 0x6f088
cmpl $0x0, 0x694(%r13)
jne 0x2aefe
leaq 0x2b537(%rip), %rsi     # 0x5641e
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
movl $0x1, 0x694(%r13)
leaq 0x2b6b6(%rip), %rsi     # 0x565bb
leaq 0x29208(%rip), %rdx     # 0x54114
movl $0x3, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x19c06
cmpl $0xb, %ebx
jne 0x2af36
movq 0x10(%r15), %rdx
leaq 0x2b6b5(%rip), %rsi     # 0x565df
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
movq 0x680(%r13), %rdx
movq 0x688(%r13), %rcx
movl 0x690(%r13), %r8d
leaq 0x2b6af(%rip), %rsi     # 0x56601
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
leaq 0x2b6bd(%rip), %rsi     # 0x56622
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
movq %r14, %rdi
callq 0x2aa63
leaq 0x2b6b2(%rip), %rsi     # 0x56632
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
leaq 0x2b60a(%rip), %rdi     # 0x5659d
callq 0x1c6d3
movq %rax, %r15
callq 0x1840f
leaq 0x2b69b(%rip), %rsi     # 0x56642
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1e826
movq %rax, %r15
movl $0x3, %edi
movq %rax, %rsi
callq 0x19a92
leaq 0x2b68d(%rip), %rsi     # 0x56657
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
callq 0x23f57
movq %rax, %r12
movl $0x3, %edi
movq %rax, %rsi
callq 0x19a92
movq %r15, %rdi
callq 0x1dc25
movq %r12, %rdi
callq 0x1dc25
callq 0x2aae8
movq %r14, %rdi
callq 0x2a911
leaq 0x2b65f(%rip), %rsi     # 0x5666e
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
callq 0x2f011
callq 0x2aba1
testl %eax, %eax
leaq 0x2b68b(%rip), %rax     # 0x566b9
leaq 0x2b64e(%rip), %rsi     # 0x56683
cmoveq %rax, %rsi
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
leaq 0x2b6e7(%rip), %rsi     # 0x56733
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
cmpl $0x0, 0x5b8(%r13)
je 0x2b075
cmpl $0x0, 0x5b0(%r13)
jne 0x2b075
movq 0x50(%r13), %rdi
callq 0x120f0
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x124e0
movl $0xc8000000, 0x80(%r14) # imm = 0xC8000000
movq $0x0, -0x8(%r14)
leaq 0x8(%rsp), %rsi
movl %ebx, %edi
xorl %edx, %edx
callq 0x12170
callq 0x121f0
movl %eax, %edi
movl %ebx, %esi
callq 0x12530
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq