// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0xd480
leaq 0xd0(%rsp), %rdi
callq 0xd480
movq 0x110(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x10af0
jmp 0x4df90
leaq 0xf0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movq %rsi, 0x70(%rsp)
callq 0xd6f0
movq 0x70(%rsp), %rdi
callq 0xdf50
movq 0x110(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x10220
jmp 0x4dfcb
leaq 0xd0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movq %rsi, 0x60(%rsp)
callq 0xd6f0
movq 0x60(%rsp), %rdi
callq 0xdf50
movl $0x44, %edi
callq 0xd250
movq %rax, 0x68(%rsp)
jmp 0x4e000
movq 0x68(%rsp), %rdi
xorl %esi, %esi
movl $0x44, %edx
callq 0xd430
movq 0x68(%rsp), %rcx
movq 0x110(%rsp), %rax
movq %rcx, 0x290(%rax)
movq 0x110(%rsp), %rax
movq 0x290(%rax), %rax
addq $0x4, %rax
movq %rax, 0x58(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xd190
movq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0xd580
leaq 0xf0(%rsp), %rdi
callq 0xd3f0
testb $0x1, %al
jne 0x4e0d4
movq 0x110(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0xd190
movq 0x50(%rsp), %rdi
movq %rax, %rcx
leaq 0x72143(%rip), %rdx     # 0xc01d4
xorl %eax, %eax
movl $0x1, %esi
callq 0xb1f80
jmp 0x4e09f
jmp 0x4e0f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xdf50
leaq 0xf0(%rsp), %rdi
callq 0xdf50
jmp 0x4e293
movq 0x110(%rsp), %rdi
leaq 0x720f7(%rip), %rdx     # 0xc01da
xorl %eax, %eax
movl $0x1, %esi
callq 0xb1f80
jmp 0x4e0f1
jmp 0x4e0f3
leaq 0xa108e(%rip), %rdi     # 0xef188
callq 0x4e410
cmpq $0x0, %rax
jbe 0x4e274
movl $0x0, 0x7c(%rsp)
movslq 0x7c(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0xa1066(%rip), %rdi     # 0xef188
callq 0x4e410
movq %rax, %rcx
movq 0x48(%rsp), %rax
cmpq %rcx, %rax
jae 0x4e272
movslq 0x7c(%rsp), %rsi
leaq 0xa1044(%rip), %rdi     # 0xef188
callq 0x4e4d0
movq (%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0xa0ec8(%rip), %rdi     # 0xef020
callq 0xd190
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0xdab0
cmpl $0x0, %eax
jne 0x4e1db
movq 0x110(%rsp), %rax
movq %rax, 0x30(%rsp)
movslq 0x7c(%rsp), %rsi
leaq 0xa1000(%rip), %rdi     # 0xef188
movq %rdi, 0x28(%rsp)
callq 0x4e4d0
movq 0x28(%rsp), %rdi
movq (%rax), %rax
movq 0x440(%rax), %rax
movq %rax, 0x38(%rsp)
movslq 0x7c(%rsp), %rsi
callq 0x4e4d0
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rcx
movq (%rax), %r8
addq $0x40, %r8
leaq 0x7201c(%rip), %rdx     # 0xc01e4
xorl %eax, %eax
movl $0x1, %esi
callq 0xb1f80
jmp 0x4e1d6
jmp 0x4e260
movq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
movslq 0x7c(%rsp), %rsi
leaq 0xa0f94(%rip), %rdi     # 0xef188
movq %rdi, 0x8(%rsp)
callq 0x4e4d0
movq 0x8(%rsp), %rdi
movq (%rax), %rax
movq 0x440(%rax), %rax
movq %rax, 0x18(%rsp)
movslq 0x7c(%rsp), %rsi
callq 0x4e4d0
movq 0x8(%rsp), %rdi
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movslq 0x7c(%rsp), %rsi
callq 0x4e4d0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq (%rax), %r9
addq $0x40, %r9
leaq 0x71fa8(%rip), %rdx     # 0xc01f8
xorl %eax, %eax
movl $0x1, %esi
callq 0xb1f80
jmp 0x4e25e
jmp 0x4e260
jmp 0x4e262
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x4e111
jmp 0x4e274
movq 0x110(%rsp), %rdi
leaq 0x71f88(%rip), %rdx     # 0xc020b
xorl %eax, %eax
movl $0x1, %esi
callq 0xb1f80
jmp 0x4e291
ud2
movq 0xa8(%rsp), %rdi
callq 0xd8a0