// File: /workspace/github_c_makefile_star2_O1/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, %r13
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
xorl %eax, %eax
movq %rax, -0x8(%r15)
movb %al, (%r15)
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0xf5d8
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0xc5e0
movq (%r14), %rdi
leaq 0x58(%rsp), %rbx
cmpq %rbx, %rdi
je 0x2aad4
callq 0xc640
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0xef81
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0xc5e0
movq (%r14), %rdi
cmpq %rbx, %rdi
je 0x2ab00
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(%r13)
addq $0x4, %rax
movq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0xc490
cmpq $0x0, 0x10(%rsp)
jne 0x2ab5b
leaq 0x496d0(%rip), %rdx     # 0x7421a
movq %r13, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x6a321
jmp 0x2ab76
movq 0x8(%rsp), %rcx
leaq 0x496ad(%rip), %rdx     # 0x74214
movq %r13, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x6a321
movq %r13, (%rsp)
movq 0x6c257(%rip), %rax     # 0x96dd8
movq %rax, %rcx
subq 0x6c22d(%rip), %rcx     # 0x96db8
shrq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
movq 0x6c222(%rip), %rax     # 0x96dc0
subq 0x6c223(%rip), %rax     # 0x96dc8
shlq $0x6, %rcx
sarq $0x3, %rax
addq %rcx, %rax
movq 0x6c1f9(%rip), %rcx     # 0x96db0
subq 0x6c1e2(%rip), %rcx     # 0x96da0
sarq $0x3, %rcx
addq %rax, %rcx
jne 0x2abe8
leaq 0x4967d(%rip), %rdx     # 0x7424b
movq (%rsp), %rdi
movl $0x1, %esi
xorl %eax, %eax
leaq 0x18(%rsp), %r15
leaq 0x38(%rsp), %r12
callq 0x6a321
movabsq $-0x400000000000000, %rbp # imm = 0xFC00000000000000
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x6c1d9(%rip), %rax     # 0x96dd8
movq 0x6c1b2(%rip), %r15     # 0x96db8
movq %rax, %rcx
subq %r15, %rcx
shrq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
shlq $0x6, %rcx
movq 0x6c19d(%rip), %rax     # 0x96dc0
subq 0x6c19e(%rip), %rax     # 0x96dc8
sarq $0x3, %rax
movq 0x6c17b(%rip), %rdx     # 0x96db0
movq 0x6c164(%rip), %rbx     # 0x96da0
subq %rbx, %rdx
sarq $0x3, %rdx
addq %rax, %rdx
addq %rcx, %rdx
cmpq %r14, %rdx
jbe 0x2abc7
movq %rbx, %r12
subq 0x6c14c(%rip), %r12     # 0x96da8
sarq $0x3, %r12
addq %r14, %r12
cmpq $0x3f, %r12
ja 0x2ac6f
leaq (%rbx,%r13), %rax
jmp 0x2ac98
movq %r12, %rax
shrq $0x6, %rax
movq %rax, %rcx
orq %rbp, %rcx
testq %r12, %r12
cmovgq %rax, %rcx
movq %rcx, %rdx
shlq $0x6, %rdx
movq %r12, %rax
subq %rdx, %rax
shlq $0x3, %rax
addq (%r15,%rcx,8), %rax
movq (%rax), %rdi
leaq 0x6bf86(%rip), %rax     # 0x96c28
movq (%rax), %rsi
callq 0xc950
testl %eax, %eax
je 0x2acba
cmpq $0x3f, %r12
ja 0x2accd
leaq (%rbx,%r13), %rax
jmp 0x2acf6
cmpq $0x3f, %r12
ja 0x2ad8f
leaq (%rbx,%r13), %rax
jmp 0x2adb8
movq %r12, %rax
shrq $0x6, %rax
movq %rax, %rcx
orq %rbp, %rcx
testq %r12, %r12
cmovgq %rax, %rcx
movq %rcx, %rdx
shlq $0x6, %rdx
movq %r12, %rax
subq %rdx, %rax
shlq $0x3, %rax
addq (%r15,%rcx,8), %rax
cmpq $0x3f, %r12
ja 0x2ad02
leaq (%rbx,%r13), %rdx
jmp 0x2ad2b
movq %r12, %rcx
shrq $0x6, %rcx
movq %rcx, %rsi
orq %rbp, %rsi
testq %r12, %r12
cmovgq %rcx, %rsi
movq %rsi, %rcx
shlq $0x6, %rcx
movq %r12, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
addq (%r15,%rsi,8), %rdx
cmpq $0x3f, %r12
ja 0x2ad36
addq %r13, %rbx
jmp 0x2ad5f
movq %r12, %rcx
shrq $0x6, %rcx
movq %rcx, %rsi
orq %rbp, %rsi
testq %r12, %r12
cmovgq %rcx, %rsi
movq %rsi, %rcx
shlq $0x6, %rcx
subq %rcx, %r12
shlq $0x3, %r12
addq (%r15,%rsi,8), %r12
movq %r12, %rbx
movq (%rax), %rax
movq 0x440(%rax), %rcx
movq (%rdx), %r8
movq (%rbx), %r9
addq $0x40, %r9
movq (%rsp), %rdi
movl $0x1, %esi
leaq 0x494b5(%rip), %rdx     # 0x74238
xorl %eax, %eax
callq 0x6a321
jmp 0x2ae14
movq %r12, %rax
shrq $0x6, %rax
movq %rax, %rcx
orq %rbp, %rcx
testq %r12, %r12
cmovgq %rax, %rcx
movq %rcx, %rdx
shlq $0x6, %rdx
movq %r12, %rax
subq %rdx, %rax
shlq $0x3, %rax
addq (%r15,%rcx,8), %rax
cmpq $0x3f, %r12
ja 0x2adc3
addq %r13, %rbx
jmp 0x2adec
movq %r12, %rcx
shrq $0x6, %rcx
movq %rcx, %rdx
orq %rbp, %rdx
testq %r12, %r12
cmovgq %rcx, %rdx
movq %rdx, %rcx
shlq $0x6, %rcx
subq %rcx, %r12
shlq $0x3, %r12
addq (%r15,%rdx,8), %r12
movq %r12, %rbx
movq (%rax), %rax
movq 0x440(%rax), %rcx
movq (%rbx), %r8
addq $0x40, %r8
movq (%rsp), %rdi
movl $0x1, %esi
leaq 0x49417(%rip), %rdx     # 0x74224
xorl %eax, %eax
callq 0x6a321
incq %r14
addq $0x8, %r13
jmp 0x2abf8
movq %rax, %rbx
leaq 0x18(%rsp), %r15
leaq 0x38(%rsp), %r12
jmp 0x2ae36
jmp 0x2ae33
jmp 0x2ae33
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x2ae45
callq 0xc640
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x2ae54
callq 0xc640
movq %rbx, %rdi
callq 0xc760