// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./src/main.cpp
// Function: event_handle(mg_connection*, mg_event)
static int event_handle(struct mg_connection *conn, enum mg_event ev) {
    switch(ev){
        case MG_REQUEST:
            if (conn->is_websocket) {
                websocket::poll(conn);
                return MG_TRUE;
            } 
            else if (strstr(conn->uri, "/assets/")){
                mg_send_file(conn, conn->uri + 1, "");
                return MG_MORE;
            }
            else{
                pair<int, map<string, string>> r = route::route(conn->uri);
                // for(auto i = r.second.begin(); i != r.second.end(); ++i) cout << i->first << "=" << i ->second << endl;
                
                int id;
                struct Thread *tt;

                switch(r.first){
                    case route::POST_THREAD:
                    case route::POST_REPLY:
                        if(!check_ip(conn) || configs.global().get<bool>("archive")) break;
                        actions::post::call(conn, r.first == route::POST_THREAD ? 0 : atol(r.second["no"].c_str()));
                        break;
                    case route::SUCCESS:
                        views::success::render(conn, r.second["cookie"], atol(r.second["no"].c_str()));
                        break;
                    case route::THREAD:
                    case route::DAERHT:
                        id = atol(r.second["no"].c_str());
                        views::expand::render(conn, id, r.first == route::DAERHT);
                        break;
                    case route::TIMELINE:
                        views::timeline::render(conn, false);
                        break;
                    case route::GALLERY:
                        views::gallery::render(conn);
                        break;
                    case route::LINEAR:
                        if(!check_ip(conn, true)) break;
                        views::linear::render(conn);
                        break;
                    case route::LINEAR_IP:
                        views::linear::render(conn, true, false, r.second["ip"].c_str());
                        break;
                    case route::LINEAR_ID:
                        views::linear::render(conn, false, true, r.second["id"].c_str());
                        break;
                    case route::ADMIN_PANEL:
                        views::admin::render(conn);
                        break;
                    case route::SELF_DELETE:
                        id = atol(r.second["no"].c_str());
                        if(actions::kill::call(conn, id))
                            views::info::render(conn, templates.invoke("misc").toggle("delete_okay").var("THREAD_NO", id).build_destory().c_str());
                        else
                            views::info::render(conn, templates.invoke("misc").toggle("try_to_usurp").build_destory().c_str());
                        break;
                    case route::API_THREAD:
                        tt = unq_read_thread(pDb, atol( r.second["no"].c_str() ));
                        views::each_thread(conn, tt, 0, is_admin(conn));
                        delete tt;
                        break;
                    case route::IMAGE:
                        cc_serve_image_file(conn);
                        break;
                    case route::ADMIN_ACTION:
                        actions::admin::call(conn);
                        break;
                    default:
                    if(configs.global().get<bool>("welcome")){
                        templates.invoke("site_header").pipe_to(conn).destory();
                        templates.invoke("site_welcome").pipe_to(conn).destory();
                        templates.invoke("site_footer").var("TIME", 0).pipe_to(conn).destory();
                    }else
                        views::timeline::render(conn, true);
                }

                fflush(log_file); // flush the buffer
                return MG_TRUE;
            }
        case MG_WS_CONNECT:
            websocket::connect(conn);
            return MG_FALSE;
        case MG_CLOSE:
            websocket::disconnect(conn);
            return MG_TRUE;
        case MG_AUTH:
            return MG_TRUE;
        default:
            return MG_FALSE;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
addl $-0x66, %esi
cmpl $0x6, %esi
ja 0x17697
movq %rdi, %r14
movl $0x1, %ebx
leaq 0x5a078(%rip), %rax     # 0x716e0
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
cmpl $0x0, 0x278(%r14)
je 0x176ad
movq %r14, %rdi
callq 0x2a586
jmp 0x17699
movq %r14, %rdi
callq 0x2a9ff
jmp 0x17699
movq %r14, %rdi
callq 0x2a69e
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %r15
leaq 0x5a6a9(%rip), %rsi     # 0x71d61
movq %r15, %rdi
callq 0xc570
testq %rax, %rax
je 0x176e1
incq %r15
leaq 0x5ffa3(%rip), %rdx     # 0x77672
movq %r14, %rdi
movq %r15, %rsi
callq 0x6b391
movl $0x2, %ebx
jmp 0x17699
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
movq %r15, %rsi
callq 0xcae0
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0x13080
leaq 0x10(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x17711
callq 0xc640
movl 0x60(%rsp), %eax
cmpl $0x63, %eax
jg 0x177ed
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0x178ce
cmpl $0x3, %eax
je 0x1793e
cmpl $0x4, %eax
jne 0x1795f
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5a33c(%rip), %rsi     # 0x71a85
leaq 0x5a33b(%rip), %rdx     # 0x71a8b
callq 0xedf0
leaq 0x68(%rsp), %r15
movq %rsp, %rsi
movq %r15, %rdi
callq 0x1ce6c
leaq 0xc8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x12380
leaq 0x30(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x5a419(%rip), %rsi     # 0x71bb2
leaq 0x5a414(%rip), %rdx     # 0x71bb4
leaq 0x20(%rsp), %rdi
callq 0xedf0
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x1ce6c
movq (%rax), %rdi
callq 0xc710
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
movl %eax, %edx
callq 0x24790
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x177e0
callq 0xc640
movq 0xb8(%rsp), %rdi
jmp 0x17ad4
leal -0x64(%rax), %ecx
cmpl $0x4, %ecx
jbe 0x17927
leal -0x1f5(%rax), %ecx
cmpl $0x4, %ecx
ja 0x1794b
leaq 0x59f01(%rip), %rax     # 0x71710
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %r14, %rdi
xorl %esi, %esi
callq 0x133cc
testb %al, %al
je 0x17b9d
leaq 0x7d31f(%rip), %rdi     # 0x94b50
callq 0x11bec
movq %rax, %r15
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5fe42(%rip), %rsi     # 0x77688
leaq 0x5fe42(%rip), %rdx     # 0x7768f
callq 0xedf0
movq %rsp, %rsi
movq %r15, %rdi
callq 0x180f2
movl %eax, %ebp
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x1786d
callq 0xc640
testb %bpl, %bpl
jne 0x17b9d
movl 0x60(%rsp), %ebp
xorl %esi, %esi
cmpl $0x1f8, %ebp            # imm = 0x1F8
je 0x178b5
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5a321(%rip), %rsi     # 0x71bb2
leaq 0x5a31c(%rip), %rdx     # 0x71bb4
callq 0xedf0
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1ce6c
movq (%rax), %rdi
callq 0xc710
movq %rax, %rsi
movq %r14, %rdi
callq 0x2aed0
cmpl $0x1f8, %ebp            # imm = 0x1F8
jne 0x17b8f
jmp 0x17b9d
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5a2d7(%rip), %rsi     # 0x71bb2
leaq 0x5a2d2(%rip), %rdx     # 0x71bb4
callq 0xedf0
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1ce6c
movq (%rax), %rdi
callq 0xc710
movq %rax, %r15
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x1790d
callq 0xc640
xorl %edx, %edx
cmpl $0x2, 0x60(%rsp)
sete %dl
movq %r14, %rdi
movl %r15d, %esi
callq 0x24ab4
jmp 0x17b9d
leaq 0x59dce(%rip), %rax     # 0x716fc
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
jmp 0x17ae7
movq %r14, %rdi
callq 0x1149a
jmp 0x17b9d
cmpl $0xc8, %eax
jne 0x1795f
movq %r14, %rdi
callq 0x15767
jmp 0x17b9d
leaq 0x7d1ea(%rip), %rdi     # 0x94b50
callq 0x11bec
movq %rax, %r15
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5a40a(%rip), %rsi     # 0x71d85
leaq 0x5a40a(%rip), %rdx     # 0x71d8c
callq 0xedf0
movq %rsp, %rsi
movq %r15, %rdi
callq 0x180f2
movl %eax, %ebp
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x179a2
callq 0xc640
movb $0x1, %al
testb %bpl, %bpl
je 0x17ae7
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x59fe3(%rip), %rsi     # 0x7199d
leaq 0x59fe7(%rip), %rdx     # 0x719a8
callq 0xedf0
leaq 0x7d35b(%rip), %rdi     # 0x94d28
movq %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 (%rsp), %rdi
cmpq %r13, %rdi
je 0x17a01
callq 0xc640
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5a372(%rip), %rsi     # 0x71d80
leaq 0x5a377(%rip), %rdx     # 0x71d8c
callq 0xedf0
leaq 0x7d307(%rip), %rdi     # 0x94d28
movq %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 (%rsp), %rdi
cmpq %r13, %rdi
je 0x17a55
callq 0xc640
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x59fbb(%rip), %rsi     # 0x71a1d
leaq 0x59fbf(%rip), %rdx     # 0x71a28
callq 0xedf0
leaq 0x7d2b3(%rip), %rdi     # 0x94d28
movq %rsp, %rsi
callq 0x181be
movq %rax, %r15
leaq 0x30(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x59f53(%rip), %rsi     # 0x719e4
leaq 0x59f50(%rip), %rdx     # 0x719e8
leaq 0x20(%rsp), %rdi
callq 0xedf0
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x18388
movq %rax, %rdi
movq %r14, %rsi
callq 0x18304
movq %rax, %r14
movq %rax, %rdi
callq 0x19de2
movq %r14, %rdi
callq 0xc640
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x17b8f
callq 0xc640
jmp 0x17b8f
movzbl %al, %esi
movq %r14, %rdi
callq 0x293ca
jmp 0x17b9d
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5a0f5(%rip), %rsi     # 0x71bf9
leaq 0x5a0f0(%rip), %rdx     # 0x71bfb
callq 0xedf0
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1ce6c
movq (%rax), %rcx
movq %r14, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x284ac
jmp 0x17b8f
movq %r14, %rdi
movl $0x1, %esi
callq 0x133cc
testb %al, %al
je 0x17b9d
leaq 0x5fb29(%rip), %rcx     # 0x77672
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x284ac
jmp 0x17b9d
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5a088(%rip), %rsi     # 0x71bec
leaq 0x5a083(%rip), %rdx     # 0x71bee
callq 0xedf0
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1ce6c
movq (%rax), %rcx
movq %r14, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x284ac
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17b9d
callq 0xc640
movq 0x7d0d4(%rip), %rdi     # 0x94c78
callq 0xc5b0
leaq 0x68(%rsp), %rdi
callq 0x19c46
jmp 0x17699
movq %r14, %rdi
callq 0x138f4
jmp 0x17b9d
movq %r14, %rdi
callq 0x25bf2
jmp 0x17b9d
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x59fd9(%rip), %rsi     # 0x71bb2
leaq 0x59fd4(%rip), %rdx     # 0x71bb4
callq 0xedf0
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1ce6c
movq (%rax), %rdi
callq 0xc710
movq %rax, %r15
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17c0b
callq 0xc640
movq %r14, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x2ae08
leaq 0x30(%rsp), %rbp
leaq 0x20(%rsp), %rdi
testb %al, %al
je 0x17da1
movq %rbp, (%rdi)
leaq 0x5bc86(%rip), %rsi     # 0x738ba
leaq 0x5bc83(%rip), %rdx     # 0x738be
callq 0xedf0
leaq 0x7d0e1(%rip), %rdi     # 0x94d28
leaq 0x20(%rsp), %rsi
callq 0x181be
movq %rax, %r12
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5a106(%rip), %rsi     # 0x71d6a
leaq 0x5a10a(%rip), %rdx     # 0x71d75
leaq 0x40(%rsp), %rdi
callq 0xedf0
leaq 0x1c8(%r12), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1c4c8
movb $0x1, (%rax)
leaq 0xa8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x5a0d9(%rip), %rsi     # 0x71d76
leaq 0x5a0db(%rip), %rdx     # 0x71d7f
leaq 0x98(%rsp), %rdi
callq 0xedf0
leaq 0x98(%rsp), %rsi
movq %r12, %rdi
movl %r15d, %edx
callq 0x18388
movq %rsp, %rdi
movq %rax, %rsi
callq 0x18208
movq (%rsp), %rsi
movq %r14, %rdi
callq 0x22d28
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17ce9
callq 0xc640
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x17cfb
callq 0xc640
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
leaq 0x30(%rsp), %r14
je 0x17d14
callq 0xc640
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
jne 0x17b98
jmp 0x17b9d
movq 0x7ceca(%rip), %r15     # 0x94bf8
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x59e77(%rip), %rsi     # 0x71bb2
leaq 0x59e72(%rip), %rdx     # 0x71bb4
callq 0xedf0
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1ce6c
movq (%rax), %rdi
callq 0xc710
movq %r15, %rdi
movl %eax, %esi
callq 0xe181
movq %rax, %r15
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17d77
callq 0xc640
movq %r14, %rdi
callq 0xef14
movzbl %al, %ecx
leaq 0x5f8e9(%rip), %r8      # 0x77672
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r8, %r9
callq 0x22fc8
movq %r15, %rdi
jmp 0x17b98
movq %rbp, (%rdi)
leaq 0x5bb0f(%rip), %rsi     # 0x738ba
leaq 0x5bb0c(%rip), %rdx     # 0x738be
callq 0xedf0
leaq 0x7cf6a(%rip), %rdi     # 0x94d28
leaq 0x20(%rsp), %rsi
callq 0x181be
movq %rax, %r15
leaq 0x50(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x59a92(%rip), %rsi     # 0x7186e
leaq 0x59a97(%rip), %rdx     # 0x7187a
leaq 0x40(%rsp), %rdi
callq 0xedf0
leaq 0x1c8(%r15), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1c4c8
movb $0x1, (%rax)
movq %rsp, %rdi
movq %r15, %rsi
callq 0x18208
movq (%rsp), %rsi
movq %r14, %rdi
callq 0x22d28
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17e26
callq 0xc640
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x17e35
callq 0xc640
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x17b98
jmp 0x17b9d
jmp 0x17f69
jmp 0x17f7e
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17eae
callq 0xc640
jmp 0x17eae
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17eef
callq 0xc640
jmp 0x17eef
jmp 0x17e7a
movq %rax, %rbx
jmp 0x17ec0
jmp 0x17e97
jmp 0x17e9c
movq %rax, %rbx
cmpl $0x1f8, %ebp            # imm = 0x1F8
jne 0x17f6c
jmp 0x17f81
movq %rax, %rbx
jmp 0x17efe
movq %rax, %rbx
jmp 0x17ed4
jmp 0x17f7e
jmp 0x17f7e
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x17ec0
callq 0xc640
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x17ed4
callq 0xc640
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
jne 0x17f75
jmp 0x17f81
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x17efe
callq 0xc640
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x17f75
jmp 0x17f81
jmp 0x17f69
jmp 0x17f69
jmp 0x17f7e
jmp 0x17f7e
jmp 0x17f7e
jmp 0x17f7e
jmp 0x17f7e
jmp 0x17f69
jmp 0x17f69
jmp 0x17f7e
jmp 0x17f7e
jmp 0x17f7e
jmp 0x17f69
jmp 0x17f69
jmp 0x17f69
movq %rax, %rbx
movq 0x20(%rsp), %rdi
jmp 0x17f5b
jmp 0x17f69
jmp 0x17f69
jmp 0x17f69
jmp 0x17f7e
movq %rax, %rbx
jmp 0x17f53
jmp 0x17f7e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x17f53
callq 0xc640
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0x17f6c
callq 0xc640
jmp 0x17f6c
jmp 0x17f69
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17f81
callq 0xc640
jmp 0x17f81
jmp 0x17f7e
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x19c46
jmp 0x17fa8
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17fa8
callq 0xc640
jmp 0x17fa8
movq %rax, %rbx
movq %rbx, %rdi
callq 0xc760