// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./src/actions/chat.cpp
// Function: websocket::connect(mg_connection*)
int connect(mg_connection *conn) {
        string username, ssid;
        username = cck_verify_ssid(conn);
        ssid = cck_extract_ssid(conn);

        conn->connection_param = new ChatData();
        strcpy(((struct ChatData *)conn->connection_param)->ssid, ssid.c_str());

        if(!username.empty()){
            mg_websocket_printf(conn, WEBSOCKET_OPCODE_TEXT, "id %s", username.c_str());               
        }else
            mg_websocket_printf(conn, WEBSOCKET_OPCODE_TEXT, "id (null)");
        
        if(history.size() > 0){
                // for(auto i = chatHistory.size() - 1; i >= 0; i--){
            for(auto i = 0; i < history.size(); ++i){
                if(strcmp(history[i]->ssid, admin_cookie.c_str()) == 0)
                    mg_websocket_printf(conn, WEBSOCKET_OPCODE_TEXT, "history %d Admin %s", 
                    history[i]->timestamp, history[i]->message);
                else
                    mg_websocket_printf(conn, WEBSOCKET_OPCODE_TEXT, "history %d %.9s %s", 
                        history[i]->timestamp, history[i]->ssid, history[i]->message);
            }
        }

        mg_websocket_printf(conn, WEBSOCKET_OPCODE_TEXT, "end history");
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
xorl %eax, %eax
movq %rax, -0x8(%r12)
movb %al, (%r12)
leaq 0x38(%rsp), %r13
movq %r13, -0x10(%r13)
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0xf5d5
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0xc5e0
movq (%r14), %rdi
leaq 0x58(%rsp), %r15
cmpq %r15, %rdi
je 0x2a706
callq 0xc640
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0xef7f
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0xc5e0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x2a732
callq 0xc640
movl $0x44, %edi
callq 0xc1d0
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movl $0x0, 0x40(%rax)
movq %rax, 0x290(%rbx)
addq $0x4, %rax
movq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0xc490
cmpq $0x0, 0x10(%rsp)
jne 0x2a78d
leaq 0x47a8e(%rip), %rdx     # 0x7220a
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x6877b
jmp 0x2a7a8
movq 0x8(%rsp), %rcx
leaq 0x47a6b(%rip), %rdx     # 0x72204
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x6877b
movq 0x6a629(%rip), %rcx     # 0x94dd8
movq 0x6a602(%rip), %r14     # 0x94db8
movq %rcx, %rax
subq %r14, %rax
shrq $0x3, %rax
cmpq $0x1, %rcx
movq %rax, %rdi
adcq $-0x1, %rdi
movq 0x6a5ee(%rip), %rdx     # 0x94dc0
subq 0x6a5ef(%rip), %rdx     # 0x94dc8
shlq $0x6, %rdi
sarq $0x3, %rdx
addq %rdx, %rdi
movq 0x6a5c5(%rip), %rsi     # 0x94db0
movq 0x6a5ae(%rip), %rbp     # 0x94da0
subq %rbp, %rsi
sarq $0x3, %rsi
addq %rsi, %rdi
je 0x2a9a3
cmpq $0x1, %rcx
adcq $-0x1, %rax
shlq $0x6, %rax
addq %rdx, %rax
addq %rsi, %rax
je 0x2a9a3
xorl %r12d, %r12d
movq %rbp, %r15
xorl %r13d, %r13d
subq 0x6a57e(%rip), %r15     # 0x94da8
sarq $0x3, %r15
addq %r13, %r15
js 0x2a83f
cmpq $0x3f, %r15
ja 0x2a848
leaq (%r12,%rbp), %rcx
jmp 0x2a864
movq %r15, %rax
sarq $0x6, %rax
jmp 0x2a84f
movq %r15, %rax
shrq $0x6, %rax
movq %rax, %rdx
shlq $0x6, %rdx
movq %r15, %rcx
subq %rdx, %rcx
shlq $0x3, %rcx
addq (%r14,%rax,8), %rcx
movq (%rcx), %rdi
leaq 0x6a3ba(%rip), %rax     # 0x94c28
movq (%rax), %rsi
callq 0xc950
testl %eax, %eax
je 0x2a88f
testq %r15, %r15
js 0x2a8a2
cmpq $0x3f, %r15
ja 0x2a8ab
movq (%rbp,%r12), %r9
movq %r9, %r8
jmp 0x2a8cb
testq %r15, %r15
js 0x2a8ee
cmpq $0x3f, %r15
ja 0x2a8f7
addq %r12, %rbp
movq %rbp, %rax
jmp 0x2a917
movq %r15, %rax
sarq $0x6, %rax
jmp 0x2a8b2
movq %r15, %rax
shrq $0x6, %rax
movq (%r14,%rax,8), %rcx
movl %r15d, %edx
andl $0x3f, %edx
movq (%rcx,%rdx,8), %r8
shlq $0x6, %rax
subq %rax, %r15
movq (%rcx,%r15,8), %r9
movq 0x440(%r8), %rcx
addq $0x40, %r9
movq %rbx, %rdi
movl $0x1, %esi
leaq 0x47943(%rip), %rdx     # 0x72228
xorl %eax, %eax
callq 0x6877b
jmp 0x2a93f
movq %r15, %rax
sarq $0x6, %rax
jmp 0x2a8fe
movq %r15, %rax
shrq $0x6, %rax
movq (%r14,%rax,8), %rcx
movl %r15d, %edx
andl $0x3f, %edx
leaq (%rcx,%rdx,8), %rbp
shlq $0x6, %rax
subq %rax, %r15
leaq (%rcx,%r15,8), %rax
movq (%rbp), %rcx
movq 0x440(%rcx), %rcx
movq (%rax), %r8
addq $0x40, %r8
movq %rbx, %rdi
movl $0x1, %esi
leaq 0x478dc(%rip), %rdx     # 0x72214
xorl %eax, %eax
callq 0x6877b
incq %r13
movq 0x6a48f(%rip), %rcx     # 0x94dd8
movq 0x6a468(%rip), %r14     # 0x94db8
movq 0x6a469(%rip), %rdx     # 0x94dc0
movq 0x6a452(%rip), %rax     # 0x94db0
movq %rcx, %rsi
subq %r14, %rsi
shrq $0x3, %rsi
cmpq $0x1, %rcx
adcq $-0x1, %rsi
movq 0x6a429(%rip), %r15     # 0x94da0
shlq $0x6, %rsi
subq 0x6a446(%rip), %rdx     # 0x94dc8
sarq $0x3, %rdx
subq %r15, %rax
sarq $0x3, %rax
addq %rdx, %rax
addq %rsi, %rax
addq $0x8, %r12
movq %r15, %rbp
cmpq %r13, %rax
ja 0x2a823
leaq 0x47891(%rip), %rdx     # 0x7223b
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
leaq 0x18(%rsp), %r12
leaq 0x38(%rsp), %r13
callq 0x6877b
movq %rax, %rbx
leaq 0x18(%rsp), %r12
leaq 0x38(%rsp), %r13
jmp 0x2a9d9
jmp 0x2a9d6
jmp 0x2a9d6
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x2a9e8
callq 0xc640
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x2a9f7
callq 0xc640
movq %rbx, %rdi
callq 0xc760