// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x278, %rsp            # imm = 0x278
movq %rdi, 0x270(%rsp)
movl %esi, 0x26c(%rsp)
movl %edx, 0x268(%rsp)
leaq 0xa429c(%rip), %rax     # 0xeeff0
movq (%rax), %rsi
leaq 0x258(%rsp), %rdi
xorl %edx, %edx
callq 0xfbc0
movl $0x0, 0x254(%rsp)
movq 0x270(%rsp), %rdi
callq 0x101d0
movb %al, 0xfe(%rsp)
jmp 0x4ad87
movb 0xfe(%rsp), %al
andb $0x1, %al
movb %al, 0x253(%rsp)
movq 0x270(%rsp), %rsi
leaq 0x220(%rsp), %rdi
callq 0x10af0
jmp 0x4adae
leaq 0x258(%rsp), %rdi
callq 0xfd00
movl 0xcc(%rax), %eax
movl %eax, 0x21c(%rsp)
leaq 0x1f7(%rsp), %rdi
movq %rdi, 0xf0(%rsp)
callq 0xdc30
movq 0xf0(%rsp), %rdx
leaq 0x752ab(%rip), %rsi     # 0xc0097
leaq 0x1f8(%rsp), %rdi
callq 0xdad0
jmp 0x4adfb
leaq 0xa431e(%rip), %rdi     # 0xef120
leaq 0x1f8(%rsp), %rsi
callq 0x23b70
movq %rax, 0xe8(%rsp)
jmp 0x4ae19
movq 0xe8(%rsp), %rdi
movq 0x270(%rsp), %rsi
callq 0x24010
movq %rax, 0xe0(%rsp)
jmp 0x4ae38
movq 0xe0(%rsp), %rdi
callq 0x240c0
jmp 0x4ae47
leaq 0x1f8(%rsp), %rdi
callq 0xdf50
leaq 0x1f7(%rsp), %rdi
callq 0xdf30
leaq 0x258(%rsp), %rdi
callq 0xfd00
cmpl $0x0, 0xbc(%rax)
je 0x4b71f
leaq 0xa416e(%rip), %rax     # 0xeeff0
movq (%rax), %rax
movq %rax, 0xd8(%rsp)
leaq 0x258(%rsp), %rdi
callq 0xfd00
movq 0xd8(%rsp), %rsi
movl 0xbc(%rax), %edx
leaq 0x1e0(%rsp), %rdi
callq 0xfbc0
jmp 0x4aeb7
leaq 0x258(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x44cf0
leaq 0x1e0(%rsp), %rdi
callq 0xfd10
movl 0x254(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x254(%rsp)
movl 0x254(%rsp), %eax
cmpl 0x26c(%rsp), %eax
jl 0x4b703
movl 0x254(%rsp), %eax
cmpl 0x268(%rsp), %eax
jg 0x4b703
movq 0x270(%rsp), %rdi
leaq 0x7514b(%rip), %rsi     # 0xc006c
xorl %eax, %eax
callq 0xb1bf0
jmp 0x4af2a
movq 0x270(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0x258(%rsp), %rdi
callq 0xfd00
movq %rax, 0xd0(%rsp)
movzbl 0x253(%rsp), %eax
movl %eax, 0xc4(%rsp)
leaq 0x220(%rsp), %rdi
callq 0xd190
movl 0xc4(%rsp), %ecx
movq 0xc8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq %rax, %r9
andl $0x1, %ecx
leaq 0x7abbc(%rip), %r8      # 0xc5b4b
movl $0x16, %edx
callq 0x3fe90
jmp 0x4af9b
movl $0xa, %edi
callq 0xd650
movq %rax, 0xb8(%rsp)
jmp 0x4afaf
movq 0xb8(%rsp), %rax
movq %rax, 0x1d8(%rsp)
movq 0x1d8(%rsp), %rax
movq %rax, 0xb0(%rsp)
leaq 0x258(%rsp), %rdi
callq 0xfd00
movq 0xb0(%rsp), %rdi
movq %rax, %rsi
addq $0x91, %rsi
callq 0xd580
leaq 0x1c8(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x4cc00
leaq 0x258(%rsp), %rdi
callq 0xfd00
cmpl $0x0, 0xc4(%rax)
je 0x4b6c4
leaq 0x1b8(%rsp), %rdi
leaq 0x258(%rsp), %rsi
movq %rsi, 0xa0(%rsp)
callq 0x4cc00
movq 0xa0(%rsp), %rdi
leaq 0xa3fa2(%rip), %rax     # 0xeeff0
movq (%rax), %rax
movq %rax, 0xa8(%rsp)
callq 0xfd00
movq 0xa8(%rsp), %rsi
movl 0xc4(%rax), %edx
leaq 0x1a8(%rsp), %rdi
callq 0xfbc0
jmp 0x4b07b
leaq 0x1b8(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x44cf0
movq %rax, %rsi
leaq 0x258(%rsp), %rdi
callq 0x4cc30
leaq 0x1a8(%rsp), %rdi
callq 0xfd10
leaq 0x190(%rsp), %rdi
callq 0x4cc60
movl $0x1, 0x18c(%rsp)
cmpl $0x4, 0x18c(%rsp)
jg 0x4b24f
leaq 0xa3f16(%rip), %rax     # 0xeeff0
movq (%rax), %rax
movq %rax, 0x98(%rsp)
leaq 0x258(%rsp), %rdi
callq 0xfd00
movq 0x98(%rsp), %rsi
movl 0xc0(%rax), %edx
leaq 0x178(%rsp), %rdi
callq 0xfbc0
jmp 0x4b10f
leaq 0x258(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x44cf0
leaq 0x178(%rsp), %rdi
callq 0xfd10
leaq 0x258(%rsp), %rdi
callq 0xfd00
movl 0xb8(%rax), %eax
movl %eax, 0x94(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0xfd00
movq %rax, %rcx
movl 0x94(%rsp), %eax
cmpl 0xb8(%rcx), %eax
je 0x4b248
leaq 0x190(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x4cc70
jmp 0x4b185
movl 0x18c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18c(%rsp)
jmp 0x4b24a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b74e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b1eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0xdf50
leaq 0x1f7(%rsp), %rdi
callq 0xdf30
jmp 0x4b741
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b741
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b6a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b69b
jmp 0x4b24f
jmp 0x4b0c5
leaq 0x190(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x4cc70
jmp 0x4b266
leaq 0x1b8(%rsp), %rdi
callq 0xfd00
cmpl $0x5, 0xcc(%rax)
jg 0x4b349
leaq 0x190(%rsp), %rdi
callq 0x4cce0
subq $0x1, %rax
movl %eax, 0x174(%rsp)
cmpl $0x0, 0x174(%rsp)
jl 0x4b344
movq 0x270(%rsp), %rax
movq %rax, 0x78(%rsp)
movslq 0x174(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x4cd00
movq %rax, %rdi
callq 0xfd00
movq %rax, 0x80(%rsp)
movq 0x1d8(%rsp), %rax
movq %rax, 0x88(%rsp)
movzbl 0x253(%rsp), %eax
movl %eax, 0x74(%rsp)
leaq 0x220(%rsp), %rdi
callq 0xd190
movl 0x74(%rsp), %ecx
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %r8
movq %rax, %r9
andl $0x1, %ecx
movl $0x5, %edx
callq 0x3fe90
jmp 0x4b32c
jmp 0x4b32e
movl 0x174(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x174(%rsp)
jmp 0x4b298
jmp 0x4b67f
leaq 0x190(%rsp), %rdi
callq 0x4cce0
subq $0x1, %rax
movl %eax, 0x170(%rsp)
cmpl $0x0, 0x170(%rsp)
jl 0x4b67d
movq 0x270(%rsp), %rax
movq %rax, 0x58(%rsp)
movslq 0x170(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x4cd00
movq %rax, %rdi
callq 0xfd00
movq %rax, 0x60(%rsp)
movq 0x1d8(%rsp), %rax
movq %rax, 0x68(%rsp)
movzbl 0x253(%rsp), %eax
movl %eax, 0x54(%rsp)
leaq 0x220(%rsp), %rdi
callq 0xd190
movl 0x54(%rsp), %ecx
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %r8
movq %rax, %r9
andl $0x1, %ecx
movl $0x5, %edx
callq 0x3fe90
jmp 0x4b3e9
movslq 0x170(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x4cce0
movq %rax, %rcx
movq 0x48(%rsp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x4b665
leaq 0x14f(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xdc30
movq 0x40(%rsp), %rdx
leaq 0x74d1e(%rip), %rsi     # 0xc0154
leaq 0x150(%rsp), %rdi
callq 0xdad0
jmp 0x4b445
leaq 0xa3cd4(%rip), %rdi     # 0xef120
leaq 0x150(%rsp), %rsi
callq 0x23b70
movq %rax, 0x38(%rsp)
jmp 0x4b460
leaq 0x127(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xdc30
movq 0x30(%rsp), %rdx
leaq 0x748c0(%rip), %rsi     # 0xbfd3e
leaq 0x128(%rsp), %rdi
callq 0xdad0
jmp 0x4b48d
leaq 0x1c8(%rsp), %rdi
callq 0xfd00
movq 0x38(%rsp), %rdi
movl 0xb8(%rax), %edx
leaq 0x128(%rsp), %rsi
callq 0x24100
movq %rax, 0x28(%rsp)
jmp 0x4b4b9
leaq 0xff(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0xdc30
movq 0x20(%rsp), %rdx
leaq 0x74c93(%rip), %rsi     # 0xc016a
leaq 0x100(%rsp), %rdi
callq 0xdad0
jmp 0x4b4e6
leaq 0x1b8(%rsp), %rdi
callq 0xfd00
movq 0x28(%rsp), %rdi
movl 0xcc(%rax), %edx
addl $-0x5, %edx
leaq 0x100(%rsp), %rsi
callq 0x24100
movq %rax, 0x18(%rsp)
jmp 0x4b515
movq 0x18(%rsp), %rdi
movq 0x270(%rsp), %rsi
callq 0x24010
movq %rax, 0x10(%rsp)
jmp 0x4b52e
movq 0x10(%rsp), %rdi
callq 0x240c0
jmp 0x4b53a
leaq 0x100(%rsp), %rdi
callq 0xdf50
leaq 0xff(%rsp), %rdi
callq 0xdf30
leaq 0x128(%rsp), %rdi
callq 0xdf50
leaq 0x127(%rsp), %rdi
callq 0xdf30
leaq 0x150(%rsp), %rdi
callq 0xdf50
leaq 0x14f(%rsp), %rdi
callq 0xdf30
jmp 0x4b665
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b656
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b649
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b63c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b62f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x4b622
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xdf50
leaq 0xff(%rsp), %rdi
callq 0xdf30
leaq 0x128(%rsp), %rdi
callq 0xdf50
leaq 0x127(%rsp), %rdi
callq 0xdf30
leaq 0x150(%rsp), %rdi
callq 0xdf50
leaq 0x14f(%rsp), %rdi
callq 0xdf30
jmp 0x4b69b
jmp 0x4b667
movl 0x170(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x170(%rsp)
jmp 0x4b361
jmp 0x4b67f
leaq 0x190(%rsp), %rdi
callq 0x4cd20
leaq 0x1b8(%rsp), %rdi
callq 0xfd10
jmp 0x4b6c4
leaq 0x190(%rsp), %rdi
callq 0x4cd20
leaq 0x1b8(%rsp), %rdi
callq 0xfd10
leaq 0x1c8(%rsp), %rdi
callq 0xfd10
jmp 0x4b741
leaq 0x258(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x4cc30
movq 0x1d8(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x4b6f6
movq 0x8(%rsp), %rdi
callq 0xd4d0
leaq 0x1c8(%rsp), %rdi
callq 0xfd10
movl 0x254(%rsp), %eax
movl 0x268(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x4b71a
jmp 0x4b71f
jmp 0x4ae61
leaq 0x220(%rsp), %rdi
callq 0xdf50
leaq 0x258(%rsp), %rdi
callq 0xfd10
addq $0x278, %rsp            # imm = 0x278
retq
leaq 0x220(%rsp), %rdi
callq 0xdf50
leaq 0x258(%rsp), %rdi
callq 0xfd10
movq 0x248(%rsp), %rdi
callq 0xd8a0
nopl (%rax,%rax)