// File: /workspace/github_c_makefile_star2_O1/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 0x17998
movq %rdi, %r14
movl $0x1, %ebx
leaq 0x5bd77(%rip), %rax     # 0x736e0
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
cmpl $0x0, 0x278(%r14)
je 0x179ae
movq %r14, %rdi
callq 0x2a957
jmp 0x1799a
movq %r14, %rdi
callq 0x2ae5c
jmp 0x1799a
movq %r14, %rdi
callq 0x2aa6d
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 0x5c3ae(%rip), %rsi     # 0x73d67
movq %r15, %rdi
callq 0xc570
testq %rax, %rax
je 0x179e2
incq %r15
leaq 0x61c97(%rip), %rdx     # 0x79667
movq %r14, %rdi
movq %r15, %rsi
callq 0x6cf1d
movl $0x2, %ebx
jmp 0x1799a
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
movq %r15, %rsi
callq 0xcae0
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0x130ab
leaq 0x10(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x17a12
callq 0xc640
movl 0x60(%rsp), %eax
cmpl $0x63, %eax
jg 0x17aee
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0x17bfc
cmpl $0x3, %eax
je 0x17c6c
cmpl $0x4, %eax
jne 0x17c8d
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5c03e(%rip), %rsi     # 0x73a88
leaq 0x5c03d(%rip), %rdx     # 0x73a8e
callq 0xedfa
leaq 0x68(%rsp), %r15
movq %rsp, %rsi
movq %r15, %rdi
callq 0x1d1ca
leaq 0xc8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x12396
leaq 0x30(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x5c11b(%rip), %rsi     # 0x73bb5
leaq 0x5c116(%rip), %rdx     # 0x73bb7
leaq 0x20(%rsp), %rdi
callq 0xedfa
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x1d1ca
movq (%rax), %rdi
callq 0xc710
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
movl %eax, %edx
callq 0x24b7c
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x17ae1
callq 0xc640
movq 0xb8(%rsp), %rdi
jmp 0x17e02
leal -0x64(%rax), %ecx
cmpl $0x4, %ecx
jbe 0x17c55
leal -0x1f5(%rax), %ecx
cmpl $0x4, %ecx
ja 0x17c79
leaq 0x5bc00(%rip), %rax     # 0x73710
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %r14, %rdi
xorl %esi, %esi
callq 0x133f7
movl %eax, %ebp
movb $0x1, %r15b
testb %al, %al
je 0x17b62
leaq 0x7f01d(%rip), %rdi     # 0x96b50
callq 0x11bfe
movq %rax, %r15
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x61b35(%rip), %rsi     # 0x7967d
leaq 0x61b35(%rip), %rdx     # 0x79684
callq 0xedfa
movq %rsp, %rsi
movq %r15, %rdi
callq 0x18460
movl %eax, %r15d
testb %bpl, %bpl
je 0x17b75
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17b75
callq 0xc640
testb %r15b, %r15b
jne 0x17ecb
movl 0x60(%rsp), %ebp
xorl %esi, %esi
cmpl $0x1f8, %ebp            # imm = 0x1F8
setne %r12b
je 0x17bce
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5c015(%rip), %rsi     # 0x73bb5
leaq 0x5c010(%rip), %rdx     # 0x73bb7
leaq 0x20(%rsp), %rdi
callq 0xedfa
movb $0x1, %r15b
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1d1ca
movq (%rax), %rdi
callq 0xc710
movq %rax, %rsi
movl %r12d, %r15d
movq %r14, %rdi
callq 0x2b328
cmpl $0x1f8, %ebp            # imm = 0x1F8
je 0x17ecb
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x17ec6
jmp 0x17ecb
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5bfac(%rip), %rsi     # 0x73bb5
leaq 0x5bfa7(%rip), %rdx     # 0x73bb7
callq 0xedfa
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1d1ca
movq (%rax), %rdi
callq 0xc710
movq %rax, %r15
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17c3b
callq 0xc640
xorl %edx, %edx
cmpl $0x2, 0x60(%rsp)
sete %dl
movq %r14, %rdi
movl %r15d, %esi
callq 0x24ea0
jmp 0x17ecb
leaq 0x5baa0(%rip), %rax     # 0x736fc
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
jmp 0x17e15
movq %r14, %rdi
callq 0x114ac
jmp 0x17ecb
cmpl $0xc8, %eax
jne 0x17c8d
movq %r14, %rdi
callq 0x15a66
jmp 0x17ecb
leaq 0x7eebc(%rip), %rdi     # 0x96b50
callq 0x11bfe
movq %rax, %r15
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5c0e2(%rip), %rsi     # 0x73d8b
leaq 0x5c0e2(%rip), %rdx     # 0x73d92
callq 0xedfa
movq %rsp, %rsi
movq %r15, %rdi
callq 0x18460
movl %eax, %ebp
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17cd0
callq 0xc640
movb $0x1, %al
testb %bpl, %bpl
je 0x17e15
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5bcb5(%rip), %rsi     # 0x7399d
leaq 0x5bcb9(%rip), %rdx     # 0x739a8
callq 0xedfa
leaq 0x7f02d(%rip), %rdi     # 0x96d28
movq %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 (%rsp), %rdi
cmpq %r13, %rdi
je 0x17d2f
callq 0xc640
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5c04a(%rip), %rsi     # 0x73d86
leaq 0x5c04f(%rip), %rdx     # 0x73d92
callq 0xedfa
leaq 0x7efd9(%rip), %rdi     # 0x96d28
movq %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 (%rsp), %rdi
cmpq %r13, %rdi
je 0x17d83
callq 0xc640
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5bc8d(%rip), %rsi     # 0x73a1d
leaq 0x5bc91(%rip), %rdx     # 0x73a28
callq 0xedfa
leaq 0x7ef85(%rip), %rdi     # 0x96d28
movq %rsp, %rsi
callq 0x1852c
movq %rax, %r15
leaq 0x30(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x5bc25(%rip), %rsi     # 0x739e4
leaq 0x5bc22(%rip), %rdx     # 0x739e8
leaq 0x20(%rsp), %rdi
callq 0xedfa
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x186f6
movq %rax, %rdi
movq %r14, %rsi
callq 0x18672
movq %rax, %r14
movq %rax, %rdi
callq 0x1a17a
movq %r14, %rdi
callq 0xc640
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x17ebd
callq 0xc640
jmp 0x17ebd
movzbl %al, %esi
movq %r14, %rdi
callq 0x2978b
jmp 0x17ecb
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5bdca(%rip), %rsi     # 0x73bfc
leaq 0x5bdc5(%rip), %rdx     # 0x73bfe
callq 0xedfa
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1d1ca
movq (%rax), %rcx
movq %r14, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x2889c
jmp 0x17ebd
movq %r14, %rdi
movl $0x1, %esi
callq 0x133f7
testb %al, %al
je 0x17ecb
leaq 0x617f0(%rip), %rcx     # 0x79667
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2889c
jmp 0x17ecb
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5bd5d(%rip), %rsi     # 0x73bef
leaq 0x5bd58(%rip), %rdx     # 0x73bf1
callq 0xedfa
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1d1ca
movq (%rax), %rcx
movq %r14, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2889c
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17ecb
callq 0xc640
movq 0x7eda6(%rip), %rdi     # 0x96c78
callq 0xc5b0
leaq 0x68(%rsp), %rdi
callq 0x19fde
jmp 0x1799a
movq %r14, %rdi
callq 0x1391f
jmp 0x17ecb
movq %r14, %rdi
callq 0x25fcf
jmp 0x17ecb
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5bcae(%rip), %rsi     # 0x73bb5
leaq 0x5bca9(%rip), %rdx     # 0x73bb7
callq 0xedfa
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1d1ca
movq (%rax), %rdi
callq 0xc710
movq %rax, %r15
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x17f39
callq 0xc640
movq %r14, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x2b260
testb %al, %al
je 0x180d9
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5d954(%rip), %rsi     # 0x758b2
leaq 0x5d951(%rip), %rdx     # 0x758b6
leaq 0x20(%rsp), %rdi
callq 0xedfa
leaq 0x7edb2(%rip), %rdi     # 0x96d28
leaq 0x20(%rsp), %rsi
callq 0x1852c
movq %rax, %r12
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5bddd(%rip), %rsi     # 0x73d70
leaq 0x5bde1(%rip), %rdx     # 0x73d7b
leaq 0x40(%rsp), %rdi
callq 0xedfa
leaq 0x1c8(%r12), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1c82a
movb $0x1, (%rax)
leaq 0xa8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x5bdb0(%rip), %rsi     # 0x73d7c
leaq 0x5bdb2(%rip), %rdx     # 0x73d85
leaq 0x98(%rsp), %rdi
callq 0xedfa
leaq 0x98(%rsp), %rsi
movq %r12, %rdi
movl %r15d, %edx
callq 0x186f6
movq %rsp, %rdi
movq %rax, %rsi
callq 0x18576
movq (%rsp), %rsi
movq %r14, %rdi
callq 0x2307c
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x18018
callq 0xc640
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1802a
callq 0xc640
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
leaq 0x30(%rsp), %r14
je 0x18043
callq 0xc640
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
jne 0x17ec6
jmp 0x17ecb
movq 0x7eb9b(%rip), %r15     # 0x96bf8
movq %rsp, %rdi
movq %r13, (%rdi)
leaq 0x5bb4b(%rip), %rsi     # 0x73bb5
leaq 0x5bb46(%rip), %rdx     # 0x73bb7
callq 0xedfa
leaq 0x68(%rsp), %rdi
movq %rsp, %rsi
callq 0x1d1ca
movq (%rax), %rdi
callq 0xc710
movq %r15, %rdi
movl %eax, %esi
callq 0xe181
movq %rax, %r15
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x180a6
callq 0xc640
movq %r14, %rdi
callq 0xef24
movzbl %al, %ecx
leaq 0x615af(%rip), %r8      # 0x79667
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r8, %r9
callq 0x2331c
testq %r15, %r15
je 0x17ecb
movq %r15, %rdi
jmp 0x17ec6
leaq 0x30(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x5d7c8(%rip), %rsi     # 0x758b2
leaq 0x5d7c5(%rip), %rdx     # 0x758b6
leaq 0x20(%rsp), %rdi
callq 0xedfa
leaq 0x7ec26(%rip), %rdi     # 0x96d28
leaq 0x20(%rsp), %rsi
callq 0x1852c
movq %rax, %r15
leaq 0x50(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x5b74f(%rip), %rsi     # 0x7386e
leaq 0x5b754(%rip), %rdx     # 0x7387a
leaq 0x40(%rsp), %rdi
callq 0xedfa
leaq 0x1c8(%r15), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1c82a
movb $0x1, (%rax)
movq %rsp, %rdi
movq %r15, %rsi
callq 0x18576
movq (%rsp), %rsi
movq %r14, %rdi
callq 0x2307c
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x18169
callq 0xc640
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x18178
callq 0xc640
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
jne 0x17ec6
jmp 0x17ecb
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x181de
callq 0xc640
jmp 0x181de
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x1821f
callq 0xc640
jmp 0x1821f
jmp 0x181b3
movq %rax, %rbx
jmp 0x181f0
jmp 0x181bc
jmp 0x181c1
movq %rax, %rbx
jmp 0x1822e
movq %rax, %rbx
jmp 0x18204
jmp 0x182ed
jmp 0x182ed
movq %rax, %rbx
movb $0x1, %r15b
jmp 0x1828c
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x181f0
callq 0xc640
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x18204
callq 0xc640
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
jne 0x182e4
jmp 0x182f0
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1822e
callq 0xc640
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
jne 0x182e4
jmp 0x182f0
jmp 0x182d8
jmp 0x182d8
jmp 0x182ed
jmp 0x182ed
jmp 0x182ed
jmp 0x182ed
jmp 0x182ed
jmp 0x182d8
jmp 0x182d8
jmp 0x182ed
jmp 0x182ed
jmp 0x182ed
movq %rax, %rbx
testb %r15b, %r15b
je 0x1828c
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1828c
callq 0xc640
testb %r15b, %r15b
jmp 0x182f0
jmp 0x182d8
jmp 0x182d8
jmp 0x182d8
movq %rax, %rbx
movq 0x20(%rsp), %rdi
jmp 0x182ca
jmp 0x182d8
jmp 0x182d8
jmp 0x182d8
jmp 0x182ed
movq %rax, %rbx
jmp 0x182c2
jmp 0x182ed
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x182c2
callq 0xc640
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0x182db
callq 0xc640
jmp 0x182db
jmp 0x182d8
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x182f0
callq 0xc640
jmp 0x182f0
jmp 0x182ed
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x19fde
jmp 0x18317
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x18317
callq 0xc640
jmp 0x18317
movq %rax, %rbx
movq %rbx, %rdi
callq 0xc760