// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
subq $0xf0, %rsp
addl $-0x66, %esi
cmpl $0x6, %esi
ja 0x145a7
movq %rdi, %r14
pushq $0x1
popq %rbx
leaq 0x4d138(%rip), %rax     # 0x616b0
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
cmpl $0x0, 0x278(%r14)
je 0x145bb
movq %r14, %rdi
callq 0x2485c
jmp 0x145a9
movq %r14, %rdi
callq 0x24b33
jmp 0x145a9
movq %r14, %rdi
callq 0x24944
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xf0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %r15
leaq 0x4d795(%rip), %rsi     # 0x61d5b
movq %r15, %rdi
callq 0xc570
testq %rax, %rax
je 0x145ed
incq %r15
leaq 0x53075(%rip), %rdx     # 0x67652
movq %r14, %rdi
movq %r15, %rsi
callq 0x5bfa7
pushq $0x2
popq %rbx
jmp 0x145a9
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
movq %r15, %rsi
callq 0xcb10
leaq 0x78(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1158f
leaq 0x10(%rsp), %rdi
callq 0xcd88
movl 0x78(%rsp), %eax
leal -0x64(%rax), %ecx
cmpl $0x4, %ecx
jbe 0x1472c
leal -0x1f5(%rax), %ecx
cmpl $0x4, %ecx
jbe 0x14669
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0x14743
cmpl $0x3, %eax
je 0x14a5f
cmpl $0x4, %eax
je 0x1480f
cmpl $0xc8, %eax
jne 0x14a79
movq %r14, %rdi
callq 0x12eed
jmp 0x14c62
leaq 0x4d070(%rip), %rax     # 0x616e0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %r14, %rdi
xorl %esi, %esi
callq 0x11869
testb %al, %al
je 0x14c62
leaq 0x734de(%rip), %rdi     # 0x87b70
callq 0x1008c
movq %rax, %r15
leaq 0x52fc7(%rip), %rsi     # 0x67668
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x14efa
movl %eax, %ebp
leaq 0x10(%rsp), %rdi
callq 0xcd88
testb %bpl, %bpl
jne 0x14c62
movl 0x78(%rsp), %ebp
xorl %esi, %esi
cmpl $0x1f8, %ebp            # imm = 0x1F8
je 0x14713
leaq 0x4d49b(%rip), %rsi     # 0x61b82
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1924e
movq (%rax), %rdi
callq 0xc730
movq %rax, %rsi
movq %r14, %rdi
callq 0x25130
cmpl $0x1f8, %ebp            # imm = 0x1F8
jne 0x14bb9
jmp 0x14c62
leaq 0x4cf99(%rip), %rax     # 0x616cc
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
jmp 0x14bc3
leaq 0x4d438(%rip), %rsi     # 0x61b82
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1924e
movq (%rax), %rdi
callq 0xc730
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0xcd88
xorl %edx, %edx
cmpl $0x2, 0x78(%rsp)
sete %dl
movq %r14, %rdi
movl %r15d, %esi
callq 0x1fcf8
jmp 0x14c62
leaq 0x4d428(%rip), %rsi     # 0x61bc9
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1924e
movq (%rax), %rcx
pushq $0x1
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x22f18
jmp 0x14bb9
movq %r14, %rdi
callq 0x11c3d
jmp 0x14c62
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x11869
testb %al, %al
je 0x14c62
leaq 0x52e54(%rip), %rcx     # 0x67652
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22f18
jmp 0x14c62
leaq 0x4d23f(%rip), %rsi     # 0x61a55
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0xcb10
leaq 0x80(%rsp), %r15
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x1924e
leaq 0xd0(%rsp), %rdi
movq %rax, %rsi
callq 0xc640
leaq 0x4d331(%rip), %rsi     # 0x61b82
leaq 0x38(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
callq 0xcb10
leaq 0x38(%rsp), %rsi
movq %r15, %rdi
callq 0x1924e
movq (%rax), %rdi
callq 0xc730
leaq 0xd0(%rsp), %rsi
movq %r14, %rdi
movl %eax, %edx
callq 0x1fa84
leaq 0x38(%rsp), %rdi
callq 0xcd88
leaq 0xd0(%rsp), %rdi
jmp 0x14bb4
leaq 0x4d2da(%rip), %rsi     # 0x61b82
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1924e
movq (%rax), %rdi
callq 0xc730
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0xcd88
movq %r14, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x2507c
testb %al, %al
je 0x14bd3
leaq 0x4efa0(%rip), %rsi     # 0x6389a
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0xcb10
leaq 0x73438(%rip), %rdi     # 0x87d48
leaq 0x38(%rsp), %rsi
callq 0x14fb0
movq %rax, %r12
leaq 0x4d440(%rip), %rsi     # 0x61d64
leaq 0x58(%rsp), %rdi
leaq 0x37(%rsp), %rdx
callq 0xcb10
leaq 0x1c8(%r12), %rdi
leaq 0x58(%rsp), %rsi
callq 0x189cc
movb $0x1, (%rax)
leaq 0x4d421(%rip), %rsi     # 0x61d70
leaq 0xb0(%rsp), %rdi
leaq 0x36(%rsp), %rdx
callq 0xcb10
leaq 0xb0(%rsp), %rsi
movq %r12, %rdi
movl %r15d, %edx
callq 0x15236
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x1501c
movq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x1e718
leaq 0x10(%rsp), %rdi
callq 0xcd88
leaq 0xb0(%rsp), %rdi
jmp 0x14c49
movq 0x7326c(%rip), %r15     # 0x87c18
leaq 0x4d1cf(%rip), %rsi     # 0x61b82
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1924e
movq (%rax), %rdi
callq 0xc730
movq %r15, %rdi
movl %eax, %esi
callq 0xd515
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0xcd88
movq %r14, %rdi
callq 0xe080
movzbl %al, %ecx
leaq 0x52c4d(%rip), %r8      # 0x67652
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r8, %r9
callq 0x1e914
movq %r15, %rdi
callq 0xc660
jmp 0x14c62
leaq 0x4d193(%rip), %rsi     # 0x61bbc
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1924e
movq (%rax), %rcx
pushq $0x1
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x22f18
jmp 0x14bb9
movq %r14, %rdi
callq 0xfa64
jmp 0x14c62
movq %r14, %rdi
callq 0x20a2a
jmp 0x14c62
leaq 0x730f0(%rip), %rdi     # 0x87b70
callq 0x1008c
movq %rax, %r15
leaq 0x4d2f0(%rip), %rsi     # 0x61d7f
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x14efa
movl %eax, %ebp
leaq 0x10(%rsp), %rdi
callq 0xcd88
movb $0x1, %al
testb %bpl, %bpl
je 0x14bc3
leaq 0x4cea4(%rip), %rsi     # 0x6196d
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x73269(%rip), %rdi     # 0x87d48
leaq 0x10(%rsp), %rsi
callq 0x14fb0
movq %rax, %rdi
movq %r14, %rsi
callq 0x151b6
movq %rax, %rdi
callq 0x15224
leaq 0x10(%rsp), %rdi
callq 0xcd88
leaq 0x4d26d(%rip), %rsi     # 0x61d7a
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xcb10
leaq 0x73225(%rip), %rdi     # 0x87d48
leaq 0x10(%rsp), %rsi
callq 0x14fb0
movq %rax, %rdi
movq %r14, %rsi
callq 0x151b6
movq %rax, %rdi
callq 0x15224
leaq 0x10(%rsp), %rdi
callq 0xcd88
leaq 0x4ce9c(%rip), %rsi     # 0x619ed
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0xcb10
leaq 0x731e1(%rip), %rdi     # 0x87d48
leaq 0x10(%rsp), %rsi
callq 0x14fb0
movq %rax, %r15
leaq 0x4ce39(%rip), %rsi     # 0x619b4
leaq 0x38(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
callq 0xcb10
leaq 0x38(%rsp), %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x15236
movq %rax, %rdi
movq %r14, %rsi
callq 0x151b6
movq %rax, %rdi
callq 0x15224
leaq 0x38(%rsp), %rdi
callq 0xcd88
leaq 0x10(%rsp), %rdi
jmp 0x14c5d
movzbl %al, %esi
movq %r14, %rdi
callq 0x23a45
jmp 0x14c62
leaq 0x4ecc0(%rip), %rsi     # 0x6389a
leaq 0x38(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
callq 0xcb10
leaq 0x73155(%rip), %rdi     # 0x87d48
leaq 0x38(%rsp), %rsi
callq 0x14fb0
movq %rax, %r15
leaq 0x4cc37(%rip), %rsi     # 0x6183e
leaq 0x58(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0xcb10
leaq 0x1c8(%r15), %rdi
leaq 0x58(%rsp), %rsi
callq 0x189cc
movb $0x1, (%rax)
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x1501c
movq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x1e718
leaq 0x10(%rsp), %rdi
callq 0xcd88
leaq 0x58(%rsp), %rdi
callq 0xcd88
leaq 0x38(%rsp), %rdi
callq 0xcd88
movq 0x7302f(%rip), %rdi     # 0x87c98
callq 0xc5c0
leaq 0x80(%rsp), %rdi
callq 0x161aa
jmp 0x145a9
jmp 0x14d5a
jmp 0x14d6b
jmp 0x14d5a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xcd88
jmp 0x14cf6
jmp 0x14d5a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x14cfe
jmp 0x14d6b
jmp 0x14d05
jmp 0x14d05
jmp 0x14cc1
jmp 0x14d6b
jmp 0x14cc1
jmp 0x14cc1
movq %rax, %rbx
jmp 0x14d12
movq %rax, %rbx
cmpl $0x1f8, %ebp            # imm = 0x1F8
jne 0x14d5d
jmp 0x14d6e
jmp 0x14d6b
jmp 0x14d6b
jmp 0x14d6b
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x14d4b
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xcd88
jmp 0x14d08
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0xcd88
leaq 0x38(%rsp), %rdi
jmp 0x14d62
jmp 0x14d5a
jmp 0x14d5a
movq %rax, %rbx
jmp 0x14d43
jmp 0x14d5a
jmp 0x14d5a
jmp 0x14d5a
jmp 0x14d6b
jmp 0x14d6b
jmp 0x14d6b
jmp 0x14d6b
jmp 0x14d6b
jmp 0x14d6b
jmp 0x14d6b
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xcd88
leaq 0xd0(%rsp), %rdi
callq 0xcd88
jmp 0x14d5d
jmp 0x14d5a
jmp 0x14d5a
jmp 0x14d5a
jmp 0x14d5a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xcd88
jmp 0x14d6e
jmp 0x14d6b
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x161aa
jmp 0x14d8f
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xcd88
jmp 0x14d8f
movq %rax, %rbx
movq %rbx, %rdi
callq 0xc790