// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movl %esi, 0x2c(%rsp)
movq %rdi, %r12
leaq 0x646bb(%rip), %rax     # 0x87c18
movq (%rax), %rsi
leaq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0xdeda
movq %r12, %rdi
callq 0xe080
movl %eax, %ebx
leaq 0x98(%rsp), %rdi
movq %r12, %rsi
callq 0xe580
leaq 0x3eb3a(%rip), %rsi     # 0x620c7
leaq 0x78(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
callq 0xcb10
movl %ebp, 0x24(%rsp)
leaq 0x6479e(%rip), %rdi     # 0x87d48
leaq 0x78(%rsp), %rsi
callq 0x14fb0
movq %rax, %rdi
movq %r12, %rsi
callq 0x151b6
movq %rax, %rdi
callq 0x15224
leaq 0x78(%rsp), %r13
movq %r13, %rdi
callq 0xcd88
movzbl %bl, %eax
movl %eax, 0x8(%rsp)
leaq 0x60(%rsp), %rbx
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
movl 0xbc(%rax), %edx
testl %edx, %edx
je 0x23972
leaq 0x6461b(%rip), %rax     # 0x87c18
movq (%rax), %rsi
movq %r13, %rdi
callq 0xdeda
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x2089a
leaq 0x80(%rsp), %rdi
callq 0xdf66
leal 0x1(%r14), %edx
cmpl 0x2c(%rsp), %edx
setl %al
movl 0x24(%rsp), %esi
cmpl %esi, %r14d
setge %cl
orb %al, %cl
jne 0x23966
movl %edx, 0x28(%rsp)
movq %r12, %rdi
leaq 0x3ea4f(%rip), %rsi     # 0x6209c
xorl %eax, %eax
callq 0x59649
movq 0x10(%rsp), %rsi
movq 0x98(%rsp), %r9
movq %r12, %rdi
pushq $0x16
popq %rdx
movl 0x8(%rsp), %ecx
leaq 0x43fe0(%rip), %r8      # 0x67652
callq 0x1e914
pushq $0xa
popq %rdi
callq 0xc560
movq %rax, %rbp
movq 0x10(%rsp), %rsi
movl $0x91, %eax
addq %rax, %rsi
movq %rbp, %rdi
callq 0xc490
movq %rbx, %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x243bc
movq 0x10(%rsp), %rax
cmpl $0x0, 0xc4(%rax)
je 0x2393c
movq %r14, 0x70(%rsp)
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x243bc
leaq 0x64543(%rip), %rax     # 0x87c18
movq (%rax), %rsi
movq 0x10(%rsp), %rax
movl 0xc4(%rax), %edx
movq %r13, %rdi
callq 0xdeda
movq %r14, %rdi
movq %r13, %r15
movq %r13, %rsi
callq 0x2089a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x243f0
leaq 0x80(%rsp), %rdi
callq 0xdf66
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
pushq $0x4
popq %rbx
leaq 0x30(%rsp), %r14
subl $0x1, %ebx
jb 0x2378d
leaq 0x644e5(%rip), %rax     # 0x87c18
movq (%rax), %rsi
movq 0x10(%rsp), %rax
movl 0xc0(%rax), %edx
movq %r15, %r13
movq %r15, %rdi
callq 0xdeda
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x2089a
leaq 0x80(%rsp), %rdi
callq 0xdf66
movq 0x10(%rsp), %rax
movl 0xb8(%rax), %eax
movq 0x50(%rsp), %rcx
cmpl 0xb8(%rcx), %eax
je 0x2378d
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x2436e
jmp 0x23727
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
callq 0x2436e
movq 0x50(%rsp), %rax
movq 0x38(%rsp), %rcx
subq 0x30(%rsp), %rcx
shrq $0x4, %rcx
cmpl $0x6, 0xcc(%rax)
movl %ecx, %r14d
jge 0x237f9
decq %r14
testl %r14d, %r14d
js 0x2391b
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x30(%rsp), %rcx
shlq $0x4, %rax
movq (%rcx,%rax), %rsi
movq 0x98(%rsp), %r9
decq %r14
movq %r12, %rdi
pushq $0x5
popq %rdx
movl 0x8(%rsp), %ecx
movq %rbp, %r8
callq 0x1e914
jmp 0x237bc
decq %r14
testl %r14d, %r14d
js 0x2391b
movl %r14d, %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq 0x30(%rsp), %rax
movq %rbx, %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rsi
movq 0x98(%rsp), %r9
movq %r12, %rdi
pushq $0x5
popq %rdx
movl 0x8(%rsp), %ecx
movq %rbp, %r8
callq 0x1e914
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
sarq $0x4, %rax
decq %rax
cmpq %rbx, %rax
jne 0x237f9
movq %r15, %rbx
movq %r15, %rdi
leaq 0x3e929(%rip), %rsi     # 0x62184
leaq 0xf(%rsp), %rdx
callq 0xcb10
leaq 0x644dc(%rip), %rdi     # 0x87d48
movq %rbx, %rsi
callq 0x14fb0
movq %rax, %rbx
leaq 0xb8(%rsp), %r13
movq %r13, %rdi
leaq 0x3e4e7(%rip), %rsi     # 0x61d70
leaq 0xe(%rsp), %rdx
callq 0xcb10
movq 0x60(%rsp), %rax
movl 0xb8(%rax), %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x15236
movq %rax, %rbx
leaq 0xd8(%rsp), %r13
movq %r13, %rdi
leaq 0x3e8dc(%rip), %rsi     # 0x6219a
leaq 0xd(%rsp), %rdx
callq 0xcb10
movq 0x50(%rsp), %rax
movl 0xcc(%rax), %edx
addl $-0x5, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x15236
movq %rax, %rdi
movq %r12, %rsi
callq 0x151b6
movq %rax, %rdi
callq 0x15224
leaq 0xd8(%rsp), %rdi
callq 0xcd88
leaq 0xb8(%rsp), %rdi
callq 0xcd88
movq %r15, %rdi
callq 0xcd88
jmp 0x237f9
leaq 0x30(%rsp), %rdi
callq 0x2439a
leaq 0x58(%rsp), %rdi
callq 0xdf66
leaq 0x10(%rsp), %rbx
movq %r15, %r13
movq 0x70(%rsp), %r14
movq %rbx, %rdi
leaq 0x60(%rsp), %rbx
movq %rbx, %rsi
callq 0x243f0
movq %rbp, %rdi
callq 0xc400
leaq 0x68(%rsp), %rdi
callq 0xdf66
movl 0x28(%rsp), %edx
movl 0x24(%rsp), %esi
cmpl %esi, %r14d
movl %edx, %r14d
jne 0x235e3
leaq 0x98(%rsp), %rdi
callq 0xcd88
leaq 0x18(%rsp), %rdi
callq 0xdf66
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x239c1
jmp 0x2399f
movq %rax, %rbx
jmp 0x23a33
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xcd88
jmp 0x23a26
movq %rax, %rbx
jmp 0x23a12
jmp 0x23a05
jmp 0x239c1
jmp 0x239c1
movq %rax, %rbx
jmp 0x23a26
jmp 0x239d1
jmp 0x239ca
movq %rax, %rbx
jmp 0x239e8
jmp 0x23a05
movq %rax, %rbx
jmp 0x239f5
jmp 0x23a05
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0xcd88
leaq 0xb8(%rsp), %rdi
callq 0xcd88
leaq 0x78(%rsp), %rdi
callq 0xcd88
jmp 0x23a08
jmp 0x23a05
jmp 0x23a05
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2439a
leaq 0x58(%rsp), %rdi
callq 0xdf66
leaq 0x68(%rsp), %rdi
callq 0xdf66
leaq 0x98(%rsp), %rdi
callq 0xcd88
leaq 0x18(%rsp), %rdi
callq 0xdf66
movq %rbx, %rdi
callq 0xc790