// File: /workspace/github_c_makefile_star2_O2/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, %rbp
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0xe580
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rbx
movq %rbx, %rsi
callq 0xc5f0
movq %rbx, %rdi
callq 0xcd88
leaq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0xe0b8
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rbx
movq %rbx, %rsi
callq 0xc5f0
movq %rbx, %rdi
callq 0xcd88
pushq $0x44
popq %rdi
callq 0xc1f0
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x10(%rax)
andl $0x0, 0x40(%rax)
movaps %xmm0, (%rax)
movq %rax, 0x290(%rbp)
addq $0x4, %rax
movq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0xc490
cmpq $0x0, 0x10(%rsp)
jne 0x24a19
leaq 0x3d800(%rip), %rdx     # 0x6220a
pushq $0x1
popq %rsi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x59874
jmp 0x24a32
movq 0x8(%rsp), %rcx
leaq 0x3d7df(%rip), %rdx     # 0x62204
pushq $0x1
popq %rsi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x59874
leaq 0x63377(%rip), %rdi     # 0x87db0
callq 0x24b66
testq %rax, %rax
jne 0x24a57
leaq 0x3d7f1(%rip), %rdx     # 0x6223b
pushq $0x1
popq %rsi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x59874
leaq 0x63362(%rip), %r15     # 0x87dc0
xorl %r12d, %r12d
leaq 0x63348(%rip), %rdi     # 0x87db0
callq 0x24b66
cmpq %r12, %rax
jbe 0x24a43
movq %r15, %rdi
movq %r12, %rsi
callq 0x24fdc
movq (%rax), %rdi
leaq 0x631c1(%rip), %rax     # 0x87c48
movq (%rax), %rsi
callq 0xc970
movl %eax, %r14d
movq %r15, %rdi
movq %r12, %rsi
callq 0x24fdc
movq (%rax), %rax
movq 0x440(%rax), %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x24fdc
movq (%rax), %rbx
testl %r14d, %r14d
je 0x24ae8
movq %r15, %rdi
movq %r12, %rsi
callq 0x24fdc
movq (%rax), %r9
addq $0x40, %r9
movq %rbp, %rdi
pushq $0x1
popq %rsi
leaq 0x3d74f(%rip), %rdx     # 0x62228
movq %r13, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x59874
jmp 0x24b06
addq $0x40, %rbx
movq %rbp, %rdi
pushq $0x1
popq %rsi
leaq 0x3d71b(%rip), %rdx     # 0x62214
movq %r13, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x59874
incq %r12
jmp 0x24a61
jmp 0x24b14
jmp 0x24b14
jmp 0x24b14
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xcd88
leaq 0x8(%rsp), %rdi
callq 0xcd88
movq %rbx, %rdi
callq 0xc790