// File: /workspace/github_c_makefile_star2_O3/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 0x6bebe(%rip), %rax     # 0x94bf8
movq (%rax), %rsi
movq %rsp, %rdi
xorl %edx, %edx
callq 0xecde
movq %r14, %rdi
callq 0xef14
movl %eax, %ebx
leaq 0xd8(%rsp), %rdi
movq %r14, %rsi
callq 0xf5d5
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x49356(%rip), %rsi     # 0x720c7
leaq 0x4935a(%rip), %rdx     # 0x720d2
leaq 0x20(%rsp), %rdi
callq 0xedf0
leaq 0x6bf9f(%rip), %rdi     # 0x94d28
leaq 0x20(%rsp), %rsi
callq 0x181be
movq %rax, %rdi
movq %r14, %rsi
callq 0x18304
movq %rax, %r15
movq %rax, %rdi
callq 0x19de2
movq %r15, %rdi
callq 0xc640
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x28dc5
callq 0xc640
leaq 0x20(%rsp), %r12
movzbl %bl, %eax
movl %eax, 0x1c(%rsp)
xorl %r15d, %r15d
leaq 0x6be1d(%rip), %rbx     # 0x94bf8
movl %r13d, 0x74(%rsp)
movq (%rsp), %rax
movl 0xbc(%rax), %edx
testl %edx, %edx
je 0x29296
movq (%rbx), %rsi
movq %r12, %rdi
callq 0xecde
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0x8(%rsp), %rdi
movaps %xmm0, (%rsp)
testq %rdi, %rdi
je 0x28e2c
callq 0xed76
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x28e2c
callq 0xed76
leal 0x1(%r15), %edx
cmpl 0x7c(%rsp), %edx
setl %al
cmpl %r13d, %r15d
setge %cl
orb %al, %cl
jne 0x2928a
movl %edx, 0x78(%rsp)
movq %r14, %rdi
leaq 0x49249(%rip), %rsi     # 0x7209c
xorl %eax, %eax
callq 0x68533
movq (%rsp), %rsi
movq 0xd8(%rsp), %r9
movq %r14, %rdi
movl $0x16, %edx
movl 0x1c(%rsp), %ecx
leaq 0x4e7f9(%rip), %r8      # 0x77672
callq 0x22fc8
movq %r15, 0x90(%rsp)
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
je 0x28edb
movq 0x6b0ff(%rip), %rcx     # 0x93fc8
cmpb $0x0, (%rcx)
je 0x28ed3
incl 0x8(%rax)
jmp 0x28edb
lock
incl 0x8(%rax)
movq (%rsp), %r15
cmpl $0x0, 0xc4(%r15)
je 0x2923d
movq %r15, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x28f16
movq 0x6b0c4(%rip), %rcx     # 0x93fc8
cmpb $0x0, (%rcx)
je 0x28f0e
incl 0x8(%rax)
jmp 0x28f16
lock
incl 0x8(%rax)
movq (%rsp), %r15
leaq 0x6bcdb(%rip), %rax     # 0x94bf8
movq (%rax), %rsi
movl 0xc4(%r15), %edx
movq %r12, %rdi
callq 0xecde
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
movq %rcx, 0x48(%rsp)
testq %rdi, %rdi
movq %rsp, %rbx
je 0x28f62
callq 0xed76
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2a0e6
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
leaq 0x6bc74(%rip), %r15     # 0x94bf8
je 0x28f8b
callq 0xed76
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 0xecde
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0x8(%rsp), %rdi
movaps %xmm0, (%rsp)
testq %rdi, %rdi
je 0x28fe7
callq 0xed76
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x28fe7
callq 0xed76
movq (%rsp), %rax
movl 0xb8(%rax), %eax
movq 0x40(%rsp), %rcx
cmpl 0xb8(%rcx), %eax
je 0x2900f
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x2a05a
decl %ebp
jne 0x28fa1
leaq 0x50(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2a05a
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
movq 0x40(%rsp), %rcx
shrq $0x4, %rax
cmpl $0x5, 0xcc(%rcx)
leaq 0x20(%rsp), %r12
jg 0x29086
movl %eax, %r15d
decq %r15
testl %r15d, %r15d
js 0x2921f
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 0x22fc8
jmp 0x29045
decl %eax
js 0x2921f
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 0x22fc8
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
leaq -0x1(%r15), %rcx
sarq $0x4, %rax
decq %rax
cmpq %rax, %rcx
jne 0x29212
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r12, %rdi
leaq 0x49092(%rip), %rsi     # 0x72184
leaq 0x490a0(%rip), %rdx     # 0x72199
callq 0xedf0
movq %r14, %rbx
leaq 0x6bc20(%rip), %rdi     # 0x94d28
movq %r12, %rsi
callq 0x181be
movq %rax, %rbp
leaq 0xc8(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
leaq 0x48c41(%rip), %rsi     # 0x71d76
leaq 0x48c43(%rip), %rdx     # 0x71d7f
callq 0xedf0
movq 0x80(%rsp), %rax
movl 0xb8(%rax), %edx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x18388
movq %rax, %rbp
leaq 0xa8(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x98(%rsp), %r12
movq %r12, %rdi
leaq 0x4901b(%rip), %rsi     # 0x7219a
leaq 0x49026(%rip), %rdx     # 0x721ac
callq 0xedf0
movq %rbx, %r14
movq 0x40(%rsp), %rax
movl 0xcc(%rax), %edx
addl $-0x5, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x18388
movq %rax, %rdi
movq %r14, %rsi
callq 0x18304
movq %rax, %rbp
movq %rax, %rdi
callq 0x19de2
movq %rbp, %rdi
callq 0xc640
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x291df
callq 0xc640
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
leaq 0x20(%rsp), %r12
je 0x291fe
callq 0xc640
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x29212
callq 0xc640
addq $-0x10, %r13
decq %r15
jg 0x29099
leaq 0x50(%rsp), %rdi
callq 0x2a0a0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x29238
callq 0xed76
movl 0x74(%rsp), %r13d
movq 0x80(%rsp), %rax
movq %rax, (%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x2a0e6
movq 0x68(%rsp), %rdi
callq 0xc400
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x29277
callq 0xed76
leaq 0x6b97a(%rip), %rbx     # 0x94bf8
movq 0x90(%rsp), %r15
movl 0x78(%rsp), %edx
cmpl %r13d, %r15d
movl %edx, %r15d
jne 0x28de0
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x292ac
callq 0xc640
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x292bb
callq 0xed76
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x29304
jmp 0x292d1
movq %rax, %rbx
jmp 0x293b3
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2939d
callq 0xc640
jmp 0x2939d
movq %rax, %rbx
jmp 0x2937c
jmp 0x2936f
jmp 0x29304
jmp 0x29304
movq %rax, %rbx
jmp 0x2939d
jmp 0x29310
jmp 0x29317
movq %rax, %rbx
jmp 0x29355
jmp 0x2936f
movq %rax, %rbx
jmp 0x2933b
jmp 0x2936f
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x2933b
callq 0xc640
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x29355
callq 0xc640
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x29372
callq 0xc640
jmp 0x29372
jmp 0x2936f
jmp 0x2936f
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x2a0a0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x2938b
callq 0xed76
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2939d
callq 0xed76
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x293b3
callq 0xc640
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x293c2
callq 0xed76
movq %rbx, %rdi
callq 0xc760