// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./src/views/list/timeline.cpp
// Function: views::timeline::showThreads(mg_connection*, int, int)
void showThreads(mg_connection* conn, int startID, int endID){
            //struct Thread *r = unq_read_thread(pDb, 0); // get the root thread
            auto r = unq_read_thread_sp(pDb, 0);
            int c = 0;

            bool admin_view = is_admin(conn);
            string username = cck_verify_ssid(conn);

            int totalThreads = r.get()->childCount;

            templates.invoke("site_slogan").pipe_to(conn).destory();

            while (r.get()->nextThread){
                // int tmpid = r->nextThread;
                // delete r;
                // r = unq_read_thread(pDb, tmpid);
                r = unq_read_thread_sp(pDb, r.get()->nextThread);
                c++;

                if (c >= startID && c <= endID){
                    mg_printf_data(conn, "<hr>");
                    views::each_thread(conn, r.get(), SEND_SHOW_REPLY_LINK + SEND_CUT_LONG_COMMENT + SEND_CUT_REPLY_COUNT, admin_view, "", username.c_str());

                    char *iid = new char[10];
                    strcpy(iid, r.get()->ssid);

                    // struct Thread *oldr = r;
                    auto oldr = r;

                    if (r.get()->childThread) {
                        // struct Thread* first_thread;
                        // first_thread = unq_read_thread(pDb, r->childThread); // beginning of the circle
                        // r = first_thread;
                        // vector<struct Thread *> vt;
                        auto first_thread = r;
                        r = first_thread = unq_read_thread_sp(pDb, r.get()->childThread);
                        vector<decltype(r)> vt;

                        int i = 1;
                        while(i <= 4){
                            r = unq_read_thread_sp(pDb, r.get()->prevThread);

                            if(r.get()->threadID != first_thread.get()->threadID) {
                                vt.push_back(r);
                                i++;
                            }else
                                break;
                        }

                        vt.push_back(first_thread);

                        if(first_thread.get()->childCount <= 5)
                        {
                            for (int i = vt.size() - 1; i >= 0; i--)
                            {
                                views::each_thread(conn, vt[i].get(), 
                                    SEND_IS_REPLY + SEND_CUT_LONG_COMMENT, admin_view, iid, username.c_str());
                                // delete vt[i];
                            }
                        }
                        else
                        {
                            for (int i = vt.size() - 1; i >= 0; i--){
                                views::each_thread(conn, vt[i].get(), SEND_IS_REPLY + SEND_CUT_LONG_COMMENT, admin_view, iid, username.c_str());
                                // delete vt[i];
                                if(i == vt.size() - 1){
                                    templates.invoke("expand_hidden_replies") \
                                        .var("THREAD_NO", oldr.get()->threadID) \
                                        .var("NUM_HIDDEN_REPLIES", first_thread.get()->childCount - 5) \
                                        .pipe_to(conn).destory();
                                }
                            }
                        }

                    }

                    r = oldr;
                    delete [] iid;
                }
                
                if (c == endID + 1) break;
            }

            // if(r) delete r;
        }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %edx, %r13d
movl %esi, 0x7c(%rsp)
movq %rdi, %r14
leaq 0x6dafe(%rip), %rax     # 0x96bf8
movq (%rax), %rsi
movq %rsp, %rdi
xorl %edx, %edx
callq 0xece8
movq %r14, %rdi
callq 0xef24
movl %eax, %ebx
leaq 0xd8(%rsp), %rdi
movq %r14, %rsi
callq 0xf5d8
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4afa6(%rip), %rsi     # 0x740d7
leaq 0x4afaa(%rip), %rdx     # 0x740e2
leaq 0x20(%rsp), %rdi
callq 0xedfa
leaq 0x6dbdf(%rip), %rdi     # 0x96d28
leaq 0x20(%rsp), %rsi
callq 0x1852c
movq %rax, %rdi
movq %r14, %rsi
callq 0x18672
movq %rax, %r15
movq %rax, %rdi
callq 0x1a17a
movq %r15, %rdi
callq 0xc640
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x29185
callq 0xc640
leaq 0x20(%rsp), %r12
movzbl %bl, %eax
movl %eax, 0x1c(%rsp)
xorl %ecx, %ecx
leaq 0x6da5e(%rip), %r15     # 0x96bf8
movl %r13d, 0x74(%rsp)
movq (%rsp), %rax
movl 0xbc(%rax), %edx
testl %edx, %edx
je 0x29657
movq %rcx, 0x90(%rsp)
movq (%r15), %rsi
movq %r12, %rdi
callq 0xece8
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0x8(%rsp), %rdi
movaps %xmm0, (%rsp)
testq %rdi, %rdi
je 0x291e4
callq 0xed80
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x291f3
callq 0xed80
movq 0x90(%rsp), %rdx
leal 0x1(%rdx), %esi
cmpl 0x7c(%rsp), %esi
setl %al
cmpl %r13d, %edx
setge %cl
orb %al, %cl
jne 0x2964c
movl %esi, 0x78(%rsp)
movq %r14, %rdi
leaq 0x4ae8b(%rip), %rsi     # 0x740ac
xorl %eax, %eax
callq 0x6a0f7
movq (%rsp), %rsi
movq 0xd8(%rsp), %r9
movq %r14, %rdi
movl $0x16, %edx
movl 0x1c(%rsp), %ecx
leaq 0x50420(%rip), %r8      # 0x79667
callq 0x2331c
movl $0xa, %edi
callq 0xc560
movq (%rsp), %r15
leaq 0x91(%r15), %rsi
movq %rax, 0x68(%rsp)
movq %rax, %rdi
callq 0xc490
movq %r15, 0x80(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x88(%rsp)
testq %rax, %rax
leaq 0x6d96b(%rip), %r15     # 0x96bf8
je 0x292a4
movq 0x6cd32(%rip), %rcx     # 0x95fc8
cmpb $0x0, (%rcx)
je 0x292a0
incl 0x8(%rax)
jmp 0x292a4
lock
incl 0x8(%rax)
movq (%rsp), %rax
cmpl $0x0, 0xc4(%rax)
je 0x29606
movq %rax, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x292de
movq 0x6ccf8(%rip), %rcx     # 0x95fc8
cmpb $0x0, (%rcx)
je 0x292da
incl 0x8(%rax)
jmp 0x292de
lock
incl 0x8(%rax)
movq (%r15), %rsi
movq (%rsp), %rax
movl 0xc4(%rax), %edx
movq %r12, %rdi
callq 0xece8
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0x48(%rsp), %rdi
movaps %xmm0, 0x40(%rsp)
testq %rdi, %rdi
movq %rsp, %rbx
je 0x29317
callq 0xed80
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2a4ae
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2933e
callq 0xed80
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movl $0x4, %ebp
movq (%r15), %rsi
movq (%rsp), %rax
movl 0xc0(%rax), %edx
leaq 0x20(%rsp), %rdi
callq 0xece8
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0x8(%rsp), %rdi
movaps %xmm0, (%rsp)
testq %rdi, %rdi
je 0x2938b
callq 0xed80
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2939a
callq 0xed80
movq (%rsp), %rax
movl 0xb8(%rax), %eax
movq 0x40(%rsp), %rcx
cmpl 0xb8(%rcx), %eax
je 0x293c2
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x2a42e
decl %ebp
jne 0x29354
leaq 0x50(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2a42e
movq 0x40(%rsp), %rax
cmpl $0x5, 0xcc(%rax)
movq 0x50(%rsp), %rcx
leaq 0x20(%rsp), %r12
jg 0x2943c
movq 0x58(%rsp), %rax
subq %rcx, %rax
shrq $0x4, %rax
movl %eax, %r15d
decq %r15
testl %r15d, %r15d
js 0x295e1
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x50(%rsp), %rcx
shlq $0x4, %rax
movq (%rcx,%rax), %rsi
movq 0xd8(%rsp), %r9
decq %r15
movq %r14, %rdi
movl $0x5, %edx
movl 0x1c(%rsp), %ecx
movq 0x68(%rsp), %r8
callq 0x2331c
jmp 0x293fb
movq 0x58(%rsp), %rax
subq %rcx, %rax
shrq $0x4, %rax
decl %eax
js 0x295e1
movl %eax, %r13d
leaq 0x1(%r13), %r15
shlq $0x4, %r13
movq 0x50(%rsp), %rax
movq (%rax,%r13), %rsi
movq 0xd8(%rsp), %r9
movq %r14, %rdi
movl $0x5, %edx
movl 0x1c(%rsp), %ecx
movq 0x68(%rsp), %r8
callq 0x2331c
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
leaq -0x1(%r15), %rcx
sarq $0x4, %rax
decq %rax
cmpq %rax, %rcx
jne 0x295d4
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r12, %rdi
leaq 0x4ace0(%rip), %rsi     # 0x74194
leaq 0x4acee(%rip), %rdx     # 0x741a9
callq 0xedfa
movq %r14, %rbx
leaq 0x6d85e(%rip), %rdi     # 0x96d28
movq %r12, %rsi
callq 0x1852c
movq %rax, %rbp
leaq 0xc8(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
leaq 0x4a885(%rip), %rsi     # 0x73d7c
leaq 0x4a887(%rip), %rdx     # 0x73d85
callq 0xedfa
movq 0x80(%rsp), %rax
movl 0xb8(%rax), %edx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x186f6
movq %rax, %rbp
leaq 0xa8(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x98(%rsp), %r12
movq %r12, %rdi
leaq 0x4ac69(%rip), %rsi     # 0x741aa
leaq 0x4ac74(%rip), %rdx     # 0x741bc
callq 0xedfa
movq %rbx, %r14
movq 0x40(%rsp), %rax
movl 0xcc(%rax), %edx
addl $-0x5, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x186f6
movq %rax, %rdi
movq %r14, %rsi
callq 0x18672
movq %rax, %rbp
movq %rax, %rdi
callq 0x1a17a
movq %rbp, %rdi
callq 0xc640
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x295a1
callq 0xc640
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
leaq 0x20(%rsp), %r12
je 0x295c0
callq 0xc640
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x295d4
callq 0xc640
addq $-0x10, %r13
decq %r15
jg 0x2945b
leaq 0x50(%rsp), %rdi
callq 0x2a46e
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x295fa
callq 0xed80
movl 0x74(%rsp), %r13d
leaq 0x6d5f2(%rip), %r15     # 0x96bf8
movq 0x80(%rsp), %rax
movq %rax, (%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x2a4ae
movq 0x68(%rsp), %rdi
callq 0xc400
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x29640
callq 0xed80
movq 0x90(%rsp), %rdx
movl 0x78(%rsp), %esi
cmpl %r13d, %edx
movl %esi, %ecx
jne 0x2919f
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2966d
callq 0xc640
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2967c
callq 0xed80
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x296c5
jmp 0x29692
movq %rax, %rbx
jmp 0x29774
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2975e
callq 0xc640
jmp 0x2975e
movq %rax, %rbx
jmp 0x2973d
jmp 0x29730
jmp 0x296c5
jmp 0x296c5
movq %rax, %rbx
jmp 0x2975e
jmp 0x296d1
jmp 0x296d8
movq %rax, %rbx
jmp 0x29716
jmp 0x29730
movq %rax, %rbx
jmp 0x296fc
jmp 0x29730
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x296fc
callq 0xc640
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x29716
callq 0xc640
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x29733
callq 0xc640
jmp 0x29733
jmp 0x29730
jmp 0x29730
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x2a46e
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x2974c
callq 0xed80
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2975e
callq 0xed80
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29774
callq 0xc640
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x29783
callq 0xed80
movq %rbx, %rdi
callq 0xc760